From 8d27baaf507bf1ed5c87db3fe3b6d71d2c3fa7db Mon Sep 17 00:00:00 2001 From: Pirata Date: Thu, 1 Aug 2024 18:31:17 -0300 Subject: [PATCH] Mic Fix for Cardputer, small BLE changes Fixed mic pins for Cardputer Removed music_player from StickCPlus2, because it doesn't have the hardware needed Changed BLE Scan results filte to show all devices found, if it doesn't have a name, it will display the mac address on Scan menu, and on information --- src/core/main_menu.cpp | 4 ---- src/core/serialcmds.cpp | 12 ++++++++-- src/modules/ble/ble_common.cpp | 43 +++++++++++++++++++--------------- src/modules/others/mic.cpp | 22 +++++++++++++---- 4 files changed, 52 insertions(+), 29 deletions(-) diff --git a/src/core/main_menu.cpp b/src/core/main_menu.cpp index 294e07bf..af5487c2 100644 --- a/src/core/main_menu.cpp +++ b/src/core/main_menu.cpp @@ -70,10 +70,8 @@ void wifiOptions() { **********************************************************************/ void bleOptions() { options = { - #if defined(STICK_C_PLUS2) {"BLE Beacon", [=]() { ble_test(); }}, {"BLE Scan", [=]() { ble_scan(); }}, - #endif {"AppleJuice", [=]() { aj_adv(0); }}, {"SwiftPair", [=]() { aj_adv(1); }}, {"Samsung Spam", [=]() { aj_adv(2); }}, @@ -143,9 +141,7 @@ void irOptions(){ **********************************************************************/ void otherOptions(){ options = { - #if defined(STICK_C_PLUS2) {"Mic Spectrum", [=]() { mic_test(); }}, - #endif {"QRCodes", [=]() { qrcode_menu(); }}, {"SD Card", [=]() { loopSD(SD); }}, {"LittleFS", [=]() { loopSD(LittleFS); }}, diff --git a/src/core/serialcmds.cpp b/src/core/serialcmds.cpp index 4f9ad811..acb154c0 100644 --- a/src/core/serialcmds.cpp +++ b/src/core/serialcmds.cpp @@ -202,14 +202,22 @@ void handleSerialCommands() { } } // endof rf - #ifndef STICK_C_PLUS + #if defined(CARDPUTER) //M5StickCs doesn't have speakers.. they have buzzers on pin 02 that only beeps in different frequencies if(cmd_str.startsWith("music_player " ) || cmd_str.startsWith("tts" ) || cmd_str.startsWith("say" ) ) { // TODO: move in audio.cpp module AudioOutputI2S *audioout = new AudioOutputI2S(); // https://github.com/earlephilhower/ESP8266Audio/blob/master/src/AudioOutputI2S.cpp#L32 #ifdef CARDPUTER - audioout->SetPinout(41, 43, 42); // bclk, wclk, dout + #define BCLK 41 + #define WCLK 43 + #define DOUT 42 // TODO: other pinouts + #elif define(CORE2) // Core uses buzzer and CoreS3 uses I2C communication (SDA-12, SCL-11 addr 0x36) + #define BCLK 12 + #define WCLK 0 + #define DOUT 2 #endif + + audioout->SetPinout(BCLK, WCLK, DOUT); // bclk, wclk, dout AudioGenerator* generator = NULL; AudioFileSource* source = NULL; diff --git a/src/modules/ble/ble_common.cpp b/src/modules/ble/ble_common.cpp index db1b7812..793e683e 100644 --- a/src/modules/ble/ble_common.cpp +++ b/src/modules/ble/ble_common.cpp @@ -831,9 +831,9 @@ void ble_info(String name, String address, String signal) tft.setTextColor(FGCOLOR); tft.drawCentreString("-=Information=-", tft.width()/2, 28,SMOOTH_FONT); tft.drawString("Name: " + name, 10, 48); - tft.drawString("Adresse: " + address, 10, 84); - tft.drawString("Signal: " + String(signal) + " dBm", 10, 102); - tft.drawString(" Press " + String(BTN_ALIAS) + " to act",10,tft.height()-20); + tft.drawString("Adresse: " + address, 10, 66); + tft.drawString("Signal: " + String(signal) + " dBm", 10, 84); + tft.drawCentreString(" Press " + String(BTN_ALIAS) + " to act",WIDTH/2,tft.height()-20,1); delay(300); while(!checkSelPress()) { @@ -845,7 +845,7 @@ void ble_info(String name, String address, String signal) class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks { void onResult(BLEAdvertisedDevice advertisedDevice) { - const char* bt_title; + String bt_title; String bt_name; String bt_address; String bt_signal; @@ -854,10 +854,12 @@ class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks { bt_title = advertisedDevice.getName().c_str(); bt_address = advertisedDevice.getAddress().toString().c_str(); bt_signal = String(advertisedDevice.getRSSI()); + //Serial.println("\n\nAddress - " + bt_address + "Name-"+ bt_name +"\n\n"); + if(bt_title.isEmpty()) bt_title = bt_address; + if(bt_name.isEmpty()) bt_name=""; // If BT name is empty, set NONAME - if (bt_name != "" and bt_name != " " and bt_name != " " and bt_name != " ") { - options.push_back({bt_title, [=]() { ble_info(bt_name, bt_address, bt_signal); }}); - } + options.push_back({bt_title.c_str(), [=]() { ble_info(bt_name, bt_address, bt_signal); }}); + } }; @@ -899,7 +901,7 @@ void ble_scan() bool initBLEServer() { uint64_t chipid = ESP.getEfuseMac(); - String blename = "M5-" + String((uint32_t)(chipid >> 32), HEX); + String blename = "Bruce-" + String((uint8_t)(chipid >> 32), HEX); BLEDevice::init(blename.c_str()); // BLEDevice::setPower(ESP_PWR_LVL_N12); @@ -926,10 +928,12 @@ void disPlayBLESend() pServer->getAdvertising()->start(); uint64_t chipid = ESP.getEfuseMac(); - String blename = "M5-" + String((uint32_t)(chipid >> 32), HEX); + String blename = "Bruce-" + String((uint8_t)(chipid >> 32), HEX); tft.setTextSize(1); tft.fillRect(0, 0, 240, 135, TFT_BLACK); + BLEConnected=true; + drawMainBorder(); bool wasConnected = false; bool first_run = true; @@ -938,17 +942,17 @@ void disPlayBLESend() if (deviceConnected) { if (!wasConnected) { - tft.fillRect(0, 0, 240, 135, TFT_BLACK); - tft.pushImage(180, 16, 48, 48, (uint16_t *)icon_ble); + tft.fillRect(10, 26, WIDTH-20, HEIGHT-36, TFT_BLACK); + tft.pushImage(180, 46, 48, 48, (uint16_t *)icon_ble); tft.setTextColor(tft.color565(180, 180, 180)); tft.setTextSize(3); - tft.setCursor(12, 20); + tft.setCursor(12, 50); // tft.printf("BLE connect!\n"); tft.printf("BLE Send\n"); tft.setTextSize(5); } - tft.fillRect(10, 70, 240, 50, TFT_BLACK); - tft.setCursor(12, 75); + tft.fillRect(10, 100, WIDTH-20, 50, TFT_BLACK); + tft.setCursor(12, 105); if (senddata[0] % 4 == 0) { tft.printf("0x%02X> ", senddata[0]); @@ -980,18 +984,18 @@ void disPlayBLESend() { if (wasConnected or first_run) { first_run = false; - tft.fillRect(0, 0, 240, 135, TFT_BLACK); + tft.fillRect(10, 26, WIDTH-20, HEIGHT-36, TFT_BLACK); tft.setTextSize(2); - tft.setCursor(12, 20); + tft.setCursor(12, 50); tft.setTextColor(TFT_RED); tft.printf("BLE disconnect\n"); - tft.setCursor(12, 45); + tft.setCursor(12, 75); tft.setTextColor(tft.color565(18, 150, 219)); tft.printf(String("Name:" + blename + "\n").c_str()); - tft.setCursor(12, 70); + tft.setCursor(12, 100); tft.printf("UUID:1bc68b2a\n"); - tft.pushImage(180, 16, 48, 48, (uint16_t *)icon_ble_disconnect); + tft.pushImage(180, 46, 48, 48, (uint16_t *)icon_ble_disconnect); } wasConnected = false; } @@ -1001,6 +1005,7 @@ void disPlayBLESend() tft.setTextColor(TFT_WHITE); pService->stop(); pServer->getAdvertising()->stop(); + BLEConnected=false; } static bool is_ble_inited = false; diff --git a/src/modules/others/mic.cpp b/src/modules/others/mic.cpp index 21b1006a..de6c59a4 100644 --- a/src/modules/others/mic.cpp +++ b/src/modules/others/mic.cpp @@ -1,5 +1,6 @@ #include "mic.h" #include "core/mykeyboard.h" +#include "core/powerSave.h" /** * @file test_mic.cpp @@ -12,10 +13,22 @@ * */ -#define PIN_CLK 0 -#define I2S_SCLK_PIN 0 -#define I2S_DATA_PIN 34 -#define PIN_DATA 34 +#if defined(STICK_C_PLUS) || defined(STICK_C_PLUS2) || defined(CORE2) + #define PIN_CLK 0 + #define I2S_SCLK_PIN 0 + #define I2S_DATA_PIN 34 + #define PIN_DATA 34 +#elif defined (CARDPUTER) + #define PIN_CLK 43 + #define I2S_SCLK_PIN 43 + #define I2S_DATA_PIN 46 + #define PIN_DATA 46 +#else // to avoid fail when porting to other devices + #define PIN_CLK -1 + #define I2S_SCLK_PIN -1 + #define I2S_DATA_PIN -1 + #define PIN_DATA -1 +#endif extern const unsigned char ImageData[768]; @@ -193,6 +206,7 @@ void mic_test_one_task() } } spr_main.pushSprite(0,0); + wakeUpScreen(); } }