diff --git a/FactoryTest/FactoryTest.ino b/FactoryTest/FactoryTest.ino index 2180885..737087b 100644 --- a/FactoryTest/FactoryTest.ino +++ b/FactoryTest/FactoryTest.ino @@ -3,6 +3,7 @@ // #include "esp_pm.h" #include #include + // #include // #include // #include @@ -100,10 +101,6 @@ if (M5.BtnPWR.wasPressed()) // 電源ボタン押下したら { powerOffOrDeepSleep(); - // do - // { - // M5.delay(20); - // } while (M5.BtnPWR.wasPressed()); // ESP.restart(); } @@ -130,8 +127,10 @@ if (true) { Disbuff.fillRect(0, 0, 240, 135, TFT_RED); - Disbuff.setCursor(12, 20, 4); + Disbuff.setFont(&fonts::Font0); + Disbuff.setCursor(12, 20); Disbuff.setTextColor(TFT_WHITE); + Disbuff.setTextSize(3); Disbuff.printf("Enter Deep Sleep"); Disbuff.pushSprite(0, 0); M5.delay(3000); @@ -141,6 +140,7 @@ else { Disbuff.fillRect(0, 0, 240, 135, TFT_GREEN); + Disbuff.setFont(&fonts::Font0); Disbuff.setCursor(12, 20); Disbuff.setTextColor(TFT_BLACK); Disbuff.printf("Power Off"); @@ -544,7 +544,7 @@ M5.Display.setFont(&fonts::lgfxJapanGothic_16); M5.Display.startWrite(); M5.Display.clear(); - M5.Display.setTextColor( WHITE, TFT_BLACK ); + M5.Display.setTextColor(WHITE, TFT_BLACK); rec_data = (typeof(rec_data))heap_caps_malloc(record_size * sizeof(int16_t), MALLOC_CAP_8BIT); memset(rec_data, 0, record_size * sizeof(int16_t)); M5.Speaker.setVolume(132); // 0-255だが、あまり大きいと音が割れる @@ -598,15 +598,6 @@ } } - // if (M5.BtnA.wasHold() || M5.BtnB.wasClicked()) - // { - // auto cfg = M5.Mic.config(); - // cfg.noise_filter_level = (cfg.noise_filter_level + 8) & 255; - // M5.Mic.config(cfg); - // M5.Display.setCursor(32,0); - // M5.Display.printf("nf:%03d", cfg.noise_filter_level); - // } - // else { if (M5.BtnB.wasPressed()) { if (M5.Speaker.isEnabled()) @@ -738,169 +729,6 @@ Disbuff.setTextColor(TFT_WHITE); } -#ifdef ENABLE_IRSEND -static esp_pm_lock_handle_t rmt_freq_lock; -#define RMT_TX_CHANNEL RMT_CHANNEL_0 -#define RMT_TX_GPIO_NUM GPIO_NUM_9 -#define RMT_CLK_DIV (1) // 80000000 / 1(HZ) - -rmt_item32_t *tx_buffer = NULL; - -void ir_tx_callback(rmt_channel_t channel, void *arg) -{ - // static BaseType_t xHigherPriorityTaskWoken = false; - if (channel == RMT_TX_CHANNEL) - { - esp_pm_lock_release(rmt_freq_lock); - // xHigherPriorityTaskWoken = pdFALSE; - // xSemaphoreGiveFromISR( irTxSem, &xHigherPriorityTaskWoken ); - free(tx_buffer); - } -} - -bool InitIRTx() // 赤外線通信 初期化 -{ - rmt_config_t rmt_tx; - rmt_tx.rmt_mode = RMT_MODE_TX; - rmt_tx.channel = RMT_TX_CHANNEL; - rmt_tx.gpio_num = RMT_TX_GPIO_NUM; - - rmt_tx.mem_block_num = 1; - rmt_tx.clk_div = RMT_CLK_DIV; - - rmt_tx.tx_config.loop_en = false; - rmt_tx.tx_config.carrier_duty_percent = 50; - rmt_tx.tx_config.carrier_freq_hz = 38000; - rmt_tx.tx_config.carrier_level = RMT_CARRIER_LEVEL_LOW; - rmt_tx.tx_config.carrier_en = true; - rmt_tx.tx_config.idle_level = RMT_IDLE_LEVEL_HIGH; - rmt_tx.tx_config.idle_output_en = true; - rmt_config(&rmt_tx); - rmt_driver_install(rmt_tx.channel, 0, 0); - - return true; -} - -bool ir_uart_tx(const uint8_t *src, uint8_t len, bool wait_tx_done) -{ - /* - if(src == NULL || recvFlag == true) { - return false; - } - */ - if (src == NULL) - { - return false; - } - -#if BAUD == 4800 - const rmt_item32_t bit0 = {{{8421, 1, 8421, 1}}}; // Logical 0 - const rmt_item32_t bit1 = {{{8421, 0, 8421, 0}}}; // Logical 1 -#else - const rmt_item32_t bit0 = {{{16842, 1, 16842, 1}}}; // Logical 0 - const rmt_item32_t bit1 = {{{16842, 0, 16842, 0}}}; // Logical 1 -#endif - - uint8_t *psrc = (uint8_t *)src; - // xSemaphoreTake(irTxSem, portMAX_DELAY); - - tx_buffer = (rmt_item32_t *)malloc(sizeof(rmt_item32_t) * 10 * len); - if (tx_buffer == NULL) - { - return false; - } - - rmt_item32_t *pdest = tx_buffer; - - for (uint8_t ptr = 0; ptr < len; ptr++) - { - pdest->val = bit0.val; - pdest++; - for (int i = 0; i < 8; i++) - { - if (*psrc & (0x1 << i)) - { - pdest->val = bit1.val; - } - else - { - pdest->val = bit0.val; - } - pdest++; - } - pdest->val = bit1.val; - pdest++; - psrc++; - } - - esp_pm_lock_acquire(rmt_freq_lock); - rmt_write_items(RMT_TX_CHANNEL, tx_buffer, 10 * len, true); - free(tx_buffer); - return true; -} -#endif - -#ifdef ENABLE_BLE -#define SERVICE_UUID "1bc68b2a-f3e3-11e9-81b4-2a2ae2dbcce4" -#define CHARACTERISTIC_RX_UUID "1bc68da0-f3e3-11e9-81b4-2a2ae2dbcce4" -#define CHARACTERISTIC_TX_UUID "1bc68efe-f3e3-11e9-81b4-2a2ae2dbcce4" - -BLEServer *pServer = NULL; -BLEService *pService = NULL; -BLECharacteristic *pTxCharacteristic; -bool deviceConnected = false; -bool oldDeviceConnected = false; - -class MyServerCallbacks : public BLEServerCallbacks -{ - void onConnect(BLEServer *pServer) - { - deviceConnected = true; - }; - - void onDisconnect(BLEServer *pServer) - { - deviceConnected = false; - } -}; - -uint8_t *data = new uint8_t[128]; - -class MyCallbacks : public BLECharacteristicCallbacks -{ - - void onWrite(BLECharacteristic *pCharacteristic) - { - data = pCharacteristic->getData(); - } -}; - -bool InitBLEServer() // Bluetooth Low Energyサーバ初期化 -{ - uint64_t chipid = ESP.getEfuseMac(); - String blename = "M5-" + String((uint32_t)(chipid >> 32), HEX); - - BLEDevice::init(blename.c_str()); - // BLEDevice::setPower(ESP_PWR_LVL_N12); - pServer = BLEDevice::createServer(); - - pServer->setCallbacks(new MyServerCallbacks()); - pService = pServer->createService(SERVICE_UUID); - pTxCharacteristic = pService->createCharacteristic( - CHARACTERISTIC_RX_UUID, - BLECharacteristic::PROPERTY_NOTIFY); - - pTxCharacteristic->addDescriptor(new BLE2902()); - BLECharacteristic *pRxCharacteristic = pService->createCharacteristic( - CHARACTERISTIC_TX_UUID, - BLECharacteristic::PROPERTY_WRITE); - pRxCharacteristic->setCallbacks(new MyCallbacks()); - - return true; -} - -#endif - bool checkAXP192() // 電源・バッテリー管理モジュール { float VBat = M5.Power.getBatteryVoltage(); @@ -937,145 +765,35 @@ return crc; } -#ifdef ENABLE_IRSEND -void DisIRSend() // 赤外線通信 画面表示 +void DisplayQRCode() { - uint8_t senddata[20] = {0}; - memset(senddata, 0x00, sizeof(uint8_t) * 20); - - while ((!M5.BtnA.isPressed()) && (!M5.BtnB.isPressed())) + while ((!M5.BtnA.isPressed()) /*&& (!M5.BtnB.isPressed())*/ ) { - Disbuff.fillRect(0, 0, 240, 135, TFT_BLACK); - // Disbuff.setSwapBytes(true); - Disbuff.pushImage(180, 16, 48, 48, (uint16_t *)icon_ir); - Disbuff.setTextColor(Disbuff.color565(180, 180, 180)); - Disbuff.setTextSize(3); - Disbuff.setCursor(12, 20); - Disbuff.printf("IR Send "); + // M5.Display.fillRect(0, 0, 240, 135, TFT_BLACK); + // M5.Display.qrcode("https://istlab.info", 20, 20, 120); + Disbuff.fillRect(0, 0, 240, 135, TFT_WHITE); + Disbuff.setFont(&fonts::lgfxJapanGothic_16); + Disbuff.setCursor(0,5); + Disbuff.setTextColor(TFT_BLUE); + Disbuff.println("↑電源ボタン\n←Aボタン\n\n詳しい使い方\n QRコード→\n\nBボタン(側面)↓"); + Disbuff.qrcode("https://scrapbox.io/iot-programming/usage", 115, 8, 120); - Disbuff.setTextSize(5); - Disbuff.setCursor(12, 75); - if (senddata[0] % 4 == 0) - { - Disbuff.printf("0x%02X> ", senddata[0]); - } - else if (senddata[0] % 4 == 1) - { - Disbuff.printf("0x%02X>>", senddata[0]); - } - else if (senddata[0] % 4 == 2) - { - Disbuff.printf("0x%02X >>", senddata[0]); - } - else if (senddata[0] % 4 == 3) - { - Disbuff.printf("0x%02X >", senddata[0]); - } + // M5.Display.setTextScroll(true); + Disbuff.pushSprite(0, 0); - Displaybuff(); - senddata[1]++; - if (senddata[1] > 3) - { - senddata[1] = 0; - senddata[0]++; - ir_uart_tx(senddata, 20, true); - } checkAXPPress(); M5.update(); - M5.delay(100); - } - while ((M5.BtnA.isPressed()) || (M5.BtnB.isPressed())) - { - M5.update(); - checkAXPPress(); - } - M5.delay(50); - Disbuff.setTextColor(TFT_WHITE); -} -#endif - -#ifdef ENABLE_BLE -void DisPlayBLESend() // Bluetooth Low Energy 画面表示 -{ - uint8_t senddata[2] = {0}; - - pService->start(); - pServer->getAdvertising()->start(); - - uint64_t chipid = ESP.getEfuseMac(); - String blename = "M5-" + String((uint32_t)(chipid >> 32), HEX); - - while ((!M5.BtnA.isPressed()) && (!M5.BtnB.isPressed())) - { - Disbuff.fillRect(0, 0, 240, 135, TFT_BLACK); - if (deviceConnected) - { - Disbuff.pushImage(180, 16, 48, 48, (uint16_t *)icon_ble); - Disbuff.setTextColor(Disbuff.color565(180, 180, 180)); - Disbuff.setTextSize(3); - Disbuff.setCursor(12, 20); - // Disbuff.printf("BLE connect!\n"); - Disbuff.printf("BLE Send\n"); - Disbuff.setTextSize(5); - Disbuff.setCursor(12, 75); - if (senddata[0] % 4 == 0) - { - Disbuff.printf("0x%02X> ", senddata[0]); - } - else if (senddata[0] % 4 == 1) - { - Disbuff.printf("0x%02X>>", senddata[0]); - } - else if (senddata[0] % 4 == 2) - { - Disbuff.printf("0x%02X >>", senddata[0]); - } - else if (senddata[0] % 4 == 3) - { - Disbuff.printf("0x%02X >", senddata[0]); - } - - senddata[1]++; - if (senddata[1] > 3) - { - senddata[1] = 0; - senddata[0]++; - pTxCharacteristic->setValue(senddata, 1); - pTxCharacteristic->notify(); - } - } - else - { - Disbuff.setTextSize(2); - Disbuff.setCursor(12, 20); - Disbuff.setTextColor(TFT_RED); - Disbuff.printf("BLE disconnect\n"); - Disbuff.setCursor(12, 45); - Disbuff.setTextColor(Disbuff.color565(18, 150, 219)); - - Disbuff.printf(String("Name:" + blename + "\n").c_str()); - Disbuff.setCursor(12, 70); - Disbuff.printf("UUID:1bc68b2a\n"); - Disbuff.pushImage(180, 16, 48, 48, (uint16_t *)icon_ble_disconnect); - } - Displaybuff(); - - M5.update(); - M5.delay(100); - checkAXPPress(); - } - while ((M5.BtnA.isPressed()) || (M5.BtnB.isPressed())) - { - M5.update(); - checkAXPPress(); M5.delay(10); + // count++; } - M5.delay(50); + while ((M5.BtnA.isPressed()) /*|| (M5.BtnB.isPressed())*/ ) + { + M5.update(); + checkAXPPress(); + mytone_switch(1000, 200); + } Disbuff.setTextColor(TFT_WHITE); - pService->stop(); - pServer->getAdvertising()->stop(); } -#endif void DisplayTestMode() // テストモード:ピンの電圧とバッテリー電圧 { @@ -1107,6 +825,7 @@ while ((!M5.BtnA.isPressed()) && (!M5.BtnB.isPressed())) { Disbuff.fillRect(0, 0, 240, 135, TFT_BLACK); + Disbuff.setFont(&fonts::Font0); // Disbuff.setSwapBytes(true); Disbuff.setTextColor(Disbuff.color565(180, 180, 180)); Disbuff.setTextSize(3); @@ -1285,6 +1004,7 @@ startWebOTA = true; } } + void countDownShutdown() { int countsec = 10; @@ -1292,6 +1012,7 @@ while ((!M5.BtnA.isPressed()) && (!M5.BtnB.isPressed())) { Disbuff.fillRect(0, 0, 240, 135, TFT_ORANGE); + Disbuff.setFont(&fonts::Font0); Disbuff.setTextColor(TFT_BLACK); Disbuff.setTextSize(3); Disbuff.setCursor(12, 20); @@ -1321,6 +1042,7 @@ int subcount = 10; while ((!M5.BtnA.isPressed()) && (!M5.BtnB.isPressed())) { + Disbuff.setFont(&fonts::Font0); Disbuff.fillRect(0, 0, 240, 135, TFT_PURPLE); Disbuff.setTextColor(TFT_WHITE); Disbuff.setTextSize(3); @@ -1361,6 +1083,7 @@ { while ((!M5.BtnA.isPressed()) /*&& (!M5.BtnB.isPressed())*/) { + Disbuff.setFont(&fonts::Font0); if (TestMode) { Disbuff.fillRect(0, 0, 240, 135, TFT_PURPLE); @@ -1634,15 +1357,6 @@ checkAXP192(); // バッテリー電圧チェック。低下してたらエラーメッセージ表示 - // M5.Imu.init(); // 加速度・角速度(ジャイロ)初期化 - // InitI2SMicroPhone(); // マイク初期化 -#ifdef ENABLE_IRSEND - InitIRTx(); // 赤外線通信 初期化 -#endif -#ifdef ENABLE_BLE - InitBLEServer(); // Bluetooth Low Energyサーバ初期化 -#endif - pinMode(19, OUTPUT); // LEDのポートを出力に設定 // timerSemaphore = xSemaphoreCreateBinary(); // バイナリセマフォ作成 // timer = timerBegin(0, 80, true); // タイマーID=0, 80クロックで1カウントする, カウントアップならtrue @@ -1668,18 +1382,11 @@ { // それぞれのテスト中は、関数のなかのループがまわる // A(orB)ボタンを押したら、現在実行中の関数のループを抜け、次の関数を実行する - MPU6886Test(); // 加速度・ジャイロ - DisplayRTC(); // リアルタイムクロック - DisplayMicro(); // マイク -#ifdef ENABLE_IRSEND - DisIRSend(); // 赤外線通信 -#endif - + MPU6886Test(); // 加速度・ジャイロ + DisplayRTC(); // リアルタイムクロック + DisplayMicro(); // マイク + DisplayQRCode(); // QRコード // DisplayTestMode(); // バッテリー電圧 - -#ifdef ENABLE_BLE - DisPlayBLESend(); -#endif ESP_NOW_SendShutdown(); // シャットダウン信号の送信 M5.update(); diff --git a/FactoryTest/wifi.ino b/FactoryTest/wifi.ino index a66a9c9..ba036a8 100644 --- a/FactoryTest/wifi.ino +++ b/FactoryTest/wifi.ino @@ -21,8 +21,9 @@ M5.delay(500); M5.Display.print("."); count--; - if (count < 1) + if (count < 1){ break; + } } if (count > 0) { @@ -45,6 +46,9 @@ M5.Display.println(macstr); return true; + } else { + // 一旦、Wifiを切断 + wifi_down(); } return false; }