1
+ #include < Arduino.h>
1
2
#include < M5Stack.h>
3
+ #include < stdlib.h>
4
+ // #include "FastLED.h"
2
5
3
6
#include " WiFi.h"
4
7
#include " utility/MPU9250.h"
@@ -12,6 +15,11 @@ extern const unsigned char m5stack_startup_music[];
12
15
13
16
MPU9250 IMU;
14
17
18
+
19
+ // #define LEDS_PIN 15
20
+ // #define LEDS_NUM 10
21
+ // CRGB ledsBuff[LEDS_NUM];
22
+
15
23
void startupLogo () {
16
24
static uint8_t brightness, pre_brightness;
17
25
uint32_t length = strlen ((char *)m5stack_startup_music);
@@ -120,20 +128,53 @@ void writeFile(fs::FS &fs, const char *path, const char *message) {
120
128
}
121
129
122
130
void buttons_test () {
123
- if (M5.BtnA .wasPressed ( )) {
131
+ if (M5.BtnA .wasReleased () || M5. BtnA . pressedFor ( 1000 , 200 )) {
124
132
M5.Lcd .printf (" A" );
125
133
Serial.printf (" A" );
126
134
}
127
- if (M5.BtnB .wasPressed ( )) {
135
+ if (M5.BtnB .wasReleased () || M5. BtnB . pressedFor ( 1000 , 200 )) {
128
136
M5.Lcd .printf (" B" );
129
137
Serial.printf (" B" );
130
138
}
131
- if (M5.BtnC .wasPressed ( )) {
139
+ if (M5.BtnC .wasReleased () || M5. BtnC . pressedFor ( 1000 , 200 )) {
132
140
M5.Lcd .printf (" C" );
133
141
Serial.printf (" C" );
134
142
}
135
143
}
136
144
145
+ static byte c1;
146
+
147
+ byte utf8ascii (byte ascii) {
148
+ if ( ascii<128 ) // Standard ASCII-set 0..0x7F handling
149
+ { c1=0 ;
150
+ return ( ascii );
151
+ }
152
+
153
+ // get previous input
154
+ byte last = c1; // get last char
155
+ c1=ascii; // remember actual character
156
+
157
+ switch (last) // conversion depending on first UTF8-character
158
+ { case 0xC2 : return (ascii); break ;
159
+ case 0xC3 : return (ascii | 0xC0 ); break ;
160
+ case 0x82 : if (ascii==0xAC ) return (0x80 ); // special case Euro-symbol
161
+ }
162
+
163
+ return (0 ); // otherwise: return zero, if character has to be ignored
164
+ }
165
+
166
+ String utf8ascii (String s)
167
+ {
168
+ String r=" " ;
169
+ char c;
170
+ for (int i=0 ; i<s.length (); i++)
171
+ {
172
+ c = utf8ascii (s.charAt (i));
173
+ if (c!=0 ) r+=c;
174
+ }
175
+ return r;
176
+ }
177
+
137
178
void wifi_test () {
138
179
WiFi.mode (WIFI_STA);
139
180
WiFi.disconnect ();
@@ -160,18 +201,18 @@ void wifi_test() {
160
201
M5.Lcd .print (i + 1 );
161
202
Serial.print (" : " );
162
203
M5.Lcd .print (" : " );
163
- Serial.print (WiFi.SSID (i));
164
- M5.Lcd .print (WiFi.SSID (i));
204
+ Serial.print (WiFi.SSID (i). c_str () );
205
+ M5.Lcd .print (utf8ascii ( WiFi.SSID (i). c_str () ));
165
206
Serial.print (" (" );
166
207
M5.Lcd .print (" (" );
167
208
Serial.print (WiFi.RSSI (i));
168
209
M5.Lcd .print (WiFi.RSSI (i));
169
210
Serial.print (" )" );
170
211
M5.Lcd .print (" )" );
171
212
Serial.println ((WiFi.encryptionType (i) == WIFI_AUTH_OPEN) ? " "
172
- : " *" );
213
+ : " *" );
173
214
M5.Lcd .println ((WiFi.encryptionType (i) == WIFI_AUTH_OPEN) ? " "
174
- : " *" );
215
+ : " *" );
175
216
delay (5 );
176
217
}
177
218
}
@@ -409,6 +450,15 @@ unsigned long testFilledRoundRects() {
409
450
return micros () - start;
410
451
}
411
452
453
+ // void ledBar()
454
+ // {
455
+ // FastLED.addLeds<SK6812, LEDS_PIN>(ledsBuff, LEDS_NUM);
456
+ // for (int i = 0; i < LEDS_NUM; i++) {
457
+ // ledsBuff[i].setRGB(20, 20, 20);
458
+ // }
459
+ // FastLED.show();
460
+ // }
461
+
412
462
// the setup routine runs once when M5Stack starts up
413
463
void setup () {
414
464
// gpio test
@@ -436,8 +486,8 @@ void setup() {
436
486
// {
437
487
// adc_test();
438
488
// }
439
-
440
489
startupLogo ();
490
+ // ledBar();
441
491
Wire.begin ();
442
492
443
493
// Lcd display
@@ -629,4 +679,4 @@ void setup() {
629
679
void loop () {
630
680
buttons_test ();
631
681
M5.update ();
632
- }
682
+ }
0 commit comments