User | Revision | Line number | New contents of line |
daan |
1:578d6bbe9f09
|
1
|
#include "WriterBase.h"
|
daan |
1:578d6bbe9f09
|
2
|
|
daan |
1:578d6bbe9f09
|
3
|
#include "assert.h"
|
daan |
1:578d6bbe9f09
|
4
|
#include "VectorFormat.h"
|
daan |
1:578d6bbe9f09
|
5
|
|
daan |
1:578d6bbe9f09
|
6
|
// for strlen
|
daan |
1:578d6bbe9f09
|
7
|
#include "string.h"
|
daan |
1:578d6bbe9f09
|
8
|
|
daan |
1:578d6bbe9f09
|
9
|
olc::WriterBase::WriterBase() :
|
daan |
1:578d6bbe9f09
|
10
|
mData(0),
|
daan |
1:578d6bbe9f09
|
11
|
mPlayHead(0),
|
daan |
1:578d6bbe9f09
|
12
|
mCapacity(0),
|
daan |
1:578d6bbe9f09
|
13
|
mPenDown(0),
|
daan |
1:578d6bbe9f09
|
14
|
mLaserPower(0),
|
daan |
1:578d6bbe9f09
|
15
|
mGalvoX(0),
|
daan |
1:578d6bbe9f09
|
16
|
mGalvoY(0)
|
daan |
1:578d6bbe9f09
|
17
|
{
|
daan |
1:578d6bbe9f09
|
18
|
}
|
daan |
1:578d6bbe9f09
|
19
|
|
daan |
1:578d6bbe9f09
|
20
|
|
daan |
1:578d6bbe9f09
|
21
|
bool olc::WriterBase::penUp()
|
daan |
1:578d6bbe9f09
|
22
|
{
|
daan |
1:578d6bbe9f09
|
23
|
if (spaceLeft() < 1) return false;
|
daan |
1:578d6bbe9f09
|
24
|
put((uint8_t)olc::PEN_UP );
|
daan |
1:578d6bbe9f09
|
25
|
return true;
|
daan |
1:578d6bbe9f09
|
26
|
}
|
daan |
1:578d6bbe9f09
|
27
|
|
daan |
1:578d6bbe9f09
|
28
|
bool olc::WriterBase::penDown()
|
daan |
1:578d6bbe9f09
|
29
|
{
|
daan |
1:578d6bbe9f09
|
30
|
if (spaceLeft() < 1) return false;
|
daan |
1:578d6bbe9f09
|
31
|
put((uint8_t)olc::PEN_DOWN );
|
daan |
1:578d6bbe9f09
|
32
|
return true;
|
daan |
1:578d6bbe9f09
|
33
|
}
|
daan |
1:578d6bbe9f09
|
34
|
|
daan |
1:578d6bbe9f09
|
35
|
bool olc::WriterBase::wait(uint16_t aWait)
|
daan |
1:578d6bbe9f09
|
36
|
{
|
daan |
1:578d6bbe9f09
|
37
|
if (spaceLeft() < 2) return false;
|
daan |
1:578d6bbe9f09
|
38
|
put( (uint8_t)olc::WAIT );
|
daan |
1:578d6bbe9f09
|
39
|
encodeU16( aWait );
|
daan |
1:578d6bbe9f09
|
40
|
return true;
|
daan |
1:578d6bbe9f09
|
41
|
}
|
daan |
1:578d6bbe9f09
|
42
|
|
daan |
1:578d6bbe9f09
|
43
|
|
daan |
1:578d6bbe9f09
|
44
|
bool olc::WriterBase::moveTo(uint16_t aX, uint16_t aY) {
|
daan |
1:578d6bbe9f09
|
45
|
if (spaceLeft() < 5) return false;
|
daan |
1:578d6bbe9f09
|
46
|
put( (uint8_t)olc::MOVE_TO );
|
daan |
1:578d6bbe9f09
|
47
|
encodeU16( aX );
|
daan |
1:578d6bbe9f09
|
48
|
encodeU16( aY );
|
daan |
1:578d6bbe9f09
|
49
|
return true;
|
daan |
1:578d6bbe9f09
|
50
|
}
|
daan |
1:578d6bbe9f09
|
51
|
|
daan |
1:578d6bbe9f09
|
52
|
bool olc::WriterBase::lineTo(uint16_t x, uint16_t y)
|
daan |
1:578d6bbe9f09
|
53
|
{
|
daan |
1:578d6bbe9f09
|
54
|
if (spaceLeft() < 5) return false;
|
daan |
1:578d6bbe9f09
|
55
|
put((uint8_t)olc::LINE_TO );
|
daan |
1:578d6bbe9f09
|
56
|
encodeU16( x );
|
daan |
1:578d6bbe9f09
|
57
|
encodeU16( y );
|
daan |
1:578d6bbe9f09
|
58
|
return true;
|
daan |
1:578d6bbe9f09
|
59
|
}
|
daan |
1:578d6bbe9f09
|
60
|
|
daan |
1:578d6bbe9f09
|
61
|
bool olc::WriterBase::setLaserPower(uint16_t aPower)
|
daan |
1:578d6bbe9f09
|
62
|
{
|
daan |
1:578d6bbe9f09
|
63
|
if (spaceLeft() < 2) return false;
|
daan |
1:578d6bbe9f09
|
64
|
put( (uint8_t)olc::LASER_POWER );
|
daan |
1:578d6bbe9f09
|
65
|
encodeU16( aPower );
|
daan |
1:578d6bbe9f09
|
66
|
return true;
|
daan |
1:578d6bbe9f09
|
67
|
}
|
daan |
1:578d6bbe9f09
|
68
|
|
daan |
1:578d6bbe9f09
|
69
|
bool olc::WriterBase::setStepSize(uint16_t aStepSize)
|
daan |
1:578d6bbe9f09
|
70
|
{
|
daan |
1:578d6bbe9f09
|
71
|
if (spaceLeft() < 2) return false;
|
daan |
1:578d6bbe9f09
|
72
|
put( (uint8_t)olc::STEP_SIZE );
|
daan |
1:578d6bbe9f09
|
73
|
encodeU16( aStepSize );
|
daan |
1:578d6bbe9f09
|
74
|
return true;
|
daan |
1:578d6bbe9f09
|
75
|
}
|
daan |
1:578d6bbe9f09
|
76
|
|
daan |
2:ce4c7e5ab241
|
77
|
bool olc::WriterBase::readColor()
|
daan |
1:578d6bbe9f09
|
78
|
{
|
daan |
1:578d6bbe9f09
|
79
|
if (spaceLeft() < 2) return false;
|
daan |
2:ce4c7e5ab241
|
80
|
put( (uint8_t)olc::READ_COLOR );
|
daan |
1:578d6bbe9f09
|
81
|
return true;
|
daan |
1:578d6bbe9f09
|
82
|
}
|
daan |
1:578d6bbe9f09
|
83
|
|
daan |
2:ce4c7e5ab241
|
84
|
bool olc::WriterBase::reportColor(uint8_t c)
|
daan |
1:578d6bbe9f09
|
85
|
{
|
daan |
1:578d6bbe9f09
|
86
|
if (spaceLeft() < 4) return false;
|
daan |
2:ce4c7e5ab241
|
87
|
put( (uint8_t)olc::REPORT_COLOR );
|
daan |
2:ce4c7e5ab241
|
88
|
put( c );
|
daan |
1:578d6bbe9f09
|
89
|
return true;
|
daan |
1:578d6bbe9f09
|
90
|
}
|
daan |
1:578d6bbe9f09
|
91
|
|
daan |
2:ce4c7e5ab241
|
92
|
bool olc::WriterBase::reportBufferInSize()
|
daan |
2:ce4c7e5ab241
|
93
|
{
|
daan |
2:ce4c7e5ab241
|
94
|
if (spaceLeft() < 2) return false;
|
daan |
2:ce4c7e5ab241
|
95
|
put( (uint8_t)olc::REPORT_BUFFER_IN_SIZE );
|
daan |
2:ce4c7e5ab241
|
96
|
return true;
|
daan |
2:ce4c7e5ab241
|
97
|
}
|
daan |
2:ce4c7e5ab241
|
98
|
|
daan |
2:ce4c7e5ab241
|
99
|
bool olc::WriterBase::bufferInSize(uint16_t aSize)
|
daan |
2:ce4c7e5ab241
|
100
|
{
|
daan |
2:ce4c7e5ab241
|
101
|
if (spaceLeft() < 3) return false;
|
daan |
2:ce4c7e5ab241
|
102
|
put( (uint8_t)olc::BUFFER_IN_SIZE );
|
daan |
2:ce4c7e5ab241
|
103
|
encodeU16( aSize );
|
daan |
2:ce4c7e5ab241
|
104
|
return true;
|
daan |
2:ce4c7e5ab241
|
105
|
}
|
daan |
2:ce4c7e5ab241
|
106
|
|
daan |
2:ce4c7e5ab241
|
107
|
bool olc::WriterBase::bitmapU8(uint8_t *aData, uint8_t aSize)
|
daan |
2:ce4c7e5ab241
|
108
|
{
|
daan |
1:578d6bbe9f09
|
109
|
if (spaceLeft() < 2) return false;
|
daan |
1:578d6bbe9f09
|
110
|
put( (uint8_t)olc::BITMAPU8 );
|
daan |
1:578d6bbe9f09
|
111
|
put( aSize );
|
daan |
1:578d6bbe9f09
|
112
|
for(int i=0; i < (int)aSize; i++) {
|
daan |
1:578d6bbe9f09
|
113
|
put( aData[i] );
|
daan |
1:578d6bbe9f09
|
114
|
}
|
daan |
1:578d6bbe9f09
|
115
|
return true;
|
daan |
1:578d6bbe9f09
|
116
|
}
|
daan |
1:578d6bbe9f09
|
117
|
|
daan |
1:578d6bbe9f09
|
118
|
bool olc::WriterBase::message(int aLevel, const char *aString) {
|
daan |
1:578d6bbe9f09
|
119
|
// first calculate size
|
daan |
1:578d6bbe9f09
|
120
|
size_t size = strlen(aString);
|
daan |
1:578d6bbe9f09
|
121
|
if (size > 254 ) return false;
|
daan |
1:578d6bbe9f09
|
122
|
if (spaceLeft() < 4+size) return false;
|
daan |
1:578d6bbe9f09
|
123
|
|
daan |
1:578d6bbe9f09
|
124
|
put( (uint8_t)olc::MESSAGE );
|
daan |
1:578d6bbe9f09
|
125
|
put( (uint8_t)aLevel );
|
daan |
1:578d6bbe9f09
|
126
|
put( (uint8_t)size );
|
daan |
1:578d6bbe9f09
|
127
|
const char* ptr = &(aString[0]);
|
daan |
1:578d6bbe9f09
|
128
|
while (*ptr != '\0') {
|
daan |
1:578d6bbe9f09
|
129
|
put( *ptr );
|
daan |
1:578d6bbe9f09
|
130
|
ptr++;
|
daan |
1:578d6bbe9f09
|
131
|
}
|
daan |
1:578d6bbe9f09
|
132
|
put ( 0 ); // end message with a zero.
|
daan |
1:578d6bbe9f09
|
133
|
return true;
|
daan |
1:578d6bbe9f09
|
134
|
}
|
daan |
1:578d6bbe9f09
|
135
|
|
daan |
1:578d6bbe9f09
|
136
|
bool olc::WriterBase::areYouThere() {
|
daan |
1:578d6bbe9f09
|
137
|
if (spaceLeft() < 1) return false;
|
daan |
1:578d6bbe9f09
|
138
|
put( (uint8_t)olc::AYT );
|
daan |
1:578d6bbe9f09
|
139
|
return true;
|
daan |
1:578d6bbe9f09
|
140
|
}
|
daan |
1:578d6bbe9f09
|
141
|
|
daan |
1:578d6bbe9f09
|
142
|
bool olc::WriterBase::ready() {
|
daan |
1:578d6bbe9f09
|
143
|
if (spaceLeft() < 1) return false;
|
daan |
1:578d6bbe9f09
|
144
|
put( (uint8_t)olc::READY );
|
daan |
1:578d6bbe9f09
|
145
|
return true;
|
daan |
1:578d6bbe9f09
|
146
|
}
|
daan |
1:578d6bbe9f09
|
147
|
|
daan |
1:578d6bbe9f09
|
148
|
|
daan |
1:578d6bbe9f09
|
149
|
void olc::WriterBase::setData(uint8_t *aData, int aCapacity) {
|
daan |
1:578d6bbe9f09
|
150
|
assert(aCapacity > 0);
|
daan |
1:578d6bbe9f09
|
151
|
assert(aData != 0);
|
daan |
1:578d6bbe9f09
|
152
|
mPlayHead = 0;
|
daan |
1:578d6bbe9f09
|
153
|
mCapacity = aCapacity;
|
daan |
1:578d6bbe9f09
|
154
|
mData = aData;
|
daan |
1:578d6bbe9f09
|
155
|
}
|
daan |
1:578d6bbe9f09
|
156
|
|
daan |
1:578d6bbe9f09
|
157
|
|
daan |
1:578d6bbe9f09
|
158
|
|