@@ -55,6 +55,8 @@ void handleMessage(AdafruitIO_Data *data) {
55
55
uint16_t strpos = 0 ;
56
56
byte lineLengths[] = {0 , 0 , 0 , 0 };
57
57
byte lineNum = 0 ;
58
+ byte messageHeight = 0 ;
59
+ byte lineHeight = 0 ;
58
60
// Calculate line lengths
59
61
boolean paramRead = false ;
60
62
boolean newLine = false ;
@@ -83,17 +85,25 @@ void handleMessage(AdafruitIO_Data *data) {
83
85
84
86
if (plainText.charAt (strpos) != ' \n ' ) {
85
87
lineLengths[lineNum] += textSize * BASE_CHAR_WIDTH;
88
+ if (textSize * BASE_CHAR_HEIGHT > lineHeight) {
89
+ lineHeight = textSize * BASE_CHAR_HEIGHT;
90
+ }
86
91
}
87
92
88
93
// We want to keep adding up the characters * textSize until we hit a newline character
89
94
// or we reach the width of the message panel. Then we go down to the next line
90
95
if (plainText.charAt (strpos) == ' \n ' || lineLengths[lineNum] >= matrix.width ()) {
96
+ messageHeight += lineHeight;
97
+ lineHeight = 0 ;
91
98
lineNum++;
92
99
}
93
100
94
101
strpos++;
95
102
}
96
103
104
+ // Add the last line
105
+ messageHeight += lineHeight;
106
+
97
107
textSize = 1 ;
98
108
lineNum = 0 ;
99
109
for (uint16_t i=0 ; i<message.length (); i++) {
@@ -103,7 +113,7 @@ void handleMessage(AdafruitIO_Data *data) {
103
113
} else if (message.charAt (i) == ' }' ) {
104
114
paramRead = false ;
105
115
int wheelPos = atoi (message.substring (colorStartIndex, i).c_str ());
106
- if (wheelPos < 25 ) {
116
+ if (wheelPos < 24 ) {
107
117
color = Wheel (wheelPos);
108
118
} else {
109
119
color = matrix.Color333 (7 , 7 , 7 );
@@ -118,7 +128,7 @@ void handleMessage(AdafruitIO_Data *data) {
118
128
if (paramRead) continue ;
119
129
120
130
if (matrix.getCursorX () == 0 && matrix.getCursorY () == 0 ) {
121
- matrix.setCursor (floor ((matrix.width () / 2 ) - (lineLengths[lineNum] / 2 )), 0 );
131
+ matrix.setCursor (floor ((matrix.width () / 2 ) - (lineLengths[lineNum] / 2 )), matrix. height () / 2 - messageHeight / 2 );
122
132
} else if (newLine) {
123
133
matrix.setCursor (floor ((matrix.width () / 2 ) - (lineLengths[++lineNum] / 2 )), matrix.getCursorY ());
124
134
newLine = false ;
@@ -159,16 +169,16 @@ void loop() {
159
169
io.run ();
160
170
}
161
171
162
- // Input a value 0 to 24 to get a color value.
172
+ // Input a value 0 to 23 to get a color value.
163
173
// The colours are a transition r - g - b - back to r.
164
174
uint16_t Wheel (byte WheelPos) {
165
175
if (WheelPos < 8 ) {
166
176
return matrix.Color333 (7 - WheelPos, WheelPos, 0 );
167
177
} else if (WheelPos < 16 ) {
168
178
WheelPos -= 8 ;
169
- return matrix.Color333 (0 , 7 - WheelPos, WheelPos);
179
+ return matrix.Color333 (0 , 7 - WheelPos, WheelPos);
170
180
} else {
171
181
WheelPos -= 16 ;
172
- return matrix.Color333 (0 , WheelPos , 7 - WheelPos);
182
+ return matrix.Color333 (WheelPos, 0 , 7 - WheelPos);
173
183
}
174
184
}
0 commit comments