#include <Arduino.h>
#include "neb_pulse_program.h"
/**
* @brief ESP32 Arduino sketch that demonstrates how to:
* [1] Build a NebProgram2 in RAM
* [2] Serialize it into a raw byte buffer with nebSetProgram
* [3] Deserialize it back with nebGetProgram
* [4] Access decoded values via getters and print them to Serial
*/
// Local byte buffer that simulates the parameter area
static uint8_t paramBuffer[NebProgram3::sizeBytes()];
void setup() {
Serial.begin(115200);
while (!Serial) { /* wait for USB CDC if needed */ }
delay(200);
Serial.println();
Serial.println("=== NebPulseProgram get-set demo [ESP32 Arduino] ===");
// [1] Create and configure a 2-slot program
NebProgram3 prog{}; // total size 10 bytes
// Configure slot 0, example values
prog.slots[0].setTimesMs(500, 2000); // 500 ms ON, 2000 ms OFF
prog.slots[0].setRepeats(10); // 11 cycles total
prog.slots[0].setJitter(5); // +/- 5 percent
// Configure slot 0, example values
prog.slots[1].setTimesMs(800, 1500); // 500 ms ON, 2000 ms OFF
prog.slots[1].setRepeats(20); // 11 cycles total
prog.slots[1].setJitter(10); // +/- 5 percent
// Configure slot 0, example values
prog.slots[2].setTimesMs(100, 1700); // 500 ms ON, 2000 ms OFF
prog.slots[2].setRepeats(28); // 11 cycles total
prog.slots[2].setJitter(4); // +/- 5 percent
// [3] Write program into the raw buffer
nebSetProgram(paramBuffer, prog);
// Clear the program to prove that read repopulates fields
memset(&prog, 0, sizeof(prog));
// [3] Read program back from the raw buffer
NebProgram3 readProg{};
nebGetProgram(paramBuffer, readProg);
// [4] Access and print decoded values directly using getters
Serial.println("[Decoded values]"); Serial.println(sizeof(prog));
{
const NebPulseSlot5 &s0 = readProg.slots[0];
Serial.print("Slot 0, onMs = "); Serial.print(s0.getOnMs());
Serial.print(", offMs = "); Serial.print(s0.getOffMs());
Serial.print(", repeats = "); Serial.print(s0.getRepeats());
Serial.print(", jitter = "); Serial.print(s0.getJitter());
Serial.println(" %");
}
{
const NebPulseSlot5 &s1 = readProg.slots[1];
Serial.print("Slot 1, onMs = "); Serial.print(s1.getOnMs());
Serial.print(", offMs = "); Serial.print(s1.getOffMs());
Serial.print(", repeats = "); Serial.print(s1.getRepeats());
Serial.print(", jitter = "); Serial.print(s1.getJitter());
Serial.println(" %");
}
{
const NebPulseSlot5 &s2 = readProg.slots[2];
Serial.print("Slot 2, onMs = "); Serial.print(s2.getOnMs());
Serial.print(", offMs = "); Serial.print(s2.getOffMs());
Serial.print(", repeats = "); Serial.print(s2.getRepeats());
Serial.print(", jitter = "); Serial.print(s2.getJitter());
Serial.println(" %");
}
Serial.println("=== End ===");
}
void loop() {
// No periodic work in this demo
delay(1000);
}