Override new operator for SpanAccessory, SpanService, and SpanCharacteristic

New Operator now uses PSRAM if available, else uses Internal RAM.  Obviates the need for the ps_new() macro, though will keep definition since it may be useful for any class that does not already override malloc() to use PSRAM.
This commit is contained in:
Gregg 2023-11-24 10:30:20 -06:00
parent b7c294d210
commit 9e3f6c8303
4 changed files with 22 additions and 19 deletions

View File

@ -185,9 +185,9 @@ void Span::pollTask() {
HAPClient::init(); // read NVS and load HAP settings HAPClient::init(); // read NVS and load HAP settings
if(heap_caps_get_minimum_free_size(MALLOC_CAP_DEFAULT)<DEFAULT_LOW_MEM_THRESHOLD) if(heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL)<DEFAULT_LOW_MEM_THRESHOLD)
LOG0("\n**** WARNING! Low Memory Watermark of %d bytes is less than Low Threshold of %d bytes. Device *may* run out of memory.\n\n", LOG0("\n**** WARNING! Low Internal RAM Watermark of %d bytes is less than Low Threshold of %d bytes. Device *may* run out of memory.\n\n",
heap_caps_get_minimum_free_size(MALLOC_CAP_DEFAULT),DEFAULT_LOW_MEM_THRESHOLD); heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL),DEFAULT_LOW_MEM_THRESHOLD);
if(!strlen(network.wifiData.ssid)){ if(!strlen(network.wifiData.ssid)){
LOG0("*** WIFI CREDENTIALS DATA NOT FOUND. "); LOG0("*** WIFI CREDENTIALS DATA NOT FOUND. ");

View File

@ -428,6 +428,7 @@ class SpanAccessory{
public: public:
void *operator new(size_t size){return(HS_MALLOC(size));} // override new operator to use PSRAM when available
SpanAccessory(uint32_t aid=0); // constructor SpanAccessory(uint32_t aid=0); // constructor
}; };
@ -460,6 +461,7 @@ class SpanService{
public: public:
void *operator new(size_t size){return(HS_MALLOC(size));} // override new operator to use PSRAM when available
SpanService(const char *type, const char *hapName, boolean isCustom=false); // constructor SpanService(const char *type, const char *hapName, boolean isCustom=false); // constructor
SpanService *setPrimary(); // sets the Service Type to be primary and returns pointer to self SpanService *setPrimary(); // sets the Service Type to be primary and returns pointer to self
SpanService *setHidden(); // sets the Service Type to be hidden and returns pointer to self SpanService *setHidden(); // sets the Service Type to be hidden and returns pointer to self
@ -656,6 +658,7 @@ class SpanCharacteristic{
public: public:
void *operator new(size_t size){return(HS_MALLOC(size));} // override new operator to use PSRAM when available
SpanCharacteristic(HapChar *hapChar, boolean isCustom=false); // constructor SpanCharacteristic(HapChar *hapChar, boolean isCustom=false); // constructor
template <class T=int> T getVal(){ template <class T=int> T getVal(){

View File

@ -84,7 +84,7 @@
#define DEFAULT_WEBLOG_URL "status" // change with optional fourth argument in homeSpan.enableWebLog() #define DEFAULT_WEBLOG_URL "status" // change with optional fourth argument in homeSpan.enableWebLog()
#define DEFAULT_LOW_MEM_THRESHOLD 80000 // default low watermark memory threshold that triggers warning #define DEFAULT_LOW_MEM_THRESHOLD 80000 // default low watermark memory (for internal RAM) threshold that triggers warning
#define DEFAULT_REBOOT_CALLBACK_TIME 5000 // default time (in milliseconds) to check for reboot callback #define DEFAULT_REBOOT_CALLBACK_TIME 5000 // default time (in milliseconds) to check for reboot callback

View File

@ -38,22 +38,22 @@ void setup() {
homeSpan.begin(Category::Lighting,"HomeSpan Max"); homeSpan.begin(Category::Lighting,"HomeSpan Max");
ps_new(SpanAccessory)(); new SpanAccessory();
ps_new(Service::AccessoryInformation)(); new Service::AccessoryInformation();
ps_new(Characteristic::Identify)(); new Characteristic::Identify();
for(int i=0;i<149;i++){ for(int i=0;i<50;i++){
ps_new(SpanAccessory)(); new SpanAccessory();
ps_new(Service::AccessoryInformation)(); new Service::AccessoryInformation();
ps_new(Characteristic::Identify)(); new Characteristic::Identify();
char c[30]; char c[30];
sprintf(c,"Light-%d",i); sprintf(c,"Light-%d",i);
ps_new(Characteristic::Name)(c); new Characteristic::Name(c);
ps_new(Service::LightBulb)(); new Service::LightBulb();
ps_new(Characteristic::On)(0,true); new Characteristic::On(0,false);
ps_new(Characteristic::Brightness)(50,true); new Characteristic::Brightness(50,false);
ps_new(Characteristic::Hue)(120,true); new Characteristic::Hue(120,false);
ps_new(Characteristic::Saturation)(100,true); new Characteristic::Saturation(100,false);
} }
} }