From 87515225c1f963edf23f1d72630e3d7326fe3154 Mon Sep 17 00:00:00 2001 From: Tinyu Date: Tue, 25 Jan 2022 16:09:46 +0800 Subject: [PATCH 01/16] Update BasicHttpClient.ino --- examples/Advanced/WIFI/BasicHttpClient/BasicHttpClient.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Advanced/WIFI/BasicHttpClient/BasicHttpClient.ino b/examples/Advanced/WIFI/BasicHttpClient/BasicHttpClient.ino index a3c0030d..12d3a948 100644 --- a/examples/Advanced/WIFI/BasicHttpClient/BasicHttpClient.ino +++ b/examples/Advanced/WIFI/BasicHttpClient/BasicHttpClient.ino @@ -21,7 +21,7 @@ HTTPClient http; void setup() { M5.begin(); //Init M5Core2. 初始化 M5Core2 - wifiMulti.addAP("M5-2.4G", "Office@888888"); //Storage wifi configuration information. 存储wifi配置信息 + wifiMulti.addAP("WIFINAME", "WIFIPASSWORD"); //Storage wifi configuration information. 存储wifi配置信息 M5.Lcd.print("\nConnecting Wifi...\n"); //print format output string on lcd. 串口格式化输出字符串 } From 4258276f3f7a0d40eb9ac82950c06f04c4a9af24 Mon Sep 17 00:00:00 2001 From: Tinyu Date: Tue, 25 Jan 2022 20:36:59 +0800 Subject: [PATCH 02/16] Update library.properties --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 32209b0c..b3d78701 100644 --- a/library.properties +++ b/library.properties @@ -8,4 +8,4 @@ category=Device Control url=https://github.com/m5stack/M5Core2.git architectures=esp32 includes=M5Core2.h -depends=M5GFX,UNIT_ENV,UNIT_4RELAY,Adafruit MCP4725,Adafruit TCS34725,Adafruit NeoPixel,Adafruit MCP4725,MAX30100lib,MFRC522_I2C,M5_BM8563,M5_ADS1100,M5_ADS1115,M5_FPC1020A,HX711 Arduino Library,PCA9554,TinyGPSPlus-ESP32,Adafruit SGP30 Sensor,FFT,TFTTerminal,ClosedCube TCA9548A,M5GFX,ArduinoJson,M5_EzData,PubSubClient,UNIT_SONIC,PoE_CAM,M5_RoverC,UNIT_UHF_RFID,M5_JoyC,UNIT_MQTT,M5_BH1750FVI +depends=M5GFX,UNIT_ENV,UNIT_4RELAY,Adafruit MCP4725,Adafruit TCS34725,Adafruit NeoPixel,Adafruit MCP4725,MAX30100lib,MFRC522_I2C,M5_BM8563,M5_ADS1100,M5_ADS1115,M5_FPC1020A,HX711 Arduino Library,PCA9554,TinyGPSPlus-ESP32,Adafruit SGP30 Sensor,FFT,TFTTerminal,ClosedCube TCA9548A,M5GFX,ArduinoJson,M5_EzData,PubSubClient,UNIT_SONIC,PoE_CAM,M5_RoverC,UNIT_UHF_RFID,M5_JoyC,UNIT_MQTT,M5_BH1750FVI,ATOM_DTU_CAT1 From fd93e8e904eaeafa82fecb1716adb1c01378987a Mon Sep 17 00:00:00 2001 From: GoT Date: Thu, 3 Feb 2022 17:32:51 +0100 Subject: [PATCH 03/16] Wrong character usage CWE-0:The code contains unhandled character(s) (character code=226). Neither unicode nor extended ascii is supported. --- src/M5Core2.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/M5Core2.h b/src/M5Core2.h index 400cf24c..57e0c21c 100644 --- a/src/M5Core2.h +++ b/src/M5Core2.h @@ -139,7 +139,7 @@ #define m5 M5 #define lcd Lcd #else - #error “This library only supports boards with ESP32 processor.” + #error "This library only supports boards with ESP32 processor." #endif #endif From f269e692ded509cb537f5b0502e69c8d358b1bec Mon Sep 17 00:00:00 2001 From: Sean Kwok <45260108+Gitshaoxiang@users.noreply.github.com> Date: Fri, 11 Feb 2022 16:20:50 +0800 Subject: [PATCH 04/16] add comx cat example --- .../COM_CAT1_SIM7680/COM_CAT1_SIM7680.ino | 213 ++++++++++++++++++ library.properties | 2 +- 2 files changed, 214 insertions(+), 1 deletion(-) create mode 100644 examples/Module/COM_CAT1_SIM7680/COM_CAT1_SIM7680.ino diff --git a/examples/Module/COM_CAT1_SIM7680/COM_CAT1_SIM7680.ino b/examples/Module/COM_CAT1_SIM7680/COM_CAT1_SIM7680.ino new file mode 100644 index 00000000..a6b507f6 --- /dev/null +++ b/examples/Module/COM_CAT1_SIM7680/COM_CAT1_SIM7680.ino @@ -0,0 +1,213 @@ +/* +******************************************************************************* +* Copyright (c) 2022 by M5Stack +* Equipped with M5Core sample source code +* 配套 M5Core 示例源代码 +* Visit the website for more +information:https://docs.m5stack.com/en/module/comx_cat1 +* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/module/comx_cat1 +* +* describe: comx_cat1. +* date:2022/01/11 +******************************************************************************* +This case will use COM.CAT1 Module combined with M5Core2 to implement MQTT +Client. After successfully connecting to MQTT, press button B to realize data +publishing. Before use, adjust the DIP switch of the module base to G16/17 ON +(it actually connect M5Core2 G13/14) Libraries: +- [TinyGSM](https://github.com/vshymanskyy/TinyGSM) +- [PubSubClient](https://github.com/knolleary/pubsubclient.git) +*/ + +#include +#include "M5GFX.h" + +// Compatible with SIM76XX series. +#define TINY_GSM_MODEM_SIM7600 + +// Set serial for debug console (to the Serial Monitor, default speed 115200) +#define SerialMon Serial +#define SerialAT Serial2 + +uint32_t lastReconnectAttempt = 0; + +#define TINY_GSM_RX_BUFFER 650 + +#define TINY_GSM_DEBUG SerialMon + +#define MODULE_BAUD 115200 + +// Your GPRS credentials, if any +const char apn[] = "YourAPN"; +const char gprsUser[] = ""; +const char gprsPass[] = ""; + +#include +#include + +TinyGsm modem(SerialAT); +TinyGsmClient client(modem); + +M5GFX display; +M5Canvas canvas(&display); + +const char* broker = "mqtt.m5stack.com"; + +const char* topic_up = "cat1/up"; +const char* topic_down = "cat1/down"; + +PubSubClient mqtt(client); + +unsigned long start; + +inline String time() { + return "..." + String((millis() - start) / 1000) + 's'; +} + +void log(String info) { + SerialMon.println(info); + canvas.println(info); + canvas.pushSprite(0, 0); +} + +void mqttCallback(char* topic, byte* payload, unsigned int len) { + log("Message arrived :"); + log(topic); + log("payload: "); + char _payload[len]; + memcpy(_payload, payload, len); + _payload[len] = '\0'; + log(_payload); +} + +boolean mqttConnect() { + log("Connecting to "); + log(broker); + + // Connect to MQTT Broker + boolean status = mqtt.connect("GsmClientTest"); + + // Or, if you want to authenticate MQTT: + // boolean status = mqtt.connect("GsmClientName", "mqtt_user", "mqtt_pass"); + + if (status == false) { + SerialMon.println(" fail"); + return false; + } + SerialMon.println(" success"); + mqtt.publish(topic_up, "GsmClientTest started"); + mqtt.subscribe(topic_down); + log("Subscribe Topic: " + String(topic_down)); + return mqtt.connected(); +} + +void setup() { + M5.begin(); + display.begin(); + start = millis(); + canvas.setColorDepth(1); // mono color + canvas.setFont(&fonts::efontCN_14); + canvas.createSprite(display.width(), display.height()); + canvas.setTextSize(2); + canvas.setPaletteColor(1, GREEN); + canvas.setTextScroll(true); + + log("Initializing modem..." + time()); + + // (it actually connect M5Core2 G13/14) + Serial2.begin(115200, SERIAL_8N1, 13, 14); + + log("check UART connect..." + time()); + + unsigned long timerout = millis(); + while (1) { + if (millis() - timerout > 10000) { + log("UART connect error..." + time()); + delay(100000); + } + SerialAT.print("AT\r\n"); + String input = SerialAT.readString(); + if (input.indexOf("OK") >= 0) { + break; + } + } + // modem.restart(); + modem.init(); + String modemInfo = modem.getModemInfo(); + log("Modem Info: "); + log(modemInfo + time()); + while (!modem.getSimStatus()) { + log("not sim card" + time()); + } +} + +void loop() { + log("Waiting for network...." + time()); + if (!modem.waitForNetwork()) { + log("fail" + time()); + delay(10000); + return; + } + if (modem.isNetworkConnected()) { + log("Network connected" + time()); + } + log("GPRS connect..." + time()); + if (!modem.gprsConnect(apn, gprsUser, gprsPass)) { + log("fail"); + delay(10000); + return; + } + if (modem.isGprsConnected()) { + log("GPRS connected"); + } + + String ccid = modem.getSimCCID(); + log("CCID: "); + log(ccid); + + String imei = modem.getIMEI(); + log("IMEI: " + imei); + + String imsi = modem.getIMSI(); + log("IMSI: " + imsi); + + String cop = modem.getOperator(); + log("Operator: " + cop); + + IPAddress local = modem.localIP(); + log("REMOTE IP: " + local.toString()); + + int csq = modem.getSignalQuality(); + log("RSSI:" + String(csq) + time()); + log("IP:" + local.toString() + time()); + + // MQTT Broker setup + mqtt.setServer(broker, 1883); + mqtt.setCallback(mqttCallback); + + while (true) { + M5.update(); + if (!mqtt.connected()) { + log("=== MQTT NOT CONNECTED ==="); + // Reconnect every 10 seconds + uint32_t t = millis(); + if (t - lastReconnectAttempt > 3000L) { + lastReconnectAttempt = t; + if (mqttConnect()) { + lastReconnectAttempt = 0; + log("mqtt.m5stack.com" + time()); + log("MQTT Connected!" + time()); + log("Press Btn B to Publish"); + log("Topic: " + String(topic_up)); + } + } + delay(100); + } else { + mqtt.loop(); + M5.update(); + if (M5.BtnB.wasPressed()) { + log("Publish:" + String(topic_up)); + mqtt.publish(topic_up, "Hello From COM.X CAT1"); + } + } + } +} diff --git a/library.properties b/library.properties index b3d78701..7a87591d 100644 --- a/library.properties +++ b/library.properties @@ -8,4 +8,4 @@ category=Device Control url=https://github.com/m5stack/M5Core2.git architectures=esp32 includes=M5Core2.h -depends=M5GFX,UNIT_ENV,UNIT_4RELAY,Adafruit MCP4725,Adafruit TCS34725,Adafruit NeoPixel,Adafruit MCP4725,MAX30100lib,MFRC522_I2C,M5_BM8563,M5_ADS1100,M5_ADS1115,M5_FPC1020A,HX711 Arduino Library,PCA9554,TinyGPSPlus-ESP32,Adafruit SGP30 Sensor,FFT,TFTTerminal,ClosedCube TCA9548A,M5GFX,ArduinoJson,M5_EzData,PubSubClient,UNIT_SONIC,PoE_CAM,M5_RoverC,UNIT_UHF_RFID,M5_JoyC,UNIT_MQTT,M5_BH1750FVI,ATOM_DTU_CAT1 +depends=M5GFX,UNIT_ENV,UNIT_4RELAY,Adafruit MCP4725,Adafruit TCS34725,Adafruit NeoPixel,Adafruit MCP4725,MAX30100lib,MFRC522_I2C,M5_BM8563,M5_ADS1100,M5_ADS1115,M5_FPC1020A,HX711 Arduino Library,PCA9554,TinyGPSPlus-ESP32,Adafruit SGP30 Sensor,FFT,TFTTerminal,ClosedCube TCA9548A,M5GFX,ArduinoJson,M5_EzData,PubSubClient,UNIT_SONIC,PoE_CAM,M5_RoverC,UNIT_UHF_RFID,M5_JoyC,UNIT_MQTT,M5_BH1750FVI,ATOM_DTU_CAT1,TinyGSM From c5f336496cd091feb3dd4188a926582b4b92e0e1 Mon Sep 17 00:00:00 2001 From: GoT Date: Wed, 16 Feb 2022 16:30:54 +0100 Subject: [PATCH 05/16] The 0.1.1 has been released weeks ago --- library.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library.json b/library.json index 3590ff9f..bb3f3ae7 100644 --- a/library.json +++ b/library.json @@ -10,8 +10,8 @@ "type": "git", "url": "https://github.com/m5stack/M5Core2.git" }, - "version": "0.1.0", + "version": "0.1.1", "frameworks": "arduino", "platforms": "espressif32", "headers": "M5Core2.h" -} \ No newline at end of file +} From c8c8084815da9d5a890a42096c26b00445917793 Mon Sep 17 00:00:00 2001 From: GoT Date: Wed, 16 Feb 2022 16:32:07 +0100 Subject: [PATCH 06/16] Update library.properties version to 0.1.1 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 7a87591d..58a7d935 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=M5Core2 -version=0.1.0 +version=0.1.1 author=M5Stack maintainer=M5Stack sentence=Library for M5Stack Core2 development kit From d11e848f3704434fa0d216ba05fd130502528bbc Mon Sep 17 00:00:00 2001 From: Sean Kwok <45260108+Gitshaoxiang@users.noreply.github.com> Date: Thu, 17 Feb 2022 11:09:06 +0800 Subject: [PATCH 07/16] fix i2s mclk with arduino-esp32 v2.0.2 compile issues --- examples/Basics/record/record.ino | 3 +++ examples/Basics/speak/speak.ino | 4 ++++ examples/Unit/PDM_SPM1423/PDM_SPM1423.ino | 3 +++ examples/core2_for_aws/FactoryTest/FactoryTest.ino | 4 +++- 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/examples/Basics/record/record.ino b/examples/Basics/record/record.ino index 30dfb559..b396c12a 100644 --- a/examples/Basics/record/record.ino +++ b/examples/Basics/record/record.ino @@ -52,6 +52,9 @@ bool InitI2SSpeakOrMic(int mode){ //Init I2S. 初始化I2S err += i2s_driver_install(Speak_I2S_NUMBER, &i2s_config, 0, NULL); i2s_pin_config_t tx_pin_config; + #if (ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(4, 3, 0)) + tx_pin_config.mck_io_num = I2S_PIN_NO_CHANGE; + #endif tx_pin_config.bck_io_num = CONFIG_I2S_BCK_PIN; // Link the BCK to the CONFIG_I2S_BCK_PIN pin. 将BCK链接至CONFIG_I2S_BCK_PIN引脚 tx_pin_config.ws_io_num = CONFIG_I2S_LRCK_PIN; // ... tx_pin_config.data_out_num = CONFIG_I2S_DATA_PIN; // ... diff --git a/examples/Basics/speak/speak.ino b/examples/Basics/speak/speak.ino index 2257ce4c..5ccd5b46 100644 --- a/examples/Basics/speak/speak.ino +++ b/examples/Basics/speak/speak.ino @@ -51,6 +51,10 @@ bool InitI2SSpeakOrMic(int mode){ //Init I2S. 初始化I2S err += i2s_driver_install(Speak_I2S_NUMBER, &i2s_config, 0, NULL); i2s_pin_config_t tx_pin_config; + + #if (ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(4, 3, 0)) + tx_pin_config.mck_io_num = I2S_PIN_NO_CHANGE; + #endif tx_pin_config.bck_io_num = CONFIG_I2S_BCK_PIN; // Link the BCK to the CONFIG_I2S_BCK_PIN pin. 将BCK链接至CONFIG_I2S_BCK_PIN引脚 tx_pin_config.ws_io_num = CONFIG_I2S_LRCK_PIN; // ... tx_pin_config.data_out_num = CONFIG_I2S_DATA_PIN; // ... diff --git a/examples/Unit/PDM_SPM1423/PDM_SPM1423.ino b/examples/Unit/PDM_SPM1423/PDM_SPM1423.ino index 15f1a5dc..eaa1829b 100644 --- a/examples/Unit/PDM_SPM1423/PDM_SPM1423.ino +++ b/examples/Unit/PDM_SPM1423/PDM_SPM1423.ino @@ -52,6 +52,9 @@ bool InitI2SSpakerOrMic(int mode){ i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL); // Install and drive I2S. 安装并驱动I2S i2s_pin_config_t pin_config; + #if (ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(4, 3, 0)) + tx_pin_config.mck_io_num = I2S_PIN_NO_CHANGE; + #endif pin_config.bck_io_num = I2S_PIN_NO_CHANGE; pin_config.ws_io_num = PIN_CLK; pin_config.data_out_num = I2S_PIN_NO_CHANGE; diff --git a/examples/core2_for_aws/FactoryTest/FactoryTest.ino b/examples/core2_for_aws/FactoryTest/FactoryTest.ino index a5c5aa90..d467c4c9 100644 --- a/examples/core2_for_aws/FactoryTest/FactoryTest.ino +++ b/examples/core2_for_aws/FactoryTest/FactoryTest.ino @@ -330,7 +330,9 @@ bool InitI2SSpakerOrMic(int mode) err += i2s_driver_install(SPAKER_I2S_NUMBER, &i2s_config, 0, NULL); i2s_pin_config_t tx_pin_config; - + #if (ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(4, 3, 0)) + tx_pin_config.mck_io_num = I2S_PIN_NO_CHANGE; + #endif tx_pin_config.bck_io_num = CONFIG_I2S_BCK_PIN; tx_pin_config.ws_io_num = CONFIG_I2S_LRCK_PIN; tx_pin_config.data_out_num = CONFIG_I2S_DATA_PIN; From 2ab6af5cf14fe521086cc3344d5a99b4537183d1 Mon Sep 17 00:00:00 2001 From: Tinyu Date: Tue, 22 Feb 2022 18:53:04 +0800 Subject: [PATCH 08/16] Update speak.ino --- examples/Basics/speak/speak.ino | 156 +++++++++++++++++++------------- 1 file changed, 92 insertions(+), 64 deletions(-) diff --git a/examples/Basics/speak/speak.ino b/examples/Basics/speak/speak.ino index 5ccd5b46..93094722 100644 --- a/examples/Basics/speak/speak.ino +++ b/examples/Basics/speak/speak.ino @@ -7,92 +7,119 @@ * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/core/gray * * describe:Speaker example. 喇叭示例 -* date:2021/7/21 +* date:2022/2/22 ******************************************************************************* */ #include #include -extern const unsigned char previewR[120264]; // Referring to external data (Dingdong audio files are stored inside). 引用外部数据(dingdong音频文件存储在内) +extern const unsigned char + previewR[120264]; // Referring to external data (Dingdong audio files are + // stored inside). + // 引用外部数据(dingdong音频文件存储在内) -#define CONFIG_I2S_BCK_PIN 12 //定义I2S相关端口 -#define CONFIG_I2S_LRCK_PIN 0 -#define CONFIG_I2S_DATA_PIN 2 +#define CONFIG_I2S_BCK_PIN 12 //定义I2S相关端口 +#define CONFIG_I2S_LRCK_PIN 0 +#define CONFIG_I2S_DATA_PIN 2 #define CONFIG_I2S_DATA_IN_PIN 34 #define Speak_I2S_NUMBER I2S_NUM_0 //定义扬声器端口 -#define MODE_MIC 0 //定义工作模式 -#define MODE_SPK 1 +#define MODE_MIC 0 //定义工作模式 +#define MODE_SPK 1 #define DATA_SIZE 1024 -bool InitI2SSpeakOrMic(int mode){ //Init I2S. 初始化I2S +bool InitI2SSpeakOrMic(int mode) { // Init I2S. 初始化I2S esp_err_t err = ESP_OK; - i2s_driver_uninstall(Speak_I2S_NUMBER); // Uninstall the I2S driver. 卸载I2S驱动 + i2s_driver_uninstall( + Speak_I2S_NUMBER); // Uninstall the I2S driver. 卸载I2S驱动 i2s_config_t i2s_config = { - .mode = (i2s_mode_t)(I2S_MODE_MASTER), // Set the I2S operating mode. 设置I2S工作模式 - .sample_rate = 44100, // Set the I2S sampling rate. 设置I2S采样率 - .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, // Fixed 12-bit stereo MSB. 固定为12位立体声MSB - .channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT, // Set the channel format. 设置频道格式 - .communication_format = I2S_COMM_FORMAT_I2S, // Set the format of the communication. 设置通讯格式 - .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, // Set the interrupt flag. 设置中断的标志 - .dma_buf_count = 2, //DMA buffer count. DMA缓冲区计数 - .dma_buf_len = 128, //DMA buffer length. DMA缓冲区长度 + .mode = (i2s_mode_t)(I2S_MODE_MASTER), // Set the I2S operating mode. + // 设置I2S工作模式 + .sample_rate = 44100, // Set the I2S sampling rate. 设置I2S采样率 + .bits_per_sample = + I2S_BITS_PER_SAMPLE_16BIT, // Fixed 12-bit stereo MSB. + // 固定为12位立体声MSB + .channel_format = + I2S_CHANNEL_FMT_ONLY_RIGHT, // Set the channel format. 设置频道格式 + .communication_format = + I2S_COMM_FORMAT_I2S, // Set the format of the communication. + // 设置通讯格式 + .intr_alloc_flags = + ESP_INTR_FLAG_LEVEL1, // Set the interrupt flag. 设置中断的标志 + .dma_buf_count = 2, // DMA buffer count. DMA缓冲区计数 + .dma_buf_len = 128, // DMA buffer length. DMA缓冲区长度 }; - if (mode == MODE_MIC){ - i2s_config.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_PDM); - }else{ - i2s_config.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX); - i2s_config.use_apll = false; //I2S clock setup. I2S时钟设置 - i2s_config.tx_desc_auto_clear = true; // Enables auto-cleanup descriptors for understreams. 开启欠流自动清除描述符 + if (mode == MODE_MIC) { + i2s_config.mode = + (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_PDM); + } else { + i2s_config.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX); + i2s_config.use_apll = false; // I2S clock setup. I2S时钟设置 + i2s_config.tx_desc_auto_clear = + true; // Enables auto-cleanup descriptors for understreams. + // 开启欠流自动清除描述符 } // Install and drive I2S. 安装并驱动I2S err += i2s_driver_install(Speak_I2S_NUMBER, &i2s_config, 0, NULL); i2s_pin_config_t tx_pin_config; - #if (ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(4, 3, 0)) - tx_pin_config.mck_io_num = I2S_PIN_NO_CHANGE; - #endif - tx_pin_config.bck_io_num = CONFIG_I2S_BCK_PIN; // Link the BCK to the CONFIG_I2S_BCK_PIN pin. 将BCK链接至CONFIG_I2S_BCK_PIN引脚 - tx_pin_config.ws_io_num = CONFIG_I2S_LRCK_PIN; // ... - tx_pin_config.data_out_num = CONFIG_I2S_DATA_PIN; // ... - tx_pin_config.data_in_num = CONFIG_I2S_DATA_IN_PIN; // ... - err += i2s_set_pin(Speak_I2S_NUMBER, &tx_pin_config); // Set the I2S pin number. 设置I2S引脚编号 - err += i2s_set_clk(Speak_I2S_NUMBER, 44100, I2S_BITS_PER_SAMPLE_16BIT, I2S_CHANNEL_MONO); // Set the clock and bitwidth used by I2S Rx and Tx. 设置I2S RX、Tx使用的时钟和位宽 +#if (ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(4, 3, 0)) + tx_pin_config.mck_io_num = I2S_PIN_NO_CHANGE; +#endif + tx_pin_config.bck_io_num = + CONFIG_I2S_BCK_PIN; // Link the BCK to the CONFIG_I2S_BCK_PIN pin. + // 将BCK链接至CONFIG_I2S_BCK_PIN引脚 + tx_pin_config.ws_io_num = CONFIG_I2S_LRCK_PIN; // ... + tx_pin_config.data_out_num = CONFIG_I2S_DATA_PIN; // ... + tx_pin_config.data_in_num = CONFIG_I2S_DATA_IN_PIN; // ... + err += + i2s_set_pin(Speak_I2S_NUMBER, + &tx_pin_config); // Set the I2S pin number. 设置I2S引脚编号 + err += i2s_set_clk( + Speak_I2S_NUMBER, 44100, I2S_BITS_PER_SAMPLE_16BIT, + I2S_CHANNEL_MONO); // Set the clock and bitwidth used by I2S Rx and Tx. + // 设置I2S RX、Tx使用的时钟和位宽 return true; } -void DisplayInit(void){ // Initialize the display. 显示屏初始化 - M5.Lcd.fillScreen(WHITE); //Set the screen background color to white. 设置屏幕背景色为白色 - M5.Lcd.setTextColor(BLACK); //Set the text color to black. 设置文字颜色为黑色 - M5.Lcd.setTextSize(2); //Set font size to 2. 设置字体大小为2 +void DisplayInit(void) { // Initialize the display. 显示屏初始化 + M5.Lcd.fillScreen(WHITE); // Set the screen background color to white. + // 设置屏幕背景色为白色 + M5.Lcd.setTextColor( + BLACK); // Set the text color to black. 设置文字颜色为黑色 + M5.Lcd.setTextSize(2); // Set font size to 2. 设置字体大小为2 } -void SpeakInit(void){ // 初始化扬声器 - M5.Axp.SetSpkEnable(true); //启用扬声器电源 - InitI2SSpeakOrMic(MODE_SPK); +void SpeakInit(void) { // 初始化扬声器 + M5.Axp.SetSpkEnable(true); //启用扬声器电源 + InitI2SSpeakOrMic(MODE_SPK); } -void DingDong(void){ - size_t bytes_written = 0; - i2s_write(Speak_I2S_NUMBER, previewR, 120264, &bytes_written, portMAX_DELAY); +void DingDong(void) { + size_t bytes_written = 0; + i2s_write(Speak_I2S_NUMBER, previewR, 120264, &bytes_written, + portMAX_DELAY); } -//在 M5Core 启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 +//在 M5Core +//启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 void setup() { - M5.begin(true, true, true, true); //Init M5Core2. 初始化 M5Core2 - DisplayInit(); - M5.Lcd.setTextColor(RED); - M5.Lcd.setCursor(10, 10); // Set the cursor at (10,10). 将光标设在(10,10)处 - M5.Lcd.printf("Speak Test!"); // The screen prints the formatted string and wraps it. 屏幕打印格式化字符串并换行 - M5.Lcd.setTextColor(BLACK); - M5.Lcd.setCursor(10, 26); - M5.Lcd.printf("Press Left Button to listen DingDong!"); - SpeakInit(); - DingDong(); - delay(100); + M5.begin(true, true, true, true); // Init M5Core2. 初始化 M5Core2 + DisplayInit(); + M5.Lcd.setTextColor(RED); + M5.Lcd.setCursor(10, + 10); // Set the cursor at (10,10). 将光标设在(10,10)处 + M5.Lcd.printf("Speak Test!"); // The screen prints the formatted string and + // wraps it. 屏幕打印格式化字符串并换行 + M5.Lcd.setTextColor(BLACK); + M5.Lcd.setCursor(10, 26); + M5.Lcd.printf("Press Left Button to listen DingDong!"); + SpeakInit(); + DingDong(); + delay(100); } /* After the program in setup() runs, it runs the program in loop() @@ -100,14 +127,15 @@ The loop() function is an infinite loop in which the program runs repeatedly 在setup()函数中的程序执行完后,会接着执行loop()函数中的程序 loop()函数是一个死循环,其中的程序会不断的重复运行 */ void loop() { - TouchPoint_t pos= M5.Touch.getPressPoint(); // Stores the touch coordinates in pos. 将触摸坐标存储在pos.内 - if(pos.y > 240) - if(pos.x < 109) - { - M5.Axp.SetLDOEnable(3,true); //Open the vibration. 开启震动马达 - delay(100); - M5.Axp.SetLDOEnable(3,false); - DingDong(); - } - delay(10); + TouchPoint_t pos = + M5.Touch.getPressPoint(); // Stores the touch coordinates in pos. + // 将触摸坐标存储在pos.内 + if (pos.y > 240) + if (pos.x < 109) { + M5.Axp.SetLDOEnable(3, true); // Open the vibration. 开启震动马达 + delay(100); + M5.Axp.SetLDOEnable(3, false); + DingDong(); + } + delay(10); } From 5999ead2ae215292acbbb40b70f0b1d275796259 Mon Sep 17 00:00:00 2001 From: Tinyu Date: Tue, 22 Feb 2022 18:53:39 +0800 Subject: [PATCH 09/16] Update record.ino --- examples/Basics/record/record.ino | 160 ++++++++++++++++++------------ 1 file changed, 94 insertions(+), 66 deletions(-) diff --git a/examples/Basics/record/record.ino b/examples/Basics/record/record.ino index b396c12a..a5b31e93 100644 --- a/examples/Basics/record/record.ino +++ b/examples/Basics/record/record.ino @@ -7,83 +7,106 @@ * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/core/core2 * * describe:NS4168--I2S power amplifier. 功放示例 -* date:2021/7/21 +* date:2022/2/22 ******************************************************************************* */ #include #include -#define CONFIG_I2S_BCK_PIN 12 //Define I2S related ports. 定义I2S相关端口 -#define CONFIG_I2S_LRCK_PIN 0 -#define CONFIG_I2S_DATA_PIN 2 +#define CONFIG_I2S_BCK_PIN 12 // Define I2S related ports. 定义I2S相关端口 +#define CONFIG_I2S_LRCK_PIN 0 +#define CONFIG_I2S_DATA_PIN 2 #define CONFIG_I2S_DATA_IN_PIN 34 #define Speak_I2S_NUMBER I2S_NUM_0 // Define the speaker port. 定义扬声器端口 -#define MODE_MIC 0 // Define the working mode. 定义工作模式 -#define MODE_SPK 1 +#define MODE_MIC 0 // Define the working mode. 定义工作模式 +#define MODE_SPK 1 #define DATA_SIZE 1024 uint8_t microphonedata0[1024 * 100]; int data_offset = 0; -bool InitI2SSpeakOrMic(int mode){ //Init I2S. 初始化I2S +bool InitI2SSpeakOrMic(int mode) { // Init I2S. 初始化I2S esp_err_t err = ESP_OK; - i2s_driver_uninstall(Speak_I2S_NUMBER); // Uninstall the I2S driver. 卸载I2S驱动 + i2s_driver_uninstall( + Speak_I2S_NUMBER); // Uninstall the I2S driver. 卸载I2S驱动 i2s_config_t i2s_config = { - .mode = (i2s_mode_t)(I2S_MODE_MASTER), // Set the I2S operating mode. 设置I2S工作模式 - .sample_rate = 44100, // Set the I2S sampling rate. 设置I2S采样率 - .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, // Fixed 12-bit stereo MSB. 固定为12位立体声MSB - .channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT, // Set the channel format. 设置频道格式 - .communication_format = I2S_COMM_FORMAT_I2S, // Set the format of the communication. 设置通讯格式 - .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, // Set the interrupt flag. 设置中断的标志 - .dma_buf_count = 2, //DMA buffer count. DMA缓冲区计数 - .dma_buf_len = 128, //DMA buffer length. DMA缓冲区长度 + .mode = (i2s_mode_t)(I2S_MODE_MASTER), // Set the I2S operating mode. + // 设置I2S工作模式 + .sample_rate = 44100, // Set the I2S sampling rate. 设置I2S采样率 + .bits_per_sample = + I2S_BITS_PER_SAMPLE_16BIT, // Fixed 12-bit stereo MSB. + // 固定为12位立体声MSB + .channel_format = + I2S_CHANNEL_FMT_ONLY_RIGHT, // Set the channel format. 设置频道格式 + .communication_format = + I2S_COMM_FORMAT_STAND_I2S, // Set the format of the communication. + // 设置通讯格式 + .intr_alloc_flags = + ESP_INTR_FLAG_LEVEL1, // Set the interrupt flag. 设置中断的标志 + .dma_buf_count = 2, // DMA buffer count. DMA缓冲区计数 + .dma_buf_len = 128, // DMA buffer length. DMA缓冲区长度 }; - if (mode == MODE_MIC){ - i2s_config.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_PDM); - }else{ - i2s_config.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX); - i2s_config.use_apll = false; //I2S clock setup. I2S时钟设置 - i2s_config.tx_desc_auto_clear = true; // Enables auto-cleanup descriptors for understreams. 开启欠流自动清除描述符 + if (mode == MODE_MIC) { + i2s_config.mode = + (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_PDM); + } else { + i2s_config.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX); + i2s_config.use_apll = false; // I2S clock setup. I2S时钟设置 + i2s_config.tx_desc_auto_clear = + true; // Enables auto-cleanup descriptors for understreams. + // 开启欠流自动清除描述符 } // Install and drive I2S. 安装并驱动I2S err += i2s_driver_install(Speak_I2S_NUMBER, &i2s_config, 0, NULL); i2s_pin_config_t tx_pin_config; - #if (ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(4, 3, 0)) - tx_pin_config.mck_io_num = I2S_PIN_NO_CHANGE; - #endif - tx_pin_config.bck_io_num = CONFIG_I2S_BCK_PIN; // Link the BCK to the CONFIG_I2S_BCK_PIN pin. 将BCK链接至CONFIG_I2S_BCK_PIN引脚 - tx_pin_config.ws_io_num = CONFIG_I2S_LRCK_PIN; // ... - tx_pin_config.data_out_num = CONFIG_I2S_DATA_PIN; // ... - tx_pin_config.data_in_num = CONFIG_I2S_DATA_IN_PIN; // ... - err += i2s_set_pin(Speak_I2S_NUMBER, &tx_pin_config); // Set the I2S pin number. 设置I2S引脚编号 - err += i2s_set_clk(Speak_I2S_NUMBER, 44100, I2S_BITS_PER_SAMPLE_16BIT, I2S_CHANNEL_MONO); // Set the clock and bitwidth used by I2S Rx and Tx. 设置I2S RX、Tx使用的时钟和位宽 +#if (ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(4, 3, 0)) + tx_pin_config.mck_io_num = I2S_PIN_NO_CHANGE; +#endif + tx_pin_config.bck_io_num = + CONFIG_I2S_BCK_PIN; // Link the BCK to the CONFIG_I2S_BCK_PIN pin. + // 将BCK链接至CONFIG_I2S_BCK_PIN引脚 + tx_pin_config.ws_io_num = CONFIG_I2S_LRCK_PIN; // ... + tx_pin_config.data_out_num = CONFIG_I2S_DATA_PIN; // ... + tx_pin_config.data_in_num = CONFIG_I2S_DATA_IN_PIN; // ... + err += + i2s_set_pin(Speak_I2S_NUMBER, + &tx_pin_config); // Set the I2S pin number. 设置I2S引脚编号 + err += i2s_set_clk( + Speak_I2S_NUMBER, 44100, I2S_BITS_PER_SAMPLE_16BIT, + I2S_CHANNEL_MONO); // Set the clock and bitwidth used by I2S Rx and Tx. + // 设置I2S RX、Tx使用的时钟和位宽 return true; } -void DisplayInit(void){ // Initialize the display. 显示屏初始化 - M5.Lcd.fillScreen(WHITE); //Set the screen background color to white. 设置屏幕背景色为白色 - M5.Lcd.setTextColor(BLACK); //Set the text color to black. 设置文字颜色为黑色 - M5.Lcd.setTextSize(2); //Set font size to 2. 设置字体大小为2 +void DisplayInit(void) { // Initialize the display. 显示屏初始化 + M5.Lcd.fillScreen(WHITE); // Set the screen background color to white. + // 设置屏幕背景色为白色 + M5.Lcd.setTextColor( + BLACK); // Set the text color to black. 设置文字颜色为黑色 + M5.Lcd.setTextSize(2); // Set font size to 2. 设置字体大小为2 } /* After M5Core2 is started or reset -the program in the setUp () function will be run, and this part will only be run once. -在 M5Core2 启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 */ -void setup(){ - M5.begin(true, true, true, true); //Init M5Core2. 初始化 M5Core2 - M5.Axp.SetSpkEnable(true); //Enable speaker power. 启用扬声器电源 - DisplayInit(); - M5.Lcd.setTextColor(RED); - M5.Lcd.setCursor(10, 10); // Set the cursor at (10,10). 将光标设在(10,10)处 - M5.Lcd.printf("Recorder!"); // The screen prints the formatted string and wraps it. 屏幕打印格式化字符串并换行 - M5.Lcd.setTextColor(BLACK); - M5.Lcd.setCursor(10, 26); - M5.Lcd.printf("Press Left Button to recording!"); - delay(100); //delay 100ms. 延迟100ms +the program in the setUp () function will be run, and this part will only be run +once. 在 M5Core2 +启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 */ +void setup() { + M5.begin(true, true, true, true); // Init M5Core2. 初始化 M5Core2 + M5.Axp.SetSpkEnable(true); // Enable speaker power. 启用扬声器电源 + DisplayInit(); + M5.Lcd.setTextColor(RED); + M5.Lcd.setCursor(10, + 10); // Set the cursor at (10,10). 将光标设在(10,10)处 + M5.Lcd.printf("Recorder!"); // The screen prints the formatted string and + // wraps it. 屏幕打印格式化字符串并换行 + M5.Lcd.setTextColor(BLACK); + M5.Lcd.setCursor(10, 26); + M5.Lcd.printf("Press Left Button to recording!"); + delay(100); // delay 100ms. 延迟100ms } /* After the program in setup() runs, it runs the program in loop() @@ -91,24 +114,29 @@ The loop() function is an infinite loop in which the program runs repeatedly 在setup()函数中的程序执行完后,会接着执行loop()函数中的程序 loop()函数是一个死循环,其中的程序会不断的重复运行 */ void loop() { - TouchPoint_t pos= M5.Touch.getPressPoint(); // Stores the touch coordinates in pos. 将触摸坐标存储在pos.内 - if(pos.y > 240){ - if(pos.x < 109){ - M5.Axp.SetLDOEnable(3,true); //Open the vibration. 开启震动马达 - delay(100); - M5.Axp.SetLDOEnable(3,false); - data_offset = 0; - InitI2SSpeakOrMic(MODE_MIC); - size_t byte_read; - while (1){ - i2s_read(Speak_I2S_NUMBER, (char *)(microphonedata0 + data_offset), DATA_SIZE, &byte_read, (100 / portTICK_RATE_MS)); - data_offset += 1024; - if(data_offset == 1024 * 100 || M5.Touch.ispressed() != true) - break; + TouchPoint_t pos = + M5.Touch.getPressPoint(); // Stores the touch coordinates in pos. + // 将触摸坐标存储在pos.内 + if (pos.y > 240) { + if (pos.x < 109) { + M5.Axp.SetLDOEnable(3, true); // Open the vibration. 开启震动马达 + delay(100); + M5.Axp.SetLDOEnable(3, false); + data_offset = 0; + InitI2SSpeakOrMic(MODE_MIC); + size_t byte_read; + while (1) { + i2s_read(Speak_I2S_NUMBER, + (char *)(microphonedata0 + data_offset), DATA_SIZE, + &byte_read, (100 / portTICK_RATE_MS)); + data_offset += 1024; + if (data_offset == 1024 * 100 || M5.Touch.ispressed() != true) + break; + } + size_t bytes_written; + InitI2SSpeakOrMic(MODE_SPK); + i2s_write(Speak_I2S_NUMBER, microphonedata0, data_offset, + &bytes_written, portMAX_DELAY); } - size_t bytes_written; - InitI2SSpeakOrMic(MODE_SPK); - i2s_write(Speak_I2S_NUMBER, microphonedata0, data_offset, &bytes_written, portMAX_DELAY); } - } } From c75c3a45e39bcc48a0340a81114ddc15149b3acf Mon Sep 17 00:00:00 2001 From: Tinyu Date: Tue, 22 Feb 2022 18:55:08 +0800 Subject: [PATCH 10/16] Update PDM_SPM1423.ino --- examples/Unit/PDM_SPM1423/PDM_SPM1423.ino | 308 +++++++++++----------- 1 file changed, 152 insertions(+), 156 deletions(-) diff --git a/examples/Unit/PDM_SPM1423/PDM_SPM1423.ino b/examples/Unit/PDM_SPM1423/PDM_SPM1423.ino index eaa1829b..3ad89170 100644 --- a/examples/Unit/PDM_SPM1423/PDM_SPM1423.ino +++ b/examples/Unit/PDM_SPM1423/PDM_SPM1423.ino @@ -7,16 +7,18 @@ * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/unit/pdm * * describe: pdm. 麦克风 -* date:2021/8/27 +* date:2022/2/22 ******************************************************************************* - Please connect to Port A,Read the microphone data of the PDM Unit and display the audio frequency spectrum. - 请连接端口A,读取PDM Unit的麦克风数据,显示音频频谱。 - Note: Remove the M5GO base when using this example, otherwise it will not work properly - 注意:在使用本示例时删除M5GO base,否则它将无法正常工作 + Please connect to Port A,Read the microphone data of the PDM Unit and display + the audio frequency spectrum. 请连接端口A,读取PDM +Unit的麦克风数据,显示音频频谱。 Note: Remove the M5GO base when using this +example, otherwise it will not work properly 注意:在使用本示例时删除M5GO +base,否则它将无法正常工作 */ #include #include + #include "fft.h" #define PIN_CLK 33 @@ -24,174 +26,168 @@ #define MODE_MIC 0 -TFT_eSprite DisFFTbuff = TFT_eSprite(&M5.Lcd); +TFT_eSprite DisFFTbuff = TFT_eSprite(&M5.Lcd); static QueueHandle_t fftvalueQueue = nullptr; static QueueHandle_t i2sstateQueue = nullptr; -typedef struct{ - uint8_t state; - void* audioPtr; - uint32_t audioSize; -}i2sQueueMsg_t; - -bool InitI2SSpakerOrMic(int mode){ - i2s_config_t i2s_config = { - .mode = (i2s_mode_t)(I2S_MODE_MASTER), // Set the I2S operating mode. 设置I2S工作模式 - .sample_rate = 44100, // Set the I2S sampling rate. 设置I2S采样率 - .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, // Fixed 12-bit stereo MSB. 固定为12位立体声MSB - .channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT, // Set the channel format. 设置频道格式 - .communication_format = I2S_COMM_FORMAT_I2S, // Set the format of the communication. 设置通讯格式 - .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, // Set the interrupt flag. 设置中断的标志 - .dma_buf_count = 2, //DMA buffer count. DMA缓冲区计数 - .dma_buf_len = 128, //DMA buffer length. DMA缓冲区长度 - }; - if (mode == MODE_MIC) - { - i2s_config.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_PDM); - } - - i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL); // Install and drive I2S. 安装并驱动I2S - i2s_pin_config_t pin_config; - #if (ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(4, 3, 0)) - tx_pin_config.mck_io_num = I2S_PIN_NO_CHANGE; - #endif - pin_config.bck_io_num = I2S_PIN_NO_CHANGE; - pin_config.ws_io_num = PIN_CLK; - pin_config.data_out_num = I2S_PIN_NO_CHANGE; - pin_config.data_in_num = PIN_DATA; - - i2s_set_pin(I2S_NUM_0, &pin_config); - i2s_set_clk(I2S_NUM_0, 44100, I2S_BITS_PER_SAMPLE_16BIT, I2S_CHANNEL_MONO); - - return true; -} - -static void i2sMicroFFTtask(void *arg) -{ - uint8_t FFTDataBuff[128]; - uint8_t FFTValueBuff[24]; - uint8_t* microRawData = (uint8_t*)calloc(2048,sizeof(uint8_t)); - size_t bytesread; - int16_t* buffptr; - double data = 0; - float adc_data; - uint16_t ydata; - uint32_t subData; - - uint8_t state = MODE_MIC; - i2sQueueMsg_t QueueMsg; - while(1) - { - if( xQueueReceive(i2sstateQueue,&QueueMsg,(TickType_t)0) == pdTRUE) - { - //Serial.println("Queue Now"); - if( QueueMsg.state == MODE_MIC ) - { - InitI2SSpakerOrMic(MODE_MIC); - state = MODE_MIC; - } +typedef struct { + uint8_t state; + void* audioPtr; + uint32_t audioSize; +} i2sQueueMsg_t; + +bool InitI2SSpakerOrMic(int mode) { + i2s_config_t i2s_config = { + .mode = (i2s_mode_t)(I2S_MODE_MASTER), // Set the I2S operating mode. + // 设置I2S工作模式 + .sample_rate = 44100, // Set the I2S sampling rate. 设置I2S采样率 + .bits_per_sample = + I2S_BITS_PER_SAMPLE_16BIT, // Fixed 12-bit stereo MSB. + // 固定为12位立体声MSB + .channel_format = + I2S_CHANNEL_FMT_ONLY_RIGHT, // Set the channel format. 设置频道格式 + .communication_format = + I2S_COMM_FORMAT_STAND_I2S, // Set the format of the communication. + // 设置通讯格式 + .intr_alloc_flags = + ESP_INTR_FLAG_LEVEL1, // Set the interrupt flag. 设置中断的标志 + .dma_buf_count = 2, // DMA buffer count. DMA缓冲区计数 + .dma_buf_len = 128, // DMA buffer length. DMA缓冲区长度 + }; + if (mode == MODE_MIC) { + i2s_config.mode = + (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_PDM); } - else if( state == MODE_MIC ) - { - fft_config_t *real_fft_plan = fft_init(1024, FFT_REAL, FFT_FORWARD, NULL, NULL); - i2s_read(I2S_NUM_0, (char *)microRawData, 2048, &bytesread, (100 / portTICK_RATE_MS)); - buffptr = ( int16_t*)microRawData; - - for ( int count_n = 0; count_n < real_fft_plan->size; count_n++) - { - adc_data = (float)map(buffptr[count_n], INT16_MIN, INT16_MAX, -2000, 2000); - real_fft_plan->input[count_n] = adc_data; - } - fft_execute(real_fft_plan); - - for ( int count_n = 1; count_n < real_fft_plan->size / 4; count_n++) - { - data = sqrt(real_fft_plan->output[2 * count_n] * real_fft_plan->output[2 * count_n] + real_fft_plan->output[2 * count_n + 1] * real_fft_plan->output[2 * count_n + 1]); - if ((count_n - 1) < 128) - { - data = ( data > 2000 ) ? 2000 : data; - ydata = map(data, 0, 2000, 0, 255); - FFTDataBuff[128 - count_n] = ydata; - } - } - for( int count = 0; count < 24; count++ ) - { - subData = 0; - for( int count_i = 0; count_i < 5; count_i++ ) - { - subData += FFTDataBuff[count * 5 + count_i ]; - } - subData /= 5; - FFTValueBuff[count] = map(subData,0,255,0,8); + i2s_driver_install(I2S_NUM_0, &i2s_config, 0, + NULL); // Install and drive I2S. 安装并驱动I2S + i2s_pin_config_t pin_config; +#if (ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(4, 3, 0)) + tx_pin_config.mck_io_num = I2S_PIN_NO_CHANGE; +#endif + pin_config.bck_io_num = I2S_PIN_NO_CHANGE; + pin_config.ws_io_num = PIN_CLK; + pin_config.data_out_num = I2S_PIN_NO_CHANGE; + pin_config.data_in_num = PIN_DATA; + + i2s_set_pin(I2S_NUM_0, &pin_config); + i2s_set_clk(I2S_NUM_0, 44100, I2S_BITS_PER_SAMPLE_16BIT, I2S_CHANNEL_MONO); + + return true; +} + +static void i2sMicroFFTtask(void* arg) { + uint8_t FFTDataBuff[128]; + uint8_t FFTValueBuff[24]; + uint8_t* microRawData = (uint8_t*)calloc(2048, sizeof(uint8_t)); + size_t bytesread; + int16_t* buffptr; + double data = 0; + float adc_data; + uint16_t ydata; + uint32_t subData; + + uint8_t state = MODE_MIC; + i2sQueueMsg_t QueueMsg; + while (1) { + if (xQueueReceive(i2sstateQueue, &QueueMsg, (TickType_t)0) == pdTRUE) { + // Serial.println("Queue Now"); + if (QueueMsg.state == MODE_MIC) { + InitI2SSpakerOrMic(MODE_MIC); + state = MODE_MIC; + } + } else if (state == MODE_MIC) { + fft_config_t* real_fft_plan = + fft_init(1024, FFT_REAL, FFT_FORWARD, NULL, NULL); + i2s_read(I2S_NUM_0, (char*)microRawData, 2048, &bytesread, + (100 / portTICK_RATE_MS)); + buffptr = (int16_t*)microRawData; + + for (int count_n = 0; count_n < real_fft_plan->size; count_n++) { + adc_data = (float)map(buffptr[count_n], INT16_MIN, INT16_MAX, + -2000, 2000); + real_fft_plan->input[count_n] = adc_data; + } + fft_execute(real_fft_plan); + + for (int count_n = 1; count_n < real_fft_plan->size / 4; + count_n++) { + data = sqrt(real_fft_plan->output[2 * count_n] * + real_fft_plan->output[2 * count_n] + + real_fft_plan->output[2 * count_n + 1] * + real_fft_plan->output[2 * count_n + 1]); + if ((count_n - 1) < 128) { + data = (data > 2000) ? 2000 : data; + ydata = map(data, 0, 2000, 0, 255); + FFTDataBuff[128 - count_n] = ydata; + } + } + + for (int count = 0; count < 24; count++) { + subData = 0; + for (int count_i = 0; count_i < 5; count_i++) { + subData += FFTDataBuff[count * 5 + count_i]; + } + subData /= 5; + FFTValueBuff[count] = map(subData, 0, 255, 0, 8); + } + xQueueSend(fftvalueQueue, (void*)&FFTValueBuff, 0); + fft_destroy(real_fft_plan); + } else { + delay(10); } - xQueueSend( fftvalueQueue, (void * )&FFTValueBuff, 0 ); - fft_destroy(real_fft_plan); - } - else - { - delay(10); } - } } -void microPhoneSetup() -{ - fftvalueQueue = xQueueCreate(5, 24 * sizeof(uint8_t)); - if( fftvalueQueue == 0 ) - { - return; - } +void microPhoneSetup() { + fftvalueQueue = xQueueCreate(5, 24 * sizeof(uint8_t)); + if (fftvalueQueue == 0) { + return; + } - i2sstateQueue = xQueueCreate(5, sizeof(i2sQueueMsg_t)); - if( i2sstateQueue == 0 ) - { - return; - } + i2sstateQueue = xQueueCreate(5, sizeof(i2sQueueMsg_t)); + if (i2sstateQueue == 0) { + return; + } - InitI2SSpakerOrMic(MODE_MIC); - xTaskCreatePinnedToCore(i2sMicroFFTtask, "microPhoneTask", 4096, NULL, 3, NULL, 0); + InitI2SSpakerOrMic(MODE_MIC); + xTaskCreatePinnedToCore(i2sMicroFFTtask, "microPhoneTask", 4096, NULL, 3, + NULL, 0); - DisFFTbuff.createSprite(320,54); + DisFFTbuff.createSprite(320, 54); } -void MicroPhoneFFT() -{ - uint8_t FFTValueBuff[24]; - xQueueReceive( fftvalueQueue, (void * )&FFTValueBuff, portMAX_DELAY ); - DisFFTbuff.fillRect(0,0,320,54,DisFFTbuff.color565(0x00,0x00,0x00)); - uint32_t colorY = DisFFTbuff.color565(0xff,0x9c,0x00); - uint32_t colorG = DisFFTbuff.color565(0x66,0xff,0x00); - uint32_t colorRect; - for( int x = 0; x < 24; x++ ) - { - for( int y = 0; y < 9; y++ ) - { - if( y < FFTValueBuff[23-x] ){ - colorRect = colorY; - }else if( y == FFTValueBuff[23-x] ){ - colorRect = colorG; - }else{ - continue; - } - DisFFTbuff.fillRect(x*12,54-y*6 - 5,5,5,colorRect); +void MicroPhoneFFT() { + uint8_t FFTValueBuff[24]; + xQueueReceive(fftvalueQueue, (void*)&FFTValueBuff, portMAX_DELAY); + DisFFTbuff.fillRect(0, 0, 320, 54, DisFFTbuff.color565(0x00, 0x00, 0x00)); + uint32_t colorY = DisFFTbuff.color565(0xff, 0x9c, 0x00); + uint32_t colorG = DisFFTbuff.color565(0x66, 0xff, 0x00); + uint32_t colorRect; + for (int x = 0; x < 24; x++) { + for (int y = 0; y < 9; y++) { + if (y < FFTValueBuff[23 - x]) { + colorRect = colorY; + } else if (y == FFTValueBuff[23 - x]) { + colorRect = colorG; + } else { + continue; + } + DisFFTbuff.fillRect(x * 12, 54 - y * 6 - 5, 5, 5, colorRect); + } } - } - DisFFTbuff.pushSprite(20, 120); + DisFFTbuff.pushSprite(20, 120); } - void setup() { - M5.begin(true, true, true, true); - M5.Lcd.fillScreen(BLACK); - M5.Lcd.setTextSize(1); - M5.Lcd.setTextColor(WHITE, BLACK); - M5.Lcd.fillRect(0, 0, 320, 30, BLACK); - M5.Lcd.setTextDatum(TC_DATUM); - M5.Lcd.drawString("PDM Unit", 160, 3, 4); - microPhoneSetup(); + M5.begin(true, true, true, true); + M5.Lcd.fillScreen(BLACK); + M5.Lcd.setTextSize(1); + M5.Lcd.setTextColor(WHITE, BLACK); + M5.Lcd.fillRect(0, 0, 320, 30, BLACK); + M5.Lcd.setTextDatum(TC_DATUM); + M5.Lcd.drawString("PDM Unit", 160, 3, 4); + microPhoneSetup(); } -void loop() { - MicroPhoneFFT(); -} +void loop() { MicroPhoneFFT(); } From 245c9d9380c7e01762c5941c9632d63fbf618847 Mon Sep 17 00:00:00 2001 From: Tinyu Date: Tue, 22 Feb 2022 18:55:47 +0800 Subject: [PATCH 11/16] Update FactoryTest.ino --- .../core2_for_aws/FactoryTest/FactoryTest.ino | 2393 ++++++++--------- 1 file changed, 1051 insertions(+), 1342 deletions(-) diff --git a/examples/core2_for_aws/FactoryTest/FactoryTest.ino b/examples/core2_for_aws/FactoryTest/FactoryTest.ino index d467c4c9..d2a05f92 100644 --- a/examples/core2_for_aws/FactoryTest/FactoryTest.ino +++ b/examples/core2_for_aws/FactoryTest/FactoryTest.ino @@ -1,26 +1,26 @@ /* Description: This case is used to test CORE FOR AWS. - Please install the following libraries before compiling: - 1) ArduinoECCX08: + Please install the following libraries before compiling: + 1) ArduinoECCX08: - Arduino menu --> Sketch --> Include Library --> Add .ZIP library... - - Location of the M5Core2 Arduino library --> examples --> core2_for_aws --> ArduinoECCX08.zip - 2) FastLED v3.4.0: + - Location of the M5Core2 Arduino library --> examples --> core2_for_aws + --> ArduinoECCX08.zip 2) FastLED v3.4.0: - Arduino menu --> Tools --> Manage Libraries - Library manager search bar --> "FastLED" - Install FastLED v3.4.0 by Daniel Garcia */ +#include #include #include -#include "fft.h" -#include "Fonts/EVA_20px.h" -#include "Fonts/EVA_11px.h" -#include "line3D.h" -#include "Wire.h" -#include "WiFi.h" #include "FastLED.h" -#include +#include "Fonts/EVA_11px.h" +#include "Fonts/EVA_20px.h" +#include "WiFi.h" +#include "Wire.h" +#include "fft.h" +#include "line3D.h" #define LEDS_PIN 25 #define LEDS_NUM 10 @@ -117,96 +117,72 @@ extern const unsigned char image_TouchFish_0004[1672]; extern const unsigned char image_TouchFish_0005[1672]; extern const unsigned char image_TouchFish_0006[1672]; -uint8_t *rectptrBuff[6] = -{ - (uint8_t*)image_rect_0001, - (uint8_t*)image_rect_0002, - (uint8_t*)image_rect_0003, - (uint8_t*)image_rect_0004, - (uint8_t*)image_rect_0005, - (uint8_t*)image_rect_0006, +uint8_t *rectptrBuff[6] = { + (uint8_t *)image_rect_0001, (uint8_t *)image_rect_0002, + (uint8_t *)image_rect_0003, (uint8_t *)image_rect_0004, + (uint8_t *)image_rect_0005, (uint8_t *)image_rect_0006, }; -uint8_t *rect320ptrBuff[7] = -{ - (uint8_t*)image_rect320_20_0001, - (uint8_t*)image_rect320_20_0002, - (uint8_t*)image_rect320_20_0003, - (uint8_t*)image_rect320_20_0004, - (uint8_t*)image_rect320_20_0005, - (uint8_t*)image_rect320_20_0006, - (uint8_t*)image_rect320_20_0007, +uint8_t *rect320ptrBuff[7] = { + (uint8_t *)image_rect320_20_0001, (uint8_t *)image_rect320_20_0002, + (uint8_t *)image_rect320_20_0003, (uint8_t *)image_rect320_20_0004, + (uint8_t *)image_rect320_20_0005, (uint8_t *)image_rect320_20_0006, + (uint8_t *)image_rect320_20_0007, }; -uint8_t *DigNumber[11] = -{ - (uint8_t*)image_DigNumber_0000_0, - (uint8_t*)image_DigNumber_0001_1, - (uint8_t*)image_DigNumber_0002_2, - (uint8_t*)image_DigNumber_0003_3, - (uint8_t*)image_DigNumber_0004_4, - (uint8_t*)image_DigNumber_0005_5, - (uint8_t*)image_DigNumber_0006_6, - (uint8_t*)image_DigNumber_0007_7, - (uint8_t*)image_DigNumber_0008_8, - (uint8_t*)image_DigNumber_0009_9, - (uint8_t*)image_DigNumber_0010_10, +uint8_t *DigNumber[11] = { + (uint8_t *)image_DigNumber_0000_0, (uint8_t *)image_DigNumber_0001_1, + (uint8_t *)image_DigNumber_0002_2, (uint8_t *)image_DigNumber_0003_3, + (uint8_t *)image_DigNumber_0004_4, (uint8_t *)image_DigNumber_0005_5, + (uint8_t *)image_DigNumber_0006_6, (uint8_t *)image_DigNumber_0007_7, + (uint8_t *)image_DigNumber_0008_8, (uint8_t *)image_DigNumber_0009_9, + (uint8_t *)image_DigNumber_0010_10, }; -uint8_t *DigNumber_35px[11] = -{ - (uint8_t*)image_DigNumber_35px_0000_0, - (uint8_t*)image_DigNumber_35px_0001_1, - (uint8_t*)image_DigNumber_35px_0002_2, - (uint8_t*)image_DigNumber_35px_0003_3, - (uint8_t*)image_DigNumber_35px_0004_4, - (uint8_t*)image_DigNumber_35px_0005_5, - (uint8_t*)image_DigNumber_35px_0006_6, - (uint8_t*)image_DigNumber_35px_0007_7, - (uint8_t*)image_DigNumber_35px_0008_8, - (uint8_t*)image_DigNumber_35px_0009_9, - (uint8_t*)image_DigNumber_35px_0010_10, +uint8_t *DigNumber_35px[11] = { + (uint8_t *)image_DigNumber_35px_0000_0, + (uint8_t *)image_DigNumber_35px_0001_1, + (uint8_t *)image_DigNumber_35px_0002_2, + (uint8_t *)image_DigNumber_35px_0003_3, + (uint8_t *)image_DigNumber_35px_0004_4, + (uint8_t *)image_DigNumber_35px_0005_5, + (uint8_t *)image_DigNumber_35px_0006_6, + (uint8_t *)image_DigNumber_35px_0007_7, + (uint8_t *)image_DigNumber_35px_0008_8, + (uint8_t *)image_DigNumber_35px_0009_9, + (uint8_t *)image_DigNumber_35px_0010_10, }; -uint8_t *Number_7x10px[16] = -{ - (uint8_t*)image_number8x7_01, // 0 - (uint8_t*)image_number8x7_02, // 1 - (uint8_t*)image_number8x7_03, // 2 - (uint8_t*)image_number8x7_04, // 3 - (uint8_t*)image_number8x7_05, // 4 - (uint8_t*)image_number8x7_06, // 5 - (uint8_t*)image_number8x7_07, // 6 - (uint8_t*)image_number8x7_08, // 7 - (uint8_t*)image_number8x7_09, // 8 - (uint8_t*)image_number8x7_10, // 9 - (uint8_t*)image_number8x7_11, // V - (uint8_t*)image_number8x7_12, // X - (uint8_t*)image_number8x7_13, // Y - (uint8_t*)image_number8x7_14, // : - (uint8_t*)image_number8x7_15, // CHARGING - (uint8_t*)image_number8x7_16, // G +uint8_t *Number_7x10px[16] = { + (uint8_t *)image_number8x7_01, // 0 + (uint8_t *)image_number8x7_02, // 1 + (uint8_t *)image_number8x7_03, // 2 + (uint8_t *)image_number8x7_04, // 3 + (uint8_t *)image_number8x7_05, // 4 + (uint8_t *)image_number8x7_06, // 5 + (uint8_t *)image_number8x7_07, // 6 + (uint8_t *)image_number8x7_08, // 7 + (uint8_t *)image_number8x7_09, // 8 + (uint8_t *)image_number8x7_10, // 9 + (uint8_t *)image_number8x7_11, // V + (uint8_t *)image_number8x7_12, // X + (uint8_t *)image_number8x7_13, // Y + (uint8_t *)image_number8x7_14, // : + (uint8_t *)image_number8x7_15, // CHARGING + (uint8_t *)image_number8x7_16, // G }; -uint8_t *batRect[7] = -{ - (uint8_t*)image_chaging_0001, - (uint8_t*)image_chaging_0002, - (uint8_t*)image_chaging_0003, - (uint8_t*)image_chaging_0004, - (uint8_t*)image_chaging_0005, - (uint8_t*)image_chaging_0006, - (uint8_t*)image_chaging_0007, +uint8_t *batRect[7] = { + (uint8_t *)image_chaging_0001, (uint8_t *)image_chaging_0002, + (uint8_t *)image_chaging_0003, (uint8_t *)image_chaging_0004, + (uint8_t *)image_chaging_0005, (uint8_t *)image_chaging_0006, + (uint8_t *)image_chaging_0007, }; -uint8_t *TouchFishBuff[7] = -{ - (uint8_t*)image_TouchFish_0001, - (uint8_t*)image_TouchFish_0002, - (uint8_t*)image_TouchFish_0003, - (uint8_t*)image_TouchFish_0004, - (uint8_t*)image_TouchFish_0005, - (uint8_t*)image_TouchFish_0006, +uint8_t *TouchFishBuff[7] = { + (uint8_t *)image_TouchFish_0001, (uint8_t *)image_TouchFish_0002, + (uint8_t *)image_TouchFish_0003, (uint8_t *)image_TouchFish_0004, + (uint8_t *)image_TouchFish_0005, (uint8_t *)image_TouchFish_0006, }; extern const unsigned char image_External[1425]; @@ -214,9 +190,9 @@ extern const unsigned char image_Internal[1425]; extern const unsigned char image_PowerC[310]; extern const unsigned char image_power[924]; -#define CONFIG_I2S_BCK_PIN 12 -#define CONFIG_I2S_LRCK_PIN 0 -#define CONFIG_I2S_DATA_PIN 2 +#define CONFIG_I2S_BCK_PIN 12 +#define CONFIG_I2S_LRCK_PIN 0 +#define CONFIG_I2S_DATA_PIN 2 #define CONFIG_I2S_DATA_IN_PIN 34 #define SPAKER_I2S_NUMBER I2S_NUM_0 @@ -224,17 +200,16 @@ extern const unsigned char image_power[924]; #define MODE_MIC 0 #define MODE_SPK 1 -typedef struct i2cDevice -{ - i2cDevice(){ - Name = ""; - addr = 0; +typedef struct i2cDevice { + i2cDevice() { + Name = ""; + addr = 0; nextPtr = nullptr; }; String Name; uint8_t addr; - struct i2cDevice* nextPtr; -}i2cDevice_t; + struct i2cDevice *nextPtr; +} i2cDevice_t; i2cDevice_t i2cParentptr; @@ -242,164 +217,153 @@ typedef enum { kPOWER_EXTERNAL = 0, kPOWER_INTERNAL, kPOWER_MAX -}system_power_t; +} system_power_t; -struct systemState -{ +struct systemState { RTC_TimeTypeDef Rtctime; system_power_t power = kPOWER_MAX; - uint16_t clockCount = 0; - uint16_t timeCount = 0; - uint16_t batCount = 0; + uint16_t clockCount = 0; + uint16_t timeCount = 0; + uint16_t batCount = 0; - uint8_t batVoltageBuff[15]; - uint8_t batVoltageWriteptr = 11; - uint8_t batVoltageReadptr = 0; + uint8_t batVoltageBuff[15]; + uint8_t batVoltageWriteptr = 11; + uint8_t batVoltageReadptr = 0; uint16_t batVoltageWriteCount = 0; - bool touchState = false; - bool SDCardState = false; + bool touchState = false; + bool SDCardState = false; uint16_t SDCardscaneCount = 0; - HotZone_t* App1Zone[6]; - HotZone_t* MPU6886; + HotZone_t *App1Zone[6]; + HotZone_t *MPU6886; - bool soundFlag = true; + bool soundFlag = true; -}sytState; +} sytState; static QueueHandle_t fftvalueQueue = nullptr; static QueueHandle_t i2sstateQueue = nullptr; -typedef struct -{ +typedef struct { uint8_t state; - void* audioPtr; + void *audioPtr; uint32_t audioSize; -}i2sQueueMsg_t; - - -TFT_eSprite Disbuff = TFT_eSprite(&M5.Lcd); -TFT_eSprite Dis3Dbuff = TFT_eSprite(&M5.Lcd); -TFT_eSprite DisClockbuff = TFT_eSprite(&M5.Lcd); -TFT_eSprite DisPowerbuff = TFT_eSprite(&M5.Lcd); -TFT_eSprite DisFFTbuff = TFT_eSprite(&M5.Lcd); -TFT_eSprite DisBatbuff = TFT_eSprite(&M5.Lcd); -TFT_eSprite DisTouchbuff = TFT_eSprite(&M5.Lcd); -TFT_eSprite DisSDCardbuff = TFT_eSprite(&M5.Lcd); -TFT_eSprite DisWarningbuff = TFT_eSprite(&M5.Lcd); +} i2sQueueMsg_t; + +TFT_eSprite Disbuff = TFT_eSprite(&M5.Lcd); +TFT_eSprite Dis3Dbuff = TFT_eSprite(&M5.Lcd); +TFT_eSprite DisClockbuff = TFT_eSprite(&M5.Lcd); +TFT_eSprite DisPowerbuff = TFT_eSprite(&M5.Lcd); +TFT_eSprite DisFFTbuff = TFT_eSprite(&M5.Lcd); +TFT_eSprite DisBatbuff = TFT_eSprite(&M5.Lcd); +TFT_eSprite DisTouchbuff = TFT_eSprite(&M5.Lcd); +TFT_eSprite DisSDCardbuff = TFT_eSprite(&M5.Lcd); +TFT_eSprite DisWarningbuff = TFT_eSprite(&M5.Lcd); TFT_eSprite DisCoverScrollbuff = TFT_eSprite(&M5.Lcd); // 40-80-119 130-160-200 230-270-310 -HotZone_t touchBtn0(10,241,120,280); -HotZone_t touchBtn1(130,241,200,280); -HotZone_t touchBtn2(230,241,310,280); +HotZone_t touchBtn0(10, 241, 120, 280); +HotZone_t touchBtn1(130, 241, 200, 280); +HotZone_t touchBtn2(230, 241, 310, 280); -#define FAILD_COLOR 255,35,35 -#define SUCCE_COLOR 255,255,255 +#define FAILD_COLOR 255, 35, 35 +#define SUCCE_COLOR 255, 255, 255 void setCheckState(int number, bool state, bool flush = false); -bool InitI2SSpakerOrMic(int mode) -{ +bool InitI2SSpakerOrMic(int mode) { esp_err_t err = ESP_OK; i2s_driver_uninstall(SPAKER_I2S_NUMBER); i2s_config_t i2s_config = { - .mode = (i2s_mode_t)(I2S_MODE_MASTER), + .mode = (i2s_mode_t)(I2S_MODE_MASTER), .sample_rate = 44100, - .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, // is fixed at 12bit, stereo, MSB - .channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT, - .communication_format = I2S_COMM_FORMAT_I2S, - .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, - .dma_buf_count = 2, - .dma_buf_len = 128, + .bits_per_sample = + I2S_BITS_PER_SAMPLE_16BIT, // is fixed at 12bit, stereo, MSB + .channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT, + .communication_format = I2S_COMM_FORMAT_STAND_I2S, + .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, + .dma_buf_count = 2, + .dma_buf_len = 128, }; - if (mode == MODE_MIC) - { - i2s_config.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_PDM); - } - else - { - i2s_config.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX); + if (mode == MODE_MIC) { + i2s_config.mode = + (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_PDM); + } else { + i2s_config.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX); i2s_config.use_apll = false; i2s_config.tx_desc_auto_clear = true; } - //Serial.println("Init i2s_driver_install"); + // Serial.println("Init i2s_driver_install"); err += i2s_driver_install(SPAKER_I2S_NUMBER, &i2s_config, 0, NULL); i2s_pin_config_t tx_pin_config; - #if (ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(4, 3, 0)) - tx_pin_config.mck_io_num = I2S_PIN_NO_CHANGE; - #endif - tx_pin_config.bck_io_num = CONFIG_I2S_BCK_PIN; - tx_pin_config.ws_io_num = CONFIG_I2S_LRCK_PIN; +#if (ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(4, 3, 0)) + tx_pin_config.mck_io_num = I2S_PIN_NO_CHANGE; +#endif + tx_pin_config.bck_io_num = CONFIG_I2S_BCK_PIN; + tx_pin_config.ws_io_num = CONFIG_I2S_LRCK_PIN; tx_pin_config.data_out_num = CONFIG_I2S_DATA_PIN; - tx_pin_config.data_in_num = CONFIG_I2S_DATA_IN_PIN; + tx_pin_config.data_in_num = CONFIG_I2S_DATA_IN_PIN; - //Serial.println("Init i2s_set_pin"); + // Serial.println("Init i2s_set_pin"); err += i2s_set_pin(SPAKER_I2S_NUMBER, &tx_pin_config); - //Serial.println("Init i2s_set_clk"); - err += i2s_set_clk(SPAKER_I2S_NUMBER, 44100, I2S_BITS_PER_SAMPLE_16BIT, I2S_CHANNEL_MONO); + // Serial.println("Init i2s_set_clk"); + err += i2s_set_clk(SPAKER_I2S_NUMBER, 44100, I2S_BITS_PER_SAMPLE_16BIT, + I2S_CHANNEL_MONO); return true; } - -void CoverScrollText(String strNext,uint32_t color) -{ +void CoverScrollText(String strNext, uint32_t color) { static String strLast; uint32_t colorLast = 0xffff; - uint32_t bkColor16 = DisCoverScrollbuff.color565(0x22,0x22,0x22); + uint32_t bkColor16 = DisCoverScrollbuff.color565(0x22, 0x22, 0x22); DisCoverScrollbuff.setFreeFont(&EVA_20px); DisCoverScrollbuff.setTextSize(1); - DisCoverScrollbuff.setTextColor(Disbuff.color565(255,0,0),bkColor16); + DisCoverScrollbuff.setTextColor(Disbuff.color565(255, 0, 0), bkColor16); DisCoverScrollbuff.setTextDatum(TC_DATUM); - DisCoverScrollbuff.fillRect(0,0,320,60,bkColor16); + DisCoverScrollbuff.fillRect(0, 0, 320, 60, bkColor16); DisCoverScrollbuff.setTextColor(color); - for( int i = 0; i < 20 ; i++ ) - { - DisCoverScrollbuff.fillRect(0,20,320,20,bkColor16); + for (int i = 0; i < 20; i++) { + DisCoverScrollbuff.fillRect(0, 20, 320, 20, bkColor16); DisCoverScrollbuff.setTextColor(colorLast); - DisCoverScrollbuff.drawString(strLast,160,20 - i); + DisCoverScrollbuff.drawString(strLast, 160, 20 - i); DisCoverScrollbuff.setTextColor(color); - DisCoverScrollbuff.drawString(strNext,160,40 - i); - DisCoverScrollbuff.fillRect(0,0,320,20,bkColor16); - DisCoverScrollbuff.fillRect(0,40,320,20,bkColor16); - delay(5); - DisCoverScrollbuff.pushSprite(0,150); + DisCoverScrollbuff.drawString(strNext, 160, 40 - i); + DisCoverScrollbuff.fillRect(0, 0, 320, 20, bkColor16); + DisCoverScrollbuff.fillRect(0, 40, 320, 20, bkColor16); + delay(5); + DisCoverScrollbuff.pushSprite(0, 150); } - strLast = strNext; + strLast = strNext; colorLast = color; } -void sysErrorSkip() -{ - uint32_t bkColor16 = Disbuff.color565(0x22,0x22,0x22); - //Disbuff.drawJpg(CoverImage,21301,0,0,320,240,0,0); - //Disbuff.fillRect(bkColor16) +void sysErrorSkip() { + uint32_t bkColor16 = Disbuff.color565(0x22, 0x22, 0x22); + // Disbuff.drawJpg(CoverImage,21301,0,0,320,240,0,0); + // Disbuff.fillRect(bkColor16) Disbuff.setFreeFont(&EVA_20px); - //Disbuff.setTextFont(1); + // Disbuff.setTextFont(1); Disbuff.setTextSize(1); - Disbuff.setTextColor(Disbuff.color565(0xff,0,0),bkColor16); + Disbuff.setTextColor(Disbuff.color565(0xff, 0, 0), bkColor16); Disbuff.setTextDatum(TC_DATUM); - Disbuff.pushInSprite(&DisCoverScrollbuff,0,0,320,60,0,150); - Disbuff.setCursor(94,220); + Disbuff.pushInSprite(&DisCoverScrollbuff, 0, 0, 320, 60, 0, 150); + Disbuff.setCursor(94, 220); Disbuff.print("Touch to Skip"); - //Disbuff.drawString("Touch to Skip",160,200); - Disbuff.pushSprite(0,0); - //M5.Axp.SetLDOEnable(3,false); + // Disbuff.drawString("Touch to Skip",160,200); + Disbuff.pushSprite(0, 0); + // M5.Axp.SetLDOEnable(3,false); - HotZone_t toucZone(0,0,320,280); + HotZone_t toucZone(0, 0, 320, 280); - while(1) - { - if( M5.Touch.ispressed()) - { + while (1) { + if (M5.Touch.ispressed()) { TouchPoint_t point = M5.Touch.getPressPoint(); - if( toucZone.inHotZone(point)) - { + if (toucZone.inHotZone(point)) { break; } } @@ -407,115 +371,95 @@ void sysErrorSkip() } } -void addI2cDevice(String name, uint8_t addr ) -{ +void addI2cDevice(String name, uint8_t addr) { i2cDevice_t *lastptr = &i2cParentptr; - - while(lastptr->nextPtr != nullptr ) - { + + while (lastptr->nextPtr != nullptr) { lastptr = lastptr->nextPtr; } - i2cDevice_t* ptr = ( i2cDevice_t * )calloc(1,sizeof(i2cDevice_t)); - ptr->Name = name; - ptr->addr = addr; - ptr->nextPtr = nullptr; + i2cDevice_t *ptr = (i2cDevice_t *)calloc(1, sizeof(i2cDevice_t)); + ptr->Name = name; + ptr->addr = addr; + ptr->nextPtr = nullptr; lastptr->nextPtr = ptr; } -int scani2caddr() -{ - for (int i = 0; i < 120; i++) - { +int scani2caddr() { + for (int i = 0; i < 120; i++) { Wire1.beginTransmission(i); - if (Wire1.endTransmission() == 0) - { + if (Wire1.endTransmission() == 0) { Serial.printf("%02X |FIND", i); Serial.println("."); } } return 0; } -int checkPsram() -{ - uint8_t* testbuff = ( uint8_t* )ps_calloc( 100*1024 ,sizeof(uint8_t)); - if( testbuff == nullptr ) - { - CoverScrollText("PSRAM malloc failed",M5.Lcd.color565(FAILD_COLOR)); +int checkPsram() { + uint8_t *testbuff = (uint8_t *)ps_calloc(100 * 1024, sizeof(uint8_t)); + if (testbuff == nullptr) { + CoverScrollText("PSRAM malloc failed", M5.Lcd.color565(FAILD_COLOR)); sysErrorSkip(); return -1; - } - else - { - CoverScrollText("PSRAM malloc Successful",M5.Lcd.color565(SUCCE_COLOR)); + } else { + CoverScrollText("PSRAM malloc Successful", + M5.Lcd.color565(SUCCE_COLOR)); } delay(100); - - for( size_t i = 0; i < 102400; i++ ) - { + + for (size_t i = 0; i < 102400; i++) { testbuff[i] = 0xA5; - if( testbuff[i] != 0xA5 ) - { - CoverScrollText("PSRAM read failed",M5.Lcd.color565(FAILD_COLOR)); + if (testbuff[i] != 0xA5) { + CoverScrollText("PSRAM read failed", M5.Lcd.color565(FAILD_COLOR)); sysErrorSkip(); return -1; } } - CoverScrollText("PSRAM W&R Successful",M5.Lcd.color565(SUCCE_COLOR)); + CoverScrollText("PSRAM W&R Successful", M5.Lcd.color565(SUCCE_COLOR)); return 0; } -int checkI2cAddr() -{ - uint8_t count = 0; +int checkI2cAddr() { + uint8_t count = 0; i2cDevice_t *lastptr = &i2cParentptr; - do{ + do { lastptr = lastptr->nextPtr; - Serial.printf("Addr:0x%02X - Name:%s\r\n",lastptr->addr,lastptr->Name.c_str()); - Wire1.beginTransmission( lastptr->addr ); - if ( Wire1.endTransmission() == ESP_OK ) - { + Serial.printf("Addr:0x%02X - Name:%s\r\n", lastptr->addr, + lastptr->Name.c_str()); + Wire1.beginTransmission(lastptr->addr); + if (Wire1.endTransmission() == ESP_OK) { String log = "I2C " + lastptr->Name + " Found"; - CoverScrollText(log,M5.Lcd.color565(SUCCE_COLOR)); - } - else - { + CoverScrollText(log, M5.Lcd.color565(SUCCE_COLOR)); + } else { String log = "I2C " + lastptr->Name + " Find failed"; - CoverScrollText(log,M5.Lcd.color565(FAILD_COLOR)); + CoverScrollText(log, M5.Lcd.color565(FAILD_COLOR)); sysErrorSkip(); } delay(100); count++; - }while(lastptr->nextPtr != nullptr ); + } while (lastptr->nextPtr != nullptr); return 0; } -int checkIMUInit() -{ - if( M5.IMU.Init() == 0 ) - { - CoverScrollText("IMU Check Successful",M5.Lcd.color565(SUCCE_COLOR)); - } - else - { - CoverScrollText("IMU Check failed",M5.Lcd.color565(FAILD_COLOR)); +int checkIMUInit() { + if (M5.IMU.Init() == 0) { + CoverScrollText("IMU Check Successful", M5.Lcd.color565(SUCCE_COLOR)); + } else { + CoverScrollText("IMU Check failed", M5.Lcd.color565(FAILD_COLOR)); sysErrorSkip(); } return 0; } -int checkAETCC608AInit() -{ - if (!myECCX08.begin()) - { - CoverScrollText("AT608A Check failed",M5.Lcd.color565(FAILD_COLOR)); - while (1)delay(100); - } - else - { - CoverScrollText("AT608A Check Successful",M5.Lcd.color565(SUCCE_COLOR)); +int checkAETCC608AInit() { + if (!myECCX08.begin()) { + CoverScrollText("AT608A Check failed", M5.Lcd.color565(FAILD_COLOR)); + while (1) delay(100); + } else { + CoverScrollText("AT608A Check Successful", + M5.Lcd.color565(SUCCE_COLOR)); } - + String serialNumber = myECCX08.serialNumber(); Serial.print("ECCX08 Serial Number = "); @@ -523,95 +467,77 @@ int checkAETCC608AInit() Serial.println(); myECCX08.end(); - Wire1.begin(21,22,100000UL); + Wire1.begin(21, 22, 100000UL); } -int checkSDCard() -{ +int checkSDCard() { sdcard_type_t Type = SD.cardType(); - if( Type == CARD_UNKNOWN || Type == CARD_NONE ) - { - CoverScrollText("SDCard Find failed",M5.Lcd.color565(FAILD_COLOR)); + if (Type == CARD_UNKNOWN || Type == CARD_NONE) { + CoverScrollText("SDCard Find failed", M5.Lcd.color565(FAILD_COLOR)); sysErrorSkip(); - } - else - { - CoverScrollText("SDCard Found",M5.Lcd.color565(SUCCE_COLOR)); + } else { + CoverScrollText("SDCard Found", M5.Lcd.color565(SUCCE_COLOR)); Serial.printf("SDCard Type = %d \r\n", Type); - Serial.printf("SDCard Size = %d \r\n", (int)(SD.cardSize() / 1024 / 1024)); + Serial.printf("SDCard Size = %d \r\n", + (int)(SD.cardSize() / 1024 / 1024)); } return 0; } void i2s_task(void *arg) { size_t bytes_written = 0; - //Core2CovreSig[160908] - i2s_write(SPAKER_I2S_NUMBER, previewR, 120264, &bytes_written, portMAX_DELAY); - //delay(500); + // Core2CovreSig[160908] + i2s_write(SPAKER_I2S_NUMBER, previewR, 120264, &bytes_written, + portMAX_DELAY); + // delay(500); vTaskDelete(NULL); } -void powerSetup() -{ - DisPowerbuff.createSprite(77,102); - DisPowerbuff.fillRect(0,0,77,102,TFT_BLACK); - DisPowerbuff.drawColorBitmap(0,39,77,24, - (uint8_t*)image_power, - 0xff9c00, - 0x000000); - DisPowerbuff.pushSprite(240,3); +void powerSetup() { + DisPowerbuff.createSprite(77, 102); + DisPowerbuff.fillRect(0, 0, 77, 102, TFT_BLACK); + DisPowerbuff.drawColorBitmap(0, 39, 77, 24, (uint8_t *)image_power, + 0xff9c00, 0x000000); + DisPowerbuff.pushSprite(240, 3); } -void choosePower() -{ - uint32_t color1 = 0,color2 = 0; - uint16_t posy = 6; +void choosePower() { + uint32_t color1 = 0, color2 = 0; + uint16_t posy = 6; system_power_t PowerNow; - PowerNow = ( M5.Axp.isACIN()) ? kPOWER_EXTERNAL : kPOWER_INTERNAL; + PowerNow = (M5.Axp.isACIN()) ? kPOWER_EXTERNAL : kPOWER_INTERNAL; - if( PowerNow == sytState.power ) return; + if (PowerNow == sytState.power) return; - if( PowerNow == kPOWER_EXTERNAL ) - { + if (PowerNow == kPOWER_EXTERNAL) { color1 = 0x6c6c6c; color2 = 0xff9c00; - posy = 68; - } - else - { + posy = 68; + } else { color2 = 0x6c6c6c; color1 = 0xff9c00; - posy = 3; + posy = 3; } - DisPowerbuff.fillRect(0,3,77,37,TFT_BLACK); - DisPowerbuff.fillRect(0,68,77,37,TFT_BLACK); + DisPowerbuff.fillRect(0, 3, 77, 37, TFT_BLACK); + DisPowerbuff.fillRect(0, 68, 77, 37, TFT_BLACK); - DisPowerbuff.drawColorBitmap(0,0,77,37, - (uint8_t*)image_Internal, - color1, - 0x000000); + DisPowerbuff.drawColorBitmap(0, 0, 77, 37, (uint8_t *)image_Internal, + color1, 0x000000); - DisPowerbuff.drawColorBitmap(0,65,77,37, - (uint8_t*)image_External, - color2, - 0x000000); + DisPowerbuff.drawColorBitmap(0, 65, 77, 37, (uint8_t *)image_External, + color2, 0x000000); - DisPowerbuff.drawColorBitmap(54,posy,20,31, - (uint8_t*)image_PowerC, - 0xae2828, - 0x000000); + DisPowerbuff.drawColorBitmap(54, posy, 20, 31, (uint8_t *)image_PowerC, + 0xae2828, 0x000000); - DisPowerbuff.drawColorBitmap(0,39,77,24, - (uint8_t*)image_power, - 0xff9c00, - 0x000000); - - - DisPowerbuff.pushSprite(240,3); + DisPowerbuff.drawColorBitmap(0, 39, 77, 24, (uint8_t *)image_power, + 0xff9c00, 0x000000); + + DisPowerbuff.pushSprite(240, 3); sytState.power = PowerNow; } @@ -622,19 +548,19 @@ line_3d_t rect[12] = { {.start_point = {-1, 1, 1}, .end_point = {-1, -1, 1}}, { .start_point = {-1, -1, 1}, - .end_point = {-1, -1, -1}, + .end_point = {-1, -1, -1}, }, { .start_point = {1, -1, 1}, - .end_point = {1, -1, -1}, + .end_point = {1, -1, -1}, }, { .start_point = {1, 1, 1}, - .end_point = {1, 1, -1}, + .end_point = {1, 1, -1}, }, { .start_point = {-1, 1, 1}, - .end_point = {-1, 1, -1}, + .end_point = {-1, 1, -1}, }, {.start_point = {-1, -1, -1}, .end_point = {1, -1, -1}}, {.start_point = {1, -1, -1}, .end_point = {1, 1, -1}}, @@ -643,30 +569,27 @@ line_3d_t rect[12] = { }; line_3d_t rect_source[12]; -//85 56 -void setup3D() -{ - Dis3Dbuff.createSprite(85,56); - Dis3Dbuff.fillRect(0,0,85,56,Dis3Dbuff.color565(0x33,0x20,0x00)); - for (int n = 0; n < 12; n++) - { +// 85 56 +void setup3D() { + Dis3Dbuff.createSprite(85, 56); + Dis3Dbuff.fillRect(0, 0, 85, 56, Dis3Dbuff.color565(0x33, 0x20, 0x00)); + for (int n = 0; n < 12; n++) { rect_source[n].start_point.x = rect[n].start_point.x * 12; rect_source[n].start_point.y = rect[n].start_point.y * 12; rect_source[n].start_point.z = rect[n].start_point.z * 12; - rect_source[n].end_point.x = rect[n].end_point.x * 12; - rect_source[n].end_point.y = rect[n].end_point.y * 12; - rect_source[n].end_point.z = rect[n].end_point.z * 12; + rect_source[n].end_point.x = rect[n].end_point.x * 12; + rect_source[n].end_point.y = rect[n].end_point.y * 12; + rect_source[n].end_point.z = rect[n].end_point.z * 12; } } -void Polar2Cartesian(double Angle, double radius, point_2d_t *point, int16_t offsetX = 42, int16_t officeY = 28) -{ - point->x = radius * cos( Angle ) + offsetX; - point->y = officeY - radius * sin( Angle ); +void Polar2Cartesian(double Angle, double radius, point_2d_t *point, + int16_t offsetX = 42, int16_t officeY = 28) { + point->x = radius * cos(Angle) + offsetX; + point->y = officeY - radius * sin(Angle); } -void MPU6886Test() -{ +void MPU6886Test() { float accX = 0; float accY = 0; float accZ = 0; @@ -675,35 +598,27 @@ void MPU6886Test() double phi = 0, last_phi = 0; double alpha = 0.2; - line_3d_t x = { - .start_point = {0, 0, 0}, - .end_point = {0, 0, 0}}; - line_3d_t y = { - .start_point = {0, 0, 0}, - .end_point = {0, 0, 0}}; - line_3d_t z = { - .start_point = {0, 0, 0}, - .end_point = {0, 0, 30}}; + line_3d_t x = {.start_point = {0, 0, 0}, .end_point = {0, 0, 0}}; + line_3d_t y = {.start_point = {0, 0, 0}, .end_point = {0, 0, 0}}; + line_3d_t z = {.start_point = {0, 0, 0}, .end_point = {0, 0, 30}}; line_3d_t rect_dis; line3D line3d; - line3d.setZeroOffset(42,28); + line3d.setZeroOffset(42, 28); M5.IMU.getAccelData(&accX, &accY, &accZ); - if ((accX < 1) && (accX > -1)) - { + if ((accX < 1) && (accX > -1)) { theta = asin(-accX) * 57.295; } - if (accZ != 0) - { + if (accZ != 0) { phi = atan(accY / accZ) * 57.295; } theta = alpha * theta + (1 - alpha) * last_theta; - phi = alpha * phi + (1 - alpha) * last_phi; + phi = alpha * phi + (1 - alpha) * last_phi; - Dis3Dbuff.fillRect(0,0,85,56,Dis3Dbuff.color565(0x33,0x20,0x00)); + Dis3Dbuff.fillRect(0, 0, 85, 56, Dis3Dbuff.color565(0x33, 0x20, 0x00)); z.end_point.x = 0; z.end_point.y = 0; z.end_point.z = 24; @@ -715,90 +630,84 @@ void MPU6886Test() line3d.printLine3D(&Dis3Dbuff, &y, TFT_GREEN); line3d.printLine3D(&Dis3Dbuff, &z, TFT_GREEN); - uint16_t linecolor = Dis3Dbuff.color565(0xff,0x9c,0x00); + uint16_t linecolor = Dis3Dbuff.color565(0xff, 0x9c, 0x00); - for (int n = 0; n < 12; n++) - { - line3d.RotatePoint(&rect_source[n].start_point, &rect_dis.start_point, theta, phi, (double)0); - line3d.RotatePoint(&rect_source[n].end_point, &rect_dis.end_point, theta, phi, (double)0); + for (int n = 0; n < 12; n++) { + line3d.RotatePoint(&rect_source[n].start_point, &rect_dis.start_point, + theta, phi, (double)0); + line3d.RotatePoint(&rect_source[n].end_point, &rect_dis.end_point, + theta, phi, (double)0); line3d.printLine3D(&Dis3Dbuff, &rect_dis, linecolor); } - Dis3Dbuff.pushSprite(74,130); + Dis3Dbuff.pushSprite(74, 130); last_theta = theta; - last_phi = phi; + last_phi = phi; } -void clockSetup() -{ +void clockSetup() { RTC_TimeTypeDef RTCTime; - RTCTime.Hours = 23; + RTCTime.Hours = 23; RTCTime.Minutes = 33; RTCTime.Seconds = 33; M5.Rtc.SetTime(&RTCTime); - DisClockbuff.createSprite(164,101); - DisClockbuff.drawJpg(clockImage,18401,0,0,163,101); + DisClockbuff.createSprite(164, 101); + DisClockbuff.drawJpg(clockImage, 18401, 0, 0, 163, 101); } -void clockFlush() -{ - uint16_t posx[6] = { 4, 28, 66, 90, 127, 144 }; +void clockFlush() { + uint16_t posx[6] = {4, 28, 66, 90, 127, 144}; - DisClockbuff.fillRect(0, 20, 162, 50, DisClockbuff.color565(0x1a, 0x11, 0x00)); - DisClockbuff.fillRect(0, 25, 2 , 45, DisClockbuff.color565(0xff, 0x9c, 0x00)); + DisClockbuff.fillRect(0, 20, 162, 50, + DisClockbuff.color565(0x1a, 0x11, 0x00)); + DisClockbuff.fillRect(0, 25, 2, 45, + DisClockbuff.color565(0xff, 0x9c, 0x00)); - DisClockbuff.fillRect(56,35, 5 , 5 , DisClockbuff.color565(0xff, 0x9c, 0x00)); - DisClockbuff.fillRect(56,54, 5 , 5 , DisClockbuff.color565(0xff, 0x9c, 0x00)); + DisClockbuff.fillRect(56, 35, 5, 5, + DisClockbuff.color565(0xff, 0x9c, 0x00)); + DisClockbuff.fillRect(56, 54, 5, 5, + DisClockbuff.color565(0xff, 0x9c, 0x00)); - DisClockbuff.fillRect(118,40, 5 , 5 , DisClockbuff.color565(0xff, 0x9c, 0x00)); - DisClockbuff.fillRect(118,57, 5 , 5 , DisClockbuff.color565(0xff, 0x9c, 0x00)); + DisClockbuff.fillRect(118, 40, 5, 5, + DisClockbuff.color565(0xff, 0x9c, 0x00)); + DisClockbuff.fillRect(118, 57, 5, 5, + DisClockbuff.color565(0xff, 0x9c, 0x00)); M5.Rtc.GetTime(&sytState.Rtctime); - - DisClockbuff.drawColorBitmap(posx[0],26,24,42, - DigNumber[ sytState.Rtctime.Hours / 10 ], - 0xff9c00, - 0x1a1100); - DisClockbuff.drawColorBitmap(posx[1],26,24,42, - DigNumber[ sytState.Rtctime.Hours % 10 ], - 0xff9c00, - 0x1a1100); - DisClockbuff.drawColorBitmap(posx[2],26,24,42, - DigNumber[ sytState.Rtctime.Minutes / 10 ], - 0xff9c00, - 0x1a1100); - DisClockbuff.drawColorBitmap(posx[3],26,24,42, - DigNumber[ sytState.Rtctime.Minutes % 10 ], - 0xff9c00, - 0x1a1100); - DisClockbuff.drawColorBitmap(posx[4],33,18,35, - DigNumber_35px[ sytState.Rtctime.Seconds / 10 ], - 0xff9c00, - 0x1a1100); - DisClockbuff.drawColorBitmap(posx[5],33,18,35, - DigNumber_35px[ sytState.Rtctime.Seconds % 10 ], - 0xff9c00, - 0x1a1100); - - - sytState.clockCount ++; - sytState.clockCount %= 6; - DisClockbuff.drawColorBitmap(0,0,164,17, - rectptrBuff[sytState.clockCount], - 0xff9c00, - 0x000000); + DisClockbuff.drawColorBitmap(posx[0], 26, 24, 42, + DigNumber[sytState.Rtctime.Hours / 10], + 0xff9c00, 0x1a1100); + DisClockbuff.drawColorBitmap(posx[1], 26, 24, 42, + DigNumber[sytState.Rtctime.Hours % 10], + 0xff9c00, 0x1a1100); + DisClockbuff.drawColorBitmap(posx[2], 26, 24, 42, + DigNumber[sytState.Rtctime.Minutes / 10], + 0xff9c00, 0x1a1100); + DisClockbuff.drawColorBitmap(posx[3], 26, 24, 42, + DigNumber[sytState.Rtctime.Minutes % 10], + 0xff9c00, 0x1a1100); + DisClockbuff.drawColorBitmap(posx[4], 33, 18, 35, + DigNumber_35px[sytState.Rtctime.Seconds / 10], + 0xff9c00, 0x1a1100); + DisClockbuff.drawColorBitmap(posx[5], 33, 18, 35, + DigNumber_35px[sytState.Rtctime.Seconds % 10], + 0xff9c00, 0x1a1100); + + sytState.clockCount++; + sytState.clockCount %= 6; + DisClockbuff.drawColorBitmap( + 0, 0, 164, 17, rectptrBuff[sytState.clockCount], 0xff9c00, 0x000000); - DisClockbuff.pushSprite(72,4); + DisClockbuff.pushSprite(72, 4); } -static void i2sMicroFFTtask(void *arg) -{ +static void i2sMicroFFTtask(void *arg) { uint8_t FFTDataBuff[128]; uint8_t FFTValueBuff[24]; - uint8_t* microRawData = (uint8_t*)calloc(2048,sizeof(uint8_t)); + uint8_t *microRawData = (uint8_t *)calloc(2048, sizeof(uint8_t)); size_t bytesread; - int16_t* buffptr; + int16_t *buffptr; double data = 0; float adc_data; uint16_t ydata; @@ -806,628 +715,534 @@ static void i2sMicroFFTtask(void *arg) uint8_t state = MODE_MIC; i2sQueueMsg_t QueueMsg; - while(1) - { - if( xQueueReceive(i2sstateQueue,&QueueMsg,(TickType_t)0) == pdTRUE) - { - //Serial.println("Queue Now"); - if( QueueMsg.state == MODE_MIC ) - { + while (1) { + if (xQueueReceive(i2sstateQueue, &QueueMsg, (TickType_t)0) == pdTRUE) { + // Serial.println("Queue Now"); + if (QueueMsg.state == MODE_MIC) { InitI2SSpakerOrMic(MODE_MIC); state = MODE_MIC; - } - else - { - //Serial.println("Spaker"); - //Serial.printf("Length:%d",QueueMsg.audioSize); + } else { + // Serial.println("Spaker"); + // Serial.printf("Length:%d",QueueMsg.audioSize); InitI2SSpakerOrMic(MODE_SPK); size_t written = 0; - i2s_write(SPAKER_I2S_NUMBER,(unsigned char*)QueueMsg.audioPtr,QueueMsg.audioSize,&written,portMAX_DELAY); + i2s_write(SPAKER_I2S_NUMBER, (unsigned char *)QueueMsg.audioPtr, + QueueMsg.audioSize, &written, portMAX_DELAY); state = MODE_SPK; } - } - else if( state == MODE_MIC ) - { - fft_config_t *real_fft_plan = fft_init(1024, FFT_REAL, FFT_FORWARD, NULL, NULL); - i2s_read(I2S_NUM_0, (char *)microRawData, 2048, &bytesread, (100 / portTICK_RATE_MS)); - buffptr = ( int16_t*)microRawData; - - for ( int count_n = 0; count_n < real_fft_plan->size; count_n++) - { - adc_data = (float)map(buffptr[count_n], INT16_MIN, INT16_MAX, -2000, 2000); + } else if (state == MODE_MIC) { + fft_config_t *real_fft_plan = + fft_init(1024, FFT_REAL, FFT_FORWARD, NULL, NULL); + i2s_read(I2S_NUM_0, (char *)microRawData, 2048, &bytesread, + (100 / portTICK_RATE_MS)); + buffptr = (int16_t *)microRawData; + + for (int count_n = 0; count_n < real_fft_plan->size; count_n++) { + adc_data = (float)map(buffptr[count_n], INT16_MIN, INT16_MAX, + -2000, 2000); real_fft_plan->input[count_n] = adc_data; } fft_execute(real_fft_plan); - for ( int count_n = 1; count_n < real_fft_plan->size / 4; count_n++) - { - data = sqrt(real_fft_plan->output[2 * count_n] * real_fft_plan->output[2 * count_n] + real_fft_plan->output[2 * count_n + 1] * real_fft_plan->output[2 * count_n + 1]); - if ((count_n - 1) < 128) - { - data = ( data > 2000 ) ? 2000 : data; - ydata = map(data, 0, 2000, 0, 255); + for (int count_n = 1; count_n < real_fft_plan->size / 4; + count_n++) { + data = sqrt(real_fft_plan->output[2 * count_n] * + real_fft_plan->output[2 * count_n] + + real_fft_plan->output[2 * count_n + 1] * + real_fft_plan->output[2 * count_n + 1]); + if ((count_n - 1) < 128) { + data = (data > 2000) ? 2000 : data; + ydata = map(data, 0, 2000, 0, 255); FFTDataBuff[128 - count_n] = ydata; } } - for( int count = 0; count < 24; count++ ) - { + for (int count = 0; count < 24; count++) { subData = 0; - for( int count_i = 0; count_i < 5; count_i++ ) - { - subData += FFTDataBuff[count * 5 + count_i ]; + for (int count_i = 0; count_i < 5; count_i++) { + subData += FFTDataBuff[count * 5 + count_i]; } subData /= 5; - FFTValueBuff[count] = map(subData,0,255,0,8); + FFTValueBuff[count] = map(subData, 0, 255, 0, 8); } - xQueueSend( fftvalueQueue, (void * )&FFTValueBuff, 0 ); + xQueueSend(fftvalueQueue, (void *)&FFTValueBuff, 0); fft_destroy(real_fft_plan); - //Serial.printf("mmp\r\n"); - } - else - { + // Serial.printf("mmp\r\n"); + } else { delay(10); } } } -void microPhoneSetup() -{ +void microPhoneSetup() { fftvalueQueue = xQueueCreate(5, 24 * sizeof(uint8_t)); - if( fftvalueQueue == 0 ) - { + if (fftvalueQueue == 0) { return; } i2sstateQueue = xQueueCreate(5, sizeof(i2sQueueMsg_t)); - if( i2sstateQueue == 0 ) - { + if (i2sstateQueue == 0) { return; } InitI2SSpakerOrMic(MODE_MIC); - xTaskCreatePinnedToCore(i2sMicroFFTtask, "microPhoneTask", 4096, NULL, 3, NULL, 0); + xTaskCreatePinnedToCore(i2sMicroFFTtask, "microPhoneTask", 4096, NULL, 3, + NULL, 0); - DisFFTbuff.createSprite(143,54); + DisFFTbuff.createSprite(143, 54); } -void MicroPhoneFFT() -{ +void MicroPhoneFFT() { uint8_t FFTValueBuff[24]; - xQueueReceive( fftvalueQueue, (void * )&FFTValueBuff, portMAX_DELAY ); - DisFFTbuff.fillRect(0,0,143,54,DisFFTbuff.color565(0x33,0x20,0x00)); - uint32_t colorY = DisFFTbuff.color565(0xff,0x9c,0x00); - uint32_t colorG = DisFFTbuff.color565(0x66,0xff,0x00); + xQueueReceive(fftvalueQueue, (void *)&FFTValueBuff, portMAX_DELAY); + DisFFTbuff.fillRect(0, 0, 143, 54, DisFFTbuff.color565(0x33, 0x20, 0x00)); + uint32_t colorY = DisFFTbuff.color565(0xff, 0x9c, 0x00); + uint32_t colorG = DisFFTbuff.color565(0x66, 0xff, 0x00); uint32_t colorRect; - for( int x = 0; x < 24; x++ ) - { - for( int y = 0; y < 9; y++ ) - { - if( y < FFTValueBuff[23-x] ) - { + for (int x = 0; x < 24; x++) { + for (int y = 0; y < 9; y++) { + if (y < FFTValueBuff[23 - x]) { colorRect = colorY; - } - else if( y == FFTValueBuff[23-x] ) - { + } else if (y == FFTValueBuff[23 - x]) { colorRect = colorG; - } - else - { + } else { continue; } - DisFFTbuff.fillRect(x*6,54-y*6 - 5,5,5,colorRect); + DisFFTbuff.fillRect(x * 6, 54 - y * 6 - 5, 5, 5, colorRect); } } - DisFFTbuff.pushSprite(170,130); + DisFFTbuff.pushSprite(170, 130); } -void batPowerSetup() -{ - DisBatbuff.createSprite(64,82); - DisBatbuff.drawJpg(batPowerImage,13769,0,0,64,82); - DisBatbuff.pushSprite(3,61); +void batPowerSetup() { + DisBatbuff.createSprite(64, 82); + DisBatbuff.drawJpg(batPowerImage, 13769, 0, 0, 64, 82); + DisBatbuff.pushSprite(3, 61); } -void batpowerFlush() -{ - uint32_t colorY = DisFFTbuff.color565(0xff,0x9c,0x00); - uint32_t color = ( M5.Axp.isACIN()) ? 0x66ff00 : 0x6c6c6c; - - DisBatbuff.drawColorBitmap(3,37,60,10, - Number_7x10px[14], - color, - 0x000000); - - DisBatbuff.fillRect(10,27,2,2,colorY); - DisBatbuff.fillRect(55,4,6,10,colorY); - //80 - //3,13,20,30 - - float batVoltage = M5.Axp.GetBatVoltage(); - float batPercentage = ( batVoltage < 3.2 ) ? 0 : ( batVoltage - 3.2 ) * 100; - int rectwidth = 27 - 27 * ( int )batPercentage / 100; +void batpowerFlush() { + uint32_t colorY = DisFFTbuff.color565(0xff, 0x9c, 0x00); + uint32_t color = (M5.Axp.isACIN()) ? 0x66ff00 : 0x6c6c6c; + + DisBatbuff.drawColorBitmap(3, 37, 60, 10, Number_7x10px[14], color, + 0x000000); + + DisBatbuff.fillRect(10, 27, 2, 2, colorY); + DisBatbuff.fillRect(55, 4, 6, 10, colorY); + // 80 + // 3,13,20,30 + + float batVoltage = M5.Axp.GetBatVoltage(); + float batPercentage = (batVoltage < 3.2) ? 0 : (batVoltage - 3.2) * 100; + int rectwidth = 27 - 27 * (int)batPercentage / 100; uint8_t batVoltage1 = (uint16_t)batVoltage % 10; - uint8_t batVoltage2 = (uint16_t)(batVoltage*10) % 10; - - DisBatbuff.drawColorBitmap(3,20,7,10, - Number_7x10px[batVoltage1], - 0xff9c00, - 0x000000); - - DisBatbuff.drawColorBitmap(13,20,7,10, - Number_7x10px[batVoltage2], - 0xff9c00, - 0x000000); - - DisBatbuff.drawColorBitmap(20,20,7,10, - Number_7x10px[10], - 0xff9c00, - 0x000000); - - DisBatbuff.drawRect(29,17,31,15,colorY); - - if( M5.Axp.isACIN()) - { - sytState.batCount ++; + uint8_t batVoltage2 = (uint16_t)(batVoltage * 10) % 10; + + DisBatbuff.drawColorBitmap(3, 20, 7, 10, Number_7x10px[batVoltage1], + 0xff9c00, 0x000000); + + DisBatbuff.drawColorBitmap(13, 20, 7, 10, Number_7x10px[batVoltage2], + 0xff9c00, 0x000000); + + DisBatbuff.drawColorBitmap(20, 20, 7, 10, Number_7x10px[10], 0xff9c00, + 0x000000); + + DisBatbuff.drawRect(29, 17, 31, 15, colorY); + + if (M5.Axp.isACIN()) { + sytState.batCount++; sytState.batCount %= 7; } - DisBatbuff.drawColorBitmap(31,19,27,11, - batRect[sytState.batCount], - 0xff9c00, - 0x000000); + DisBatbuff.drawColorBitmap(31, 19, 27, 11, batRect[sytState.batCount], + 0xff9c00, 0x000000); - DisBatbuff.fillRect(58 - rectwidth,19,rectwidth,11,TFT_BLACK); + DisBatbuff.fillRect(58 - rectwidth, 19, rectwidth, 11, TFT_BLACK); - if( sytState.batVoltageWriteCount > 50 ) - { + if (sytState.batVoltageWriteCount > 50) { sytState.batVoltageWriteCount = 0; - sytState.batVoltageBuff[sytState.batVoltageWriteptr] = ( batPercentage / 20 ) + 1; + sytState.batVoltageBuff[sytState.batVoltageWriteptr] = + (batPercentage / 20) + 1; sytState.batVoltageWriteptr++; sytState.batVoltageReadptr++; sytState.batVoltageWriteptr %= 15; sytState.batVoltageReadptr %= 15; - DisBatbuff.fillRect(6,50,55,29,DisBatbuff.color565(0x33, 0x20, 0x00)); + DisBatbuff.fillRect(6, 50, 55, 29, + DisBatbuff.color565(0x33, 0x20, 0x00)); - for( int i = 0; i < 11; i++ ) - { - int lim = sytState.batVoltageBuff[(sytState.batVoltageReadptr + i) % 15 ]; - for( int y = 0; y < lim; y++ ) - { - DisBatbuff.fillRect(6 + i * 5 ,74 - y * 5,4,4,colorY); + for (int i = 0; i < 11; i++) { + int lim = + sytState.batVoltageBuff[(sytState.batVoltageReadptr + i) % 15]; + for (int y = 0; y < lim; y++) { + DisBatbuff.fillRect(6 + i * 5, 74 - y * 5, 4, 4, colorY); } } } sytState.batVoltageWriteCount++; - DisBatbuff.pushSprite(3,61); + DisBatbuff.pushSprite(3, 61); } -void touchsetup() -{ - DisTouchbuff.createSprite(64,40); - DisTouchbuff.drawJpg(touchImage,12262,0,0,64,40); - - //uint32_t colorY = DisTouchbuff.color565(0xff,0x9c,0x00); - uint32_t colorGREY = DisTouchbuff.color565(0x30,0x30,0x30); - - DisTouchbuff.drawColorBitmap(12,15,7,10, - (uint8_t*)Number_7x10px[11], - 0xff9c00, - 0x000000); - DisTouchbuff.drawColorBitmap(19,15,3,10, - (uint8_t*)Number_7x10px[13], - 0xff9c00, - 0x000000); - - DisTouchbuff.drawColorBitmap(12,26,7,10, - (uint8_t*)Number_7x10px[12], - 0xff9c00, - 0x000000); - DisTouchbuff.drawColorBitmap(19,26,3,10, - (uint8_t*)Number_7x10px[13], - 0xff9c00, - 0x000000); - for( int i = 0; i < 3; i++ ) - { - int number = ( 0 / (int)( pow( 10 , ( 2 - i )))) % 10; - DisTouchbuff.drawColorBitmap(22 + i * 7,15,7,10, - (uint8_t*)Number_7x10px[number], - 0xff9c00, - 0x000000); +void touchsetup() { + DisTouchbuff.createSprite(64, 40); + DisTouchbuff.drawJpg(touchImage, 12262, 0, 0, 64, 40); + + // uint32_t colorY = DisTouchbuff.color565(0xff,0x9c,0x00); + uint32_t colorGREY = DisTouchbuff.color565(0x30, 0x30, 0x30); + + DisTouchbuff.drawColorBitmap(12, 15, 7, 10, (uint8_t *)Number_7x10px[11], + 0xff9c00, 0x000000); + DisTouchbuff.drawColorBitmap(19, 15, 3, 10, (uint8_t *)Number_7x10px[13], + 0xff9c00, 0x000000); + + DisTouchbuff.drawColorBitmap(12, 26, 7, 10, (uint8_t *)Number_7x10px[12], + 0xff9c00, 0x000000); + DisTouchbuff.drawColorBitmap(19, 26, 3, 10, (uint8_t *)Number_7x10px[13], + 0xff9c00, 0x000000); + for (int i = 0; i < 3; i++) { + int number = (0 / (int)(pow(10, (2 - i)))) % 10; + DisTouchbuff.drawColorBitmap(22 + i * 7, 15, 7, 10, + (uint8_t *)Number_7x10px[number], 0xff9c00, + 0x000000); } - for( int i = 0; i < 3; i++ ) - { - int number = ( 0 / (int)( pow( 10 , ( 2 - i )))) % 10; - DisTouchbuff.drawColorBitmap(22 + i * 7,26,7,10, - (uint8_t*)Number_7x10px[number], - 0xff9c00, - 0x000000); + for (int i = 0; i < 3; i++) { + int number = (0 / (int)(pow(10, (2 - i)))) % 10; + DisTouchbuff.drawColorBitmap(22 + i * 7, 26, 7, 10, + (uint8_t *)Number_7x10px[number], 0xff9c00, + 0x000000); } - DisTouchbuff.fillRect(5,15,5,21,TFT_BLACK); - DisTouchbuff.fillRect(46,4,15,8,colorGREY); - DisTouchbuff.fillRect(46,16,15,8,colorGREY); - DisTouchbuff.fillRect(46,28,15,8,colorGREY); + DisTouchbuff.fillRect(5, 15, 5, 21, TFT_BLACK); + DisTouchbuff.fillRect(46, 4, 15, 8, colorGREY); + DisTouchbuff.fillRect(46, 16, 15, 8, colorGREY); + DisTouchbuff.fillRect(46, 28, 15, 8, colorGREY); - DisTouchbuff.pushSprite(3,146); + DisTouchbuff.pushSprite(3, 146); } -void touchflush() -{ - TouchPoint_t pos= M5.Touch.getPressPoint(); - bool touchStateNow = ( pos.x == -1 ) ? false : true; - +void touchflush() { + TouchPoint_t pos = M5.Touch.getPressPoint(); + bool touchStateNow = (pos.x == -1) ? false : true; + uint32_t color; i2sQueueMsg_t msg; - msg.state = MODE_SPK; - msg.audioPtr = (void*)bibiSig; + msg.state = MODE_SPK; + msg.audioPtr = (void *)bibiSig; msg.audioSize = 8820; - if( touchStateNow ) - { - if( sytState.touchState == false ) - { - xQueueSend(i2sstateQueue,&msg,(TickType_t)100); + if (touchStateNow) { + if (sytState.touchState == false) { + xQueueSend(i2sstateQueue, &msg, (TickType_t)100); msg.state = MODE_MIC; - xQueueSend(i2sstateQueue,&msg,(TickType_t)100); + xQueueSend(i2sstateQueue, &msg, (TickType_t)100); } - uint32_t colorY = DisTouchbuff.color565(0xff,0x9c,0x00); - uint32_t colorG = DisTouchbuff.color565(0x66,0xff,0x00); - uint32_t colorGREY = DisTouchbuff.color565(0x30,0x30,0x30); - DisTouchbuff.fillRect(5,15,5,21,colorG); - - DisTouchbuff.drawColorBitmap(12,15,7,10, - (uint8_t*)Number_7x10px[11], - 0xff9c00, - 0x000000); - DisTouchbuff.drawColorBitmap(19,15,3,10, - (uint8_t*)Number_7x10px[13], - 0xff9c00, - 0x000000); - - DisTouchbuff.drawColorBitmap(12,26,7,10, - (uint8_t*)Number_7x10px[12], - 0xff9c00, - 0x000000); - DisTouchbuff.drawColorBitmap(19,26,3,10, - (uint8_t*)Number_7x10px[13], - 0xff9c00, - 0x000000); - for( int i = 0; i < 3; i++ ) - { - int number = ( pos.x / (int)( pow( 10 , ( 2 - i )))) % 10; - DisTouchbuff.drawColorBitmap(22 + i * 7,15,7,10, - (uint8_t*)Number_7x10px[number], - 0xff9c00, - 0x000000); + uint32_t colorY = DisTouchbuff.color565(0xff, 0x9c, 0x00); + uint32_t colorG = DisTouchbuff.color565(0x66, 0xff, 0x00); + uint32_t colorGREY = DisTouchbuff.color565(0x30, 0x30, 0x30); + DisTouchbuff.fillRect(5, 15, 5, 21, colorG); + + DisTouchbuff.drawColorBitmap( + 12, 15, 7, 10, (uint8_t *)Number_7x10px[11], 0xff9c00, 0x000000); + DisTouchbuff.drawColorBitmap( + 19, 15, 3, 10, (uint8_t *)Number_7x10px[13], 0xff9c00, 0x000000); + + DisTouchbuff.drawColorBitmap( + 12, 26, 7, 10, (uint8_t *)Number_7x10px[12], 0xff9c00, 0x000000); + DisTouchbuff.drawColorBitmap( + 19, 26, 3, 10, (uint8_t *)Number_7x10px[13], 0xff9c00, 0x000000); + for (int i = 0; i < 3; i++) { + int number = (pos.x / (int)(pow(10, (2 - i)))) % 10; + DisTouchbuff.drawColorBitmap(22 + i * 7, 15, 7, 10, + (uint8_t *)Number_7x10px[number], + 0xff9c00, 0x000000); } - for( int i = 0; i < 3; i++ ) - { - int number = ( pos.y / (int)( pow( 10 , ( 2 - i )))) % 10; - DisTouchbuff.drawColorBitmap(22 + i * 7,26,7,10, - (uint8_t*)Number_7x10px[number], - 0xff9c00, - 0x000000); + for (int i = 0; i < 3; i++) { + int number = (pos.y / (int)(pow(10, (2 - i)))) % 10; + DisTouchbuff.drawColorBitmap(22 + i * 7, 26, 7, 10, + (uint8_t *)Number_7x10px[number], + 0xff9c00, 0x000000); } - color = ( touchBtn0.inHotZone(pos)) ? colorY : colorGREY; - DisTouchbuff.fillRect(46,4,15,8,color); + color = (touchBtn0.inHotZone(pos)) ? colorY : colorGREY; + DisTouchbuff.fillRect(46, 4, 15, 8, color); - color = ( touchBtn1.inHotZone(pos)) ? colorY : colorGREY; - DisTouchbuff.fillRect(46,16,15,8,color); + color = (touchBtn1.inHotZone(pos)) ? colorY : colorGREY; + DisTouchbuff.fillRect(46, 16, 15, 8, color); - color = ( touchBtn2.inHotZone(pos)) ? colorY : colorGREY; - DisTouchbuff.fillRect(46,28,15,8,color); + color = (touchBtn2.inHotZone(pos)) ? colorY : colorGREY; + DisTouchbuff.fillRect(46, 28, 15, 8, color); - if( sytState.touchState == false ) - { - for( int i = 0; i < 6; i++ ) - { + if (sytState.touchState == false) { + for (int i = 0; i < 6; i++) { sytState.App1Zone[i]->inHotZoneDoFun(pos); } } - } - else - { - uint32_t colorGREY = DisTouchbuff.color565(0x30,0x30,0x30); - DisTouchbuff.fillRect(5,15,5,21,TFT_BLACK); - DisTouchbuff.fillRect(46,4,15,8,colorGREY); - DisTouchbuff.fillRect(46,16,15,8,colorGREY); - DisTouchbuff.fillRect(46,28,15,8,colorGREY); + } else { + uint32_t colorGREY = DisTouchbuff.color565(0x30, 0x30, 0x30); + DisTouchbuff.fillRect(5, 15, 5, 21, TFT_BLACK); + DisTouchbuff.fillRect(46, 4, 15, 8, colorGREY); + DisTouchbuff.fillRect(46, 16, 15, 8, colorGREY); + DisTouchbuff.fillRect(46, 28, 15, 8, colorGREY); } - DisTouchbuff.pushSprite(3,146); + DisTouchbuff.pushSprite(3, 146); sytState.touchState = touchStateNow; //} } -void sdcardSetup() -{ - TFT_eSprite DisSDCardbuff = TFT_eSprite(&M5.Lcd); - DisSDCardbuff.createSprite(64,54); - DisSDCardbuff.drawJpg(SDCardImage,14835,0,0,64,54); +void sdcardSetup() { + TFT_eSprite DisSDCardbuff = TFT_eSprite(&M5.Lcd); + DisSDCardbuff.createSprite(64, 54); + DisSDCardbuff.drawJpg(SDCardImage, 14835, 0, 0, 64, 54); sdcard_type_t Type = SD.cardType(); - if( Type == CARD_UNKNOWN || Type == CARD_NONE ) - { + if (Type == CARD_UNKNOWN || Type == CARD_NONE) { sytState.SDCardState = false; - DisSDCardbuff.fillRect(55,4,6,10,TFT_BLACK); - } - else - { + DisSDCardbuff.fillRect(55, 4, 6, 10, TFT_BLACK); + } else { sytState.SDCardState = true; - uint32_t colorY = DisSDCardbuff.color565(0xff,0x9c,0x00); - - uint64_t sdcardSize = SD.cardSize() * 10 /1024 /1024/ 1024 ; - uint64_t sdcardFreeSize = ( SD.cardSize() - SD.usedBytes())* 10 /1024 /1024/ 1024 ; - - DisSDCardbuff.fillRect(55,4,6,10,colorY); - DisSDCardbuff.drawColorBitmap(3,19,7,10, - (uint8_t*)Number_7x10px[sdcardFreeSize /100 % 10 ], - 0xff9c00, - 0x000000); - DisSDCardbuff.drawColorBitmap(10,19,7,10, - (uint8_t*)Number_7x10px[sdcardFreeSize /10 % 10 ], - 0xff9c00, - 0x000000); - DisSDCardbuff.drawColorBitmap(20,19,7,10, - (uint8_t*)Number_7x10px[sdcardFreeSize % 10 ], - 0xff9c00, - 0x000000); - - DisSDCardbuff.drawColorBitmap(33,19,7,10, - (uint8_t*)Number_7x10px[sdcardSize /100 % 10], - 0xff9c00, - 0x000000); - DisSDCardbuff.drawColorBitmap(40,19,7,10, - (uint8_t*)Number_7x10px[sdcardSize /10 % 10 ], - 0xff9c00, - 0x000000); - DisSDCardbuff.drawColorBitmap(50,19,7,10, - (uint8_t*)Number_7x10px[sdcardSize % 10 ], - 0xff9c00, - 0x000000); + uint32_t colorY = DisSDCardbuff.color565(0xff, 0x9c, 0x00); + + uint64_t sdcardSize = SD.cardSize() * 10 / 1024 / 1024 / 1024; + uint64_t sdcardFreeSize = + (SD.cardSize() - SD.usedBytes()) * 10 / 1024 / 1024 / 1024; + + DisSDCardbuff.fillRect(55, 4, 6, 10, colorY); + DisSDCardbuff.drawColorBitmap( + 3, 19, 7, 10, (uint8_t *)Number_7x10px[sdcardFreeSize / 100 % 10], + 0xff9c00, 0x000000); + DisSDCardbuff.drawColorBitmap( + 10, 19, 7, 10, (uint8_t *)Number_7x10px[sdcardFreeSize / 10 % 10], + 0xff9c00, 0x000000); + DisSDCardbuff.drawColorBitmap( + 20, 19, 7, 10, (uint8_t *)Number_7x10px[sdcardFreeSize % 10], + 0xff9c00, 0x000000); + + DisSDCardbuff.drawColorBitmap( + 33, 19, 7, 10, (uint8_t *)Number_7x10px[sdcardSize / 100 % 10], + 0xff9c00, 0x000000); + DisSDCardbuff.drawColorBitmap( + 40, 19, 7, 10, (uint8_t *)Number_7x10px[sdcardSize / 10 % 10], + 0xff9c00, 0x000000); + DisSDCardbuff.drawColorBitmap(50, 19, 7, 10, + (uint8_t *)Number_7x10px[sdcardSize % 10], + 0xff9c00, 0x000000); Serial.printf("SDCard Type = %d \r\n", Type); - Serial.printf("SDCard Size = %d \r\n", (int)(SD.cardSize() / 1024 / 1024)); + Serial.printf("SDCard Size = %d \r\n", + (int)(SD.cardSize() / 1024 / 1024)); } - DisSDCardbuff.pushSprite(3,4); + DisSDCardbuff.pushSprite(3, 4); } -void sdCardFlush() -{ - sytState.SDCardscaneCount ++; - if( sytState.SDCardscaneCount < 50 ) - { +void sdCardFlush() { + sytState.SDCardscaneCount++; + if (sytState.SDCardscaneCount < 50) { return; } sytState.SDCardscaneCount = 0; - sdcard_type_t Type = SD.cardType(); + sdcard_type_t Type = SD.cardType(); - if( Type == CARD_UNKNOWN || Type == CARD_NONE ) - { + if (Type == CARD_UNKNOWN || Type == CARD_NONE) { sytState.SDCardState = false; - DisSDCardbuff.fillRect(55,4,6,10,TFT_BLACK); - } - else - { + DisSDCardbuff.fillRect(55, 4, 6, 10, TFT_BLACK); + } else { sytState.SDCardState = true; - uint32_t colorY = DisSDCardbuff.color565(0xff,0x9c,0x00); - - uint64_t sdcardSize = SD.cardSize() * 10 /1024 /1024/ 1024 ; - uint64_t sdcardFreeSize = ( SD.cardSize() - SD.usedBytes())* 10 /1024 /1024/ 1024 ; - - DisSDCardbuff.fillRect(55,4,6,10,colorY); - DisSDCardbuff.drawColorBitmap(3,19,7,10, - (uint8_t*)Number_7x10px[sdcardFreeSize /100 % 10 ], - 0xff9c00, - 0x000000); - DisSDCardbuff.drawColorBitmap(10,19,7,10, - (uint8_t*)Number_7x10px[sdcardFreeSize /10 % 10 ], - 0xff9c00, - 0x000000); - DisSDCardbuff.drawColorBitmap(20,19,7,10, - (uint8_t*)Number_7x10px[sdcardFreeSize % 10 ], - 0xff9c00, - 0x000000); - - DisSDCardbuff.drawColorBitmap(33,19,7,10, - (uint8_t*)Number_7x10px[sdcardSize /100 % 10], - 0xff9c00, - 0x000000); - DisSDCardbuff.drawColorBitmap(40,19,7,10, - (uint8_t*)Number_7x10px[sdcardSize /10 % 10 ], - 0xff9c00, - 0x000000); - DisSDCardbuff.drawColorBitmap(50,19,7,10, - (uint8_t*)Number_7x10px[sdcardSize % 10 ], - 0xff9c00, - 0x000000); - //Serial.printf("SDCard Type = %d \r\n", Type); - //Serial.printf("SDCard Size = %d \r\n", (int)(SD.cardSize() / 1024 / 1024)); + uint32_t colorY = DisSDCardbuff.color565(0xff, 0x9c, 0x00); + + uint64_t sdcardSize = SD.cardSize() * 10 / 1024 / 1024 / 1024; + uint64_t sdcardFreeSize = + (SD.cardSize() - SD.usedBytes()) * 10 / 1024 / 1024 / 1024; + + DisSDCardbuff.fillRect(55, 4, 6, 10, colorY); + DisSDCardbuff.drawColorBitmap( + 3, 19, 7, 10, (uint8_t *)Number_7x10px[sdcardFreeSize / 100 % 10], + 0xff9c00, 0x000000); + DisSDCardbuff.drawColorBitmap( + 10, 19, 7, 10, (uint8_t *)Number_7x10px[sdcardFreeSize / 10 % 10], + 0xff9c00, 0x000000); + DisSDCardbuff.drawColorBitmap( + 20, 19, 7, 10, (uint8_t *)Number_7x10px[sdcardFreeSize % 10], + 0xff9c00, 0x000000); + + DisSDCardbuff.drawColorBitmap( + 33, 19, 7, 10, (uint8_t *)Number_7x10px[sdcardSize / 100 % 10], + 0xff9c00, 0x000000); + DisSDCardbuff.drawColorBitmap( + 40, 19, 7, 10, (uint8_t *)Number_7x10px[sdcardSize / 10 % 10], + 0xff9c00, 0x000000); + DisSDCardbuff.drawColorBitmap(50, 19, 7, 10, + (uint8_t *)Number_7x10px[sdcardSize % 10], + 0xff9c00, 0x000000); + // Serial.printf("SDCard Type = %d \r\n", Type); + // Serial.printf("SDCard Size = %d \r\n", (int)(SD.cardSize() / 1024 / + // 1024)); } - DisSDCardbuff.pushSprite(3,4); + DisSDCardbuff.pushSprite(3, 4); } -void AppOut() -{ - Serial.println("Hello App"); -} +void AppOut() { Serial.println("Hello App"); } -TFT_eSprite menubuff = TFT_eSprite(&M5.Lcd); +TFT_eSprite menubuff = TFT_eSprite(&M5.Lcd); -void drawJPEGImageFromSDCard(fs::FS &fs, const char * dirname) -{ +void drawJPEGImageFromSDCard(fs::FS &fs, const char *dirname) { TouchPoint_t pos = M5.Touch.getPressPoint(); - uint16_t* buff = (uint16_t*)ps_calloc(10880,sizeof(uint16_t)); - int Count = 200, menuAmoCount = 0; - int menuPosyNow = 0; - int menuState = 1; + uint16_t *buff = (uint16_t *)ps_calloc(10880, sizeof(uint16_t)); + int Count = 200, menuAmoCount = 0; + int menuPosyNow = 0; + int menuState = 1; // 0 -> off // 1 -> runing // 2 -> open // 3 -> exiting bool flushJPEG = false; - HotZone_t _touchBtn0(10 ,206,120,280); - HotZone_t _touchBtn1(130,206,200,280); - HotZone_t _touchBtn2(230,206,310,280); - - Disbuff.fillRect(0,0,320,240,TFT_BLACK); - Disbuff.pushSprite(0,0); - - menubuff.createSprite(320,34); - menubuff.drawJpg(imageMenu,14900,0,0,320,34); + HotZone_t _touchBtn0(10, 206, 120, 280); + HotZone_t _touchBtn1(130, 206, 200, 280); + HotZone_t _touchBtn2(230, 206, 310, 280); + + Disbuff.fillRect(0, 0, 320, 240, TFT_BLACK); + Disbuff.pushSprite(0, 0); + + menubuff.createSprite(320, 34); + menubuff.drawJpg(imageMenu, 14900, 0, 0, 320, 34); File root = fs.open(dirname); - if(!root){ + if (!root) { Serial.println("Failed to open directory"); return; } - if(!root.isDirectory()){ + if (!root.isDirectory()) { Serial.println("Not a directory"); return; } - + File file = root.openNextFile(); - while( 1 ){ - if( Count >= 200 ) - { - if( !file.isDirectory() ) - { - Disbuff.drawJpgFile(fs,file.name(),0,0,320,240); - Disbuff.getSprite2Buff(buff,0,206,320,34); + while (1) { + if (Count >= 200) { + if (!file.isDirectory()) { + Disbuff.drawJpgFile(fs, file.name(), 0, 0, 320, 240); + Disbuff.getSprite2Buff(buff, 0, 206, 320, 34); flushJPEG = true; - } - file = root.openNextFile(); - if( !file ) - { - root = fs.open(dirname); - file = root.openNextFile(); - } - Count = 0; - } - delay(5); - Count ++; + } + file = root.openNextFile(); + if (!file) { + root = fs.open(dirname); + file = root.openNextFile(); + } + Count = 0; + } + delay(5); + Count++; pos = M5.Touch.getPressPoint(); - if( pos.x != -1 ) - { - switch( menuState ) - { - case 0: menuState = 1; menuPosyNow = 0; break; - case 2: menuAmoCount = 0; - if( _touchBtn2.inHotZone(pos)) goto endImage; break; + if (pos.x != -1) { + switch (menuState) { + case 0: + menuState = 1; + menuPosyNow = 0; + break; + case 2: + menuAmoCount = 0; + if (_touchBtn2.inHotZone(pos)) goto endImage; + break; } } - switch( menuState ) - { - case 1: + switch (menuState) { + case 1: menuPosyNow += 4; - if( menuPosyNow >= 34) - { - menuPosyNow = 34; - menuState = 2; + if (menuPosyNow >= 34) { + menuPosyNow = 34; + menuState = 2; menuAmoCount = 0; - flushJPEG = true; + flushJPEG = true; } break; - case 2: + case 2: menuAmoCount++; - if( menuAmoCount > 500 ) - { + if (menuAmoCount > 500) { menuAmoCount = 0; - menuPosyNow = 34; - menuState = 3; + menuPosyNow = 34; + menuState = 3; } - break; - case 3: + break; + case 3: menuPosyNow -= 4; - if( menuPosyNow <= 0) - { - menuPosyNow = 0; - menuState = 0; + if (menuPosyNow <= 0) { + menuPosyNow = 0; + menuState = 0; menuAmoCount = 0; - flushJPEG = true; + flushJPEG = true; } - break; + break; } - - if(( menuState == 1 )||( menuState == 3 )||( flushJPEG == true)) - { - if( flushJPEG == true ) flushJPEG = false; - if( menuState == 3 ) Disbuff.pushImage(0,206,320,34,buff); - Disbuff.pushInSprite(&menubuff,0,0,320,34,0,241 - menuPosyNow); - Disbuff.pushSprite(0,0); + + if ((menuState == 1) || (menuState == 3) || (flushJPEG == true)) { + if (flushJPEG == true) flushJPEG = false; + if (menuState == 3) Disbuff.pushImage(0, 206, 320, 34, buff); + Disbuff.pushInSprite(&menubuff, 0, 0, 320, 34, 0, + 241 - menuPosyNow); + Disbuff.pushSprite(0, 0); } } - endImage: - Disbuff.drawJpg(CoreMainImage,87169,0,0,320,240,0,0); - Disbuff.pushSprite(0,0); +endImage: + Disbuff.drawJpg(CoreMainImage, 87169, 0, 0, 320, 240, 0, 0); + Disbuff.pushSprite(0, 0); menubuff.deleteSprite(); sytState.power = kPOWER_MAX; free(buff); } -void AppImage() -{ - if( sytState.SDCardState == false )return; - drawJPEGImageFromSDCard(SD,"/image"); +void AppImage() { + if (sytState.SDCardState == false) return; + drawJPEGImageFromSDCard(SD, "/image"); } -void APPSleep() -{ +void APPSleep() { delay(500); M5.Axp.SetSleep(); } -void AppWifi() -{ +void AppWifi() { bool first = true; - int count = 0,count_n = 0; + int count = 0, count_n = 0; WiFi.mode(WIFI_STA); WiFi.disconnect(); - Disbuff.drawJpg(wifiSacnImage,28123,0,0,320,240); - Disbuff.pushSprite(0,0); + Disbuff.drawJpg(wifiSacnImage, 28123, 0, 0, 320, 240); + Disbuff.pushSprite(0, 0); Disbuff.setFreeFont(&EVA_20px); Disbuff.setTextSize(1); - Disbuff.setTextColor(Disbuff.color565(0xff,0xa0,0),Disbuff.color565(0,0,0)); + Disbuff.setTextColor(Disbuff.color565(0xff, 0xa0, 0), + Disbuff.color565(0, 0, 0)); Disbuff.setTextDatum(TL_DATUM); TouchPoint_t pos = M5.Touch.getPressPoint(); - uint16_t color_yellow = Disbuff.color565(0xff,0xa0,0); - uint16_t color_gery = Disbuff.color565(0x43,0x43,0x43); + uint16_t color_yellow = Disbuff.color565(0xff, 0xa0, 0); + uint16_t color_gery = Disbuff.color565(0x43, 0x43, 0x43); WiFi.scanNetworks(true); - HotZone escBtn(234,210,280,320); + HotZone escBtn(234, 210, 280, 320); - uint16_t colorWifiBar[10] = { TFT_RED, TFT_RED, - color_yellow,color_yellow,color_yellow, - TFT_GREEN,TFT_GREEN,TFT_GREEN,TFT_GREEN,TFT_GREEN}; + uint16_t colorWifiBar[10] = { + TFT_RED, TFT_RED, color_yellow, color_yellow, color_yellow, + TFT_GREEN, TFT_GREEN, TFT_GREEN, TFT_GREEN, TFT_GREEN}; delay(100); - while(1) - { + while (1) { int WifiNumber = WiFi.scanComplete(); - if ( WifiNumber == -2 ) - { - - } - else if ( WifiNumber == - 1 ) - { - if( first ) - { - //if( count >= 20 ) + if (WifiNumber == -2) { + } else if (WifiNumber == -1) { + if (first) { + // if( count >= 20 ) //{ // count = 0; // Disbuff.setTextDatum(CC_DATUM); @@ -1442,541 +1257,461 @@ void AppWifi() // count_n++; // if( count_n > 4 ) count_n = 0; //} - if( count >= 10 ) - { + if (count >= 10) { count = 0; - Disbuff.fillRect( 0,34,320,173,TFT_BLACK); - Disbuff.drawColorBitmap(122,98,76,44, - TouchFishBuff[count_n], - 0xff9c00, - 0x000000); - Disbuff.pushSprite(0,0); + Disbuff.fillRect(0, 34, 320, 173, TFT_BLACK); + Disbuff.drawColorBitmap(122, 98, 76, 44, + TouchFishBuff[count_n], 0xff9c00, + 0x000000); + Disbuff.pushSprite(0, 0); count_n++; - if( count_n >= 6 ) count_n = 0; + if (count_n >= 6) count_n = 0; } count++; } - } - else if ( WifiNumber == 0 ) - { + } else if (WifiNumber == 0) { Serial.println("no networks found"); - M5.Lcd.drawString("No networks found",15,22); - } - else - { + M5.Lcd.drawString("No networks found", 15, 22); + } else { Serial.print(WifiNumber); Serial.println(" networks found"); - Disbuff.fillRect( 0,34,320,173,TFT_BLACK); - if( WifiNumber > 8 ) WifiNumber = 7 ; + Disbuff.fillRect(0, 34, 320, 173, TFT_BLACK); + if (WifiNumber > 8) WifiNumber = 7; - - for (int i = 0; i < WifiNumber; i++) - { - Disbuff.fillRect( 18,34+i*24 + 2,7,20,Disbuff.color565(0xff,0xa0,0)); + for (int i = 0; i < WifiNumber; i++) { + Disbuff.fillRect(18, 34 + i * 24 + 2, 7, 20, + Disbuff.color565(0xff, 0xa0, 0)); String SSIDStr = WiFi.SSID(i); - if( SSIDStr.length() > 11 ) - { - SSIDStr = SSIDStr.substring(0,8); + if (SSIDStr.length() > 11) { + SSIDStr = SSIDStr.substring(0, 8); SSIDStr += "..."; } Disbuff.setTextDatum(TL_DATUM); - Disbuff.drawString( SSIDStr,35,34+i*24 + 2 ); + Disbuff.drawString(SSIDStr, 35, 34 + i * 24 + 2); } - if( first ) - { - for (int i = 0; i < WifiNumber; i++) - { - for( int n = 9; n >= 0; n-- ) - { - Disbuff.fillRect(298-12*n,34+i*24+2,8,20,color_gery); + if (first) { + for (int i = 0; i < WifiNumber; i++) { + for (int n = 9; n >= 0; n--) { + Disbuff.fillRect(298 - 12 * n, 34 + i * 24 + 2, 8, 20, + color_gery); } } - Disbuff.pushSprite(0,0); + Disbuff.pushSprite(0, 0); } - for( int n = 9; n >= 0; n-- ) - { - for (int i = 0; i < WifiNumber; i++) - { - int32_t rssi = ( WiFi.RSSI(i) < -100 ) ? -100 : WiFi.RSSI(i); - rssi = map( rssi,-100,-20,-100,0); + for (int n = 9; n >= 0; n--) { + for (int i = 0; i < WifiNumber; i++) { + int32_t rssi = (WiFi.RSSI(i) < -100) ? -100 : WiFi.RSSI(i); + rssi = map(rssi, -100, -20, -100, 0); uint16_t colorNow = color_yellow; - if( rssi < ( n * -10)) - { + if (rssi < (n * -10)) { colorNow = color_gery; + } else { + colorNow = colorWifiBar[9 - n]; } - else - { - colorNow = colorWifiBar[9-n]; - } - Disbuff.fillRect(298-12*n,34+i*24+2,8,20,colorNow); + Disbuff.fillRect(298 - 12 * n, 34 + i * 24 + 2, 8, 20, + colorNow); } - if( first ) - { - Disbuff.pushSprite(0,0); + if (first) { + Disbuff.pushSprite(0, 0); delay(5); } } WiFi.scanDelete(); WiFi.scanNetworks(true); - if( first == false ) - { - Disbuff.pushSprite(0,0); + if (first == false) { + Disbuff.pushSprite(0, 0); } first = false; - } delay(10); pos = M5.Touch.getPressPoint(); - if( pos.x != -1 ) - { - if( escBtn.inHotZone(pos)) break; + if (pos.x != -1) { + if (escBtn.inHotZone(pos)) break; } } - Disbuff.drawJpg(CoreMainImage,87169,0,0,320,240,0,0); - Disbuff.pushSprite(0,0); + Disbuff.drawJpg(CoreMainImage, 87169, 0, 0, 320, 240, 0, 0); + Disbuff.pushSprite(0, 0); sytState.power = kPOWER_MAX; } -void AppTimer() -{ - Disbuff.drawJpg(TimerAppImage,59165,0,0,320,240,0,0); - Disbuff.pushSprite(0,0); +void AppTimer() { + Disbuff.drawJpg(TimerAppImage, 59165, 0, 0, 320, 240, 0, 0); + Disbuff.pushSprite(0, 0); TouchPoint_t pos = M5.Touch.getPressPoint(); - HotZone StopBtn(240,36,320,114); - HotZone CleanBtn(240,118,320,198); - HotZone SettingBtn(185,144,249,240); - HotZone EscBtn(240,200,320,280); + HotZone StopBtn(240, 36, 320, 114); + HotZone CleanBtn(240, 118, 320, 198); + HotZone SettingBtn(185, 144, 249, 240); + HotZone EscBtn(240, 200, 320, 280); - bool stpoed = true; - bool zeroflag = false; - bool pressed = false; + bool stpoed = true; + bool zeroflag = false; + bool pressed = false; uint16_t count_bibi = 0; - uint16_t posx[6] = { 4, 28, 66, 90, 127, 144 }; + uint16_t posx[6] = {4, 28, 66, 90, 127, 144}; TFT_eSprite Timerbuff = TFT_eSprite(&M5.Lcd); - Timerbuff.createSprite(176,56); + Timerbuff.createSprite(176, 56); TFT_eSprite TimerRectbuff = TFT_eSprite(&M5.Lcd); - TimerRectbuff.createSprite(40,164); - TimerRectbuff.fillRect(0,0,40,164,TFT_BLACK); + TimerRectbuff.createSprite(40, 164); + TimerRectbuff.fillRect(0, 0, 40, 164, TFT_BLACK); unsigned long timeNow = micros(); - int64_t timeset = 65000; - int64_t timeSetting = timeset; - int min = timeSetting / 60000 % 60; - int sec = timeSetting / 1000 % 60; - int mill = timeSetting % 1000; - uint32_t colorNum = 0xff9c00; - - uint16_t color16Yellow = Timerbuff.color565(0xff,0x9c,0); - uint16_t color16Red = Timerbuff.color565(255,0,0); - uint16_t color16green = Timerbuff.color565(0,255,0); - uint16_t color_gery = Disbuff.color565(0x43,0x43,0x43); - - uint16_t colorBar[12] = {color16green,color16green,color16green,color16green,color16green,color16green, - color16Yellow,color16Yellow,color16Yellow,color16Yellow, - color16Red,color16Red}; - uint16_t color16 = color16Yellow; + int64_t timeset = 65000; + int64_t timeSetting = timeset; + int min = timeSetting / 60000 % 60; + int sec = timeSetting / 1000 % 60; + int mill = timeSetting % 1000; + uint32_t colorNum = 0xff9c00; + + uint16_t color16Yellow = Timerbuff.color565(0xff, 0x9c, 0); + uint16_t color16Red = Timerbuff.color565(255, 0, 0); + uint16_t color16green = Timerbuff.color565(0, 255, 0); + uint16_t color_gery = Disbuff.color565(0x43, 0x43, 0x43); + + uint16_t colorBar[12] = {color16green, color16green, color16green, + color16green, color16green, color16green, + color16Yellow, color16Yellow, color16Yellow, + color16Yellow, color16Red, color16Red}; + uint16_t color16 = color16Yellow; i2sQueueMsg_t msg; - msg.state = MODE_SPK; - msg.audioPtr = (void*)bibiSig; + msg.state = MODE_SPK; + msg.audioPtr = (void *)bibiSig; msg.audioSize = 8820; - //msg.state = MODE_SPK; - //msg.audioPtr = (void*)previewR; - //msg.audioSize = 120264; - //xQueueSend(i2sstateQueue,&msg,(TickType_t)portMAX_DELAY); - - Timerbuff.fillRect(56,13, 5 , 5 , Timerbuff.color565(0xff, 0x9c, 0x00)); - Timerbuff.fillRect(56,32, 5 , 5 , Timerbuff.color565(0xff, 0x9c, 0x00)); - - Timerbuff.fillRect(118,18, 5 , 5 , Timerbuff.color565(0xff, 0x9c, 0x00)); - Timerbuff.fillRect(118,35, 5 , 5 , Timerbuff.color565(0xff, 0x9c, 0x00)); - - TimerRectbuff.fillRect(0,0,40,164,TFT_BLACK); - for( int i = 0; i< 12; i++ ) - { - TimerRectbuff.fillRect(0,154-i*14,30,10,colorBar[11-i]); + // msg.state = MODE_SPK; + // msg.audioPtr = (void*)previewR; + // msg.audioSize = 120264; + // xQueueSend(i2sstateQueue,&msg,(TickType_t)portMAX_DELAY); + + Timerbuff.fillRect(56, 13, 5, 5, Timerbuff.color565(0xff, 0x9c, 0x00)); + Timerbuff.fillRect(56, 32, 5, 5, Timerbuff.color565(0xff, 0x9c, 0x00)); + + Timerbuff.fillRect(118, 18, 5, 5, Timerbuff.color565(0xff, 0x9c, 0x00)); + Timerbuff.fillRect(118, 35, 5, 5, Timerbuff.color565(0xff, 0x9c, 0x00)); + + TimerRectbuff.fillRect(0, 0, 40, 164, TFT_BLACK); + for (int i = 0; i < 12; i++) { + TimerRectbuff.fillRect(0, 154 - i * 14, 30, 10, colorBar[11 - i]); } - TimerRectbuff.pushSprite(7,36); + TimerRectbuff.pushSprite(7, 36); - while(1) - { - if( !stpoed ) - { - timeSetting = timeSetting - ( millis() - timeNow ); - if( timeSetting <= 0 ) - { + while (1) { + if (!stpoed) { + timeSetting = timeSetting - (millis() - timeNow); + if (timeSetting <= 0) { timeSetting = 0; - count_bibi = 0; - //M5.Axp.SetLDOEnable(3,true); + count_bibi = 0; + // M5.Axp.SetLDOEnable(3,true); zeroflag = true; - stpoed = true; + stpoed = true; } } - if( zeroflag ) - { + if (zeroflag) { delay(10); - count_bibi ++; - if( count_bibi > 20 ) - { + count_bibi++; + if (count_bibi > 20) { count_bibi = 0; - msg.state = MODE_SPK; - msg.audioPtr = (void*)bibiSig; + msg.state = MODE_SPK; + msg.audioPtr = (void *)bibiSig; msg.audioSize = 8820; - xQueueSend(i2sstateQueue,&msg,(TickType_t)portMAX_DELAY); + xQueueSend(i2sstateQueue, &msg, (TickType_t)portMAX_DELAY); } } - int timerect = map(timeSetting,0,timeset,1,12); - TimerRectbuff.fillRect(0,0,40,164,TFT_BLACK); - for( int i = 0; i < 12; i++ ) - { - if( i < timerect ) - TimerRectbuff.fillRect(0,154-i*14,30,10,colorBar[11-i]); + int timerect = map(timeSetting, 0, timeset, 1, 12); + TimerRectbuff.fillRect(0, 0, 40, 164, TFT_BLACK); + for (int i = 0; i < 12; i++) { + if (i < timerect) + TimerRectbuff.fillRect(0, 154 - i * 14, 30, 10, + colorBar[11 - i]); else - TimerRectbuff.fillRect(0,154-i*14,30,10,color_gery); + TimerRectbuff.fillRect(0, 154 - i * 14, 30, 10, color_gery); } - TimerRectbuff.pushSprite(7,36); - - + TimerRectbuff.pushSprite(7, 36); timeNow = millis(); - min = timeSetting / 60000 % 60; - sec = timeSetting / 1000 % 60; + min = timeSetting / 60000 % 60; + sec = timeSetting / 1000 % 60; mill = timeSetting / 10 % 100; - - colorNum = ( min == 0 ) ? 0xff0000 : 0xff9c00; - color16 = ( min == 0 ) ? color16Red : color16Yellow; - - Timerbuff.fillRect(56,13, 5 , 5 , color16); - Timerbuff.fillRect(56,32, 5 , 5 , color16); - - Timerbuff.fillRect(118,18, 5 , 5 , color16); - Timerbuff.fillRect(118,35, 5 , 5 , color16); - - Timerbuff.drawColorBitmap(posx[0],4,24,42, - DigNumber[ min / 10], - colorNum, - 0x000000); - Timerbuff.drawColorBitmap(posx[1],4,24,42, - DigNumber[ min % 10], - colorNum, - 0x000000); - Timerbuff.drawColorBitmap(posx[2],4,24,42, - DigNumber[ sec / 10 ], - colorNum, - 0x000000); - Timerbuff.drawColorBitmap(posx[3],4,24,42, - DigNumber[ sec % 10 ], - colorNum, - 0x000000); - Timerbuff.drawColorBitmap(posx[4],14,18,35, - DigNumber_35px[ mill / 10 ], - colorNum, - 0x000000); - Timerbuff.drawColorBitmap(posx[5],14,18,35, - DigNumber_35px[ mill % 10 ], - colorNum, - 0x000000); - Timerbuff.pushSprite(54,92); + + colorNum = (min == 0) ? 0xff0000 : 0xff9c00; + color16 = (min == 0) ? color16Red : color16Yellow; + + Timerbuff.fillRect(56, 13, 5, 5, color16); + Timerbuff.fillRect(56, 32, 5, 5, color16); + + Timerbuff.fillRect(118, 18, 5, 5, color16); + Timerbuff.fillRect(118, 35, 5, 5, color16); + + Timerbuff.drawColorBitmap(posx[0], 4, 24, 42, DigNumber[min / 10], + colorNum, 0x000000); + Timerbuff.drawColorBitmap(posx[1], 4, 24, 42, DigNumber[min % 10], + colorNum, 0x000000); + Timerbuff.drawColorBitmap(posx[2], 4, 24, 42, DigNumber[sec / 10], + colorNum, 0x000000); + Timerbuff.drawColorBitmap(posx[3], 4, 24, 42, DigNumber[sec % 10], + colorNum, 0x000000); + Timerbuff.drawColorBitmap( + posx[4], 14, 18, 35, DigNumber_35px[mill / 10], colorNum, 0x000000); + Timerbuff.drawColorBitmap( + posx[5], 14, 18, 35, DigNumber_35px[mill % 10], colorNum, 0x000000); + Timerbuff.pushSprite(54, 92); pos = M5.Touch.getPressPoint(); - - if(( pos.x != -1 )&&( pressed == false )) - { + + if ((pos.x != -1) && (pressed == false)) { pressed = true; - msg.state = MODE_SPK; - msg.audioPtr = (void*)bibiSig; + msg.state = MODE_SPK; + msg.audioPtr = (void *)bibiSig; msg.audioSize = 8820; - xQueueSend(i2sstateQueue,&msg,(TickType_t)portMAX_DELAY); + xQueueSend(i2sstateQueue, &msg, (TickType_t)portMAX_DELAY); - if( StopBtn.inHotZone(pos)) - { - stpoed = ( stpoed == true ) ? false : true; + if (StopBtn.inHotZone(pos)) { + stpoed = (stpoed == true) ? false : true; } - if( zeroflag ) - { - zeroflag = false; + if (zeroflag) { + zeroflag = false; timeSetting = timeset; - //M5.Axp.SetLDOEnable(3,false); + // M5.Axp.SetLDOEnable(3,false); } - if( CleanBtn.inHotZone(pos)) - { + if (CleanBtn.inHotZone(pos)) { timeSetting = timeset; - stpoed = true; + stpoed = true; - TimerRectbuff.fillRect(0,0,40,164,TFT_BLACK); - for( int i = 0; i< 12; i++ ) - { - TimerRectbuff.fillRect(0,154-i*14,30,10,colorBar[11-i]); + TimerRectbuff.fillRect(0, 0, 40, 164, TFT_BLACK); + for (int i = 0; i < 12; i++) { + TimerRectbuff.fillRect(0, 154 - i * 14, 30, 10, + colorBar[11 - i]); } - TimerRectbuff.pushSprite(7,36); + TimerRectbuff.pushSprite(7, 36); } - if( EscBtn.inHotZone(pos)) - { + if (EscBtn.inHotZone(pos)) { break; } - } - else if( pos.x == -1 ) - { + } else if (pos.x == -1) { pressed = false; } - } - msg.state = MODE_MIC; - msg.audioPtr = (uint8_t*)previewR; + msg.state = MODE_MIC; + msg.audioPtr = (uint8_t *)previewR; msg.audioSize = 120264; - xQueueSend(i2sstateQueue,&msg,(TickType_t)portMAX_DELAY); + xQueueSend(i2sstateQueue, &msg, (TickType_t)portMAX_DELAY); Timerbuff.deleteSprite(); - Disbuff.drawJpg(CoreMainImage,87169,0,0,320,240,0,0); - Disbuff.pushSprite(0,0); + Disbuff.drawJpg(CoreMainImage, 87169, 0, 0, 320, 240, 0, 0); + Disbuff.pushSprite(0, 0); sytState.power = kPOWER_MAX; } -void TFTTest() -{ - HotZone Btn(0,0,320,280); +void TFTTest() { + HotZone Btn(0, 0, 320, 280); TouchPoint_t pos = M5.Touch.getPressPoint(); - int colorIndex = 0; - uint32_t colorList[4][2] = {{TFT_RED , TFT_RED}, - {TFT_GREEN ,TFT_GREEN}, - {TFT_BLUE, TFT_BLUE}, + int colorIndex = 0; + uint32_t colorList[4][2] = {{TFT_RED, TFT_RED}, + {TFT_GREEN, TFT_GREEN}, + {TFT_BLUE, TFT_BLUE}, {TFT_WHITE, TFT_BLACK}}; - M5.Lcd.fillRect(0,0,320,240,colorList[colorIndex][1]); - M5.Lcd.drawRect(0,0,320,240,colorList[colorIndex][0]); + M5.Lcd.fillRect(0, 0, 320, 240, colorList[colorIndex][1]); + M5.Lcd.drawRect(0, 0, 320, 240, colorList[colorIndex][0]); i2sQueueMsg_t msg; - msg.state = MODE_SPK; - msg.audioPtr = (void*)bibiSig; + msg.state = MODE_SPK; + msg.audioPtr = (void *)bibiSig; msg.audioSize = 8820; bool pressed = true; - while(1) - { + while (1) { pos = M5.Touch.getPressPoint(); - - if(( pos.x != -1 )&&( pressed == false )) - { + + if ((pos.x != -1) && (pressed == false)) { pressed = true; - msg.state = MODE_SPK; - msg.audioPtr = (void*)bibiSig; + msg.state = MODE_SPK; + msg.audioPtr = (void *)bibiSig; msg.audioSize = 8820; - xQueueSend(i2sstateQueue,&msg,(TickType_t)portMAX_DELAY); + xQueueSend(i2sstateQueue, &msg, (TickType_t)portMAX_DELAY); colorIndex++; - if( colorIndex == 4 ) break; + if (colorIndex == 4) break; - M5.Lcd.fillRect(0,0,320,240,colorList[colorIndex][1]); - M5.Lcd.drawRect(0,0,320,240,colorList[colorIndex][0]); - } - else if( pos.x == -1 ) - { + M5.Lcd.fillRect(0, 0, 320, 240, colorList[colorIndex][1]); + M5.Lcd.drawRect(0, 0, 320, 240, colorList[colorIndex][0]); + } else if (pos.x == -1) { pressed = false; } - } - Disbuff.pushSprite(0,0); + Disbuff.pushSprite(0, 0); } -void AppSetting() -{ - Disbuff.drawJpg(SettingAppImage,50771,0,0,320,240); +void AppSetting() { + Disbuff.drawJpg(SettingAppImage, 50771, 0, 0, 320, 240); - HotZone IOBtn(7,99,104,154); - HotZone MoterBtn(113,99,210,154); + HotZone IOBtn(7, 99, 104, 154); + HotZone MoterBtn(113, 99, 210, 154); - HotZone TFTBtn(7,161,104,216); - HotZone SoundBtn(113,161,210,216); + HotZone TFTBtn(7, 161, 104, 216); + HotZone SoundBtn(113, 161, 210, 216); - HotZone EscBtn(240,200,320,280); + HotZone EscBtn(240, 200, 320, 280); TouchPoint_t pos = M5.Touch.getPressPoint(); - bool pressed = false; - uint8_t IOState = 0; + bool pressed = false; + uint8_t IOState = 0; uint8_t MoterState = 1; - uint8_t ioBuff[6] = {14,13,32,33,19,27}; + uint8_t ioBuff[6] = {14, 13, 32, 33, 19, 27}; uint8_t iostatebuff[4][6] = { - {1,1,1,1,1,1}, - {0,1,0,1,0,1}, - {1,0,1,0,1,0}, - {0,0,0,0,0,0}, + {1, 1, 1, 1, 1, 1}, + {0, 1, 0, 1, 0, 1}, + {1, 0, 1, 0, 1, 0}, + {0, 0, 0, 0, 0, 0}, }; uint16_t adcReadCount = 0; i2sQueueMsg_t msg; - msg.state = MODE_SPK; - msg.audioPtr = (void*)bibiSig; + msg.state = MODE_SPK; + msg.audioPtr = (void *)bibiSig; msg.audioSize = 8820; - pinMode(14,OUTPUT); - pinMode(13,OUTPUT); - pinMode(32,OUTPUT); - pinMode(33,OUTPUT); - pinMode(19,OUTPUT); - pinMode(27,OUTPUT); + pinMode(14, OUTPUT); + pinMode(13, OUTPUT); + pinMode(32, OUTPUT); + pinMode(33, OUTPUT); + pinMode(19, OUTPUT); + pinMode(27, OUTPUT); - Disbuff.fillRect(193,103,14,47,TFT_RED); + Disbuff.fillRect(193, 103, 14, 47, TFT_RED); - if( sytState.soundFlag ) - { - Disbuff.fillRect(193,165,14,47,TFT_GREEN); - } - else - { - Disbuff.fillRect(193,165,14,47,TFT_RED); + if (sytState.soundFlag) { + Disbuff.fillRect(193, 165, 14, 47, TFT_GREEN); + } else { + Disbuff.fillRect(193, 165, 14, 47, TFT_RED); } - - Disbuff.pushSprite(0,0); - while(1) - { + Disbuff.pushSprite(0, 0); + + while (1) { pos = M5.Touch.getPressPoint(); - - if(( pos.x != -1 )&&( pressed == false )) - { + + if ((pos.x != -1) && (pressed == false)) { pressed = true; - msg.state = MODE_SPK; - msg.audioPtr = (void*)bibiSig; + msg.state = MODE_SPK; + msg.audioPtr = (void *)bibiSig; msg.audioSize = 8820; - xQueueSend(i2sstateQueue,&msg,(TickType_t)portMAX_DELAY); + xQueueSend(i2sstateQueue, &msg, (TickType_t)portMAX_DELAY); - if( IOBtn.inHotZone(pos)) - { - for( int i = 0; i < 6; i++ ) - { - digitalWrite(ioBuff[i],iostatebuff[IOState][i]); + if (IOBtn.inHotZone(pos)) { + for (int i = 0; i < 6; i++) { + digitalWrite(ioBuff[i], iostatebuff[IOState][i]); } IOState++; - IOState = ( IOState >= 4 ) ? 0 : IOState; - Serial.printf("Set IOState %d \n",IOState); + IOState = (IOState >= 4) ? 0 : IOState; + Serial.printf("Set IOState %d \n", IOState); } - if( MoterBtn.inHotZone(pos)) - { - M5.Axp.SetLDOEnable(3,MoterState); - if( MoterState == 1 ) - { - Disbuff.fillRect(193,103,14,47,TFT_GREEN); + if (MoterBtn.inHotZone(pos)) { + M5.Axp.SetLDOEnable(3, MoterState); + if (MoterState == 1) { + Disbuff.fillRect(193, 103, 14, 47, TFT_GREEN); + } else { + Disbuff.fillRect(193, 103, 14, 47, TFT_RED); } - else - { - Disbuff.fillRect(193,103,14,47,TFT_RED); - } - Disbuff.pushSprite(0,0); - MoterState = ( MoterState == 0 ) ? 1 : 0; - Serial.printf("Set Moter %d \n",MoterState); - + Disbuff.pushSprite(0, 0); + MoterState = (MoterState == 0) ? 1 : 0; + Serial.printf("Set Moter %d \n", MoterState); } // - if( SoundBtn.inHotZone(pos)) - { - sytState.soundFlag = ( sytState.soundFlag == true ) ? false : true; + if (SoundBtn.inHotZone(pos)) { + sytState.soundFlag = + (sytState.soundFlag == true) ? false : true; M5.Axp.SetSpkEnable(sytState.soundFlag); - if( sytState.soundFlag ) - { - Disbuff.fillRect(193,165,14,47,TFT_GREEN); - } - else - { - Disbuff.fillRect(193,165,14,47,TFT_RED); + if (sytState.soundFlag) { + Disbuff.fillRect(193, 165, 14, 47, TFT_GREEN); + } else { + Disbuff.fillRect(193, 165, 14, 47, TFT_RED); } - Disbuff.pushSprite(0,0); + Disbuff.pushSprite(0, 0); } - if( TFTBtn.inHotZone(pos)) - { + if (TFTBtn.inHotZone(pos)) { TFTTest(); } - if( EscBtn.inHotZone(pos)) - { + if (EscBtn.inHotZone(pos)) { break; } } - - else if( pos.x == -1 ) - { + + else if (pos.x == -1) { pressed = false; } - if( adcReadCount > 50 ) - { - adcReadCount = 0; + if (adcReadCount > 50) { + adcReadCount = 0; uint16_t pin35ADC = analogRead(35); - double pin35vol = (double)pin35ADC * 3.3 / 4096; + double pin35vol = (double)pin35ADC * 3.3 / 4096; uint16_t pin36ADC = analogRead(36); - double pin36vol = (double)pin36ADC * 3.3 / 4096; + double pin36vol = (double)pin36ADC * 3.3 / 4096; - if(( pin35vol > 1.8 )&&( pin35vol < 2.2 )) - { - Disbuff.fillRect(86,103,14,21,TFT_GREEN); - } - else - { - Disbuff.fillRect(86,103,14,21,TFT_RED); + if ((pin35vol > 1.8) && (pin35vol < 2.2)) { + Disbuff.fillRect(86, 103, 14, 21, TFT_GREEN); + } else { + Disbuff.fillRect(86, 103, 14, 21, TFT_RED); } - - if(( pin36vol > 0.8 )&&( pin36vol < 1.2 )) - { - Disbuff.fillRect(86,129,14,21,TFT_GREEN); - } - else - { - Disbuff.fillRect(86,129,14,21,TFT_RED); + + if ((pin36vol > 0.8) && (pin36vol < 1.2)) { + Disbuff.fillRect(86, 129, 14, 21, TFT_GREEN); + } else { + Disbuff.fillRect(86, 129, 14, 21, TFT_RED); } - Disbuff.pushSprite(0,0); - Serial.printf("ADC:%.2f,%.2f\n",pin35vol,pin36vol); + Disbuff.pushSprite(0, 0); + Serial.printf("ADC:%.2f,%.2f\n", pin35vol, pin36vol); } - adcReadCount ++; + adcReadCount++; delay(10); } msg.state = MODE_MIC; - xQueueSend(i2sstateQueue,&msg,(TickType_t)portMAX_DELAY); + xQueueSend(i2sstateQueue, &msg, (TickType_t)portMAX_DELAY); - Disbuff.drawJpg(CoreMainImage,87169,0,0,320,240,0,0); - Disbuff.pushSprite(0,0); + Disbuff.drawJpg(CoreMainImage, 87169, 0, 0, 320, 240, 0, 0); + Disbuff.pushSprite(0, 0); sytState.power = kPOWER_MAX; - } -void MPU6886Page() -{ +void MPU6886Page() { float accX = 0; float accY = 0; float accZ = 0; @@ -1986,62 +1721,52 @@ void MPU6886Page() double alpha = 0.2; TouchPoint_t pos = M5.Touch.getPressPoint(); - int menuAmoCount = 0; - int menuPosyNow = 0; - int menuState = 1; - HotZone_t _touchBtn2(230,206,310,280); - - menubuff.createSprite(320,34); - menubuff.drawJpg(imageMenu,14900,0,0,320,34); - - line_3d_t x = { - .start_point = {0, 0, 0}, - .end_point = {0, 0, 0}}; - line_3d_t y = { - .start_point = {0, 0, 0}, - .end_point = {0, 0, 0}}; - line_3d_t z = { - .start_point = {0, 0, 0}, - .end_point = {0, 0, 30}}; + int menuAmoCount = 0; + int menuPosyNow = 0; + int menuState = 1; + HotZone_t _touchBtn2(230, 206, 310, 280); + + menubuff.createSprite(320, 34); + menubuff.drawJpg(imageMenu, 14900, 0, 0, 320, 34); + + line_3d_t x = {.start_point = {0, 0, 0}, .end_point = {0, 0, 0}}; + line_3d_t y = {.start_point = {0, 0, 0}, .end_point = {0, 0, 0}}; + line_3d_t z = {.start_point = {0, 0, 0}, .end_point = {0, 0, 30}}; line_3d_t rect_dis; line3D line3d; - for (int n = 0; n < 12; n++) - { + for (int n = 0; n < 12; n++) { rect_source[n].start_point.x = rect[n].start_point.x * 50; rect_source[n].start_point.y = rect[n].start_point.y * 50; rect_source[n].start_point.z = rect[n].start_point.z * 50; - rect_source[n].end_point.x = rect[n].end_point.x * 50; - rect_source[n].end_point.y = rect[n].end_point.y * 50; - rect_source[n].end_point.z = rect[n].end_point.z * 50; + rect_source[n].end_point.x = rect[n].end_point.x * 50; + rect_source[n].end_point.y = rect[n].end_point.y * 50; + rect_source[n].end_point.z = rect[n].end_point.z * 50; } - line3d.setZeroOffset(160,110); + line3d.setZeroOffset(160, 110); - while(1) - { + while (1) { M5.IMU.getAccelData(&accX, &accY, &accZ); - //M5.MPU6886.getAccelData(&accX, &accY, &accZ); - if ((accX < 1) && (accX > -1)) - { + // M5.MPU6886.getAccelData(&accX, &accY, &accZ); + if ((accX < 1) && (accX > -1)) { theta = asin(-accX) * 57.295; } - if (accZ != 0) - { + if (accZ != 0) { phi = atan(accY / accZ) * 57.295; } theta = alpha * theta + (1 - alpha) * last_theta; - phi = alpha * phi + (1 - alpha) * last_phi; + phi = alpha * phi + (1 - alpha) * last_phi; - Disbuff.fillRect(0,0,320,240,Dis3Dbuff.color565(0x0,0x0,0x0)); - //Disbuff.setTextSize(1); - //Disbuff.setCursor(10, 115); - //Disbuff.printf("%.2f", theta); - //Disbuff.setCursor(10, 125); - //Disbuff.printf("%.2f", phi); + Disbuff.fillRect(0, 0, 320, 240, Dis3Dbuff.color565(0x0, 0x0, 0x0)); + // Disbuff.setTextSize(1); + // Disbuff.setCursor(10, 115); + // Disbuff.printf("%.2f", theta); + // Disbuff.setCursor(10, 125); + // Disbuff.printf("%.2f", phi); z.end_point.x = 0; z.end_point.y = 0; @@ -2054,150 +1779,137 @@ void MPU6886Page() line3d.printLine3D(&Disbuff, &y, TFT_GREEN); line3d.printLine3D(&Disbuff, &z, TFT_GREEN); - uint16_t linecolor = Disbuff.color565(0xff,0x9c,0x00); + uint16_t linecolor = Disbuff.color565(0xff, 0x9c, 0x00); - for (int n = 0; n < 12; n++) - { - line3d.RotatePoint(&rect_source[n].start_point, &rect_dis.start_point, theta, phi, (double)0); - line3d.RotatePoint(&rect_source[n].end_point, &rect_dis.end_point, theta, phi, (double)0); + for (int n = 0; n < 12; n++) { + line3d.RotatePoint(&rect_source[n].start_point, + &rect_dis.start_point, theta, phi, (double)0); + line3d.RotatePoint(&rect_source[n].end_point, &rect_dis.end_point, + theta, phi, (double)0); line3d.printLine3D(&Disbuff, &rect_dis, linecolor); } - + last_theta = theta; - last_phi = phi; + last_phi = phi; pos = M5.Touch.getPressPoint(); - if( pos.x != -1 ) - { - switch( menuState ) - { - case 0: menuState = 1; menuPosyNow = 0; break; - case 2: menuAmoCount = 0; - if( _touchBtn2.inHotZone(pos)) goto endImage; break; + if (pos.x != -1) { + switch (menuState) { + case 0: + menuState = 1; + menuPosyNow = 0; + break; + case 2: + menuAmoCount = 0; + if (_touchBtn2.inHotZone(pos)) goto endImage; + break; } } - switch( menuState ) - { - case 1: + switch (menuState) { + case 1: menuPosyNow += 4; - if( menuPosyNow >= 34) - { - menuPosyNow = 34; - menuState = 2; + if (menuPosyNow >= 34) { + menuPosyNow = 34; + menuState = 2; menuAmoCount = 0; } break; - case 2: + case 2: menuAmoCount++; - if( menuAmoCount > 500 ) - { + if (menuAmoCount > 500) { menuAmoCount = 0; - menuPosyNow = 34; - menuState = 3; + menuPosyNow = 34; + menuState = 3; } - break; - case 3: + break; + case 3: menuPosyNow -= 4; - if( menuPosyNow <= 0) - { - menuPosyNow = 0; - menuState = 0; + if (menuPosyNow <= 0) { + menuPosyNow = 0; + menuState = 0; menuAmoCount = 0; } - break; + break; } - Disbuff.fillRect(0,206,320,34,TFT_BLACK); - Disbuff.pushInSprite(&menubuff,0,0,320,34,0,241 - menuPosyNow); - Disbuff.pushSprite(0,0); - + Disbuff.fillRect(0, 206, 320, 34, TFT_BLACK); + Disbuff.pushInSprite(&menubuff, 0, 0, 320, 34, 0, 241 - menuPosyNow); + Disbuff.pushSprite(0, 0); } - endImage: +endImage: - for (int n = 0; n < 12; n++) - { + for (int n = 0; n < 12; n++) { rect_source[n].start_point.x = rect[n].start_point.x * 12; rect_source[n].start_point.y = rect[n].start_point.y * 12; rect_source[n].start_point.z = rect[n].start_point.z * 12; - rect_source[n].end_point.x = rect[n].end_point.x * 12; - rect_source[n].end_point.y = rect[n].end_point.y * 12; - rect_source[n].end_point.z = rect[n].end_point.z * 12; + rect_source[n].end_point.x = rect[n].end_point.x * 12; + rect_source[n].end_point.y = rect[n].end_point.y * 12; + rect_source[n].end_point.z = rect[n].end_point.z * 12; } - Disbuff.drawJpg(CoreMainImage,87169,0,0,320,240,0,0); - Disbuff.pushSprite(0,0); + Disbuff.drawJpg(CoreMainImage, 87169, 0, 0, 320, 240, 0, 0); + Disbuff.pushSprite(0, 0); sytState.power = kPOWER_MAX; - } -void setCheckState(int number, bool state, bool flush) -{ +void setCheckState(int number, bool state, bool flush) { int posx = 0, posy = 0; - uint8_t *ptr1 = nullptr,*ptr2 = nullptr; - if( number >= 5 ) - { + uint8_t *ptr1 = nullptr, *ptr2 = nullptr; + if (number >= 5) { posx = 166; - posy = 154- ( number - 5 ) * 33; - ptr1 = (uint8_t*)image_Sysinit_0000s_0000_L1; - ptr2 = (uint8_t*)image_Sysinit_0000s_0001_L2; - } - else - { + posy = 154 - (number - 5) * 33; + ptr1 = (uint8_t *)image_Sysinit_0000s_0000_L1; + ptr2 = (uint8_t *)image_Sysinit_0000s_0001_L2; + } else { posx = 44; posy = 22 + number * 33; - ptr1 = (uint8_t*)image_Sysinit_0001s_0000_R1; - ptr2 = (uint8_t*)image_Sysinit_0001s_0001_R2; + ptr1 = (uint8_t *)image_Sysinit_0001s_0000_R1; + ptr2 = (uint8_t *)image_Sysinit_0001s_0001_R2; } - int32_t color = ( state ) ? 0x35ffae : 0xff0000; - - Disbuff.drawColorBitmapAlpha(posx,posy,53,33, - (uint8_t*)ptr2, - color, - 0x000000); - - Disbuff.drawColorBitmapAlpha(posx,posy + 1,53,33, - (uint8_t*)ptr1, - 0xff9a00, - color); - - if( flush == false ) return; - Disbuff.pushSprite(0,0); + int32_t color = (state) ? 0x35ffae : 0xff0000; + + Disbuff.drawColorBitmapAlpha(posx, posy, 53, 33, (uint8_t *)ptr2, color, + 0x000000); + + Disbuff.drawColorBitmapAlpha(posx, posy + 1, 53, 33, (uint8_t *)ptr1, + 0xff9a00, color); + + if (flush == false) return; + Disbuff.pushSprite(0, 0); } -void sysInitCheck() -{ - Disbuff.drawJpg(CoverImage,21301,0,0,320,240,0,0); - Disbuff.pushSprite(0,0); +void sysInitCheck() { + Disbuff.drawJpg(CoverImage, 21301, 0, 0, 320, 240, 0, 0); + Disbuff.pushSprite(0, 0); } -void setup() -{ +void setup() { M5.begin(true, true, true, false); M5.Axp.SetCHGCurrent(AXP192::kCHG_100mA); Disbuff.createSprite(320, 240); - - DisCoverScrollbuff.createSprite(320,60); - addI2cDevice("Axp192",0x34); - addI2cDevice("CST Touch",0x38); - addI2cDevice("IMU6886",0x68); - addI2cDevice("BM8563",0x51); - addI2cDevice("AT608A",0x35); + DisCoverScrollbuff.createSprite(320, 60); + + addI2cDevice("Axp192", 0x34); + addI2cDevice("CST Touch", 0x38); + addI2cDevice("IMU6886", 0x68); + addI2cDevice("BM8563", 0x51); + addI2cDevice("AT608A", 0x35); M5.Axp.SetLcdVoltage(2800); sysInitCheck(); SD.begin(); - sytState.App1Zone[0] = new HotZone( 20,191, 64,235,&AppImage); - sytState.App1Zone[1] = new HotZone( 79,191,123,235,&AppWifi); - sytState.App1Zone[2] = new HotZone(138,191,182,235,&AppTimer); - sytState.App1Zone[3] = new HotZone(197,191,241,235,&APPSleep); - sytState.App1Zone[4] = new HotZone(256,191,300,235,&AppSetting); - sytState.App1Zone[5] = new HotZone(72,130,161,186,&MPU6886Page); + sytState.App1Zone[0] = new HotZone(20, 191, 64, 235, &AppImage); + sytState.App1Zone[1] = new HotZone(79, 191, 123, 235, &AppWifi); + sytState.App1Zone[2] = new HotZone(138, 191, 182, 235, &AppTimer); + sytState.App1Zone[3] = new HotZone(197, 191, 241, 235, &APPSleep); + sytState.App1Zone[4] = new HotZone(256, 191, 300, 235, &AppSetting); + sytState.App1Zone[5] = new HotZone(72, 130, 161, 186, &MPU6886Page); M5.Axp.SetLcdVoltage(3300); @@ -2208,37 +1920,36 @@ void setup() InitI2SSpakerOrMic(MODE_SPK); xTaskCreatePinnedToCore(i2s_task, "i2s_task", 4096, NULL, 3, NULL, 0); - M5.Axp.SetLDOEnable(3,true); - CoverScrollText("Motor Test",M5.Lcd.color565(SUCCE_COLOR)); + M5.Axp.SetLDOEnable(3, true); + CoverScrollText("Motor Test", M5.Lcd.color565(SUCCE_COLOR)); delay(150); - M5.Axp.SetLDOEnable(3,false); + M5.Axp.SetLDOEnable(3, false); M5.Axp.SetLed(1); - CoverScrollText("LED Test",M5.Lcd.color565(SUCCE_COLOR)); + CoverScrollText("LED Test", M5.Lcd.color565(SUCCE_COLOR)); delay(100); M5.Axp.SetLed(0); - + FastLED.addLeds(ledsBuff, LEDS_NUM); - for (int i = 0; i < LEDS_NUM; i++) - { + for (int i = 0; i < LEDS_NUM; i++) { ledsBuff[i].setRGB(20, 20, 20); } FastLED.show(); - + Wire1.begin(21, 22, 100000UL); checkI2cAddr(); checkAETCC608AInit(); checkPsram(); checkIMUInit(); checkSDCard(); - + DisCoverScrollbuff.deleteSprite(); - - M5.Axp.SetLDOVoltage(3,3300); + + M5.Axp.SetLDOVoltage(3, 3300); M5.Axp.SetLed(1); - - Disbuff.drawJpg(CoreMainImage,87169,0,0,320,240,0,0); - Disbuff.pushSprite(0,0); + + Disbuff.drawJpg(CoreMainImage, 87169, 0, 0, 320, 240, 0, 0); + Disbuff.pushSprite(0, 0); setup3D(); clockSetup(); @@ -2251,12 +1962,10 @@ void setup() } uint16_t imageCount = 0; -uint16_t timecount = 0; +uint16_t timecount = 0; -void loop() -{ - if( timecount >= 2 ) - { +void loop() { + if (timecount >= 2) { timecount = 0; clockFlush(); batpowerFlush(); From 7818ef9b1ed070dd55d5dec31ab03588b31563fa Mon Sep 17 00:00:00 2001 From: Sean Kwok <45260108+Gitshaoxiang@users.noreply.github.com> Date: Wed, 23 Feb 2022 15:54:46 +0800 Subject: [PATCH 12/16] add scales kit example --- examples/KIT/SCALES_KIT/SCALES_KIT.ino | 113 +++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 examples/KIT/SCALES_KIT/SCALES_KIT.ino diff --git a/examples/KIT/SCALES_KIT/SCALES_KIT.ino b/examples/KIT/SCALES_KIT/SCALES_KIT.ino new file mode 100644 index 00000000..47371d3c --- /dev/null +++ b/examples/KIT/SCALES_KIT/SCALES_KIT.ino @@ -0,0 +1,113 @@ +/* +******************************************************************************* +* Copyright (c) 2022 by M5Stack +* Equipped with M5Core2 sample source code +* 配套 M5Core2 示例源代码 +* Visit the website for more information:https://docs.m5stack.com/en/app/scales_kit +* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/app/scales_kit +* +* describe: SCALES KIT WEIGHT UNIT EXAMPLE. +* date:2022/02/23 +******************************************************************************* + Connect WEIGHT UNIT to port A (G32/33), calibration instructions: touch button A to remove the tare weight when there is no load, + touch button B, switch the standard weight value left and right and put down the corresponding weight, confirm for calibration. + 将WEIGHT UNIT连接至端口A(G32/33), 校准说明:无负重情况下触摸按键A去处皮重, 触摸按键B,左右触摸切换标准重量值并放下对应重量砝码,comfirm进行校准。 + Libraries: + - [HX711](https://github.com/bogde/HX711) + +*/ + +#include +#include +#include "HX711.h" + +M5GFX display; +M5Canvas canvas(&display); + +// HX711 related pin Settings. HX711 相关引脚设置 +#define LOADCELL_DOUT_PIN 33 +#define LOADCELL_SCK_PIN 32 + +HX711 scale; + +void setup() { + M5.begin(); //Init M5Stack. 初始化M5Stack + display.begin(); + canvas.setColorDepth(1); // mono color + canvas.createSprite(display.width(), display.height()); + canvas.setTextDatum(MC_DATUM); + canvas.setPaletteColor(1, GREEN); + + canvas.drawString("Calibration sensor....", 160, 80); + canvas.pushSprite(0, 0); + scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN); + + + scale.set_gain(); + //The scale value is the adc value corresponding to 1g + scale.set_scale(27.61f); //set scale + scale.tare(); // auto set offset +} + +char info[100]; + +void loop() { + canvas.fillSprite(BLACK); + canvas.setTextSize(1); + canvas.drawString("Connect the Weight Unit to PortB(G26,G36)", 160, 40); + canvas.drawString("Click Btn A for Tare deduction", 160, 55); + canvas.drawString("Click Btn B Switch to Calibration mode", 160, 70); + float weight = scale.get_units(10)/1000.0; + // float weight = scale.get_units(10) / 1.0; + canvas.setTextSize(3); + if(weight >= 0) { + Serial.printf("Weight: %.2f", weight); + sprintf(info, "Weight: %.2f", weight); + canvas.drawString(String(info) + "kg", 160, 150); + // canvas.drawString(String(info) + "g", 160, 150); + }else{ + canvas.drawString("Weight: 0kg", 160, 150); + // canvas.drawString("Weight: 0g", 160, 150); + } + M5.update(); + if (M5.BtnA.wasPressed()) { + scale.tare(); + canvas.drawString("0g Calibration!", 160, 180); + } + if (M5.BtnB.wasPressed()) { + long kg = 5; + while (1) + { + M5.update(); + canvas.fillSprite(BLACK); + canvas.setTextSize(1); + canvas.drawString("Connect the Weight Unit to PortB(G26,G36)", 160, 40); + canvas.drawString("Click Btn A/C to change kg value", 160, 55); + canvas.drawString("Click Btn B Calibration Comfirm", 160, 70); + canvas.setTextSize(3); + canvas.drawString("Calibration:" + String(kg) + "kg", 160, 150); + canvas.drawString("comfirm", 160, 200); + canvas.fillTriangle(40, 200, 60, 220, 60, 180, 1); + canvas.fillTriangle(280, 200, 260, 220, 260, 180, 1); + canvas.pushSprite(0, 0); + if(M5.BtnA.isPressed()){ + kg--; + } + if(M5.BtnC.isPressed()){ + kg++; + } + if(M5.BtnB.wasPressed()){ + break; + } + delay(10); + } + long kg_adc = scale.read_average(20); + kg_adc = kg_adc - scale.get_offset(); + scale.set_scale( kg_adc / (kg * 1000.0)); + // canvas.drawString(String(kg) + "kg Calibration: " + String(kg_adc / (kg * 1000.0)), 160, 180); + canvas.drawString("Set Scale: " + String(kg_adc / (kg * 1000.0)), 160, 180); + canvas.pushSprite(0, 0); + delay(1000); + } + canvas.pushSprite(0, 0); +} \ No newline at end of file From 8a07302d0bc08ee60ea4347d9c28da554035d67b Mon Sep 17 00:00:00 2001 From: Sean Kwok <45260108+Gitshaoxiang@users.noreply.github.com> Date: Tue, 8 Mar 2022 18:41:14 +0800 Subject: [PATCH 13/16] add UNIT CATM+GNSS examples --- .../Unit/CATM_GNSS_SIM7080G/CoAP/CoAP.ino | 201 ++++++++++++++++++ .../Unit/CATM_GNSS_SIM7080G/GNSS/GNSS.ino | 178 ++++++++++++++++ .../MQTT_CLIENT/MQTT_CLIENT.ino | 201 ++++++++++++++++++ 3 files changed, 580 insertions(+) create mode 100644 examples/Unit/CATM_GNSS_SIM7080G/CoAP/CoAP.ino create mode 100644 examples/Unit/CATM_GNSS_SIM7080G/GNSS/GNSS.ino create mode 100644 examples/Unit/CATM_GNSS_SIM7080G/MQTT_CLIENT/MQTT_CLIENT.ino diff --git a/examples/Unit/CATM_GNSS_SIM7080G/CoAP/CoAP.ino b/examples/Unit/CATM_GNSS_SIM7080G/CoAP/CoAP.ino new file mode 100644 index 00000000..fe41ff88 --- /dev/null +++ b/examples/Unit/CATM_GNSS_SIM7080G/CoAP/CoAP.ino @@ -0,0 +1,201 @@ +/* +******************************************************************************* +* Copyright (c) 2022 by M5Stack +* Equipped with M5Core2 sample source code +* 配套 M5Core2 示例源代码 +* Visit the website for more +information:https://docs.m5stack.com/en/unit/catm_gnss +* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/module/catm_gnss +* +* describe: catm_gnss. +* date:2022/03/03 +******************************************************************************* +This case will use UNIT CATM+GNSS combined with M5Core +Connect to the CoAP server and send a request. +Before use, connect the UNIT CATM+GNSS to PORT C(G16/17) +Libraries: +- [TinyGSM](https://github.com/vshymanskyy/TinyGSM) +*/ + +#define RX2 13 +#define TX2 14 + +#include +#include "M5GFX.h" + +#define TINY_GSM_MODEM_SIM7080 + +// Set serial for debug console (to the Serial Monitor, default speed 115200) +#define SerialMon Serial +#define SerialAT Serial2 + +uint32_t lastReconnectAttempt = 0; + +#define TINY_GSM_RX_BUFFER 650 + +#define TINY_GSM_DEBUG SerialMon + +#define MODULE_BAUD 115200 + +// Your GPRS credentials, if any +const char apn[] = "YourAPN"; +const char gprsUser[] = ""; +const char gprsPass[] = ""; + +#include + +TinyGsm modem(SerialAT); +TinyGsmClient client(modem); + +M5GFX display; +M5Canvas canvas(&display); + +unsigned long start; + +typedef enum { GET = 1, POST, PUT, DELETE } coap_method_t; + +inline String time() { return "..." + String((millis() - start) / 1000) + 's'; } + +void log(String info) { + SerialMon.println(info); + canvas.println(info); + canvas.pushSprite(0, 0); +} + +String waitMsg(unsigned long time) { + String restr = ""; + unsigned long start = millis(); + while (1) { + if (SerialAT.available() || (millis() - start) < time) { + String str = SerialAT.readString(); + restr += str; + } else { + break; + } + } + return restr; +} + +bool craeteCoAPPacket(String url, String url_query, coap_method_t method, + String payload) { + log("Create CoAPPacket"); + // SerialAT.println("AT+CCOAPPARA=\"CODE\",4,uri-path,0,\"/m5stack-get\",uri-query,0,\"catm_test=1\",payload,0,\"hello + // world\""); + SerialAT.println("AT+CCOAPPARA=\"CODE\"," + String(method) + + ",uri-path,0,\"" + url + "\",uri-query,0,\"" + url_query + + "\",payload,0,\"" + payload + "\""); + if (waitMsg(2000).indexOf("OK") != -1) { + return true; + } else { + return false; + } +} + +bool connectCoAP(String ip, String port) { + SerialAT.println("AT+CNACT=0,0"); + log(waitMsg(500)); + SerialAT.println("AT+CNACT=0,1"); + log(waitMsg(500)); + SerialAT.println("AT+CCOAPINIT"); + log(waitMsg(500)); + SerialAT.println("AT+CCOAPURL=\"coap://120.77.157.90:5683\""); + String result = waitMsg(1000); + log(result); + if (result.indexOf("ERROR") != -1) { + SerialAT.println("AT+CCOAPTERM"); + String result = waitMsg(1000); + return false; + } else { + return true; + } +} + +String sendCoAPRequest() { + SerialAT.println("AT+CCOAPACTION"); + String result = waitMsg(5000); + log(result); + if (result.indexOf("+CCOAPRECV") != -1) { + String str1 = result.substring(result.indexOf("+CCOAPRECV") + 11); + String str2 = str1.substring(1, str1.indexOf(",")); + return str2; + } else { + return "ERROR"; + } +} + +String getCoAPreceive(String msgid) { + SerialAT.println("AT+CCOAPACTION=4"); + log(waitMsg(2000)); + // Read the packet header with messageidof 1and print + SerialAT.println("AT+CCOAPHEAD=" + msgid + ",1"); + log(waitMsg(2000)); + // Read the receive packet payload with messageid of 1 + SerialAT.println("AT+CCOAPREAD=" + msgid); + log(waitMsg(2000)); +} + +void setup() { + M5.begin(); + display.begin(); + start = millis(); + canvas.setColorDepth(1); // mono color + canvas.setFont(&fonts::efontCN_14); + canvas.createSprite(display.width(), display.height()); + canvas.setTextSize(2); + canvas.setPaletteColor(1, GREEN); + canvas.setTextScroll(true); + + log("Initializing modem..." + time()); + + // Set GSM module baud rate + if (TinyGsmAutoBaud(SerialAT, MODULE_BAUD, MODULE_BAUD) == 0) { + log("UART connect error" + time()); + } + // modem.restart(); + modem.init(); + String modemInfo = modem.getModemInfo(); + log("Modem Info: "); + log(modemInfo + time()); + while (!modem.getSimStatus()) { + log("not sim card" + time()); + } +} + +void loop() { + log("Waiting for network...." + time()); + if (!modem.waitForNetwork()) { + log("fail" + time()); + log(waitMsg(1000)); + + return; + } + if (modem.isNetworkConnected()) { + log("Network connected" + time()); + } + + IPAddress local = modem.localIP(); + log("REMOTE IP: " + local.toString()); + + int csq = modem.getSignalQuality(); + log("RSSI:" + String(csq) + time()); + log("IP:" + local.toString() + time()); + + if (connectCoAP("120.77.157.90", "5683")) { + log("connect successful, click button a to send request"); + } + while (1) { + M5.update(); + if (M5.BtnA.wasPressed()) { + craeteCoAPPacket("/m5stack-get", "catm_test=1", GET, "hello world"); + String msgid = sendCoAPRequest(); + log(msgid); + if (msgid != "ERROR") { + getCoAPreceive(msgid); + } + } + String result = waitMsg(0); + if (result != "") { + log(result); + } + } +} diff --git a/examples/Unit/CATM_GNSS_SIM7080G/GNSS/GNSS.ino b/examples/Unit/CATM_GNSS_SIM7080G/GNSS/GNSS.ino new file mode 100644 index 00000000..ade593c6 --- /dev/null +++ b/examples/Unit/CATM_GNSS_SIM7080G/GNSS/GNSS.ino @@ -0,0 +1,178 @@ +/* +******************************************************************************* +* Copyright (c) 2022 by M5Stack +* Equipped with M5Core2 sample source code +* 配套 M5Core2 示例源代码 +* Visit the website for more +information:https://docs.m5stack.com/en/unit/catm_gnss +* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/module/catm_gnss +* +* describe: catm_gnss. +* date:2022/03/03 +******************************************************************************* +This case will use UNIT CATM+GNSS combined with M5Core +Obtain positioning information through GNSS +Before use, connect the UNIT CATM+GNSS to PORT C(G16/17) +Libraries: +- [TinyGSM](https://github.com/vshymanskyy/TinyGSM) +*/ + +#define RX2 13 +#define TX2 14 + +#include +#include "M5GFX.h" + +#define TINY_GSM_MODEM_SIM7080 + +// Set serial for debug console (to the Serial Monitor, default speed 115200) +#define SerialMon Serial +#define SerialAT Serial2 + +uint32_t lastReconnectAttempt = 0; + +#define TINY_GSM_RX_BUFFER 650 + +#define TINY_GSM_DEBUG SerialMon + +#define MODULE_BAUD 115200 + +// Your GPRS credentials, if any +const char apn[] = "YourAPN"; +const char gprsUser[] = ""; +const char gprsPass[] = ""; + +#include +#include + +TinyGsm modem(SerialAT); +TinyGsmClient client(modem); + +M5GFX display; +M5Canvas canvas(&display); + +const char* broker = "mqtt.m5stack.com"; + +const char* topic_up = "cat1/up"; +const char* topic_down = "cat1/down"; + +PubSubClient mqtt(client); + +unsigned long start; + +inline String time() { + return "..." + String((millis() - start) / 1000) + 's'; +} + +void log(String info) { + SerialMon.println(info); + canvas.println(info); + canvas.pushSprite(0, 0); +} + +void mqttCallback(char* topic, byte* payload, unsigned int len) { + log("Message arrived :"); + log(topic); + log("payload: "); + char _payload[len]; + memcpy(_payload, payload, len); + _payload[len] = '\0'; + log(_payload); +} + +boolean mqttConnect() { + log("Connecting to "); + log(broker); + + // Connect to MQTT Broker + boolean status = mqtt.connect("GsmClientTest"); + + // Or, if you want to authenticate MQTT: + // boolean status = mqtt.connect("GsmClientName", "mqtt_user", "mqtt_pass"); + + if (status == false) { + SerialMon.println(" fail"); + return false; + } + SerialMon.println(" success"); + mqtt.publish(topic_up, "GsmClientTest started"); + mqtt.subscribe(topic_down); + log("Subscribe Topic: " + String(topic_down)); + return mqtt.connected(); +} + +void setup() { + M5.begin(); + display.begin(); + start = millis(); + canvas.setColorDepth(1); // mono color + canvas.setFont(&fonts::efontCN_14); + canvas.createSprite(display.width(), display.height()); + canvas.setTextSize(2); + canvas.setPaletteColor(1, GREEN); + canvas.setTextScroll(true); + + log("Initializing modem..." + time()); + + // Set GSM module baud rate + if (TinyGsmAutoBaud(SerialAT, MODULE_BAUD, MODULE_BAUD) == 0) { + log("UART connect error" + time()); + } + // modem.restart(); + modem.init(); + String modemInfo = modem.getModemInfo(); + log("Modem Info: "); + log(modemInfo + time()); +} + +bool gps_flag = false; + +void loop() { + canvas.println("INIT GNSS" + time()); + canvas.pushSprite(0, 0); + while (1) { + DBG("Enabling GPS/GNSS/GLONASS and waiting 15s for warm-up"); + modem.enableGPS(); + delay(15000L); + float lat2 = 0; + float lon2 = 0; + float speed2 = 0; + float alt2 = 0; + int vsat2 = 0; + int usat2 = 0; + float accuracy2 = 0; + int year2 = 0; + int month2 = 0; + int day2 = 0; + int hour2 = 0; + int min2 = 0; + int sec2 = 0; + for (int8_t i = 15; i; i--) { + DBG("Requesting current GPS/GNSS/GLONASS location"); + if (modem.getGPS(&lat2, &lon2, &speed2, &alt2, &vsat2, &usat2, + &accuracy2, &year2, &month2, &day2, &hour2, &min2, + &sec2)) { + log("Latitude:" + String(lat2, 8) + + "\tLongitude:" + String(lon2, 8)); + log("Speed:" + String(speed2) + + "\tAltitude:" + String(alt2)); + log("Visible Satellites:" + String(vsat2) + + "\tUsed Satellites:" + String(usat2)); + log("Accuracy:" + String(accuracy2)); + log("Year:" + String(year2) + "\tMonth:" + + String(month2) + "\tDay:" + String(day2)); + log("Hour:" + String(hour2) + "\tMinute:" + + String(min2) + "\tSecond:" + String(sec2)); + break; + } else { + log("Get GPS/GNSS/GLONASS location.." + time()); + DBG("Couldn't get GPS/GNSS/GLONASS location, retrying in 10s."); + delay(10000L); + } + } + // modem.disableGPS(); + } + while (1) { + delay(100); + } +} diff --git a/examples/Unit/CATM_GNSS_SIM7080G/MQTT_CLIENT/MQTT_CLIENT.ino b/examples/Unit/CATM_GNSS_SIM7080G/MQTT_CLIENT/MQTT_CLIENT.ino new file mode 100644 index 00000000..6eeee98c --- /dev/null +++ b/examples/Unit/CATM_GNSS_SIM7080G/MQTT_CLIENT/MQTT_CLIENT.ino @@ -0,0 +1,201 @@ +/* +******************************************************************************* +* Copyright (c) 2022 by M5Stack +* Equipped with M5Core2 sample source code +* 配套 M5Core2 示例源代码 +* Visit the website for more +information:https://docs.m5stack.com/en/unit/catm_gnss +* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/module/catm_gnss +* +* describe: catm_gnss. +* date:2022/03/03 +******************************************************************************* +This case will use UNIT CATM+GNSS combined with M5Core to implement MQTT +Client. After successfully connecting to MQTT, press button B to realize data +publishing. +Before use, connect the UNIT CATM+GNSS to PORT C(G16/17) +Libraries: +- [TinyGSM](https://github.com/vshymanskyy/TinyGSM) +- [PubSubClient](https://github.com/knolleary/pubsubclient.git) +*/ + +#define RX2 13 +#define TX2 14 + +#include +#include "M5GFX.h" + +#define TINY_GSM_MODEM_SIM7080 + +// Set serial for debug console (to the Serial Monitor, default speed 115200) +#define SerialMon Serial +#define SerialAT Serial2 + +uint32_t lastReconnectAttempt = 0; + +#define TINY_GSM_RX_BUFFER 650 + +#define TINY_GSM_DEBUG SerialMon + +#define MODULE_BAUD 115200 + +// Your GPRS credentials, if any +const char apn[] = "YourAPN"; +const char gprsUser[] = ""; +const char gprsPass[] = ""; + +#include +#include + +TinyGsm modem(SerialAT); +TinyGsmClient client(modem); + +M5GFX display; +M5Canvas canvas(&display); + +const char* broker = "mqtt.m5stack.com"; + +const char* topic_up = "cat1/up"; +const char* topic_down = "cat1/down"; + +PubSubClient mqtt(client); + +unsigned long start; + +inline String time() { return "..." + String((millis() - start) / 1000) + 's'; } + +void log(String info) { + SerialMon.println(info); + canvas.println(info); + canvas.pushSprite(0, 0); +} + +void mqttCallback(char* topic, byte* payload, unsigned int len) { + log("Message arrived :"); + log(topic); + log("payload: "); + char _payload[len]; + memcpy(_payload, payload, len); + _payload[len] = '\0'; + log(_payload); +} + +boolean mqttConnect() { + log("Connecting to "); + log(broker); + + // Connect to MQTT Broker + boolean status = mqtt.connect("GsmClientTest"); + + // Or, if you want to authenticate MQTT: + // boolean status = mqtt.connect("GsmClientName", "mqtt_user", "mqtt_pass"); + + if (status == false) { + SerialMon.println(" fail"); + return false; + } + SerialMon.println(" success"); + mqtt.publish(topic_up, "GsmClientTest started"); + mqtt.subscribe(topic_down); + log("Subscribe Topic: " + String(topic_down)); + return mqtt.connected(); +} + +void setup() { + M5.begin(); + display.begin(); + start = millis(); + canvas.setColorDepth(1); // mono color + canvas.setFont(&fonts::efontCN_14); + canvas.createSprite(display.width(), display.height()); + canvas.setTextSize(2); + canvas.setPaletteColor(1, GREEN); + canvas.setTextScroll(true); + + log("Initializing modem..." + time()); + + // Set GSM module baud rate + if (TinyGsmAutoBaud(SerialAT, MODULE_BAUD, MODULE_BAUD) == 0) { + log("UART connect error" + time()); + } + // modem.restart(); + modem.init(); + String modemInfo = modem.getModemInfo(); + log("Modem Info: "); + log(modemInfo + time()); + while (!modem.getSimStatus()) { + log("not sim card" + time()); + } +} + +void loop() { + log("Waiting for network...." + time()); + if (!modem.waitForNetwork()) { + log("fail" + time()); + delay(10000); + return; + } + if (modem.isNetworkConnected()) { + log("Network connected" + time()); + } + log("GPRS connect..." + time()); + if (!modem.gprsConnect(apn, gprsUser, gprsPass)) { + log("fail"); + delay(10000); + return; + } + if (modem.isGprsConnected()) { + log("GPRS connected"); + } + + String ccid = modem.getSimCCID(); + log("CCID: "); + log(ccid); + + String imei = modem.getIMEI(); + log("IMEI: " + imei); + + String imsi = modem.getIMSI(); + log("IMSI: " + imsi); + + String cop = modem.getOperator(); + log("Operator: " + cop); + + IPAddress local = modem.localIP(); + log("REMOTE IP: " + local.toString()); + + int csq = modem.getSignalQuality(); + log("RSSI:" + String(csq) + time()); + log("IP:" + local.toString() + time()); + + // MQTT Broker setup + mqtt.setServer(broker, 1883); + mqtt.setCallback(mqttCallback); + + while (true) { + M5.update(); + if (!mqtt.connected()) { + log("=== MQTT NOT CONNECTED ==="); + // Reconnect every 10 seconds + uint32_t t = millis(); + if (t - lastReconnectAttempt > 3000L) { + lastReconnectAttempt = t; + if (mqttConnect()) { + lastReconnectAttempt = 0; + log("mqtt.m5stack.com" + time()); + log("MQTT Connected!" + time()); + log("Press Btn B to Publish"); + log("Topic: " + String(topic_up)); + } + } + delay(100); + } else { + mqtt.loop(); + M5.update(); + if (M5.BtnB.wasPressed()) { + log("Publish:" + String(topic_up)); + mqtt.publish(topic_up, "Hello From UNIT CATM+GNSS"); + } + } + } +} From 2bcf64c9ce099c597b741d46ac43319007a52f86 Mon Sep 17 00:00:00 2001 From: Tinyu Date: Sat, 12 Mar 2022 15:46:07 +0800 Subject: [PATCH 14/16] Update FactoryTest.ino --- .../core2_for_aws/FactoryTest/FactoryTest.ino | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/examples/core2_for_aws/FactoryTest/FactoryTest.ino b/examples/core2_for_aws/FactoryTest/FactoryTest.ino index d2a05f92..ba0638b3 100644 --- a/examples/core2_for_aws/FactoryTest/FactoryTest.ino +++ b/examples/core2_for_aws/FactoryTest/FactoryTest.ino @@ -281,11 +281,16 @@ bool InitI2SSpakerOrMic(int mode) { .sample_rate = 44100, .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT, // is fixed at 12bit, stereo, MSB - .channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT, - .communication_format = I2S_COMM_FORMAT_STAND_I2S, - .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, - .dma_buf_count = 2, - .dma_buf_len = 128, + .channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT, +#if ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(4, 1, 0) + .communication_format = + I2S_COMM_FORMAT_STAND_I2S, // Set the format of the communication. +#else // 设置通讯格式 + .communication_format = I2S_COMM_FORMAT_I2S, +#endif + .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, + .dma_buf_count = 2, + .dma_buf_len = 128, }; if (mode == MODE_MIC) { i2s_config.mode = From 6e1e0c8c82ab628e6cad692a9525be812c9faef9 Mon Sep 17 00:00:00 2001 From: Tinyu Date: Sat, 12 Mar 2022 15:51:11 +0800 Subject: [PATCH 15/16] Update PDM_SPM1423.ino --- examples/Unit/PDM_SPM1423/PDM_SPM1423.ino | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/Unit/PDM_SPM1423/PDM_SPM1423.ino b/examples/Unit/PDM_SPM1423/PDM_SPM1423.ino index 3ad89170..265efa79 100644 --- a/examples/Unit/PDM_SPM1423/PDM_SPM1423.ino +++ b/examples/Unit/PDM_SPM1423/PDM_SPM1423.ino @@ -7,7 +7,7 @@ * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/unit/pdm * * describe: pdm. 麦克风 -* date:2022/2/22 +* date:2022/3/12 ******************************************************************************* Please connect to Port A,Read the microphone data of the PDM Unit and display the audio frequency spectrum. 请连接端口A,读取PDM @@ -46,9 +46,12 @@ bool InitI2SSpakerOrMic(int mode) { // 固定为12位立体声MSB .channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT, // Set the channel format. 设置频道格式 +#if ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(4, 1, 0) .communication_format = I2S_COMM_FORMAT_STAND_I2S, // Set the format of the communication. - // 设置通讯格式 +#else // 设置通讯格式 + .communication_format = I2S_COMM_FORMAT_I2S, +#endif .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, // Set the interrupt flag. 设置中断的标志 .dma_buf_count = 2, // DMA buffer count. DMA缓冲区计数 From fc39cdc5f65e23d366312da30b5bdcf654ceb234 Mon Sep 17 00:00:00 2001 From: Tinyu Date: Sat, 12 Mar 2022 21:08:31 +0800 Subject: [PATCH 16/16] Update sleep.ino --- examples/Basics/sleep/sleep.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/Basics/sleep/sleep.ino b/examples/Basics/sleep/sleep.ino index 41bea3e5..8a5585b9 100644 --- a/examples/Basics/sleep/sleep.ino +++ b/examples/Basics/sleep/sleep.ino @@ -7,7 +7,7 @@ * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/core/core2 * * describe:Sleep--Axp电源休眠 -* date:2021/7/21 +* date:2022/3/12 ******************************************************************************* */ #include @@ -37,7 +37,7 @@ void setup(){ M5.Lcd.println("Going to deep sleep for 5 seconds."); delay(2500); - M5.Axp.DeepSleep(SLEEP_SEC(5)); //Wake up after 5 seconds of light sleep, the CPU will reboot and the program will start from the beginning. 轻度睡眠5秒后唤醒,CPU将重新启动,程序将从头开始执行 + M5.Axp.DeepSleep(SLEEP_SEC(5)); //Wake up after 5 seconds of deep sleep, the CPU will reboot and the program will start from the beginning. 深度睡眠5秒后唤醒,CPU将重新启动,程序将从头开始执行 } void loop()