From 44d05682675d4f21676fbf581605792b4ad954c9 Mon Sep 17 00:00:00 2001 From: Andrey Klimov Date: Wed, 22 Dec 2021 01:50:40 +0300 Subject: [PATCH] Mega2560slim RAM optimization --- build-flags/build_flags_mega2560slim-5100 | 8 +++++- lighthub/dmx.cpp | 6 ++++- lighthub/dmx.h | 2 +- lighthub/item.cpp | 2 ++ lighthub/itemCmd.cpp | 7 ++++- lighthub/main.cpp | 17 ++++++------ lighthub/main.h | 15 ----------- lighthub/owTerm.h | 5 ++++ platformio.ini | 32 ++++++++++++++++------- 9 files changed, 57 insertions(+), 37 deletions(-) diff --git a/build-flags/build_flags_mega2560slim-5100 b/build-flags/build_flags_mega2560slim-5100 index 9ae2d55..2ae4093 100644 --- a/build-flags/build_flags_mega2560slim-5100 +++ b/build-flags/build_flags_mega2560slim-5100 @@ -20,4 +20,10 @@ #-DMDNS_ENABLE -DRESTART_LAN_ON_MQTT_ERRORS -D CORS=\"http://lazyhome.ru\" --DOTA_PORT=80 \ No newline at end of file +-DOTA_PORT=80 +-DHSV_DISABLE +-DMULTIVENT_DISABLE +-DPID_DISABLE +-DPWM_DISABLE +-DSPILED_DISABLE +-DOW_DEVICES_LIMIT=17 diff --git a/lighthub/dmx.cpp b/lighthub/dmx.cpp index faa5ea8..122e006 100644 --- a/lighthub/dmx.cpp +++ b/lighthub/dmx.cpp @@ -44,9 +44,10 @@ volatile uint16_t DMXOUT_Channels=0; volatile uint32_t checkTimestamp=0L; #endif +#if defined(_dmxin) volatile uint32_t D_State=0; - volatile unsigned long D_checkT=0; +#endif #ifdef _artnet #include @@ -134,7 +135,10 @@ for (short tch=0; tch<=3 ; tch++) }; extern volatile uint8_t timerHandlerBusy; + +#if defined(_dmxin) volatile int DMXinDoublecheck=0; +#endif void DMXUpdate(void) { diff --git a/lighthub/dmx.h b/lighthub/dmx.h index 4f8abb7..593c0b3 100644 --- a/lighthub/dmx.h +++ b/lighthub/dmx.h @@ -23,7 +23,7 @@ e-mail anklimov@gmail.com #define D_UPDATED4 8 #define D_CHECKT 300 -#define MAX_CHANNELS 60 +//#define MAX_CHANNELS 60 //define MAX_IN_CHANNELS 16 //#define DMX_OUT_PIN 3 diff --git a/lighthub/item.cpp b/lighthub/item.cpp index e8951fc..6d0b5cb 100644 --- a/lighthub/item.cpp +++ b/lighthub/item.cpp @@ -135,9 +135,11 @@ void Item::Parse() { itemExt = aJson.getArrayItem(itemArr, I_EXT); switch (itemType) { +#ifndef PWM_DISABLE case CH_PWM: driver = new out_pwm (this); break; +#endif #ifndef DMX_DISABLE case CH_RGBW: diff --git a/lighthub/itemCmd.cpp b/lighthub/itemCmd.cpp index 870fbdb..1dcb8a2 100644 --- a/lighthub/itemCmd.cpp +++ b/lighthub/itemCmd.cpp @@ -5,11 +5,13 @@ #include "item.h" #include "bright.h" +#ifndef HSV_DISABLE #ifdef ADAFRUIT_LED #include #else #include "FastLED.h" #endif +#endif //#include "hsv2rgb.h" @@ -576,7 +578,7 @@ itemCmd itemCmd::assignFrom(itemCmd from, short chanType) } } - + #ifndef HSV_DISABLE #ifdef ADAFRUIT_LED Adafruit_NeoPixel strip(0, 0, 0); uint32_t rgb = strip.ColorHSV(map(from.param.h, 0, 365, 0, 65535), rgbSaturation, rgbValue); @@ -589,6 +591,9 @@ itemCmd itemCmd::assignFrom(itemCmd from, short chanType) param.g=rgb.g; param.b=rgb.b; #endif + #else + debugSerial<type == aJson_String) return element->valuestring; } #ifdef OTA + const char defaultPassword[] PROGMEM = "password"; void setupOTA(void) { char passwordBuf[16]; if (!sysConf.getOTApwd(passwordBuf, sizeof(passwordBuf))) { - strcpy(passwordBuf,"password"); + strcpy_P(passwordBuf,defaultPassword); errorSerial< #include #include //#include "TimerInterrupt_Generic.h" @@ -18,12 +17,10 @@ //#include #include #include -//#include #endif #if defined(ARDUINO_ARCH_ESP8266) #include //this needs to be first, or it all crashes and burns... -//#include "SPIFFS.h" #ifndef FS_STORAGE #include #endif @@ -132,10 +129,6 @@ extern Streamlog errorSerial; #include #endif -//#ifndef DMX_DISABLE -//#include "FastLED.h" -//#endif - #ifdef _owire #include "owTerm.h" #endif @@ -231,9 +224,7 @@ typedef union { } UID; bool isNotRetainingStatus(); -//void watchdogSetup(void); -//int itemCommand(char *topic, char *payload); void mqttCallback(char *topic, byte *payload, unsigned int length); void printMACAddress(); @@ -256,12 +247,6 @@ int cmdFunctionLoad(int arg_cnt, char **args); int loadConfigFromEEPROM(); -//void cmdFunctionReq(int arg_cnt, char **args); - -//int mqttConfigRequest(int arg_cnt, char **args); - -//int mqttConfigResp(char *as); - int cmdFunctionSave(int arg_cnt, char **args); int cmdFunctionSetMac(int arg_cnt, char **args); diff --git a/lighthub/owTerm.h b/lighthub/owTerm.h index 548bfa6..963da8d 100644 --- a/lighthub/owTerm.h +++ b/lighthub/owTerm.h @@ -48,7 +48,12 @@ e-mail anklimov@gmail.com #define recheck_interval 5 #define check_circle 2000/t_count +#if defined (OW_DEVICES_LIMIT) #define t_max 20 //Maximum number of 1w devices +#else +#define t_max OW_DEVICES_LIMIT +#endif + #define TEMPERATURE_PRECISION 12 //9 #ifndef OWIRE_DISABLE diff --git a/platformio.ini b/platformio.ini index 21f84b7..428384d 100644 --- a/platformio.ini +++ b/platformio.ini @@ -317,6 +317,7 @@ board = megaatmega2560 upload_port = net:192.168.88.2:23000 framework = arduino build_flags = !python get_build_flags.py mega2560slim-5100 +extra_scripts = post:toBin.py lib_ignore = ;DS2482_OneWire //UNCOMMENT for software 1-wire driver DHT sensor library for ESPx @@ -330,33 +331,44 @@ lib_ignore = UIPEthernet ESP_EEPROM M5Stack + FastLED + Artnet + DMXSerial + Adafruit NeoPixel + DmxSimple + ModbusMaster + ClosedCube HDC1080 + SparkFun CCS811 Arduino Library + ;Adafruit BusIO + ;Adafruit MCP23017 Arduino Library + ;Adafruit Unified Sensor lib_deps = https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/DS2482_OneWire - https://github.com/anklimov/DmxSimple + ;https://github.com/anklimov/DmxSimple https://github.com/anklimov/httpClient https://github.com/anklimov/aJson https://github.com/anklimov/CmdArduino - https://github.com/anklimov/ModbusMaster - https://github.com/anklimov/DMXSerial + ;https://github.com/anklimov/ModbusMaster + ;https://github.com/anklimov/DMXSerial https://github.com/anklimov/Ethernet5100 ;5100 lib have ~90 bytes less footprint of RAM https://github.com/knolleary/pubsubclient.git - https://github.com/anklimov/Artnet.git - FastLED@3.3.2 + ;https://github.com/anklimov/Artnet.git + ;FastLED@3.3.2 Adafruit Unified Sensor DHT sensor library https://github.com/arcao/Syslog.git - Streaming - ClosedCube HDC1080 - SparkFun CCS811 Arduino Library@~1.0.7 - Adafruit NeoPixel + ;Streaming + ;;ClosedCube HDC1080 + ;;SparkFun CCS811 Arduino Library@~1.0.7 + ;Adafruit NeoPixel https://github.com/anklimov/ArduinoOTA Adafruit MCP23017 Arduino Library Adafruit BusIO br3ttb/PID@^1.2.1 ArduinoMDNS - https://github.com/khoih-prog/TimerInterrupt_Generic.git + ;https://github.com/khoih-prog/TimerInterrupt_Generic.git monitor_speed = 115200