Skip to content

Commit

Permalink
Merge pull request #106 from bmorcelli/main
Browse files Browse the repository at this point in the history
 Mic Fix for Cardputer, small BLE changes
  • Loading branch information
pr3y authored Aug 2, 2024
2 parents c831a29 + ab3e179 commit 7a3d461
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 29 deletions.
4 changes: 0 additions & 4 deletions src/core/main_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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); }},
Expand Down Expand Up @@ -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); }},
Expand Down
12 changes: 10 additions & 2 deletions src/core/serialcmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
43 changes: 24 additions & 19 deletions src/modules/ble/ble_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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;
Expand All @@ -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="<no 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); }});

}
};

Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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]);
Expand Down Expand Up @@ -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;
}
Expand All @@ -1001,6 +1005,7 @@ void disPlayBLESend()
tft.setTextColor(TFT_WHITE);
pService->stop();
pServer->getAdvertising()->stop();
BLEConnected=false;
}

static bool is_ble_inited = false;
Expand Down
22 changes: 18 additions & 4 deletions src/modules/others/mic.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "mic.h"
#include "core/mykeyboard.h"
#include "core/powerSave.h"

/**
* @file test_mic.cpp
Expand All @@ -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];

Expand Down Expand Up @@ -193,6 +206,7 @@ void mic_test_one_task()
}
}
spr_main.pushSprite(0,0);
wakeUpScreen();
}
}

Expand Down

0 comments on commit 7a3d461

Please sign in to comment.