diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..52e4104 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +*.bin +*.elf +*.map + +.DS_Store + + diff --git a/01_install_cli.sh b/01_install_cli.sh index 7e8ac08..796a9b7 100755 --- a/01_install_cli.sh +++ b/01_install_cli.sh @@ -31,6 +31,6 @@ if [ ! -d "build" ]; then echo "cd m5scp2_exp" echo "./compile.sh" - echo "FactoryTest2022 の初回コンパイルをします。数分固まったようにみえます。" + echo "FactoryTest2025 の初回コンパイルをします。数分固まったようにみえます。" ./compile.sh fi diff --git a/02_install_cli_lib.sh b/02_install_cli_lib.sh index b83ff14..a1a3af6 100755 --- a/02_install_cli_lib.sh +++ b/02_install_cli_lib.sh @@ -6,10 +6,6 @@ arduino-cli core install esp32:esp32 # arduino-cli core install esp32:esp32@2.0.17 --config-file arduino-cli.yaml -# 確認 -arduino-cli board listall | grep StickCPlus -arduino-cli core list - # Optional for IRsend samples arduino-cli lib install IRremoteESP8266 arduino-cli lib install WiFi HttpClient @@ -19,7 +15,6 @@ arduino-cli lib install "Adafruit SHT31 Library" arduino-cli lib install "Adafruit BMP280 Library" # arduino-cli lib install M5StickCPlus2 # M5Unified を使うので不要 -arduino-cli lib install TFT_eSPI ## You can find other libraries as follows. # arduino-cli lib search [keyword] @@ -27,6 +22,10 @@ # arduino-cli lib search [keyword] | grep -e "^Name" # Finally, just show board list +# 確認 +arduino-cli board listall | grep StickCPlus +arduino-cli core list + echo "(for Windows user) 書き込みは主にUSBで行いますので、ネットワークアクセスの許可は、しなくてもよいです。" echo "(for Windows user) Acceptance of Network setting is not mandatory." diff --git a/04_upload_factorytest.sh b/04_upload_factorytest.sh index 145f090..f121116 100755 --- a/04_upload_factorytest.sh +++ b/04_upload_factorytest.sh @@ -24,3 +24,8 @@ arduino-cli upload --fqbn esp32:esp32:m5stack_stickc_plus2 -p ${ser} -v FactoryTest done + +if [[ "${#seriallist[@]}" -eq 1 ]]; then + arduino-cli monitor -p ${seriallist[0]} --config 115200 +fi + diff --git a/FactoryTest/Battery.h b/FactoryTest/Battery.h index 7750e7e..ff72aef 100644 --- a/FactoryTest/Battery.h +++ b/FactoryTest/Battery.h @@ -203,7 +203,7 @@ bool Battery::isLowBattery() { // 低電圧状態(3.4V以下)だと1それ以外は0 - uint8_t _bat_level = M5.Power.getBatteryLevel(); + float _bat_level = M5.Power.getBatteryLevel(); if ( _bat_level < 10 ) { return false; @@ -236,7 +236,7 @@ */ int Battery::calcBatteryPercent() { - return M5.Power.getBatteryLevel(); + return (int)M5.Power.getBatteryLevel(); // float _vbat = M5.Power.getBatteryVoltage(); // float percent = (_vbat - MIN_BATTERY_VOLTAGE) / (MAX_BATTERY_VOLTAGE - MIN_BATTERY_VOLTAGE); // if (percent > 1.0f) diff --git a/FactoryTest/FactoryTest.ino b/FactoryTest/FactoryTest.ino index b802c5f..c38eb1a 100644 --- a/FactoryTest/FactoryTest.ino +++ b/FactoryTest/FactoryTest.ino @@ -1,11 +1,13 @@ #include #include "fft.h" -#include "esp_pm.h" +// #include "esp_pm.h" #include #include -#include -#include -#include +// #include +// #include +// #include + +// #define ENABLE_I2S 0 // #define ENABLE_BLE 1 #ifdef ENABLE_BLE @@ -76,7 +78,7 @@ void ntp_setup(); void wifi_down(); -LGFX_Sprite Disbuff; // = TFT_eSprite(&M5.Display); // 画面ちらつき防止スプライト(画面のバッファリング) +LGFX_Sprite Disbuff(&M5.Display); // 画面ちらつき防止スプライト(画面のバッファリング) hw_timer_t *timer = NULL; volatile SemaphoreHandle_t timerSemaphore; @@ -99,9 +101,8 @@ { do { - delay(20); + M5.delay(20); } while (M5.BtnPWR.wasPressed()); - M5.Speaker.tone(0, 1); // ESP.restart(); M5.Power.powerOff(); // 電源OFF } @@ -127,14 +128,20 @@ { Disbuff.setTextSize(1); Disbuff.setTextColor(TFT_GREENYELLOW); - Disbuff.drawString("FactoryTest 2024", 10, 0, 1); + Disbuff.drawString("FactoryTest 2025", 10, 1, 1); Disbuff.setTextColor(TFT_WHITE); - battery.batteryUpdate(); + // battery.batteryUpdate(); // battery.showBattery(); Disbuff.pushSprite(0, 0); } +void mytone_switch(int freq, int duration) +{ + M5.Speaker.tone(freq, duration); + // tone(GPIO_NUM_2, freq, duration); + // M5.Display.setBrightness(255); +} void ErrorDialog(uint8_t code, const char *str) // エラー表示(主にバッテリー切れ警告) { @@ -157,17 +164,14 @@ { M5.update(); checkAXPPress(); - delay(100); + M5.delay(100); } while ((M5.BtnA.isPressed()) || (M5.BtnB.isPressed())) { M5.update(); checkAXPPress(); - M5.Speaker.tone(4000); - delay(10); + mytone_switch(1000, 200); } - delay(50); - M5.Speaker.tone(0, 1); Disbuff.setTextColor(TFT_WHITE); Disbuff.setTextFont(1); } @@ -303,13 +307,16 @@ while ((!M5.BtnA.isPressed()) /*&& (!M5.BtnB.isPressed())*/) { - m5::IMU_Class::imu_data_t d = M5.Imu.getImuData(); - // M5.Imu.getAccelData(&accX, &accY, &accZ); - // M5.MPU6886.getAccelData(&accX, &accY, &accZ); - accX = d.accel.x; - accY = d.accel.y; - accZ = d.accel.z; - + auto imu_update = M5.Imu.update(); + if (imu_update) + { + m5::IMU_Class::imu_data_t d = M5.Imu.getImuData(); + // M5.Imu.getAccelData(&accX, &accY, &accZ); + // M5.MPU6886.getAccelData(&accX, &accY, &accZ); + accX = d.accel.x; + accY = d.accel.y; + accZ = d.accel.z; + } if ((accX < 1) && (accX > -1)) { theta = asin(-accX) * 57.295; @@ -329,7 +336,7 @@ Disbuff.setCursor(10, 125); Disbuff.printf("%.2f", phi); // Displaybuff(); - delay(20); + M5.delay(20); z.end_point.x = 0; z.end_point.y = 0; @@ -365,11 +372,8 @@ { M5.update(); checkAXPPress(); - M5.Speaker.tone(4000); - delay(10); + mytone_switch(1000, 200); } - delay(50); - M5.Speaker.tone(0, 1); Disbuff.setTextColor(TFT_WHITE); } @@ -384,6 +388,7 @@ void MicRecordfft(void *arg) // フーリエ変換 { +#ifdef ENABLE_I2S int16_t *buffptr; size_t bytesread; uint16_t count_n = 0; @@ -435,6 +440,7 @@ xSemaphoreGive(xSemaphore); fft_destroy(real_fft_plan); } +#endif } void Drawdisplay(void *arg) // フーリエ変換のときの画面表示 @@ -511,16 +517,14 @@ { M5.update(); checkAXPPress(); - M5.Speaker.tone(4000); - delay(10); + mytone_switch(1000, 200); } - delay(50); - M5.Speaker.tone(0, 1); } #define PIN_CLK 0 #define PIN_DATA 34 +#ifdef ENABLE_I2S bool InitI2SMicroPhone() // マイクの初期化 { esp_err_t err = ESP_OK; @@ -555,6 +559,7 @@ return true; } } +#endif void DisplayRTC() // リアルタイムクロック(内蔵時計) { @@ -582,7 +587,7 @@ Displaybuff(); M5.update(); checkAXPPress(); - delay(100); + M5.delay(100); } if (M5.BtnB.isPressed()) { @@ -601,11 +606,8 @@ { M5.update(); checkAXPPress(); - M5.Speaker.tone(4000); - delay(10); + mytone_switch(1000, 200); } - delay(50); - M5.Speaker.tone(0, 1); Disbuff.setTextColor(TFT_WHITE); } @@ -897,17 +899,14 @@ } checkAXPPress(); M5.update(); - delay(100); + M5.delay(100); } while ((M5.BtnA.isPressed()) || (M5.BtnB.isPressed())) { M5.update(); checkAXPPress(); - M5.Speaker.tone(4000); - delay(10); } - delay(50); - M5.Speaker.tone(0, 1); + M5.delay(50); Disbuff.setTextColor(TFT_WHITE); } #endif @@ -979,18 +978,16 @@ Displaybuff(); M5.update(); - delay(100); + M5.delay(100); checkAXPPress(); } while ((M5.BtnA.isPressed()) || (M5.BtnB.isPressed())) { M5.update(); checkAXPPress(); - M5.Speaker.tone(4000); - delay(10); + M5.delay(10); } - delay(50); - M5.Speaker.tone(0, 1); + M5.delay(50); Disbuff.setTextColor(TFT_WHITE); pService->stop(); pServer->getAdvertising()->stop(); @@ -1027,18 +1024,15 @@ // } // checkAXPPress(); // M5.update(); -// delay(100); +// M5.delay(100); // count++; // } // while ((M5.BtnA.isPressed()) || (M5.BtnB.isPressed())) // { // M5.update(); // checkAXPPress(); -// M5.Speaker.tone(4000); -// delay(10); // } -// delay(50); -// M5.Speaker.tone(0,1); +// M5.delay(50); // Disbuff.setTextColor(TFT_WHITE); // } void DisplayTestMode() // テストモード:ピンの電圧とバッテリー電圧 @@ -1046,6 +1040,7 @@ float tempdata, humdata; uint8_t count_u = 0, count_t = 0; +#ifdef ENABLE_I2S i2s_pin_config_t pin_config; pin_config.bck_io_num = I2S_PIN_NO_CHANGE; pin_config.ws_io_num = 33; @@ -1054,6 +1049,7 @@ i2s_set_pin(I2S_NUM_0, &pin_config); i2s_driver_uninstall(I2S_NUM_0); +#endif gpio_reset_pin(GPIO_NUM_0); gpio_reset_pin(GPIO_NUM_26); @@ -1103,7 +1099,7 @@ for (int i = 0; i < 10; i++) { digitalWrite(0, i % 2); - delay(10); + M5.delay(10); // pin36_adc = analogRead(36); if ((digitalRead(36) == HIGH) && (i % 2 == 1)) { @@ -1148,7 +1144,7 @@ for (int i = 0; i < 10; i++) { digitalWrite(26, i % 2); - delay(10); + M5.delay(10); // pin36_adc = analogRead(36); if ((digitalRead(36) == HIGH) && (i % 2 == 1)) { @@ -1189,21 +1185,20 @@ checkAXPPress(); M5.update(); - delay(10); + M5.delay(10); // count++; } while ((M5.BtnA.isPressed()) || (M5.BtnB.isPressed())) { M5.update(); checkAXPPress(); - M5.Speaker.tone(4000); - delay(10); + mytone_switch(1000, 200); } - delay(50); - M5.Speaker.tone(0, 1); Disbuff.setTextColor(TFT_WHITE); +#ifdef ENABLE_I2S InitI2SMicroPhone(); +#endif } esp_now_peer_info_t peerInfo; @@ -1266,7 +1261,7 @@ Disbuff.pushSprite(0, 0); M5.update(); - delay(100); + M5.delay(100); subcount--; // subcountが10から0になると、約1秒 if (subcount < 0) { @@ -1279,8 +1274,7 @@ } } startCoundDownShutdown = false; - delay(50); - M5.Speaker.tone(0, 1); + M5.delay(50); Disbuff.setTextColor(TFT_WHITE); } void countDownWebOTA() @@ -1297,7 +1291,7 @@ Disbuff.pushSprite(0, 0); M5.update(); - delay(100); + M5.delay(100); subcount--; // subcountが10から0になると、約1秒 if (subcount < 0) { @@ -1310,8 +1304,7 @@ } } startWebOTA = false; - delay(50); - M5.Speaker.tone(0, 1); + M5.delay(50); Disbuff.setTextColor(TFT_WHITE); } @@ -1359,10 +1352,9 @@ Disbuff.pushSprite(0, 0); for (int i = 4000; i > 1000; i -= 100) { - M5.Speaker.tone(i); - delay(30); + tone(GPIO_NUM_2, i, 20); } - M5.Speaker.tone(0, 1); + M5.Display.setBrightness(255); M5.update(); start_WebOTA(); // WebOTA.ino } @@ -1382,10 +1374,9 @@ Disbuff.pushSprite(0, 0); for (int i = 2000; i < 4000; i += 100) { - M5.Speaker.tone(i); - delay(30); + tone(GPIO_NUM_2, i, 20); } - M5.Speaker.tone(0, 1); + M5.Display.setBrightness(255); uint8_t data[50]; if (TestMode) @@ -1426,21 +1417,19 @@ { Serial.println("Not sure what happened"); } - delay(500); + M5.delay(500); } if (M5.BtnA.isPressed()) break; - delay(100); + M5.delay(100); } while ((M5.BtnA.isPressed()) /*|| (M5.BtnB.isPressed())*/) { M5.update(); checkAXPPress(); - M5.Speaker.tone(4000); - delay(10); + M5.Speaker.tone(3000, 200); } - delay(50); - M5.Speaker.tone(0, 1); + M5.delay(50); Disbuff.setTextColor(TFT_WHITE); } @@ -1512,7 +1501,7 @@ } } Displaybuff(); - delay(500); + M5.delay(500); for (int i = 0; i < 4; i++) { @@ -1548,7 +1537,7 @@ } } Displaybuff(); - delay(500); + M5.delay(500); } uint8_t addrcheckbuff[3] = { @@ -1563,36 +1552,35 @@ cfg.serial_baudrate = 115200; M5.begin(cfg); - // Wire.begin(32, 33); // GROOVE端子のI2C通信 - M5.Display.setRotation(3); // 画面向きは横 - tone(GPIO_NUM_2, 262, 200); - tone(GPIO_NUM_2, 330, 200); - tone(GPIO_NUM_2, 392, 200); - tone(GPIO_NUM_2, 524, 400); + M5.Speaker.setVolume(30); + M5.Speaker.tone(2000, 500); + // tone(GPIO_NUM_2, 262, 200); + // tone(GPIO_NUM_2, 330, 200); + // tone(GPIO_NUM_2, 392, 200); + // tone(GPIO_NUM_2, 524, 400); M5.Display.setBrightness(255); + M5.Display.setFont(&fonts::lgfxJapanGothic_16); + M5.Display.setTextScroll(true); - Disbuff = LGFX_Sprite(&M5.Display); - Disbuff.setPsram(false); - Disbuff.setColorDepth(16); - // Disbuff.setParent(&M5.Display); + // M5.delay(2000); + // Disbuff.setColorDepth(16); Disbuff.createSprite(240, 135); - Disbuff.fillRect(0, 0, 240, 135, Disbuff.color565(10, 10, 10)); + Disbuff.fillRect(0, 0, 240, 135, Disbuff.color565(10, 50, 50)); Disbuff.pushSprite(0, 0); - delay(500); + M5.delay(500); M5.update(); if (M5.BtnB.isPressed()) // Bボタンを押して起動したら、テストモード { - M5.Speaker.tone(4000); - delay(100); - M5.Speaker.tone(0, 1); + M5.Speaker.tone(4000, 200); + M5.delay(100); TestMode = true; while (M5.BtnB.isPressed()) { M5.update(); - delay(10); + M5.delay(10); } } M5.Display.setBrightness(200); @@ -1600,6 +1588,7 @@ battery.setSprite(&Disbuff); // バッテリー残量表示 battery.setPosAndSize(160, 1, 1); battery.setCheckRate(300); + // // deleteBattery()時の塗りつぶし色を設定 // battery.setDeleteBgColor(TFT_BLACK); // 電池図形と%表示の色を設定 @@ -1612,8 +1601,8 @@ checkAXP192(); // バッテリー電圧チェック。低下してたらエラーメッセージ表示 - M5.Imu.init(); // 加速度・角速度(ジャイロ)初期化 - InitI2SMicroPhone(); // マイク初期化 + // M5.Imu.init(); // 加速度・角速度(ジャイロ)初期化 + // InitI2SMicroPhone(); // マイク初期化 #ifdef ENABLE_IRSEND InitIRTx(); // 赤外線通信 初期化 #endif @@ -1621,22 +1610,22 @@ InitBLEServer(); // Bluetooth Low Energyサーバ初期化 #endif - pinMode(19, OUTPUT); // LEDのポートを出力に設定 - timerSemaphore = xSemaphoreCreateBinary(); // バイナリセマフォ作成 + pinMode(19, OUTPUT); // LEDのポートを出力に設定 + // timerSemaphore = xSemaphoreCreateBinary(); // バイナリセマフォ作成 // timer = timerBegin(0, 80, true); // タイマーID=0, 80クロックで1カウントする, カウントアップならtrue // timerAttachInterrupt(timer, &onTimer, true); // 割り込み関数onTimer()を登録 // timerAlarmWrite(timer, 30000, true); // トリガー条件。50000カウントで発動。trueは繰り返し実行(falseにすると1回のみ) // timerAlarmEnable(timer); - xSemaphore = xSemaphoreCreateMutex(); // ミューテックス排他制御 - start_dis = xSemaphoreCreateMutex(); - start_fft = xSemaphoreCreateMutex(); + // xSemaphore = xSemaphoreCreateMutex(); // ミューテックス排他制御 + // start_dis = xSemaphoreCreateMutex(); + // start_fft = xSemaphoreCreateMutex(); - xSemaphoreTake(start_dis, portMAX_DELAY); // フーリエ変換のときの画面表示タスクを「待ち」状態にする - xSemaphoreTake(start_fft, portMAX_DELAY); // FFTタスクを「待ち」状態にする + // xSemaphoreTake(start_dis, portMAX_DELAY); // フーリエ変換のときの画面表示タスクを「待ち」状態にする + // xSemaphoreTake(start_fft, portMAX_DELAY); // FFTタスクを「待ち」状態にする - xTaskCreate(Drawdisplay, "Drawdisplay", 1024 * 2, (void *)0, 4, &xhandle_display); - xTaskCreate(MicRecordfft, "MicRecordfft", 1024 * 2, (void *)0, 5, &xhandle_fft); + // xTaskCreate(Drawdisplay, "Drawdisplay", 1024 * 2, (void *)0, 4, &xhandle_display); + // xTaskCreate(MicRecordfft, "MicRecordfft", 1024 * 2, (void *)0, 5, &xhandle_fft); Disbuff.pushSprite(0, 0); } @@ -1646,14 +1635,14 @@ { // それぞれのテスト中は、関数のなかのループがまわる // A(orB)ボタンを押したら、現在実行中の関数のループを抜け、次の関数を実行する - MPU6886Test(); // 加速度・ジャイロ - DisplayRTC(); // リアルタイムクロック - DisplayMicro(); // マイク + MPU6886Test(); // 加速度・ジャイロ + DisplayRTC(); // リアルタイムクロック + // DisplayMicro(); // マイク #ifdef ENABLE_IRSEND DisIRSend(); // 赤外線通信 #endif - // DisplayTestMode(); // バッテリー電圧 + DisplayTestMode(); // バッテリー電圧 #ifdef ENABLE_BLE DisPlayBLESend(); @@ -1661,8 +1650,7 @@ ESP_NOW_SendShutdown(); // シャットダウン信号の送信 M5.update(); - delay(50); - Serial.println("end of loop"); + M5.delay(50); } #ifdef ENABLE_OTA @@ -1671,18 +1659,16 @@ void OTA_Setup() { WiFi.softAPdisconnect(true); - delay(1000); + M5.delay(1000); WiFi.mode(WIFI_STA); - delay(1000); + M5.delay(1000); WiFi.begin(ssid, password); int trycount = 0; while ((WiFi.status() != WL_CONNECTED)) { - M5.Speaker.tone(2000); - delay(200); - M5.Speaker.tone(0, 1); - delay(300); + M5.Speaker.tone(2000, 500); + M5.delay(200); M5.Display.print("."); trycount++; if (trycount == 100) @@ -1694,9 +1680,8 @@ M5.Display.setCursor(10, 50); M5.Display.setTextColor(BLACK, GREEN); M5.Display.println(" CONNECTED! "); - M5.Speaker.tone(4000); - delay(1000); - M5.Speaker.tone(0, 1); + M5.Speaker.tone(4000, 500); + M5.delay(1000); // Port defaults to 3232 ArduinoOTA.setPort(3232); @@ -1717,12 +1702,12 @@ type = "filesystem"; }) .onEnd([]() { - M5.Speaker.tone(2000); - delay(150); - M5.Speaker.tone(4000); - delay(150); - M5.Speaker.tone(8000); - delay(300); + M5.Speaker.tone(2000,500); + M5.delay(150); + M5.Speaker.tone(4000,500); + M5.delay(150); + M5.Speaker.tone(8000,500); + M5.delay(300); M5.Speaker.tone(0,1); }) .onProgress([](unsigned int progress, unsigned int total) { ota_progress(progress, total); }) diff --git a/FactoryTest/TFTTerminal.cpp b/FactoryTest/TFTTerminal.cpp deleted file mode 100644 index 0e38574..0000000 --- a/FactoryTest/TFTTerminal.cpp +++ /dev/null @@ -1,151 +0,0 @@ -#include "TFTTerminal.h" - -TFTTerminal::TFTTerminal(LGFX_Sprite *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; -} - -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(0); - - 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 * 8); - } - } - 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(0); - _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 * 8); - } - _dis_buff_ptr->pushSprite(_win_x_pos, _win_y_pos); - return 1; -} diff --git a/FactoryTest/TFTTerminal.h b/FactoryTest/TFTTerminal.h deleted file mode 100644 index 2d29481..0000000 --- a/FactoryTest/TFTTerminal.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef _TFTTERMINAL_H_ -#define _TFTTERMINAL_H_ - -#include -#include - -class TFTTerminal : public Print -{ -private: - LGFX_Sprite *disptr; - char discharbuff[60][55]; - uint32_t xpos = 0, ypos = 0, dispos = 0; - LGFX_Sprite *_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; - uint16_t _line_x_limit = 53, _line_y_limit = 30; - -public: - TFTTerminal(LGFX_Sprite *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/FactoryTest/WebOTA.ino b/FactoryTest/WebOTA.ino index d500be4..ced4afa 100644 --- a/FactoryTest/WebOTA.ino +++ b/FactoryTest/WebOTA.ino @@ -27,19 +27,16 @@ WiFi.begin(ssid0, password0); // 接続開始 while (WiFi.status() != WL_CONNECTED) { // 接続中... - M5.Speaker.tone(2000); - delay(200); - M5.Speaker.tone(0,1); - delay(1000); + M5.Speaker.tone(2000, 200); + M5.delay(200); + M5.delay(1000); M5.Lcd.print("."); } // 接続完了!! - M5.Speaker.tone(4000); + M5.Speaker.tone(4000, 1500); lcdprintln(" Wifi Connected!\n ", GREEN, 0); String gotip = WiFi.localIP().toString(); // m5デバイスのIPアドレス M5.Lcd.println(gotip); - delay(1500); - M5.Speaker.tone(0,1); String host = "cit.istlab.info"; int port = 80; @@ -133,11 +130,10 @@ } if (Update.end()) { - M5.Speaker.tone(4000); + M5.Speaker.tone(4000, 2000); lcdprintln("\n\n OTA Done. \n shutdown now", GREENYELLOW, 0); - delay(2000); - M5.Speaker.tone(0,1); + M5.delay(2000); Serial.println("OTA done!"); if (Update.isFinished()) diff --git a/FactoryTest/gomi/TFTTerminal.cpp b/FactoryTest/gomi/TFTTerminal.cpp new file mode 100644 index 0000000..0e38574 --- /dev/null +++ b/FactoryTest/gomi/TFTTerminal.cpp @@ -0,0 +1,151 @@ +#include "TFTTerminal.h" + +TFTTerminal::TFTTerminal(LGFX_Sprite *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; +} + +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(0); + + 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 * 8); + } + } + 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(0); + _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 * 8); + } + _dis_buff_ptr->pushSprite(_win_x_pos, _win_y_pos); + return 1; +} diff --git a/FactoryTest/gomi/TFTTerminal.h b/FactoryTest/gomi/TFTTerminal.h new file mode 100644 index 0000000..2d29481 --- /dev/null +++ b/FactoryTest/gomi/TFTTerminal.h @@ -0,0 +1,33 @@ +#ifndef _TFTTERMINAL_H_ +#define _TFTTERMINAL_H_ + +#include +#include + +class TFTTerminal : public Print +{ +private: + LGFX_Sprite *disptr; + char discharbuff[60][55]; + uint32_t xpos = 0, ypos = 0, dispos = 0; + LGFX_Sprite *_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; + uint16_t _line_x_limit = 53, _line_y_limit = 30; + +public: + TFTTerminal(LGFX_Sprite *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/FactoryTest/wifi.ino b/FactoryTest/wifi.ino index 60071bc..2d62157 100644 --- a/FactoryTest/wifi.ino +++ b/FactoryTest/wifi.ino @@ -15,10 +15,8 @@ int count = 50; while (WiFi.status() != WL_CONNECTED) { // 接続中... - M5.Speaker.tone(2000); - delay(200); - M5.Speaker.tone(0,1); - delay(300); + M5.Speaker.tone(1000, 100); + M5.delay(500); M5.Display.print("."); count--; if (count < 1) @@ -27,7 +25,7 @@ if (count > 0) { // 接続完了!! - M5.Speaker.tone(4000); + M5.Speaker.tone(2000, 1500); M5.Display.fillScreen(GREEN); M5.Display.setCursor(0, 8, 4); M5.Display.setTextColor(BLACK, GREEN); @@ -44,8 +42,6 @@ String macstr = macchar; M5.Display.println(macstr); - delay(1500); - M5.Speaker.tone(0,1); return true; } return false; @@ -61,18 +57,16 @@ { configTime(9 * 3600, 0, ntpserver); // NTPサーバからLocalTimeへの時刻同期 - delay(1000); + M5.delay(1000); while (localTime.tm_year < 80) { getLocalTime(&localTime); - M5.Speaker.tone(1000); - delay(200); - M5.Speaker.tone(0,1); - delay(300); + M5.Speaker.tone(1000, 200); + M5.delay(500); M5.Display.print("."); } - M5.Speaker.tone(2000); + M5.Speaker.tone(2000, 500); setRTCfromLT(localTime); // LocalTimeからRTCへの時刻同期 } @@ -93,6 +87,5 @@ TimeStruct.seconds = lt.tm_sec + 1; M5.Rtc.setTime(&TimeStruct); M5.Display.print(" RTC updated!\n "); - delay(1500); - M5.Speaker.tone(0,1); + M5.delay(1500); }