optimize memory

Signed-off-by: dragonchaser <christian@boltares.de>
This commit is contained in:
dragonchaser
2025-07-14 17:26:04 +02:00
parent b9c56702a0
commit cdd2349a91

View File

@@ -1,11 +1,14 @@
#include <Arduino.h>
//#include <Arduino.h>
#include <BLEDevice.h>
#include <BLEScan.h>
//#include <BLEScan.h>
#include <FastLED.h>
#include <TimerEvent.h>
#include <mutex>
// POWER SAVE ATTEMPTS
//#include <WiFi.h>
// 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<String, void*> 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<String, void*> blackList = {
BLEScan *pBLEScan;
CRGB leds[LED_NUM_LEDS];
CRGBPalette256 pal;
CRGBPalette16 pal;
std::map<String,uint8_t> 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<LED_PALETTE_SIZE; i++) {
pal[i] = CRGB(StrToHex(colors[ i % deviceDatabase.size() ].c_str()));
}
}