// Demonstrate the 'Profile' profiling object

// Report time percentages in all the built-in categories
void reportProfile(u8 *) {
  logNormal("BG=%f SI=%f OI=%f PH=%f AH=%f\n",
            Profile.getPPM(TICKER_BACKGROUND)/10000.0,
            Profile.getPPM(TICKER_SERIAL_ISR)/10000.0,
            Profile.getPPM(TICKER_OTHER_ISR)/10000.0,
            Profile.getPPM(TICKER_PACKET_HANDLER)/10000.0,
            Profile.getPPM(TICKER_ALARM_HANDLER)/10000.0);
}

void setup() {
  Profile.begin();              // Start the longer-term profiling system
  QLED.begin();                 // Let's use QLEDs to drive some alarm usage
  Body.reflex('p',reportProfile);
}

void loop() {

  // Spin the LEDs..
  for (u32 i = 0, f = NORTH; i <= 3; ++i, f = CLOCKWISE_FACE(f)) {
    QLED.off(pinInFace(FACE_LED_PIN,f),i*80);      // First, increasing off time
    QLED.on(pinInFace(FACE_LED_PIN,f),100);        // then same amount of blink time
    QLED.off(pinInFace(FACE_LED_PIN,f),(3-i)*80);  // then decreasing off time to even up
  }

  // ..once per second
  delay(1000);
}

