From 4e8896f8faf1842b46fc4dac1fded12179c59948 Mon Sep 17 00:00:00 2001 From: "icing@tomato:~$" Date: Wed, 20 Jul 2022 11:25:22 +0800 Subject: [PATCH] Fix Bug: Fix FactoryTest.ino Fix Bug: Fix FactoryTest.ino when testing WiFi in which there are some Non-ASCII characters. --- examples/Basics/FactoryTest/FactoryTest.ino | 68 ++++++++++++++++++--- 1 file changed, 59 insertions(+), 9 deletions(-) diff --git a/examples/Basics/FactoryTest/FactoryTest.ino b/examples/Basics/FactoryTest/FactoryTest.ino index f78a4fbe..9127bf10 100644 --- a/examples/Basics/FactoryTest/FactoryTest.ino +++ b/examples/Basics/FactoryTest/FactoryTest.ino @@ -1,4 +1,7 @@ +#include #include +#include +//#include "FastLED.h" #include "WiFi.h" #include "utility/MPU9250.h" @@ -12,6 +15,11 @@ extern const unsigned char m5stack_startup_music[]; MPU9250 IMU; + +// #define LEDS_PIN 15 +// #define LEDS_NUM 10 +// CRGB ledsBuff[LEDS_NUM]; + void startupLogo() { static uint8_t brightness, pre_brightness; uint32_t length = strlen((char *)m5stack_startup_music); @@ -120,20 +128,53 @@ void writeFile(fs::FS &fs, const char *path, const char *message) { } void buttons_test() { - if (M5.BtnA.wasPressed()) { + if (M5.BtnA.wasReleased() || M5.BtnA.pressedFor(1000, 200)) { M5.Lcd.printf("A"); Serial.printf("A"); } - if (M5.BtnB.wasPressed()) { + if (M5.BtnB.wasReleased() || M5.BtnB.pressedFor(1000, 200)) { M5.Lcd.printf("B"); Serial.printf("B"); } - if (M5.BtnC.wasPressed()) { + if (M5.BtnC.wasReleased() || M5.BtnC.pressedFor(1000, 200)) { M5.Lcd.printf("C"); Serial.printf("C"); } } +static byte c1; + +byte utf8ascii(byte ascii) { + if ( ascii<128 ) // Standard ASCII-set 0..0x7F handling + { c1=0; + return( ascii ); + } + + // get previous input + byte last = c1; // get last char + c1=ascii; // remember actual character + + switch (last) // conversion depending on first UTF8-character + { case 0xC2: return (ascii); break; + case 0xC3: return (ascii | 0xC0); break; + case 0x82: if(ascii==0xAC) return(0x80); // special case Euro-symbol + } + + return (0); // otherwise: return zero, if character has to be ignored +} + +String utf8ascii(String s) +{ + String r=""; + char c; + for (int i=0; i(ledsBuff, LEDS_NUM); +// for (int i = 0; i < LEDS_NUM; i++) { +// ledsBuff[i].setRGB(20, 20, 20); +// } +// FastLED.show(); +// } + // the setup routine runs once when M5Stack starts up void setup() { // gpio test @@ -436,8 +486,8 @@ void setup() { // { // adc_test(); // } - startupLogo(); + //ledBar(); Wire.begin(); // Lcd display @@ -629,4 +679,4 @@ void setup() { void loop() { buttons_test(); M5.update(); -} \ No newline at end of file +}