#include "Dezibot.h"
#define DEBUG

Dezibot dezibot = Dezibot();

const uint16_t cycleTime = 5e3;  //5000 ms = 5 s

void setup() {
  #ifdef DEBUG
  Serial.begin(112500);
  while (!Serial) {
    ; /* Wait for USB-CDC Serial init to complete. */
  }
  dezibot.display.begin();
  dezibot.display.println("Debug enabled.");
  Serial.println("Debug enabled.");
  #endif
  dezibot.communication.begin();
  dezibot.communication.setGroupNumber(1);
  dezibot.communication.sendMessage("Repeated send power consumption test commencing");
  #ifdef DEBUG
  dezibot.display.println("Mesh set up");
  /* Set up receive handler */
  dezibot.communication.onReceive(handle_receive);
  dezibot.display.println("Set up receive. Printing incoming messages:");
  Serial.println("Sending broadcast messages to generate TX power consumption:");
  #endif
}

void handle_receive(String &message) {
  dezibot.display.println(message);
}

void loop() {
    /* Continuously send to consume power on TX */
    for(int i=0; i<cycleTime; i++) {
      dezibot.communication.sendMessage("Power Test Message");
      delay(1);
    }
    delay(cycleTime);

}