 // Lame floating point format, only powers of ten = mant*10^exp
 // 4 bits mantissa (0..15), 4 bits exponent (-8..7)
 #define SCALE(mant,exp) (((exp&0xF) << 4) | (mant&0xF))
+
+static int scale_as_int(byte scale)
+{
+    int n = scale & 0xF;
+    int e = scale >> 4;
+    while(e > 0) {
+        n *= 10;
+        e--;
+    }
+    return n;
+}
 
 enum { UNIT_HUMIDITY, UNIT_TEMP, UNIT_VOLT, UNIT_OHM, UNIT_SCALAR, UNIT_TESLA, UNIT_PASCAL };
 


    rf12_config(0);         // Setup RF
    rf12_sleep(RF12_SLEEP); // and power down

    scheduler.timer(TASK_ANNOUNCE, 0);    // start the announcements
}

    } else {
        event = scheduler.pollWaiting();
    }
    if(event == TASK_ANNOUNCE) {
        // Repeat every minute for the first five minutes, then once per hour
        scheduler.timer(TASK_ANNOUNCE, millis() < 300000 ? 600 : 36000);

        sendAnnouncement();
    } else if(event == TASK_REPORT) {
        // Transmit any buffered measurements
        Serial.print("\r\n=> ");
        for(byte j=0; j<databufferpos; j++) {
            printInt(databuffer[j]);
            Serial.print(",");
        }
        Serial.print("\r\n");
        serialFlush();

        rf12_sleep(RF12_WAKEUP);
        rf12_sendNow(0, databuffer, databufferpos);
        rf12_sendWait(RADIO_SYNC_MODE);
        rf12_sleep(RF12_SLEEP);

        databufferpos = 1;  // Don't overwrite header
    } else if(event >= TASK_MEASURE0 && event <= TASK_MEASURE0+MAX_PLUGS) {
        // Take the measurement for the given plug and then schedule a report
        Plug &plug = plugs[event-TASK_MEASURE0];

        scheduler.timer(event, scale_as_int(plug.period));

        measurePlug(plug, 1);
        if(scheduler.idle(TASK_REPORT))
            scheduler.timer(TASK_REPORT, 1);
    }
}
