diff --git a/src/HomeSpan.h b/src/HomeSpan.h index 80dc1f6..05d73b5 100644 --- a/src/HomeSpan.h +++ b/src/HomeSpan.h @@ -34,9 +34,11 @@ #if defined(BOARD_HAS_PSRAM) #define HS_MALLOC ps_malloc #define HS_CALLOC ps_calloc +#define ps_new(X) new(ps_malloc(sizeof(X)))X #else #define HS_MALLOC malloc #define HS_CALLOC calloc +#define ps_new(X) new X #endif #pragma GCC diagnostic ignored "-Wpmf-conversions" // eliminates warning messages from use of pointers to member functions to detect whether update() and loop() are overridden by user diff --git a/src/src.ino b/src/src.ino index 76fbe9d..16f300a 100644 --- a/src/src.ino +++ b/src/src.ino @@ -35,21 +35,21 @@ void setup() { homeSpan.setLogLevel(2); homeSpan.begin(Category::Lighting,"HomeSpan Max"); - - new(HS_MALLOC(sizeof(SpanAccessory))) SpanAccessory(); - new(HS_MALLOC(sizeof(SpanService))) Service::AccessoryInformation(); - new(HS_MALLOC(sizeof(SpanCharacteristic))) Characteristic::Identify(); + + ps_new(SpanAccessory)(); + ps_new(Service::AccessoryInformation)(); + ps_new(Characteristic::Identify)(); for(int i=0;i<80;i++){ - new(HS_MALLOC(sizeof(SpanAccessory))) SpanAccessory(); - new(HS_MALLOC(sizeof(SpanService))) Service::AccessoryInformation(); - new(HS_MALLOC(sizeof(SpanCharacteristic))) Characteristic::Identify(); + ps_new(SpanAccessory)(); + ps_new(Service::AccessoryInformation)(); + ps_new(Characteristic::Identify)(); char c[30]; sprintf(c,"Light-%d",i); - new(HS_MALLOC(sizeof(SpanCharacteristic))) Characteristic::Name(c); - new(HS_MALLOC(sizeof(SpanService))) Service::LightBulb(); - new(HS_MALLOC(sizeof(SpanCharacteristic))) Characteristic::On(); - new(HS_MALLOC(sizeof(SpanCharacteristic))) Characteristic::Brightness(); + ps_new(Characteristic::Name)(c); + ps_new(Service::LightBulb)(); + ps_new(Characteristic::On)(); + ps_new(Characteristic::Brightness)(50,false); } }