 
 // RF12 configuration area
 typedef struct {
-  byte nodeId;              // used by rf12_config, offset 0
-  byte group;               // used by rf12_config, offset 1
-  byte format;              // used by rf12_config, offset 2
-  byte hex_output   :2;
-  byte collect_mode :1;
-  byte quiet_mode   :1;
-  byte spare_flags  :4;
-  word frequency_offset;    // offset within band
-  byte pad[RF12_EEPROM_SIZE-8];
-  word crc;
+    byte nodeId;            // used by rf12_config, offset 0
+    byte group;             // used by rf12_config, offset 1
+    byte format;            // used by rf12_config, offset 2
+    byte hex_output     :2;
+    byte collect_mode   :1;
+    byte quiet_mode     :1;
+    byte spare_flags    :4;
+    word frequency_offset;  // offset within band
+    byte pad[RF12_EEPROM_SIZE-8];
+    word crc;
 } RF12Config;
 
 static RF12Config config;


const char helpText1[] PROGMEM =
#if TINY
  "?\n"
#else
  "\n"
  "Available commands:" "\n"
  "  <nn> i     - set node ID (standard node ids are 1..30)" "\n"
  "  <n> b      - set MHz band (4 = 433, 8 = 868, 9 = 915)" "\n"
  "  <nnnn> o   - change frequency offset within the band (default 1600)" "\n"
  "               96 - 3903 is the range supported by the RFM12B" "\n"
  "  <nnn> g    - set network group (RFM12 only allows 212, 0 = any)" "\n"
  "  <n> c      - set collect mode (advanced, normally 0)" "\n"
  "  t          - broadcast max-size test packet, request ack" "\n"
  "  ...,<nn> a - send data packet to node <nn>, request ack" "\n"
  "  ...,<nn> s - send data packet to node <nn>, no ack" "\n"
  "  <n>,<c> j  - eeprom tools for node <n>, c = 42 backup RF12Demo config" "\n"
  "               restore with c = 123. Display otherwise" "\n"
  "  <n>,123 n  - remove node <n> entry from eeprom" "\n"
  "  <n> l      - turn activity LED on PB1 on or off" "\n"
  "  <n>,<d> p  - post semaphore <d> for node <n> to see with its next ack" "\n"
  "  <n> q      - set quiet mode (1 = don't report bad packets)" "\n"
  "  <n> x      - set reporting format (0 = decimal, 1 = hex, 2 = hex & ascii)" "\n"
  "  123 z      - total power down, needs a reset to start up again" "\n"
  "Remote control commands:" "\n"
  "  <hchi>,<hclo>,<addr>,<cmd> f     - FS20 command (868 MHz)" "\n"
  "  <addr>,<dev>,<on> k              - KAKU command (433 MHz)" "\n"
#endif
;

const char helpText2[] PROGMEM =
  "Flash storage (JeeLink only):" "\n"
  "  d                                - dump all log markers" "\n"
  "  <sh>,<sl>,<t3>,<t2>,<t1>,<t0> r  - replay from specified marker" "\n"
  "  123,<bhi>,<blo> e                - erase 4K block" "\n"
  "  12,34 w                          - wipe entire flash memory" "\n"
;

static void showString (PGM_P s) {
  for (;;) {
    char c = pgm_read_byte(s++);
    if (c == 0)
      break;
    if (c == '\n')
      showString(PSTR("\r"));
    Serial.print(c);
  }
}

static void showHelp () {
    showString(helpText1);
    if (df_present())
      showString(helpText2);
#if !TINY
    showString(PSTR("Current configuration:\n"));
    rf12_config();

// for 25 us SPI overhead to end up with the proper on-the-air pulse widths.
// With thanks to JGJ Veken for his help in getting these values right.
static void ookPulse(int on, int off) {
    rf12_onOff(1);
    delayMicroseconds(on + 150);
    rf12_onOff(0);
    delayMicroseconds(off - 200);
}

static void fs20sendBits(word data, byte bits) {
    if (bits == 8) {
        ++bits;
        data = (data << 1) | parity_even_bit(data);
    }
    for (word mask = bit(bits-1); mask != 0; mask >>= 1) {
        int width = data & mask ? 600 : 400;
        ookPulse(width, width);
    }
}

static void fs20cmd(word house, byte addr, byte cmd) {
    byte sum = 6 + (house >> 8) + house + addr + cmd;
    for (byte i = 0; i < 3; ++i) {
        fs20sendBits(1, 13);
        fs20sendBits(house >> 8, 8);
        fs20sendBits(house, 8);
        fs20sendBits(addr, 8);
        fs20sendBits(cmd, 8);
        fs20sendBits(sum, 8);
        fs20sendBits(0, 1);
        delay(10);
    }
}

static void kakuSend(char addr, byte device, byte on) {
    int cmd = 0x600 | ((device - 1) << 4) | ((addr - 1) & 0xF);
    if (on)
        cmd |= 0x800;
    for (byte i = 0; i < 4; ++i) {
        for (byte bit = 0; bit < 12; ++bit) {
            ookPulse(375, 1125);
            int on = bitRead(cmd, bit) ? 1125 : 375;
            ookPulse(on, 1500 - on);
        }
        ookPulse(375, 375);
        delay(11); // approximate
    }
}

#endif
