-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDuellaSerial.cpp
More file actions
95 lines (76 loc) · 1.99 KB
/
DuellaSerial.cpp
File metadata and controls
95 lines (76 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "DuellaSerial.h"
DuellaSerial::DuellaSerial()
{
}
void DuellaSerial::begin( void )
{
Serial.begin(BAUDRATE);
firstSerialPing_ = true;
}
void DuellaSerial::giveMotionControl( MotionController motionControl )
{
motionControl_ = motionControl;
}
void DuellaSerial::read( void )
{
//If the Uncia is completely unmodified, CWS will send commands as
//single chars to give instructions.
#ifdef STOCK_UNCIA
readSerialForUncia();
#endif
//If the Uncia is modified in any way, we might as well just use normal
//GCode.
#ifndef STOCK_UNCIA
readSerialForGcode();
#endif
}
void DuellaSerial::readSerialForGcode( void )
{
while(Serial.available() > 0)
{
char c = Serial.read();
sBuffer_ += c;
if(c == '\n' || c == '\r')
{
motionControl_.pushCurrentCommandForGcode( sBuffer_ );
resetBuffer();
sendReadyCommand();
}
}
}
void DuellaSerial::readSerialForUncia( void )
{
if (Serial.available() > 0)
{
int Byte = Serial.read();
motionControl_.pushCurrentCommandForStockUncia(Byte);
}
}
void DuellaSerial::CreationWorkshopSerialPing( void )
{
if (firstSerialPing_)
{
while(Serial.available() > 0) {
//The very first thing that Pomeroy's fork of CWS does on connect
//is ping the Uncia with 'P'. Knowing this, we don't have to check
//what the char that we first received is, but we do have to purge
//it from the serial buffer
char ping = Serial.read();
#ifdef STOCK_UNCIA
Serial.write('Sedgwick3D');
#endif
#ifndef STOCK_UNCIA
Serial.write('N'); //'N' for Not-Stock
#endif
firstSerialPing_ = false;
}
}
}
void DuellaSerial::resetBuffer( void )
{
sBuffer_ = "";
}
void DuellaSerial::sendReadyCommand( void )
{
Serial.print(F("\n\rok\n\r>"));
}