diff --git a/M5StickCPlus_FactoryTest2022.ino b/M5StickCPlus_FactoryTest2022.ino index 81c4b48..96da1f7 100644 --- a/M5StickCPlus_FactoryTest2022.ino +++ b/M5StickCPlus_FactoryTest2022.ino @@ -97,7 +97,7 @@ } while (M5.Axp.GetBtnPress()); M5.Beep.mute(); // ESP.restart(); - M5.Axp.Write1Byte(0x32, M5.Axp.Read8bit(0x32) | 0x80); //電源OFF + M5.Axp.Write1Byte(0x32, M5.Axp.Read8bit(0x32) | 0x80); // 電源OFF } if (startCoundDownShutdown) @@ -480,7 +480,7 @@ void DisplayMicro() { - Disbuff.fillRect(0, 0, 160, 80, Disbuff.color565(0, 0, 0)); //黒(R=0,G=0,B=0)で塗りつぶす + Disbuff.fillRect(0, 0, 160, 80, Disbuff.color565(0, 0, 0)); // 黒(R=0,G=0,B=0)で塗りつぶす Disbuff.pushSprite(0, 0); xSemaphoreGive(start_dis); // 画面表示タスク スタート @@ -490,7 +490,7 @@ xSemaphoreGive(start_dis); xSemaphoreGive(start_fft); M5.update(); - xSemaphoreTake(start_dis, portMAX_DELAY); // 画面表示タスク 一時停止 + xSemaphoreTake(start_dis, portMAX_DELAY); //  画面表示タスク 一時停止 xSemaphoreTake(start_fft, portMAX_DELAY); // フーリエ変換タスク 一時停止 checkAXPPress(); } @@ -583,8 +583,7 @@ { // RTC sync from NTP // Wifi → NTP → update RTC → WifiOff - wifi_setup(); - ntp_setup(); + if (wifi_setup()) ntp_setup(); wifi_down(); Init_ESPNOW(); // ESPNOWの初期化 @@ -778,7 +777,7 @@ return true; } -uint8_t crc8(uint8_t data, uint8_t *buff, uint32_t length) //巡回冗長検査 +uint8_t crc8(uint8_t data, uint8_t *buff, uint32_t length) // 巡回冗長検査 { uint8_t bit; // bit mask uint8_t crc = 0xFF; // calculated checksum @@ -845,6 +844,7 @@ return 0; } +#ifdef ENABLE_IRSEND void DisIRSend() // 赤外線通信 画面表示 { uint8_t senddata[20] = {0}; @@ -902,6 +902,7 @@ M5.Beep.mute(); Disbuff.setTextColor(TFT_WHITE); } +#endif #ifdef ENABLE_BLE void DisPlayBLESend() // Bluetooth Low Energy 画面表示 @@ -1065,7 +1066,7 @@ Disbuff.setTextSize(3); Disbuff.setCursor(12, 7); - if (M5.Axp.GetBatVoltage() > 3.2) //バッテリーの電圧(残量によって変化する) + if (M5.Axp.GetBatVoltage() > 3.2) // バッテリーの電圧(残量によって変化する) { Disbuff.setTextColor(TFT_GREEN); } @@ -1083,7 +1084,7 @@ { Disbuff.setTextColor(TFT_RED); } - Disbuff.printf("v%.2f", M5.Axp.GetVinVoltage()); //外部電源電圧(5V←の電圧) + Disbuff.printf("v%.2f", M5.Axp.GetVinVoltage()); // 外部電源電圧(5V←の電圧) digitalWrite(0, 0); digitalWrite(26, 0); @@ -1169,11 +1170,11 @@ getTempAndHum(&tempdata, &humdata); // ENV. II SENSORをつないだときに、温度と湿度がとれる } - Disbuff.setTextColor(TFT_WHITE); //白色で + Disbuff.setTextColor(TFT_WHITE); // 白色で Disbuff.setCursor(12, 67); - Disbuff.printf(" %.1f", tempdata); //温度? + Disbuff.printf(" %.1f", tempdata); // 温度? Disbuff.setCursor(12, 97); - Disbuff.printf(" %.1f", humdata); //湿度? + Disbuff.printf(" %.1f", humdata); // 湿度? Disbuff.pushSprite(0, 0); @@ -1222,8 +1223,8 @@ { // Pair success Serial.println("Pair success"); - esp_now_register_send_cb(onESPNOWSent); //送信後のコールバック関数を指定する - esp_now_register_recv_cb(onESPNOWReceive); ///受信時のコールバック関数を指定する + esp_now_register_send_cb(onESPNOWSent); // 送信後のコールバック関数を指定する + esp_now_register_recv_cb(onESPNOWReceive); /// 受信時のコールバック関数を指定する } } // 引用: https://101010.fun/iot/esp32-m5stickc-plus-esp-now.html @@ -1269,7 +1270,7 @@ } if (countsec < 0) { - M5.Axp.Write1Byte(0x32, M5.Axp.Read8bit(0x32) | 0x80); //電源OFF + M5.Axp.Write1Byte(0x32, M5.Axp.Read8bit(0x32) | 0x80); // 電源OFF } } startCoundDownShutdown = false; @@ -1531,7 +1532,7 @@ Init_ESPNOW(); // ESPNOWの初期化 - ColorBar(); //ディスプレイ発色チェック + ColorBar(); // ディスプレイ発色チェック checkI2CAddr(); checkAXP192(); // バッテリー電圧チェック。低下してたらエラーメッセージ表示 @@ -1571,7 +1572,9 @@ MPU6886Test(); // 加速度・ジャイロ DisplayRTC(); // リアルタイムクロック DisplayMicro(); // マイク - DisIRSend(); // 赤外線通信 +#ifdef ENABLE_IRSEND + DisIRSend(); // 赤外線通信 +#endif if (TestMode) { @@ -1581,7 +1584,7 @@ #ifdef ENABLE_BLE DisPlayBLESend(); #else - ESP_NOW_SendShutdown(); // シャットダウン信号の送信 + ESP_NOW_SendShutdown(); // シャットダウン信号の送信 #endif M5.update(); @@ -1611,7 +1614,7 @@ trycount++; if (trycount == 100) { - M5.Axp.Write1Byte(0x32, M5.Axp.Read8bit(0x32) | 0x80); //電源OFF + M5.Axp.Write1Byte(0x32, M5.Axp.Read8bit(0x32) | 0x80); // 電源OFF } } M5.Lcd.fillScreen(GREEN); diff --git a/wifi.ino b/wifi.ino index df8575e..fa99cf8 100644 --- a/wifi.ino +++ b/wifi.ino @@ -7,12 +7,13 @@ // const char *ntpserver = "192.168.11.11"; //実験室ローカルNTPサーバ const char *ntpserver = "ntp.nict.jp"; -void wifi_setup() +bool wifi_setup() { M5.Lcd.fillScreen(ORANGE); M5.Lcd.setCursor(10, 50, 4); WiFi.begin(ssid, password); // 接続開始 + int count = 50; while (WiFi.status() != WL_CONNECTED) { // 接続中... M5.Beep.tone(2000); @@ -20,26 +21,34 @@ M5.Beep.mute(); delay(300); M5.Lcd.print("."); + count--; + if (count < 1) + break; } - // 接続完了!! - M5.Beep.tone(4000); - M5.Lcd.fillScreen(GREEN); - M5.Lcd.setCursor(0, 8, 4); - M5.Lcd.setTextColor(BLACK, GREEN); - M5.Lcd.print(" Wifi Connected!\n "); - String gotip = WiFi.localIP().toString(); // m5デバイスのIPアドレス - M5.Lcd.println(gotip); + if (count > 0) + { + // 接続完了!! + M5.Beep.tone(4000); + M5.Lcd.fillScreen(GREEN); + M5.Lcd.setCursor(0, 8, 4); + M5.Lcd.setTextColor(BLACK, GREEN); + M5.Lcd.print(" Wifi Connected!\n "); + String gotip = WiFi.localIP().toString(); // m5デバイスのIPアドレス + M5.Lcd.println(gotip); - // MACアドレスを表示 - uint8_t mac[6]; - char macchar[100]; - esp_read_mac(mac, ESP_MAC_WIFI_STA); - sprintf(macchar, " %02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - String macstr = macchar; - M5.Lcd.println(macstr); + // MACアドレスを表示 + uint8_t mac[6]; + char macchar[100]; + esp_read_mac(mac, ESP_MAC_WIFI_STA); + sprintf(macchar, " %02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + String macstr = macchar; + M5.Lcd.println(macstr); - delay(1500); - M5.Beep.mute(); + delay(1500); + M5.Beep.mute(); + return true; + } + return false; } void wifi_down() { @@ -54,9 +63,10 @@ delay(1000); - while (localTime.tm_year < 80) { - getLocalTime(&localTime); - M5.Beep.tone(1000); + while (localTime.tm_year < 80) + { + getLocalTime(&localTime); + M5.Beep.tone(1000); delay(200); M5.Beep.mute(); delay(300); @@ -64,23 +74,24 @@ } M5.Beep.tone(2000); - setRTCfromLT(localTime); //LocalTimeからRTCへの時刻同期 + setRTCfromLT(localTime); // LocalTimeからRTCへの時刻同期 } // LocalTimeからRTCへの時刻同期 -void setRTCfromLT(struct tm lt) { - RTC_DateTypeDef DateStruct; - DateStruct.Year = lt.tm_year + 1900; - DateStruct.Month = lt.tm_mon + 1; - DateStruct.Date = lt.tm_mday; - DateStruct.WeekDay = lt.tm_wday; - M5.Rtc.SetDate(&DateStruct); +void setRTCfromLT(struct tm lt) +{ + RTC_DateTypeDef DateStruct; + DateStruct.Year = lt.tm_year + 1900; + DateStruct.Month = lt.tm_mon + 1; + DateStruct.Date = lt.tm_mday; + DateStruct.WeekDay = lt.tm_wday; + M5.Rtc.SetDate(&DateStruct); - RTC_TimeTypeDef TimeStruct; - TimeStruct.Hours = lt.tm_hour; - TimeStruct.Minutes = lt.tm_min; - TimeStruct.Seconds = lt.tm_sec+1; - M5.Rtc.SetTime(&TimeStruct); + RTC_TimeTypeDef TimeStruct; + TimeStruct.Hours = lt.tm_hour; + TimeStruct.Minutes = lt.tm_min; + TimeStruct.Seconds = lt.tm_sec + 1; + M5.Rtc.SetTime(&TimeStruct); M5.Lcd.print(" RTC updated!\n "); delay(1500); M5.Beep.mute();