From f77022faa11aa5c5bdc2f39d842b57d81ce70a73 Mon Sep 17 00:00:00 2001 From: TinyuChiu Date: Tue, 23 Aug 2022 15:36:13 +0800 Subject: [PATCH] fix gesture error --- .github/workflows/clang-format-check.yml | 2 +- .../Display_Unicode/Display_Unicode.ino | 4 +- .../Advanced/Display/HZK16/display_ch.cpp | 4 +- examples/Advanced/Display/HZK16/display_ch.h | 12 +- .../Advanced/Display/JpegDraw/JpegDraw.ino | 3 +- .../COM_LoRaWAN/LoRaWAN_Send/TFTTerminal.cpp | 131 ------------ .../COM_LoRaWAN/LoRaWAN_Send/TFTTerminal.h | 33 --- examples/Unit/BPS_BMP280/BPS_BMP280.ino | 46 ---- .../GESTURE_PAJ7620U2/GESTURE_PAJ7620U2.ino | 10 +- examples/Unit/LoRaWAN470/LoRaWAN470.ino | 161 -------------- examples/Unit/LoRaWAN868/LoRaWAN868.ino | 198 ------------------ examples/Unit/LoRaWAN915/LoRaWAN915.ino | 169 --------------- examples/Unit/LoRaWAN915/TFTTerminal.cpp | 131 ------------ examples/Unit/LoRaWAN915/TFTTerminal.h | 33 --- examples/Unit/RELAY/RELAY.ino | 38 ---- 15 files changed, 23 insertions(+), 952 deletions(-) delete mode 100644 examples/Modules/COM_LoRaWAN/LoRaWAN_Send/TFTTerminal.cpp delete mode 100644 examples/Modules/COM_LoRaWAN/LoRaWAN_Send/TFTTerminal.h delete mode 100644 examples/Unit/BPS_BMP280/BPS_BMP280.ino delete mode 100644 examples/Unit/LoRaWAN470/LoRaWAN470.ino delete mode 100644 examples/Unit/LoRaWAN868/LoRaWAN868.ino delete mode 100644 examples/Unit/LoRaWAN915/LoRaWAN915.ino delete mode 100644 examples/Unit/LoRaWAN915/TFTTerminal.cpp delete mode 100644 examples/Unit/LoRaWAN915/TFTTerminal.h delete mode 100644 examples/Unit/RELAY/RELAY.ino diff --git a/.github/workflows/clang-format-check.yml b/.github/workflows/clang-format-check.yml index 54713770..ca37c23a 100644 --- a/.github/workflows/clang-format-check.yml +++ b/.github/workflows/clang-format-check.yml @@ -8,7 +8,7 @@ jobs: matrix: path: - check: './' # path to include - exclude: '(Fonts|utility)' # path to exclude + exclude: '(Fonts|utility|RFID)' # path to exclude # - check: 'src' # exclude: '(Fonts)' # Exclude file paths containing "Fonts" # - check: 'examples' diff --git a/examples/Advanced/Display/Display_Unicode/Display_Unicode.ino b/examples/Advanced/Display/Display_Unicode/Display_Unicode.ino index cea97836..612be6b3 100644 --- a/examples/Advanced/Display/Display_Unicode/Display_Unicode.ino +++ b/examples/Advanced/Display/Display_Unicode/Display_Unicode.ino @@ -51,7 +51,9 @@ void loop() { M5.Lcd.fillScreen(0); M5.Lcd.setCursor(0, 30); M5.Lcd.printf( - "⛣⛤⛥⛦⛧⛨⛩⛪⛫⛬⛭⛮⛯F⛰⛱⛲⛳⛴⛵⛶⛷⛸⛹⛺⛻⛼⛽⛾⛿✀✁✂✃✄✅✆✇✈✉✊✋✌✍✎✏✐✑✒✓✔✕✖✗✘✙✚✛✜✝✞✟✠" + "⛣⛤⛥⛦⛧⛨⛩⛪⛫⛬⛭⛮⛯F⛰⛱⛲⛳⛴⛵⛶⛷⛸⛹⛺⛻⛼⛽⛾⛿✀✁✂✃✄✅✆✇✈✉✊✋✌✍✎✏✐✑✒✓✔✕✖✗✘✙✚✛✜✝✞" + "✟" + "✠" "✡" "✢" "✣" diff --git a/examples/Advanced/Display/HZK16/display_ch.cpp b/examples/Advanced/Display/HZK16/display_ch.cpp index 9f3c489b..05b4b3d6 100644 --- a/examples/Advanced/Display/HZK16/display_ch.cpp +++ b/examples/Advanced/Display/HZK16/display_ch.cpp @@ -25,7 +25,9 @@ DisplayCh::DisplayCh() { ***************************************************************************************/ -void DisplayCh::setTextWrap(boolean w) { textwrap = w; } +void DisplayCh::setTextWrap(boolean w) { + textwrap = w; +} /*************************************************************************************** ** Function name: setTextSize diff --git a/examples/Advanced/Display/HZK16/display_ch.h b/examples/Advanced/Display/HZK16/display_ch.h index 23895758..f521e462 100644 --- a/examples/Advanced/Display/HZK16/display_ch.h +++ b/examples/Advanced/Display/HZK16/display_ch.h @@ -29,7 +29,9 @@ class DisplayCh { // Highlight the text (Once set to be true, the text background will not be // transparent any more) - inline void highlight(bool isHighlight) { highlighted = isHighlight; } + inline void highlight(bool isHighlight) { + highlighted = isHighlight; + } // Set highlight color inline void setHighlightColor(uint16_t color) { highlightcolor = color; @@ -42,10 +44,14 @@ class DisplayCh { inline void setTransparentBgColor(bool isTransparent) { istransparent = isTransparent; } - inline bool isTransparentBg() { return istransparent; } + inline bool isTransparentBg() { + return istransparent; + } bool initHzk16(boolean use, const char* HZK16Path = nullptr, const char* ASC16Path = nullptr); - inline bool isHzk16Used() { return hzk16Used; } + inline bool isHzk16Used() { + return hzk16Used; + } void setTextWrap(boolean wrap); void writeHzkAsc(const char c); void writeHzkGbk(const char* c); diff --git a/examples/Advanced/Display/JpegDraw/JpegDraw.ino b/examples/Advanced/Display/JpegDraw/JpegDraw.ino index a4955a55..d179ff1b 100644 --- a/examples/Advanced/Display/JpegDraw/JpegDraw.ino +++ b/examples/Advanced/Display/JpegDraw/JpegDraw.ino @@ -12,4 +12,5 @@ void setup(void) { // jpeg_div_t scale); } -void loop() {} +void loop() { +} diff --git a/examples/Modules/COM_LoRaWAN/LoRaWAN_Send/TFTTerminal.cpp b/examples/Modules/COM_LoRaWAN/LoRaWAN_Send/TFTTerminal.cpp deleted file mode 100644 index 4a967385..00000000 --- a/examples/Modules/COM_LoRaWAN/LoRaWAN_Send/TFTTerminal.cpp +++ /dev/null @@ -1,131 +0,0 @@ -#include "TFTTerminal.h" - -TFTTerminal::TFTTerminal(TFT_eSprite *dis_buff_ptr) { - _dis_buff_ptr = dis_buff_ptr; - memset(discharbuff, 0, 55 * 60); -} - -TFTTerminal::~TFTTerminal() { -} - -void TFTTerminal::setcolor(uint16_t color, uint16_t bk_color) { - _color = color; - _bkcolor = bk_color; -} - -void TFTTerminal::setGeometry(uint16_t x, uint16_t y, uint16_t w, uint16_t h) { - _win_x_pos = x; - _win_y_pos = y; - _win_w = w; - _win_h = h; - - _line_x_limit = _win_w / _font_x_size; - _line_y_limit = _win_h / _font_y_size; -} - -void TFTTerminal::setFontsize(uint8_t size) { - size = (size == 0) ? 1 : size; - _font_x_size = 5 * size; - _font_y_size = 6 * size; - _fontSize = size; - - _line_x_limit = _win_w / _font_x_size; - _line_y_limit = _win_h / _font_y_size; -} - -size_t TFTTerminal::write(uint8_t chardata) { - bool flush_page_flag = false; - uint8_t dis_y_pos = 0; - - if ((chardata == '\r') || (chardata == '\n')) { - xpos = 0; - ypos++; - ypos = ypos % 60; - memset(discharbuff[ypos % 60], 0, 55); - return 1; - } else if (xpos >= _line_x_limit) { - xpos = 0; - ypos++; - ypos = ypos % 60; - memset(discharbuff[ypos % 60], 0, 55); - } - - discharbuff[ypos][xpos] = chardata; - xpos++; - - if ((dispos <= ypos) && ((ypos - dispos) > _line_y_limit)) { - dispos = ypos - _line_y_limit; - flush_page_flag = true; - } else if ((dispos <= ypos) && ((ypos - dispos) <= _line_y_limit)) { - dis_y_pos = ypos - dispos; - flush_page_flag = false; - } else if ((dispos > ypos) && ((60 - (dispos - ypos)) > _line_y_limit)) { - dispos = 60 - (_line_y_limit - ypos); - flush_page_flag = true; - } else if ((dispos > ypos) && ((60 - (dispos - ypos)) > _line_y_limit)) { - dis_y_pos = 60 - (dispos - ypos); - flush_page_flag = false; - } - - dispos = dispos % 60; - - _dis_buff_ptr->setTextColor(_color); - _dis_buff_ptr->setTextSize(_fontSize); - - if (flush_page_flag) { - _dis_buff_ptr->fillSprite(_bkcolor); - - for (size_t i = 0; i < _line_y_limit; i++) { - _dis_buff_ptr->drawString((char *)discharbuff[(dispos + i) % 60], 0, - i * _font_y_size); - } - } else { - _dis_buff_ptr->drawChar(chardata, (xpos - 1) * _font_x_size, - dis_y_pos * _font_y_size); - } - _dis_buff_ptr->pushSprite(_win_x_pos, _win_y_pos); - - return 1; -} - -size_t TFTTerminal::write(const uint8_t *buffer, size_t size) { - while ((size != 0) && (*buffer != '\0')) { - if ((*buffer == '\r') || (*buffer == '\n')) { - xpos = 0; - ypos++; - ypos = ypos % 60; - memset(discharbuff[ypos % 60], 0, 55); - buffer++; - size--; - continue; - } else if (xpos >= _line_x_limit) { - xpos = 0; - ypos++; - ypos = ypos % 60; - memset(discharbuff[ypos % 60], 0, 55); - } - discharbuff[ypos][xpos] = *buffer; - xpos++; - buffer++; - size--; - } - - if ((dispos <= ypos) && ((ypos - dispos) > _line_y_limit)) { - dispos = ypos - _line_y_limit; - } else if ((dispos > ypos) && ((60 - (dispos - ypos)) > _line_y_limit)) { - dispos = 60 - (_line_y_limit - ypos); - } - - dispos = dispos % 60; - - _dis_buff_ptr->setTextColor(_color); - _dis_buff_ptr->setTextSize(_fontSize); - _dis_buff_ptr->fillSprite(_bkcolor); - //_dis_buff_ptr->fillRect(_win_x_pos, _win_y_pos, _win_w, _win_h, _bkcolor); - for (size_t i = 0; i < _line_y_limit; i++) { - _dis_buff_ptr->drawString((char *)discharbuff[(dispos + i) % 60], 0, - i * _font_y_size); - } - _dis_buff_ptr->pushSprite(_win_x_pos, _win_y_pos); - return 1; -} diff --git a/examples/Modules/COM_LoRaWAN/LoRaWAN_Send/TFTTerminal.h b/examples/Modules/COM_LoRaWAN/LoRaWAN_Send/TFTTerminal.h deleted file mode 100644 index 85b8d832..00000000 --- a/examples/Modules/COM_LoRaWAN/LoRaWAN_Send/TFTTerminal.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef _TFTTERMINAL_H_ -#define _TFTTERMINAL_H_ - -#include -#include - -class TFTTerminal : public Print { - private: - TFT_eSprite *disptr; - char discharbuff[60][55]; - uint32_t xpos = 0, ypos = 0, dispos = 0; - TFT_eSprite *_dis_buff_ptr = NULL; - uint16_t _bkcolor = TFT_BLACK; - uint16_t _color = TFT_GREEN; - - uint16_t _win_x_pos = 0, _win_y_pos = 0, _win_w = 320, _win_h = 240; - uint16_t _font_x_size = 6, _font_y_size = 8; - uint8_t _fontSize = 0; - uint16_t _line_x_limit = 53, _line_y_limit = 30; - - public: - TFTTerminal(TFT_eSprite *dis_buff_ptr); - ~TFTTerminal(); - - void setcolor(uint16_t color, uint16_t bk_color); - void setGeometry(uint16_t x, uint16_t y, uint16_t w, uint16_t h); - void setFontsize(uint8_t size); - - size_t write(uint8_t); - size_t write(const uint8_t *buffer, size_t size); -}; - -#endif diff --git a/examples/Unit/BPS_BMP280/BPS_BMP280.ino b/examples/Unit/BPS_BMP280/BPS_BMP280.ino deleted file mode 100644 index 30c11eba..00000000 --- a/examples/Unit/BPS_BMP280/BPS_BMP280.ino +++ /dev/null @@ -1,46 +0,0 @@ -/* -******************************************************************************* -* Copyright (c) 2022 by M5Stack -* Equipped with M5Core sample source code -* 配套 M5Core 示例源代码 -* Visit for more information: https://docs.m5stack.com/en/core/gray -* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/gray -* -* Describe: BPS_BMP280. 压力传感器 -* Date: 2021/8/10 -******************************************** *********************************** - Please connect to Port A(22、21),Read atmospheric pressure and temperature and -display them on the display screen - 请连接端口A(22、21),读取大气压强和温度并在显示屏上显示 -*/ -#include -#include -#include //The BPS uses I2C comunication. - -#include "Adafruit_Sensor.h" - -Adafruit_BMP280 bme; - -void setup() { - M5.begin(); // Init M5Stack. 初始化M5Stack - M5.Power.begin(); // Init power 初始化电源模块 - M5.Lcd.setTextSize(2); //设置字体大小为2. Set the font size to 2 - Wire.begin(); // Wire init, adding the I2C bus. Wire初始化, 加入i2c总线 - while (!bme.begin( - 0x76)) { // Init this sensor,True if the init was successful, otherwise - // false. 初始化传感器,如果初始化成功返回1 - M5.Lcd.println("Could not find a valid BMP280 sensor, check wiring!"); - } - M5.Lcd.clear(); // Clear the screen. 清屏 -} - -float pressure, - Temp; // Store the vuale of pressure and Temperature. 存储压力和温度 - -void loop() { - pressure = bme.readPressure(); - Temp = bme.readTemperature(); - M5.Lcd.setCursor(0, 0); //将光标设置在(0 ,0). Set the cursor to (0,0) - M5.Lcd.printf("Pressure:%2.0fPa\nTemperature:%2.0f^C", pressure, Temp); - delay(100); -} diff --git a/examples/Unit/GESTURE_PAJ7620U2/GESTURE_PAJ7620U2.ino b/examples/Unit/GESTURE_PAJ7620U2/GESTURE_PAJ7620U2.ino index fc8cfdf5..3a21edb0 100644 --- a/examples/Unit/GESTURE_PAJ7620U2/GESTURE_PAJ7620U2.ino +++ b/examples/Unit/GESTURE_PAJ7620U2/GESTURE_PAJ7620U2.ino @@ -6,8 +6,8 @@ * Visit for more information: https://docs.m5stack.com/en/unit/gesture * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/gesture * -* Describe: GESTURE. 手势传感器 -* Date: 2021/11/17 +* Product: GESTURE. 手势传感器 +* Date: 2022/8/17 ******************************************************************************* Please connect to Port A (G21, G22) 请连接端口A (G21, G22) @@ -17,9 +17,9 @@ https://github.com/ouki-wang/DFRobot_PAJ7620U2 */ -#include -#include #include +#include +#include M5GFX display; M5Canvas canvas(&display); @@ -71,4 +71,4 @@ void loop() { String description = sensor.gestureDescription(gesture); log("Gesture = " + description); } -} +} \ No newline at end of file diff --git a/examples/Unit/LoRaWAN470/LoRaWAN470.ino b/examples/Unit/LoRaWAN470/LoRaWAN470.ino deleted file mode 100644 index 208150cf..00000000 --- a/examples/Unit/LoRaWAN470/LoRaWAN470.ino +++ /dev/null @@ -1,161 +0,0 @@ -/* -******************************************************************************* -* Copyright (c) 2022 by M5Stack -* Equipped with M5Core sample source code -* 配套 M5Core 示例源代码 -* Visit for more information: https://docs.m5stack.com/en/unit/lorawan868 -* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/lorawan868 -* -* Describe: LoRaWAN868. -* Date: 2021/8/31 -******************************************************************************* - Please connect to Port C,请连接端口C -*/ -#include - -#include "M5Stack.h" -#include "freertos/queue.h" - -M5GFX display; -M5Canvas canvas(&display); - -String waitRevice() { - String recvStr; - do { - recvStr = Serial2.readStringUntil('\n'); - } while (recvStr.length() == 0); - canvas.println(recvStr); - return recvStr; -} - -void sendATCMD(String cmdStr) { - Serial2.print(cmdStr); - delay(100); -} - -int sendATCMDAndRevice(String cmdStr) { - Serial2.print(cmdStr); - delay(100); - waitRevice(); - String recvStr = waitRevice(); - if (recvStr.indexOf("OK") != -1) { - return 0; - } else { - return -1; - } -} - -void setup() { - M5.begin(); - Serial2.begin(115200, SERIAL_8N1, 16, 17); - Serial2.flush(); - delay(100); - display.begin(); - display.setTextSize(2); - canvas.setColorDepth(1); // mono color - canvas.createSprite(display.width(), display.height()); - canvas.setTextSize((float)canvas.width() / 160); - canvas.setTextScroll(true); - - sendATCMD("AT?\r\n"); - delay(100); - Serial2.flush(); - sendATCMDAndRevice("AT+ILOGLVL=0\r\n"); - sendATCMDAndRevice("AT+CSAVE\r\n"); - sendATCMDAndRevice("AT+IREBOOT=0\r\n"); - display.println("LoraWan Rebooting"); - delay(2000); - display.println("LoraWan config"); - // Set Join Mode OTAA. - sendATCMDAndRevice("AT+CJOINMODE=0\r\n"); - sendATCMDAndRevice("AT+CDEVEUI=0037CAE1FC3542B9\r\n"); - sendATCMDAndRevice("AT+CAPPEUI=70B3D57ED003E04E\r\n"); - sendATCMDAndRevice("AT+CAPPKEY=67FA4ED1075A20573BCDD7594C458698\r\n"); - sendATCMDAndRevice("AT+CULDLMODE=2\r\n"); - // Set ClassC mode - sendATCMDAndRevice("AT+CCLASS=2\r\n"); - sendATCMDAndRevice("AT+CWORKMODE=2\r\n"); - - sendATCMDAndRevice("AT+CRXP=0,0,505300000\r\n"); - - // TX Freq - // 486.3 - // 486.5 - // 486.7 - // 486.9 - // 487.1 - // 487.3 - // 487.5 - // 487.7 - // MARK 0000 0100 0000 0000 | 0x0400 - - sendATCMDAndRevice("AT+CFREQBANDMASK=0400\r"); - - // RX Freq - // 506.7 (RX1) - // 506.9 (RX1) - // 507.1 (RX1) - // 507.3 (RX1) - // 507.5 (RX1) - // 507.7 (RX1) - // 507.9 (RX1) - // 508.1 (RX1) - // 505.3 (RX2)| 505300000 - sendATCMDAndRevice("AT+CJOIN=1,0,10,8\r\n"); -} - -enum systemstate { - kIdel = 0, - kJoined, - kSending, - kWaitSend, - kEnd, -}; -int system_fsm = kIdel; - -int loraWanSendNUM = -1; -int loraWanSendCNT = -1; - -void loop() { - String recvStr = waitRevice(); - if (recvStr.indexOf("+CJOIN:") != -1) { - if (recvStr.indexOf("OK") != -1) { - canvas.printf("LoraWan JOIN"); - system_fsm = kJoined; - } else { - canvas.printf("LoraWan JOIN FAIL"); - system_fsm = kIdel; - } - } else if (recvStr.indexOf("OK+RECV") != -1) { - if (system_fsm == kJoined) { - system_fsm = kSending; - } else if (system_fsm == kWaitSend) { - system_fsm = kSending; - char strbuff[128]; - if ((loraWanSendCNT < 5) && (loraWanSendNUM == 8)) { - sprintf(strbuff, "TSET OK CNT: %d", loraWanSendCNT); - canvas.print(strbuff); - } else { - sprintf(strbuff, "FAILD NUM:%d CNT:%d", loraWanSendNUM, - loraWanSendCNT); - canvas.print(strbuff); - } - } - } else if (recvStr.indexOf("OK+SEND") != -1) { - String snednum = recvStr.substring(8); - canvas.printf(" [ INFO ] SEND NUM %s \r\n", snednum.c_str()); - loraWanSendNUM = snednum.toInt(); - } else if (recvStr.indexOf("OK+SENT") != -1) { - String snedcnt = recvStr.substring(8); - canvas.printf(" [ INFO ] SEND CNT %s \r\n", snedcnt.c_str()); - loraWanSendCNT = snedcnt.toInt(); - } - - if (system_fsm == kSending) { - canvas.println("LoraWan Sending"); - sendATCMD("AT+DTRX=1,8,8,4655434b20535443\r\n"); - system_fsm = kWaitSend; - } - canvas.pushSprite(0, 0); - delay(10); -} \ No newline at end of file diff --git a/examples/Unit/LoRaWAN868/LoRaWAN868.ino b/examples/Unit/LoRaWAN868/LoRaWAN868.ino deleted file mode 100644 index 96908ea0..00000000 --- a/examples/Unit/LoRaWAN868/LoRaWAN868.ino +++ /dev/null @@ -1,198 +0,0 @@ -/* -******************************************************************************* -* Copyright (c) 2022 by M5Stack -* Equipped with M5Core sample source code -* 配套 M5Core 示例源代码 -* Visit for more information: https://docs.m5stack.com/en/unit/lorawan868 -* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/lorawan868 -* -* Describe: LoRaWAN868. -* Date: 2021/8/31 -******************************************************************************* - Please connect to Port C,请连接端口C -*/ -#include - -#include "M5Stack.h" -#include "freertos/queue.h" - -M5GFX display; -M5Canvas canvas(&display); - -String waitRevice() { - String recvStr; - do { - recvStr = Serial2.readStringUntil('\n'); - } while (recvStr.length() == 0); - canvas.println(recvStr); - return recvStr; -} - -uint16_t ypos = 55; - -void drawLineStr(String str, uint16_t color) { - M5.Lcd.setTextColor(color); - M5.Lcd.drawString(str, 10, ypos, 4); - ypos += 32; -} - -void sendATCMD(String cmdStr) { - Serial2.print(cmdStr); - delay(100); -} - -int sendATCMDAndRevice(String cmdStr) { - Serial2.print(cmdStr); - delay(10); - waitRevice(); - String recvStr = waitRevice(); - if (recvStr.indexOf("OK") != -1) { - return 0; - } else { - return -1; - } -} - -void setup() { - M5.begin(); - Serial2.begin(115200, SERIAL_8N1, 16, 17); - Serial2.flush(); - delay(100); - display.begin(); - display.setTextSize(2); - display.println("LoRaWAN868"); - canvas.setColorDepth(1); // mono color - canvas.createSprite(display.width(), display.height()); - canvas.setTextSize((float)canvas.width() / 160); - canvas.setTextScroll(true); - - sendATCMD("AT?\r"); - delay(100); - Serial2.flush(); - sendATCMDAndRevice("AT+ILOGLVL=0\r"); - sendATCMDAndRevice("AT+CSAVE\r"); - sendATCMDAndRevice("AT+IREBOOT=0\r"); - display.println("LoraWan Rebooting"); - delay(2000); - display.println("LoraWan config"); - sendATCMDAndRevice("AT+CJOINMODE=0\r"); - sendATCMDAndRevice("AT+CDEVEUI=00bb9da5b97addf1\r"); - sendATCMDAndRevice("AT+CAPPEUI=70B3D57ED004247E\r"); // 70B3D57ED003B699 - sendATCMDAndRevice("AT+CAPPKEY=27DFE264CA33AC1957C005EB48BA4721\r"); - sendATCMDAndRevice("AT+CULDLMODE=2\r"); - sendATCMDAndRevice("AT+CCLASS=2\r"); - sendATCMDAndRevice("AT+CWORKMODE=2\r"); - sendATCMDAndRevice("AT+CNBTRIALS=0,5\r"); - sendATCMDAndRevice("AT+CNBTRIALS=1,5\r"); - - // TX Freq - // 868.1 - SF7BW125 to SF12BW125 - // 868.3 - SF7BW125 to SF12BW125 and SF7BW250 - // 868.5 - SF7BW125 to SF12BW125 - // 867.1 - SF7BW125 to SF12BW125 - // 867.3 - SF7BW125 to SF12BW125 - // 867.5 - SF7BW125 to SF12BW125 - // 867.7 - SF7BW125 to SF12BW125 - // 867.9 - SF7BW125 to SF12BW125 - // 868.8 - FSK - - sendATCMDAndRevice("AT+CFREQBANDMASK=0001\r"); - - // 869.525 - SF9BW125 (RX2) | 869525000 - // sendATCMDAndRevice("AT+CRXP=0,0,869525000\r"); - - sendATCMDAndRevice("AT+CSAVE\r"); - - sendATCMDAndRevice("AT+CJOIN=1,0,10,8\r"); -} - -enum systemstate { - kIdel = 0, - kJoined, - kSending, - kWaitSend, - kEnd, -}; -int system_fsm = kIdel; - -int loraWanSendNUM = -1; -int loraWanSendCNT = -1; -int loraWanupLinkCNT = 0; -int loraWanupLinkReviceCNT = 0; - -void loop() { - String recvStr = waitRevice(); - if (recvStr.indexOf("+CJOIN:") != -1) { - if (recvStr.indexOf("OK") != -1) { - canvas.println("[ INFO ] JOIN IN SUCCESSFUL"); - system_fsm = kJoined; - } else { - canvas.println("[ INFO ] JOIN IN FAIL"); - system_fsm = kIdel; - } - } else if (recvStr.indexOf("OK+RECV") != -1) { - if (system_fsm == kJoined) { - system_fsm = kSending; - } else if (system_fsm == kWaitSend) { - system_fsm = kEnd; - char strbuff[128]; - loraWanupLinkReviceCNT++; - - // if(( loraWanSendCNT < 5 )&&( loraWanSendNUM == 8 )) - //{ - // loraWanupLinkReviceCNT ++; - // sprintf(strbuff,"SEND CNT: %d - // (%d/%d)",loraWanSendCNT,loraWanupLinkReviceCNT,loraWanupLinkCNT); - // M5.Lcd.fillRect(0,183,320,32,TFT_BLACK); - // M5.Lcd.setTextColor(TFT_GREEN); - // M5.Lcd.drawString(strbuff, 10, 183, 4); - // //drawLineStr(strbuff, TFT_GREEN); - // - //} - // else - //{ - // sprintf(strbuff,"FAILD NUM:%d CNT:%d - // (%d/%d)",loraWanSendNUM,loraWanSendCNT,loraWanupLinkReviceCNT,loraWanupLinkCNT); - // M5.Lcd.fillRect(0,183,320,32,TFT_BLACK); - // M5.Lcd.setTextColor(TFT_RED); - // M5.Lcd.drawString(strbuff, 10, 183, 4); - // drawLineStr(strbuff, TFT_RED); - //} - delay(500); - system_fsm = kSending; - } - } else if (recvStr.indexOf("OK+SEND") != -1) { - String snednum = recvStr.substring(8); - canvas.printf(" [ INFO ] SEND NUM %s \r\n", snednum.c_str()); - loraWanSendNUM = snednum.toInt(); - } else if (recvStr.indexOf("OK+SENT") != -1) { - String snedcnt = recvStr.substring(8); - canvas.printf(" [ INFO ] SEND CNT %s \r\n", snedcnt.c_str()); - loraWanSendCNT = snedcnt.toInt(); - } else if (recvStr.indexOf("ERR+SENT") != -1) { - char strbuff[128]; - String ErrorCodeStr = recvStr.substring(9); - sprintf(strbuff, "ERROR Code:%d (%d/%d)", ErrorCodeStr.toInt(), - loraWanupLinkReviceCNT, loraWanupLinkCNT); - canvas.println(strbuff); - delay(500); - - system_fsm = kSending; - } else if (recvStr.indexOf("+CLINKCHECK:") != -1) { - String checkStr = recvStr.substring(String("+CLINKCHECK:").length()); - - char strbuff[128]; - sprintf(strbuff, "%s (%d/%d)", checkStr.c_str(), loraWanupLinkReviceCNT, - loraWanupLinkCNT); - canvas.println(strbuff); - } - - if (system_fsm == kSending) { - canvas.println("LoraWan Sending"); - sendATCMD("AT+CLINKCHECK=1\r"); - loraWanupLinkCNT++; - system_fsm = kWaitSend; - } - canvas.pushSprite(0, 0); - delay(10); -} \ No newline at end of file diff --git a/examples/Unit/LoRaWAN915/LoRaWAN915.ino b/examples/Unit/LoRaWAN915/LoRaWAN915.ino deleted file mode 100644 index ab3f3987..00000000 --- a/examples/Unit/LoRaWAN915/LoRaWAN915.ino +++ /dev/null @@ -1,169 +0,0 @@ -#include "M5Stack.h" -#include "TFTTerminal.h" -#include "freertos/queue.h" -TFT_eSprite TerminalBuff = TFT_eSprite(&M5.Lcd); -TFTTerminal terminal(&TerminalBuff); - -String waitRevice() { - String recvStr; - do { - recvStr = Serial2.readStringUntil('\n'); - } while (recvStr.length() == 0); - Serial.println(recvStr); - terminal.println(recvStr); - return recvStr; -} - -void sendATCMD(String cmdStr) { - Serial2.print(cmdStr); - delay(100); -} - -int sendATCMDAndRevice(String cmdStr) { - Serial2.print(cmdStr); - delay(100); - waitRevice(); - String recvStr = waitRevice(); - if (recvStr.indexOf("OK") != -1) { - return 0; - } else { - return -1; - } -} - -void setup() { - M5.begin(); - Serial2.begin(115200, SERIAL_8N1, 16, 17); - Serial2.flush(); - delay(100); - M5.Lcd.fillRect(0, 0, 320, 240, TFT_BLACK); - M5.Lcd.fillRect(0, 0, 320, 40, TFT_WHITE); - M5.Lcd.setTextColor(TFT_BLACK); - M5.Lcd.setTextDatum(TC_DATUM); - M5.Lcd.drawString("Unit-LoraWan(915) TEST", 160, 10, 4); - M5.Lcd.setTextDatum(TL_DATUM); - M5.Lcd.setTextColor(TFT_WHITE); - TerminalBuff.createSprite(240, 200); - terminal.setGeometry(20, 55, 300, 200); - terminal.setFontsize(1); - - sendATCMD("AT?\r\n"); - delay(100); - Serial2.flush(); - sendATCMDAndRevice("AT+ILOGLVL=0\r\n"); - sendATCMDAndRevice("AT+CSAVE\r\n"); - sendATCMDAndRevice("AT+IREBOOT=0\r\n"); - terminal.println("LoraWan Rebooting"); - delay(2000); - terminal.println("LoraWan config"); - // Set Join Mode OTAA - sendATCMDAndRevice("AT+CJOINMODE=0\r\n"); - sendATCMDAndRevice("AT+CDEVEUI=d896e0ff00000240\r\n"); - sendATCMDAndRevice("AT+CAPPEUI=0000000000000001\r\n"); - sendATCMDAndRevice("AT+CAPPKEY=98929b92f09e2daf676d646d0f61d250\r\n"); - sendATCMDAndRevice("AT+CULDLMODE=2\r\n"); - // Set ClassC mode - sendATCMDAndRevice("AT+CCLASS=2\r\n"); - sendATCMDAndRevice("AT+CWORKMODE=2\r\n"); - - sendATCMDAndRevice("AT+CRXP=0,0,923300000\r\n"); - - // TX Freq - // 902.3 - // 902.5 - // 902.7 - // 902.9 - // 903.1 - // 903.3 - // 903.5 - // 903.7 - // MARK 0000 0000 0000 0001 | 0x001 - - sendATCMDAndRevice("AT+CFREQBANDMASK=0001\r\n"); - - // RX Freq - // 923.3 - (RX1) - // 923.9 - (RX1) - // 924.5 - (RX1) - // 925.1 - (RX1) - // 925.7 - (RX1) - // 926.3 - (RX1) - // 926.9 - (RX1) - // 927.5 - (RX1) - // 923.3 - (RX2) | 923300000 - - sendATCMDAndRevice("AT+CJOIN=1,0,10,8\r\n"); -} - -enum systemstate { - kIdel = 0, - kJoined, - kSending, - kWaitSend, - kEnd, -}; -int system_fsm = kIdel; - -int loraWanSendNUM = -1; -int loraWanSendCNT = -1; - -void loop() { - String recvStr = waitRevice(); - if (recvStr.indexOf("+CJOIN:") != -1) { - if (recvStr.indexOf("OK") != -1) { - Serial.println("[ INFO ] JOIN IN SUCCESSFUL"); - terminal.println("LoraWan JOIN"); - system_fsm = kJoined; - } else { - Serial.println("[ INFO ] JOIN IN FAIL"); - terminal.println("LoraWan JOIN FAIL"); - system_fsm = kIdel; - } - } else if (recvStr.indexOf("OK+RECV") != -1) { - if (system_fsm == kJoined) { - system_fsm = kSending; - } else if (system_fsm == kWaitSend) { - system_fsm = kSending; - char strbuff[128]; - if ((loraWanSendCNT < 5) && (loraWanSendNUM == 8)) { - sprintf(strbuff, "TSET OK CNT: %d", loraWanSendCNT); - terminal.println(strbuff); - } else { - sprintf(strbuff, "FAILD NUM:%d CNT:%d", loraWanSendNUM, - loraWanSendCNT); - terminal.println(strbuff); - } - } - } else if (recvStr.indexOf("OK+SEND") != -1) { - String snednum = recvStr.substring(8); - // Serial.printf(" [ INFO ] SEND NUM %s \r\n",snednum.c_str()); - loraWanSendNUM = snednum.toInt(); - } else if (recvStr.indexOf("OK+SENT") != -1) { - String snedcnt = recvStr.substring(8); - // Serial.printf(" [ INFO ] SEND CNT %s \r\n",snedcnt.c_str()); - loraWanSendCNT = snedcnt.toInt(); - } - - if (system_fsm == kSending) { - terminal.println("LoraWan Sending"); - sendATCMD("AT+DTRX=1,15,8,4655434b20535443\r\n"); - system_fsm = kWaitSend; - } - // if (M5.BtnA.wasPressed()) - // { - // sendATCMDAndRevice("AT+CLINKCHECK=1\r\n"); - // delay(100); - // } - // if (M5.BtnB.wasPressed()) - // { - // sendATCMDAndRevice("AT+DTRX=1,15,8,4655434b20535443\r\n"); - // delay(100); - // } - // if (M5.BtnC.wasPressed()) - // { - // sendATCMDAndRevice("AT+DRX?\r\n"); - // delay(100); - // } - delay(10); - M5.update(); -} diff --git a/examples/Unit/LoRaWAN915/TFTTerminal.cpp b/examples/Unit/LoRaWAN915/TFTTerminal.cpp deleted file mode 100644 index 1dac0223..00000000 --- a/examples/Unit/LoRaWAN915/TFTTerminal.cpp +++ /dev/null @@ -1,131 +0,0 @@ -#include "TFTTerminal.h" - -TFTTerminal::TFTTerminal(TFT_eSprite *dis_buff_ptr) { - _dis_buff_ptr = dis_buff_ptr; - memset(discharbuff, 0, 55 * 60); -} - -TFTTerminal::~TFTTerminal() { -} - -void TFTTerminal::setcolor(uint16_t color, uint16_t bk_color) { - _color = color; - _bkcolor = bk_color; -} - -void TFTTerminal::setGeometry(uint16_t x, uint16_t y, uint16_t w, uint16_t h) { - _win_x_pos = x; - _win_y_pos = y; - _win_w = w; - _win_h = h; - - _line_x_limit = _win_w / _font_x_size; - _line_y_limit = _win_h / _font_y_size; -} - -void TFTTerminal::setFontsize(uint8_t size) { - size = (size == 0) ? 1 : size; - _font_x_size = 5 * size; - _font_y_size = 6 * size; - _fontSize = size; - - _line_x_limit = _win_w / _font_x_size; - _line_y_limit = _win_h / _font_y_size; -} - -size_t TFTTerminal::write(uint8_t chardata) { - bool flush_page_flag = false; - uint8_t dis_y_pos = 0; - - if ((chardata == '\r') || (chardata == '\n')) { - xpos = 0; - ypos++; - ypos = ypos % 60; - memset(discharbuff[ypos % 60], 0, 55); - return 1; - } else if (xpos >= _line_x_limit) { - xpos = 0; - ypos++; - ypos = ypos % 60; - memset(discharbuff[ypos % 60], 0, 55); - } - - discharbuff[ypos][xpos] = chardata; - xpos++; - - if ((dispos <= ypos) && ((ypos - dispos) > _line_y_limit)) { - dispos = ypos - _line_y_limit; - flush_page_flag = true; - } else if ((dispos <= ypos) && ((ypos - dispos) <= _line_y_limit)) { - dis_y_pos = ypos - dispos; - flush_page_flag = false; - } else if ((dispos > ypos) && ((60 - (dispos - ypos)) > _line_y_limit)) { - dispos = 60 - (_line_y_limit - ypos); - flush_page_flag = true; - } else if ((dispos > ypos) && ((60 - (dispos - ypos)) > _line_y_limit)) { - dis_y_pos = 60 - (dispos - ypos); - flush_page_flag = false; - } - - dispos = dispos % 60; - - _dis_buff_ptr->setTextColor(_color); - _dis_buff_ptr->setTextSize(_fontSize); - - if (flush_page_flag) { - _dis_buff_ptr->fillSprite(_bkcolor); - - for (size_t i = 0; i < _line_y_limit; i++) { - _dis_buff_ptr->drawString((char *)discharbuff[(dispos + i) % 60], 0, - i * _font_y_size); - } - } else { - _dis_buff_ptr->drawChar(chardata, (xpos - 1) * _font_x_size, - dis_y_pos * _font_y_size); - } - _dis_buff_ptr->pushSprite(_win_x_pos, _win_y_pos); - - return 1; -} - -size_t TFTTerminal::write(const uint8_t *buffer, size_t size) { - while ((size != 0) && (*buffer != '\0')) { - if ((*buffer == '\r') || (*buffer == '\n')) { - xpos = 0; - ypos++; - ypos = ypos % 60; - memset(discharbuff[ypos % 60], 0, 55); - buffer++; - size--; - continue; - } else if (xpos >= _line_x_limit) { - xpos = 0; - ypos++; - ypos = ypos % 60; - memset(discharbuff[ypos % 60], 0, 55); - } - discharbuff[ypos][xpos] = *buffer; - xpos++; - buffer++; - size--; - } - - if ((dispos <= ypos) && ((ypos - dispos) > _line_y_limit)) { - dispos = ypos - _line_y_limit; - } else if ((dispos > ypos) && ((60 - (dispos - ypos)) > _line_y_limit)) { - dispos = 60 - (_line_y_limit - ypos); - } - - dispos = dispos % 60; - - _dis_buff_ptr->setTextColor(_color); - _dis_buff_ptr->setTextSize(_fontSize); - _dis_buff_ptr->fillSprite(_bkcolor); - //_dis_buff_ptr->fillRect(_win_x_pos, _win_y_pos, _win_w, _win_h, _bkcolor); - for (size_t i = 0; i < _line_y_limit; i++) { - _dis_buff_ptr->drawString((char *)discharbuff[(dispos + i) % 60], 0, - i * _font_y_size); - } - _dis_buff_ptr->pushSprite(_win_x_pos, _win_y_pos); - return 1; -} \ No newline at end of file diff --git a/examples/Unit/LoRaWAN915/TFTTerminal.h b/examples/Unit/LoRaWAN915/TFTTerminal.h deleted file mode 100644 index 85b8d832..00000000 --- a/examples/Unit/LoRaWAN915/TFTTerminal.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef _TFTTERMINAL_H_ -#define _TFTTERMINAL_H_ - -#include -#include - -class TFTTerminal : public Print { - private: - TFT_eSprite *disptr; - char discharbuff[60][55]; - uint32_t xpos = 0, ypos = 0, dispos = 0; - TFT_eSprite *_dis_buff_ptr = NULL; - uint16_t _bkcolor = TFT_BLACK; - uint16_t _color = TFT_GREEN; - - uint16_t _win_x_pos = 0, _win_y_pos = 0, _win_w = 320, _win_h = 240; - uint16_t _font_x_size = 6, _font_y_size = 8; - uint8_t _fontSize = 0; - uint16_t _line_x_limit = 53, _line_y_limit = 30; - - public: - TFTTerminal(TFT_eSprite *dis_buff_ptr); - ~TFTTerminal(); - - void setcolor(uint16_t color, uint16_t bk_color); - void setGeometry(uint16_t x, uint16_t y, uint16_t w, uint16_t h); - void setFontsize(uint8_t size); - - size_t write(uint8_t); - size_t write(const uint8_t *buffer, size_t size); -}; - -#endif diff --git a/examples/Unit/RELAY/RELAY.ino b/examples/Unit/RELAY/RELAY.ino deleted file mode 100644 index c6039c9b..00000000 --- a/examples/Unit/RELAY/RELAY.ino +++ /dev/null @@ -1,38 +0,0 @@ -/* -******************************************************************************* -* Copyright (c) 2022 by M5Stack -* Equipped with M5Core sample source code -* 配套 M5Core 示例源代码 -* Visit for more information: https://docs.m5stack.com/en/core/gray -* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/gray -* -* Describe: Relay. 继电器 -* Date: 2021/8/16 -******************************************************************************* - Please connect to Port B(26),Use RELAY to switch on and off the circuit. - 请连接端口B(26),使用继电器开关电路。 -*/ - -#include - -void setup() { - M5.begin(); // Init M5Stack. 初始化M5Stack - M5.Power.begin(); // Init power 初始化电源模块 - M5.lcd.setTextSize(2); // Set the text size to 2. 设置文字大小为2 - M5.Lcd.setCursor(50, 0); - M5.Lcd.println(("Relay Example")); - dacWrite(25, 0); // disable the speak noise. 禁用喇叭 - pinMode(26, OUTPUT); // Set pin 26 to output mode. 设置26号引脚为输出模式 -} - -void loop(void) { - M5.Lcd.setCursor(100, 40); - M5.Lcd.print("ON"); - digitalWrite(26, HIGH); - delay(1000); - M5.Lcd.fillRect(100, 40, 60, 50, BLACK); - M5.Lcd.print("OFF"); - digitalWrite(26, LOW); - delay(1000); - M5.Lcd.fillRect(100, 40, 60, 50, BLACK); -}