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:
parent
b7c294d210
commit
9e3f6c8303
|
|
@ -185,9 +185,9 @@ void Span::pollTask() {
|
|||
|
||||
HAPClient::init(); // read NVS and load HAP settings
|
||||
|
||||
if(heap_caps_get_minimum_free_size(MALLOC_CAP_DEFAULT)<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",
|
||||
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 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_INTERNAL),DEFAULT_LOW_MEM_THRESHOLD);
|
||||
|
||||
if(!strlen(network.wifiData.ssid)){
|
||||
LOG0("*** WIFI CREDENTIALS DATA NOT FOUND. ");
|
||||
|
|
|
|||
|
|
@ -428,6 +428,7 @@ class SpanAccessory{
|
|||
|
||||
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
|
||||
};
|
||||
|
||||
|
|
@ -460,6 +461,7 @@ class SpanService{
|
|||
|
||||
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 *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
|
||||
|
|
@ -656,6 +658,7 @@ class SpanCharacteristic{
|
|||
|
||||
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
|
||||
|
||||
template <class T=int> T getVal(){
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@
|
|||
|
||||
#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
|
||||
|
||||
|
|
|
|||
26
src/src.ino
26
src/src.ino
|
|
@ -38,22 +38,22 @@ void setup() {
|
|||
|
||||
homeSpan.begin(Category::Lighting,"HomeSpan Max");
|
||||
|
||||
ps_new(SpanAccessory)();
|
||||
ps_new(Service::AccessoryInformation)();
|
||||
ps_new(Characteristic::Identify)();
|
||||
new SpanAccessory();
|
||||
new Service::AccessoryInformation();
|
||||
new Characteristic::Identify();
|
||||
|
||||
for(int i=0;i<149;i++){
|
||||
ps_new(SpanAccessory)();
|
||||
ps_new(Service::AccessoryInformation)();
|
||||
ps_new(Characteristic::Identify)();
|
||||
for(int i=0;i<50;i++){
|
||||
new SpanAccessory();
|
||||
new Service::AccessoryInformation();
|
||||
new Characteristic::Identify();
|
||||
char c[30];
|
||||
sprintf(c,"Light-%d",i);
|
||||
ps_new(Characteristic::Name)(c);
|
||||
ps_new(Service::LightBulb)();
|
||||
ps_new(Characteristic::On)(0,true);
|
||||
ps_new(Characteristic::Brightness)(50,true);
|
||||
ps_new(Characteristic::Hue)(120,true);
|
||||
ps_new(Characteristic::Saturation)(100,true);
|
||||
new Characteristic::Name(c);
|
||||
new Service::LightBulb();
|
||||
new Characteristic::On(0,false);
|
||||
new Characteristic::Brightness(50,false);
|
||||
new Characteristic::Hue(120,false);
|
||||
new Characteristic::Saturation(100,false);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue