25 typedef int16_t PosType;
27 enum class Command : uint8_t
40 PosType readPosType(
const uint8_t* buffer,
unsigned index=0)
43 const uint8_t* posBuffer = buffer+index*
sizeof(PosType);
44 for (
unsigned i=0; i<
sizeof(PosType); i++)
45 ((uint8_t*)&pos)[i] = posBuffer[i];
48 void writePosType(uint8_t* buffer, PosType pos,
unsigned index=0)
50 uint8_t* posBuffer = buffer+index*
sizeof(PosType);
51 for (
unsigned i=0; i<
sizeof(PosType); i++)
52 posBuffer[i] = ((uint8_t*)&pos)[i];
54 virtual void addPoints(
const uint8_t* xys,
unsigned points) = 0;
55 virtual void deletePoints() = 0;
56 virtual void stopMove() = 0;
57 virtual void startMove() = 0;
58 virtual void setParam() = 0;
59 virtual void gotoXY(PosType x, PosType y) = 0;
60 virtual void movedXdY(PosType dx, PosType dy) = 0;
61 virtual void gotoNextPoint() = 0;
62 virtual void setNPoint(uint16_t nPoint) = 0;
63 virtual void setPos(PosType x, PosType y) = 0;
82 static const uint16_t maskProtocol = 0xF000;
83 static const uint16_t maskButton = 0x0010;
84 static const uint16_t maskMoving = 0x0008;
85 static const uint16_t maskWaitingNeedle = 0x0004;
86 static const uint16_t maskRunning = 0x0002;
87 static const uint16_t maskAlive = 0x0001;
89 static uint8_t getProtocol(uint16_t status)
91 return (status&maskProtocol)>>12;
98 virtual void onMsg(uint8_t* buffer)
100 sequence = buffer[0];
101 switch((Command)(buffer[1]&0xf))
103 case Command::kAddPoints:
104 addPoints(buffer+2, (buffer[1]>>4)+1);
106 case Command::kDeletePoints:
109 case Command::kStopMove:
112 case Command::kStartMove:
115 case Command::kSetParam:
118 case Command::kGotoXY:
119 gotoXY(readPosType(buffer+2,0), readPosType(buffer+2,1));
121 case Command::kMovedXdY:
122 movedXdY(readPosType(buffer+2,0), readPosType(buffer+2,1));
124 case Command::kGotoNextPoint:
127 case Command::kSetNPoint:
128 setNPoint((buffer[2+0]<<8) | buffer[2+1]);
130 case Command::kSetPos:
131 setPos(readPosType(buffer+2,0), readPosType(buffer+2,1));