Added ps_new() macro
A more generic version of `new(*ptr)` that allocates from PSRAM if present, otherwise is that same a normal `new`
This commit is contained in:
parent
8268e519dd
commit
458a4fb357
|
|
@ -34,9 +34,11 @@
|
||||||
#if defined(BOARD_HAS_PSRAM)
|
#if defined(BOARD_HAS_PSRAM)
|
||||||
#define HS_MALLOC ps_malloc
|
#define HS_MALLOC ps_malloc
|
||||||
#define HS_CALLOC ps_calloc
|
#define HS_CALLOC ps_calloc
|
||||||
|
#define ps_new(X) new(ps_malloc(sizeof(X)))X
|
||||||
#else
|
#else
|
||||||
#define HS_MALLOC malloc
|
#define HS_MALLOC malloc
|
||||||
#define HS_CALLOC calloc
|
#define HS_CALLOC calloc
|
||||||
|
#define ps_new(X) new X
|
||||||
#endif
|
#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
|
#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
|
||||||
|
|
|
||||||
20
src/src.ino
20
src/src.ino
|
|
@ -36,20 +36,20 @@ void setup() {
|
||||||
|
|
||||||
homeSpan.begin(Category::Lighting,"HomeSpan Max");
|
homeSpan.begin(Category::Lighting,"HomeSpan Max");
|
||||||
|
|
||||||
new(HS_MALLOC(sizeof(SpanAccessory))) SpanAccessory();
|
ps_new(SpanAccessory)();
|
||||||
new(HS_MALLOC(sizeof(SpanService))) Service::AccessoryInformation();
|
ps_new(Service::AccessoryInformation)();
|
||||||
new(HS_MALLOC(sizeof(SpanCharacteristic))) Characteristic::Identify();
|
ps_new(Characteristic::Identify)();
|
||||||
|
|
||||||
for(int i=0;i<80;i++){
|
for(int i=0;i<80;i++){
|
||||||
new(HS_MALLOC(sizeof(SpanAccessory))) SpanAccessory();
|
ps_new(SpanAccessory)();
|
||||||
new(HS_MALLOC(sizeof(SpanService))) Service::AccessoryInformation();
|
ps_new(Service::AccessoryInformation)();
|
||||||
new(HS_MALLOC(sizeof(SpanCharacteristic))) Characteristic::Identify();
|
ps_new(Characteristic::Identify)();
|
||||||
char c[30];
|
char c[30];
|
||||||
sprintf(c,"Light-%d",i);
|
sprintf(c,"Light-%d",i);
|
||||||
new(HS_MALLOC(sizeof(SpanCharacteristic))) Characteristic::Name(c);
|
ps_new(Characteristic::Name)(c);
|
||||||
new(HS_MALLOC(sizeof(SpanService))) Service::LightBulb();
|
ps_new(Service::LightBulb)();
|
||||||
new(HS_MALLOC(sizeof(SpanCharacteristic))) Characteristic::On();
|
ps_new(Characteristic::On)();
|
||||||
new(HS_MALLOC(sizeof(SpanCharacteristic))) Characteristic::Brightness();
|
ps_new(Characteristic::Brightness)(50,false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue