Mega2560slim RAM optimization

This commit is contained in:
2021-12-22 01:50:40 +03:00
parent 6cd4e5dbea
commit 44d0568267
9 changed files with 57 additions and 37 deletions

View File

@@ -21,3 +21,9 @@
-DRESTART_LAN_ON_MQTT_ERRORS -DRESTART_LAN_ON_MQTT_ERRORS
-D CORS=\"http://lazyhome.ru\" -D CORS=\"http://lazyhome.ru\"
-DOTA_PORT=80 -DOTA_PORT=80
-DHSV_DISABLE
-DMULTIVENT_DISABLE
-DPID_DISABLE
-DPWM_DISABLE
-DSPILED_DISABLE
-DOW_DEVICES_LIMIT=17

View File

@@ -44,9 +44,10 @@ volatile uint16_t DMXOUT_Channels=0;
volatile uint32_t checkTimestamp=0L; volatile uint32_t checkTimestamp=0L;
#endif #endif
#if defined(_dmxin)
volatile uint32_t D_State=0; volatile uint32_t D_State=0;
volatile unsigned long D_checkT=0; volatile unsigned long D_checkT=0;
#endif
#ifdef _artnet #ifdef _artnet
#include <Artnet.h> #include <Artnet.h>
@@ -134,7 +135,10 @@ for (short tch=0; tch<=3 ; tch++)
}; };
extern volatile uint8_t timerHandlerBusy; extern volatile uint8_t timerHandlerBusy;
#if defined(_dmxin)
volatile int DMXinDoublecheck=0; volatile int DMXinDoublecheck=0;
#endif
void DMXUpdate(void) void DMXUpdate(void)
{ {

View File

@@ -23,7 +23,7 @@ e-mail anklimov@gmail.com
#define D_UPDATED4 8 #define D_UPDATED4 8
#define D_CHECKT 300 #define D_CHECKT 300
#define MAX_CHANNELS 60 //#define MAX_CHANNELS 60
//define MAX_IN_CHANNELS 16 //define MAX_IN_CHANNELS 16
//#define DMX_OUT_PIN 3 //#define DMX_OUT_PIN 3

View File

@@ -135,9 +135,11 @@ void Item::Parse() {
itemExt = aJson.getArrayItem(itemArr, I_EXT); itemExt = aJson.getArrayItem(itemArr, I_EXT);
switch (itemType) switch (itemType)
{ {
#ifndef PWM_DISABLE
case CH_PWM: case CH_PWM:
driver = new out_pwm (this); driver = new out_pwm (this);
break; break;
#endif
#ifndef DMX_DISABLE #ifndef DMX_DISABLE
case CH_RGBW: case CH_RGBW:

View File

@@ -5,11 +5,13 @@
#include "item.h" #include "item.h"
#include "bright.h" #include "bright.h"
#ifndef HSV_DISABLE
#ifdef ADAFRUIT_LED #ifdef ADAFRUIT_LED
#include <Adafruit_NeoPixel.h> #include <Adafruit_NeoPixel.h>
#else #else
#include "FastLED.h" #include "FastLED.h"
#endif #endif
#endif
//#include "hsv2rgb.h" //#include "hsv2rgb.h"
@@ -576,7 +578,7 @@ itemCmd itemCmd::assignFrom(itemCmd from, short chanType)
} }
} }
#ifndef HSV_DISABLE
#ifdef ADAFRUIT_LED #ifdef ADAFRUIT_LED
Adafruit_NeoPixel strip(0, 0, 0); Adafruit_NeoPixel strip(0, 0, 0);
uint32_t rgb = strip.ColorHSV(map(from.param.h, 0, 365, 0, 65535), rgbSaturation, rgbValue); 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.g=rgb.g;
param.b=rgb.b; param.b=rgb.b;
#endif #endif
#else
debugSerial<<F("HSV disabled")<<endl;
#endif
debugSerial<<F("RGBx: "); debugSerial<<F("RGBx: ");
debugOut(); debugOut();
break; break;

View File

@@ -107,12 +107,15 @@ aJsonObject *dmxArr = NULL;
bool syslogInitialized = false; bool syslogInitialized = false;
#endif #endif
#ifdef WIFI_ENABLE
volatile uint32_t WiFiAwaitingTime =0;
#endif
volatile uint32_t timerPollingCheck = 0; volatile uint32_t timerPollingCheck = 0;
volatile uint32_t timerInputCheck = 0; volatile uint32_t timerInputCheck = 0;
volatile uint32_t timerLanCheckTime = 0; volatile uint32_t timerLanCheckTime = 0;
volatile uint32_t timerThermostatCheck = 0; volatile uint32_t timerThermostatCheck = 0;
volatile uint32_t timerSensorCheck =0; volatile uint32_t timerSensorCheck =0;
volatile uint32_t WiFiAwaitingTime =0;
volatile unsigned long timerCount=0; volatile unsigned long timerCount=0;
volatile int16_t timerNumber=-1; volatile int16_t timerNumber=-1;
volatile int8_t timerHandlerBusy=0; volatile int8_t timerHandlerBusy=0;
@@ -334,7 +337,7 @@ uint16_t httpHandler(Client& client, String request, uint8_t method, long conten
request+=body; request+=body;
debugSerial<<F("Cmd: ")<<request<<endl; debugSerial<<F("Cmd: ")<<request<<endl;
if (request=="reboot ") ArduinoOTA.sendHttpResponse(client,200); if (request.equalsIgnoreCase(F("reboot "))) ArduinoOTA.sendHttpResponse(client,200);
const char* res=request.c_str(); const char* res=request.c_str();
result = cmd_parse((char*) res); result = cmd_parse((char*) res);
if (! result) return 404; if (! result) return 404;
@@ -450,11 +453,12 @@ if (element && element->type == aJson_String) return element->valuestring;
} }
#ifdef OTA #ifdef OTA
const char defaultPassword[] PROGMEM = "password";
void setupOTA(void) void setupOTA(void)
{ char passwordBuf[16]; { char passwordBuf[16];
if (!sysConf.getOTApwd(passwordBuf, sizeof(passwordBuf))) if (!sysConf.getOTApwd(passwordBuf, sizeof(passwordBuf)))
{ {
strcpy(passwordBuf,"password"); strcpy_P(passwordBuf,defaultPassword);
errorSerial<<F("DEFAULT password for OTA API. Use otapwd command to set")<<endl; errorSerial<<F("DEFAULT password for OTA API. Use otapwd command to set")<<endl;
} }
@@ -1524,8 +1528,6 @@ int cmdFunctionSetMac(int arg_cnt, char **args) {
} }
sysConf.setMAC(mac); sysConf.setMAC(mac);
printMACAddress(); printMACAddress();
//for (short i = 0; i < 6; i++) { EEPROM.write(i, mac[i]); }
infoSerial<<F("Updated\n"); infoSerial<<F("Updated\n");
return 200; return 200;
} }
@@ -1572,7 +1574,7 @@ void headerHandlerProc(String header)
{ {
debugSerial<<header<<endl; debugSerial<<header<<endl;
//ETag: W/"51e-17bffcd0547" //ETag: W/"51e-17bffcd0547"
if (header.startsWith("ETag: ")) if (header.startsWith(F("ETag: ")))
{ {
sysConf.setETAG(header); sysConf.setETAG(header);
} }
@@ -1622,9 +1624,8 @@ if (!sysConf.getServer(configServer,sizeof(configServer)))
hclient.setHeaderHandler(headerHandlerProc); hclient.setHeaderHandler(headerHandlerProc);
// FILE is the return STREAM type of the HTTPClient // FILE is the return STREAM type of the HTTPClient
configStream = hclient.getURI(URI,NULL,get_header); configStream = hclient.getURI(URI,NULL,get_header);
debugSerial<<F("hclient")<<endl;delay(100);
responseStatusCode = hclient.getLastReturnCode(); responseStatusCode = hclient.getLastReturnCode();
debugSerial<<F("retcode ")<<responseStatusCode<<endl;delay(100); debugSerial<<F("http retcode ")<<responseStatusCode<<endl;delay(100);
//wdt_en(); //wdt_en();
if (configStream != NULL) { if (configStream != NULL) {

View File

@@ -7,7 +7,6 @@
#endif #endif
#if defined(__SAM3X8E__) #if defined(__SAM3X8E__)
//#include <DueFlashStorage.h>
#include <watchdog.h> #include <watchdog.h>
#include <ArduinoHttpClient.h> #include <ArduinoHttpClient.h>
//#include "TimerInterrupt_Generic.h" //#include "TimerInterrupt_Generic.h"
@@ -18,12 +17,10 @@
//#include <ArduinoHttpClient.h> //#include <ArduinoHttpClient.h>
#include <avr/pgmspace.h> #include <avr/pgmspace.h>
#include <avr/wdt.h> #include <avr/wdt.h>
//#include <EEPROM.h>
#endif #endif
#if defined(ARDUINO_ARCH_ESP8266) #if defined(ARDUINO_ARCH_ESP8266)
#include <FS.h> //this needs to be first, or it all crashes and burns... #include <FS.h> //this needs to be first, or it all crashes and burns...
//#include "SPIFFS.h"
#ifndef FS_STORAGE #ifndef FS_STORAGE
#include <ESP_EEPROM.h> #include <ESP_EEPROM.h>
#endif #endif
@@ -132,10 +129,6 @@ extern Streamlog errorSerial;
#include <ModbusMaster.h> #include <ModbusMaster.h>
#endif #endif
//#ifndef DMX_DISABLE
//#include "FastLED.h"
//#endif
#ifdef _owire #ifdef _owire
#include "owTerm.h" #include "owTerm.h"
#endif #endif
@@ -231,9 +224,7 @@ typedef union {
} UID; } UID;
bool isNotRetainingStatus(); bool isNotRetainingStatus();
//void watchdogSetup(void);
//int itemCommand(char *topic, char *payload);
void mqttCallback(char *topic, byte *payload, unsigned int length); void mqttCallback(char *topic, byte *payload, unsigned int length);
void printMACAddress(); void printMACAddress();
@@ -256,12 +247,6 @@ int cmdFunctionLoad(int arg_cnt, char **args);
int loadConfigFromEEPROM(); 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 cmdFunctionSave(int arg_cnt, char **args);
int cmdFunctionSetMac(int arg_cnt, char **args); int cmdFunctionSetMac(int arg_cnt, char **args);

View File

@@ -48,7 +48,12 @@ e-mail anklimov@gmail.com
#define recheck_interval 5 #define recheck_interval 5
#define check_circle 2000/t_count #define check_circle 2000/t_count
#if defined (OW_DEVICES_LIMIT)
#define t_max 20 //Maximum number of 1w devices #define t_max 20 //Maximum number of 1w devices
#else
#define t_max OW_DEVICES_LIMIT
#endif
#define TEMPERATURE_PRECISION 12 //9 #define TEMPERATURE_PRECISION 12 //9
#ifndef OWIRE_DISABLE #ifndef OWIRE_DISABLE

View File

@@ -317,6 +317,7 @@ board = megaatmega2560
upload_port = net:192.168.88.2:23000 upload_port = net:192.168.88.2:23000
framework = arduino framework = arduino
build_flags = !python get_build_flags.py mega2560slim-5100 build_flags = !python get_build_flags.py mega2560slim-5100
extra_scripts = post:toBin.py
lib_ignore = lib_ignore =
;DS2482_OneWire //UNCOMMENT for software 1-wire driver ;DS2482_OneWire //UNCOMMENT for software 1-wire driver
DHT sensor library for ESPx DHT sensor library for ESPx
@@ -330,33 +331,44 @@ lib_ignore =
UIPEthernet UIPEthernet
ESP_EEPROM ESP_EEPROM
M5Stack 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 = lib_deps =
https://github.com/anklimov/Arduino-Temperature-Control-Library.git https://github.com/anklimov/Arduino-Temperature-Control-Library.git
https://github.com/anklimov/DS2482_OneWire 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/httpClient
https://github.com/anklimov/aJson https://github.com/anklimov/aJson
https://github.com/anklimov/CmdArduino https://github.com/anklimov/CmdArduino
https://github.com/anklimov/ModbusMaster ;https://github.com/anklimov/ModbusMaster
https://github.com/anklimov/DMXSerial ;https://github.com/anklimov/DMXSerial
https://github.com/anklimov/Ethernet5100 https://github.com/anklimov/Ethernet5100
;5100 lib have ~90 bytes less footprint of RAM ;5100 lib have ~90 bytes less footprint of RAM
https://github.com/knolleary/pubsubclient.git https://github.com/knolleary/pubsubclient.git
https://github.com/anklimov/Artnet.git ;https://github.com/anklimov/Artnet.git
FastLED@3.3.2 ;FastLED@3.3.2
Adafruit Unified Sensor Adafruit Unified Sensor
DHT sensor library DHT sensor library
https://github.com/arcao/Syslog.git https://github.com/arcao/Syslog.git
Streaming ;Streaming
ClosedCube HDC1080 ;;ClosedCube HDC1080
SparkFun CCS811 Arduino Library@~1.0.7 ;;SparkFun CCS811 Arduino Library@~1.0.7
Adafruit NeoPixel ;Adafruit NeoPixel
https://github.com/anklimov/ArduinoOTA https://github.com/anklimov/ArduinoOTA
Adafruit MCP23017 Arduino Library Adafruit MCP23017 Arduino Library
Adafruit BusIO Adafruit BusIO
br3ttb/PID@^1.2.1 br3ttb/PID@^1.2.1
ArduinoMDNS ArduinoMDNS
https://github.com/khoih-prog/TimerInterrupt_Generic.git ;https://github.com/khoih-prog/TimerInterrupt_Generic.git
monitor_speed = 115200 monitor_speed = 115200