From cdd2349a911f2cdd8aebd73e36dd3541da350572 Mon Sep 17 00:00:00 2001 From: dragonchaser Date: Mon, 14 Jul 2025 17:26:04 +0200 Subject: [PATCH] optimize memory Signed-off-by: dragonchaser --- btcontrol.ino | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/btcontrol.ino b/btcontrol.ino index 47c14c4..6348e2f 100644 --- a/btcontrol.ino +++ b/btcontrol.ino @@ -1,11 +1,14 @@ -#include +//#include #include -#include +//#include #include #include #include +// POWER SAVE ATTEMPTS +//#include + // Methods uint64_t StrToHex(const char* str); @@ -14,7 +17,6 @@ void FillLEDsFromPaletteColors( uint8_t colorIndex); void UpdatePalette(); void Vibrate(); - // Bluetooth configuration #define BLE_ACTIVE_SCAN false #define BLE_SCAN_INTERVAL 100 @@ -31,6 +33,8 @@ void Vibrate(); #define LED_FRAMES_PER_SECOND 24 #define LED_SETUP_DISPLAY_DELAY 500 +#define LED_PALETTE_SIZE 16 + // VIBRATION MOTOR configuration #define VIBRO_PIN 2 #define VIBRO_REPEAT 3 @@ -42,6 +46,8 @@ void Vibrate(); #define MAX_VANISH_COUNTER 3 // if updateinterval is 10000 => 30s // Number of devices that can be monitored (might cause a reset because of memory oversaturation!) +// If you are using more then 16, you have to use CRGBPalette256 instead of CRGBPalette16 +// It probably makes sense to align this with LED_NUM_LEDS #define MAX_MONITOR_DEVICES 7 // Minimum transmit power the device needs to be recognice (this defines the min proximity needed for the device to be used) // TODO: add a table here that defines distance in meters for scenarios where the device is in plain sight @@ -60,7 +66,7 @@ const std::map blackList = { #define DEVICE_TYPE_PRIVATE_LAMP 2 #define DEVICE_TYPE_AMULETT 3 -#define DEVICE_TYPE DEVICE_TYPE_AMULETT +#define DEVICE_TYPE DEVICE_TYPE_PUBLIC_LAMP #ifndef DEVICE_TYPE // WE DO NOT HAVE A DEVICETYPE, so we do not have any variables here @@ -103,7 +109,7 @@ const std::map blackList = { BLEScan *pBLEScan; CRGB leds[LED_NUM_LEDS]; -CRGBPalette256 pal; +CRGBPalette16 pal; std::map deviceDatabase; @@ -205,6 +211,10 @@ void setup() { pBLEScan->setActiveScan(BLE_ACTIVE_SCAN); //active scan uses more power, but get results faster pBLEScan->setInterval(BLE_SCAN_INTERVAL); pBLEScan->setWindow(BLE_WINDOW); // less or equal setInterval value + + // POWER SAVING! + //WiFi.disconnect(true); // Disconnect from the network + //WiFi.mode(WIFI_OFF); } void loop() { @@ -215,7 +225,7 @@ void loop() { BLEScanResults *foundDevices = pBLEScan->start(BLE_SCAN_TIME, false); pBLEScan->clearResults(); // delete results fromBLEScan buffer to release memory } - FillLEDsFromPaletteColors(startindex++); + FillLEDsFromPaletteColors((startindex++) % LED_PALETTE_SIZE); FastLED.show(); FastLED.delay(1000/LED_FRAMES_PER_SECOND); } @@ -265,9 +275,9 @@ void UpdatePalette() { } if (colors.empty()) { - fill_solid(pal.entries, 256, CRGB::Black); + fill_solid(pal.entries, LED_PALETTE_SIZE, CRGB::Black); } else { - for (int i=0; i<256; i++) { + for (int i=0; i