diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..260709f --- /dev/null +++ b/.travis.yml @@ -0,0 +1,20 @@ +language: python +python: +- '2.7' +sudo: false +cache: + directories: + - "~/.platformio" +install: +- pip install -U platformio +script: +- platformio run -d firmware/RFM69CW_RF_Demo_ATmega328/RFM69CW_RF12_Demo_ATmega328 + -e rfm2pi_deploy +deploy: + provider: releases + api_key: + secure: KkNLrVnLaDA0oQPQvQ0EDduYN7nRF1FbieCqeG9C7s/V924lYdTivSs9jA0hIJy33LyFsns/52pKSmyASZo7/yogNstflqYcDahVGoB85ckbw+38MmDKByHguSIiqPgaiT2lIpIuuInsZCluuwWQBJ1geFxfad5VeLBozt798CwMw6JmIM5+73wAXQdAQnKzGTHecjz1m4+fcvaWIVzMJdc0JgC/o56Ul7PPeub4O3nQb2n9rnLA7y4esw/0malqkQiBCiXcCgZ6Dxz3pxQnuHy7Y9EGbUnNMB5M4q4M0NhBGAxSktneNjQ+Jtnl0S4iZ0F77xVZpxsfcZL+cPX0rDCYEvOnBVb6XqQjf7aHAxHcaockpNLIZ7s7ZawLnigXuF1AhXdAdELZwWcvbotHWxf+aGlcq7bCNvuYsrzQaD1kibH24M/6Y6xrLlbwNOZBv6My01kUIysLDAmLVG1R78gilas5R83xt4qHyxYf/SibgRrwkSXqqRnQP0AeDTwv2mEgvvnkmKyFGai4MgpSoJwcqKgC1r12WIKXZizN57SJLbrmf/jCbpy9+7JD8yraB4xC6qyI4glIyYXxRJ5MjLD/gW2GhCUvwRCwYucG69zw3G7sneJsmNFY7gBFztBBiLPADhyGU81n0OrBi/n0Bdqu/hZfD0kfPaCC/iP+PkE= + file: firmware/RFM69CW_RF_Demo_ATmega328/RFM69CW_RF12_Demo_ATmega328/.pioenvs/rfm2pi_deploy/firmware.hex + on: + repo: openenergymonitor/RFM2Pi + branch: master diff --git a/README.md b/README.md index 6fa0359..4f07e10 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,14 @@ # RFM2Pi ====== - +[![Build Status](https://travis-ci.org/openenergymonitor/RFM2Pi.svg?branch=master)](https://travis-ci.org/openenergymonitor/RFM2Pi) ## RFM12B / RFM69CW to Raspberry Pi board With the addition of an RFM12Pi expansion board to receive data via wireless from other [OpenEnergyMonitor modules](http://openenergymonitor.org/emon/Modules) such as an emonTx energy and temperature monitoring node or an emonGLCD display. A Raspberry Pi used to forward data to an emoncms sever or/and log data locally to a localy instance of Emoncms server running on the Pi. -# Hardware Design +# Hardware Design For hardware designs see https://github.com/openenergymonitor/Hardware/tree/master/RFM2Pi ## Documentation Overview @@ -21,5 +21,5 @@ http://wiki.openenergymonitor.org/index.php?title=RFM12Pi_V2 -### The RFM12Pi is sold through the OpenEnergyMonitor shop: +### The RFM12Pi is sold through the OpenEnergyMonitor shop: http://shop.openenergymonitor.com/raspberry-pi/ diff --git a/firmware/RFM69CW_RF_Demo_ATmega328/RFM69CW_RF12_Demo_ATmega328/.gitignore b/firmware/RFM69CW_RF_Demo_ATmega328/RFM69CW_RF12_Demo_ATmega328/.gitignore new file mode 100644 index 0000000..6c69f4c --- /dev/null +++ b/firmware/RFM69CW_RF_Demo_ATmega328/RFM69CW_RF12_Demo_ATmega328/.gitignore @@ -0,0 +1,2 @@ +.pioenvs +.piolibdeps diff --git a/firmware/RFM69CW_RF_Demo_ATmega328/RFM69CW_RF12_Demo_ATmega328/dataflash.h b/firmware/RFM69CW_RF_Demo_ATmega328/RFM69CW_RF12_Demo_ATmega328/dataflash.h deleted file mode 100644 index 868d89d..0000000 --- a/firmware/RFM69CW_RF_Demo_ATmega328/RFM69CW_RF12_Demo_ATmega328/dataflash.h +++ /dev/null @@ -1,358 +0,0 @@ -// extracted from RF12demo -// 2009-05-06 http://opensource.org/licenses/mit-license.php - -#define DF_ENABLE_PIN 8 // PB0 - -#if DATAFLASH == 4 -// settings for 0.5 Mbyte flash in JLv2 -#define DF_BLOCK_SIZE 16 // number of pages erased at same time -#define DF_LOG_BEGIN 32 // first 2 blocks reserved for future use -#define DF_LOG_LIMIT 0x0700 // last 64k is not used for logging -#define DF_MEM_TOTAL 0x0800 // 2048 pages, i.e. 0.5 Mbyte -#define DF_DEVICE_ID 0x1F44 // see AT25DF041A datasheet -#define DF_PAGE_ERASE 0x20 // erase one block of flash memory -#endif - -#if DATAFLASH == 8 -// settings for 1 Mbyte flash in JLv2 -#define DF_BLOCK_SIZE 16 // number of pages erased at same time -#define DF_LOG_BEGIN 32 // first 2 blocks reserved for future use -#define DF_LOG_LIMIT 0x0F00 // last 64k is not used for logging -#define DF_MEM_TOTAL 0x1000 // 4096 pages, i.e. 1 Mbyte -#define DF_DEVICE_ID 0x1F45 // see AT26DF081A datasheet -#define DF_PAGE_ERASE 0x20 // erase one block of flash memory -#endif - -#if DATAFLASH == 16 -// settings for 2 Mbyte flash in JLv3 -#define DF_BLOCK_SIZE 256 // number of pages erased at same time -#define DF_LOG_BEGIN 512 // first 2 blocks reserved for future use -#define DF_LOG_LIMIT 0x1F00 // last 64k is not used for logging -#define DF_MEM_TOTAL 0x2000 // 8192 pages, i.e. 2 Mbyte -#define DF_DEVICE_ID 0x2020 // see M25P16 datasheet -#define DF_PAGE_ERASE 0xD8 // erase one block of flash memory -#endif - -// structure of each page in the log buffer, size must be exactly 256 bytes -typedef struct { - byte data [248]; - word seqnum; - long timestamp; - word crc; -} FlashPage; - -// structure of consecutive entries in the data area of each FlashPage -typedef struct { - byte length; - byte offset; - byte header; - byte data[RF12_MAXDATA]; -} FlashEntry; - -static FlashPage dfBuf; // for data not yet written to flash -static word dfLastPage; // page number last written -static byte dfFill; // next byte available in buffer to store entries - -static byte df_present () { - return dfLastPage != 0; -} - -static void df_enable () { - // digitalWrite(ENABLE_PIN, 0); - bitClear(PORTB, 0); -} - -static void df_disable () { - // digitalWrite(ENABLE_PIN, 1); - bitSet(PORTB, 0); -} - -static byte df_xfer (byte cmd) { - SPDR = cmd; - while (!bitRead(SPSR, SPIF)) - ; - return SPDR; -} - -void df_command (byte cmd) { - for (;;) { - cli(); - df_enable(); - df_xfer(0x05); // Read Status Register - byte status = df_xfer(0); - df_disable(); - sei(); - // don't wait for ready bit if there is clearly no dataflash connected - if (status == 0xFF || (status & 1) == 0) - break; - } - - cli(); - df_enable(); - df_xfer(cmd); -} - -static void df_deselect () { - df_disable(); - sei(); -} - -static void df_writeCmd (byte cmd) { - df_command(0x06); // Write Enable - df_deselect(); - df_command(cmd); -} - -void df_read (word block, word off, void* buf, word len) { - df_command(0x03); // Read Array (Low Frequency) - df_xfer(block >> 8); - df_xfer(block); - df_xfer(off); - for (word i = 0; i < len; ++i) - ((byte*) buf)[(byte) i] = df_xfer(0); - df_deselect(); -} - -void df_write (word block, const void* buf) { - df_writeCmd(0x02); // Byte/Page Program - df_xfer(block >> 8); - df_xfer(block); - df_xfer(0); - for (word i = 0; i < 256; ++i) - df_xfer(((const byte*) buf)[(byte) i]); - df_deselect(); -} - -// wait for current command to complete -void df_flush () { - df_read(0, 0, 0, 0); -} - -static void df_wipe () { - showString(PSTR("DF W\n")); - - df_writeCmd(0xC7); // Chip Erase - df_deselect(); - df_flush(); -} - -static void df_erase (word block) { - showString(PSTR("DF E ")); - Serial.println(block); - - df_writeCmd(DF_PAGE_ERASE); // Block Erase - df_xfer(block >> 8); - df_xfer(block); - df_xfer(0); - df_deselect(); - df_flush(); -} - -static word df_wrap (word page) { - return page < DF_LOG_LIMIT ? page : DF_LOG_BEGIN; -} - -static void df_saveBuf () { - if (dfFill == 0) - return; - - dfLastPage = df_wrap(dfLastPage + 1); - if (dfLastPage == DF_LOG_BEGIN) - ++dfBuf.seqnum; // bump to next seqnum when wrapping - - // set remainder of buffer data to 0xFF and calculate crc over entire buffer - dfBuf.crc = ~0; - for (byte i = 0; i < sizeof dfBuf - 2; ++i) { - if (dfFill <= i && i < sizeof dfBuf.data) - dfBuf.data[i] = 0xFF; - dfBuf.crc = _crc16_update(dfBuf.crc, dfBuf.data[i]); - } - - df_write(dfLastPage, &dfBuf); - dfFill = 0; - - // wait for write to finish before reporting page, seqnum, and time stamp - df_flush(); - showString(PSTR("DF S ")); - Serial.print(dfLastPage); - Serial.print(' '); - Serial.print(dfBuf.seqnum); - Serial.print(' '); - Serial.println(dfBuf.timestamp); - - // erase next block if we just saved data into a fresh block - // at this point in time dfBuf is empty, so a lengthy erase cycle is ok - if (dfLastPage % DF_BLOCK_SIZE == 0) - df_erase(df_wrap(dfLastPage + DF_BLOCK_SIZE)); -} - -static void df_append (const void* buf, byte len) { - //FIXME the current logic can't append incoming packets during a save! - - // fill in page time stamp when appending to a fresh page - if (dfFill == 0) - dfBuf.timestamp = now(); - - long offset = now() - dfBuf.timestamp; - if (offset >= 255 || dfFill + 1 + len > sizeof dfBuf.data) { - df_saveBuf(); - - dfBuf.timestamp = now(); - offset = 0; - } - - // append new entry to flash buffer - dfBuf.data[dfFill++] = offset; - memcpy(dfBuf.data + dfFill, buf, len); - dfFill += len; -} - -// go through entire log buffer to figure out which page was last saved -static void scanForLastSave () { - dfBuf.seqnum = 0; - dfLastPage = DF_LOG_LIMIT - 1; - // look for last page before an empty page - for (word page = DF_LOG_BEGIN; page < DF_LOG_LIMIT; ++page) { - word currseq; - df_read(page, sizeof dfBuf.data, &currseq, sizeof currseq); - if (currseq != 0xFFFF) { - dfLastPage = page; - dfBuf.seqnum = currseq + 1; - } else if (dfLastPage == page - 1) - break; // careful with empty-filled-empty case, i.e. after wrap - } -} - -static void df_initialize () { - // assumes SPI has already been initialized for the RFM12B - df_disable(); - pinMode(DF_ENABLE_PIN, OUTPUT); - df_command(0x9F); // Read Manufacturer and Device ID - word info = df_xfer(0) << 8; - info |= df_xfer(0); - df_deselect(); - - if (info == DF_DEVICE_ID) { - df_writeCmd(0x01); // Write Status Register ... - df_xfer(0); // ... Global Unprotect - df_deselect(); - - scanForLastSave(); - - showString(PSTR("DF I ")); - Serial.print(dfLastPage); - Serial.print(' '); - Serial.println(dfBuf.seqnum); - - // df_wipe(); - df_saveBuf(); //XXX - } -} - -static void discardInput () { - while (Serial.read() >= 0) - ; -} - -static void df_dump () { - struct { word seqnum; long timestamp; word crc; } curr; - discardInput(); - for (word page = DF_LOG_BEGIN; page < DF_LOG_LIMIT; ++page) { - if (Serial.read() >= 0) - break; - // read marker from page in flash - df_read(page, sizeof dfBuf.data, &curr, sizeof curr); - if (curr.seqnum == 0xFFFF) - continue; // page never written to - showString(PSTR(" df# ")); - Serial.print(page); - showString(PSTR(" : ")); - Serial.print(curr.seqnum); - Serial.print(' '); - Serial.print(curr.timestamp); - Serial.print(' '); - Serial.println(curr.crc); - } -} - -static word scanForMarker (word seqnum, long asof) { - word lastPage = 0; - struct { word seqnum; long timestamp; } last, curr; - last.seqnum = 0xFFFF; - // go through all the pages in log area of flash - for (word page = DF_LOG_BEGIN; page < DF_LOG_LIMIT; ++page) { - // read seqnum and timestamp from page in flash - df_read(page, sizeof dfBuf.data, &curr, sizeof curr); - if (curr.seqnum == 0xFFFF) - continue; // page never written to - if (curr.seqnum >= seqnum && curr.seqnum < last.seqnum) { - last = curr; - lastPage = page; - } - if (curr.seqnum == last.seqnum && curr.timestamp <= asof) - lastPage = page; - } - return lastPage; -} - -static void df_replay (word seqnum, long asof) { - word page = scanForMarker(seqnum, asof); - showString(PSTR("r: page ")); - Serial.print(page); - Serial.print(' '); - Serial.println(dfLastPage); - discardInput(); - word savedSeqnum = dfBuf.seqnum; - while (page != dfLastPage) { - if (Serial.read() >= 0) - break; - page = df_wrap(page + 1); - df_read(page, 0, &dfBuf, sizeof dfBuf); // overwrites ram buffer! - if (dfBuf.seqnum == 0xFFFF) - continue; // page never written to - // skip and report bad pages - word crc = ~0; - for (word i = 0; i < sizeof dfBuf; ++i) - crc = _crc16_update(crc, dfBuf.data[i]); - if (crc != 0) { - showString(PSTR("DF C? ")); - Serial.print(page); - Serial.print(' '); - Serial.println(crc); - continue; - } - // report each entry as "R seqnum time " - byte i = 0; - while (i < sizeof dfBuf.data && dfBuf.data[i] < 255) { - if (Serial.available()) - break; - showString(PSTR("R ")); - Serial.print(dfBuf.seqnum); - Serial.print(' '); - Serial.print(dfBuf.timestamp + dfBuf.data[i++]); - Serial.print(' '); - Serial.print((int) dfBuf.data[i++]); - byte n = dfBuf.data[i++]; - while (n-- > 0) { - Serial.print(' '); - Serial.print((int) dfBuf.data[i++]); - } - Serial.println(); - } - // at end of each page, report a "DF R" marker, to allow re-starting - showString(PSTR("DF R ")); - Serial.print(page); - Serial.print(' '); - Serial.print(dfBuf.seqnum); - Serial.print(' '); - Serial.println(dfBuf.timestamp); - } - dfFill = 0; // ram buffer is no longer valid - dfBuf.seqnum = savedSeqnum + 1; // so next replay will start at a new value - showString(PSTR("DF E ")); - Serial.print(dfLastPage); - Serial.print(' '); - Serial.print(dfBuf.seqnum); - Serial.print(' '); - Serial.println(millis()); -} diff --git a/firmware/RFM69CW_RF_Demo_ATmega328/RFM69CW_RF12_Demo_ATmega328/lib/readme.txt b/firmware/RFM69CW_RF_Demo_ATmega328/RFM69CW_RF12_Demo_ATmega328/lib/readme.txt new file mode 100644 index 0000000..3f9e008 --- /dev/null +++ b/firmware/RFM69CW_RF_Demo_ATmega328/RFM69CW_RF12_Demo_ATmega328/lib/readme.txt @@ -0,0 +1,36 @@ + +This directory is intended for the project specific (private) libraries. +PlatformIO will compile them to static libraries and link to executable file. + +The source code of each library should be placed in separate directory, like +"lib/private_lib/[here are source files]". + +For example, see how can be organized `Foo` and `Bar` libraries: + +|--lib +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| |--Foo +| | |- Foo.c +| | |- Foo.h +| |- readme.txt --> THIS FILE +|- platformio.ini +|--src + |- main.c + +Then in `src/main.c` you should use: + +#include +#include + +// rest H/C/CPP code + +PlatformIO will find your libraries automatically, configure preprocessor's +include paths and build them. + +More information about PlatformIO Library Dependency Finder +- http://docs.platformio.org/en/stable/librarymanager/ldf.html diff --git a/firmware/RFM69CW_RF_Demo_ATmega328/RFM69CW_RF12_Demo_ATmega328/platformio.ini b/firmware/RFM69CW_RF_Demo_ATmega328/RFM69CW_RF12_Demo_ATmega328/platformio.ini new file mode 100644 index 0000000..53c0871 --- /dev/null +++ b/firmware/RFM69CW_RF_Demo_ATmega328/RFM69CW_RF12_Demo_ATmega328/platformio.ini @@ -0,0 +1,31 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter, extra scripting +; Upload options: custom port, speed and extra flags +; Library options: dependencies, extra library storages +; +; Please visit documentation for the other options and examples +; http://docs.platformio.org/en/stable/projectconf.html + +[platformio] +env_default = rfm2pi + +[common] +build_flags = -D BUILD_TAG=1.3.0 + +# http://docs.platformio.org/en/stable/projectconf.html#lib-deps +lib_deps_external = + https://github.com/jcw/jeelib.git#f097c0039c926881d80a74bec7a7aa020de610ee + +[env:rfm2pi] +platform = atmelavr +board = pro8MHzatmega328 +framework = arduino +lib_deps = ${common.lib_deps_external} + +[env:rfm2pi_deploy] +platform = atmelavr +framework = arduino +board = pro8MHzatmega328 +build_flags = !echo '-DBUILD_TAG='$TRAVIS_TAG +lib_deps = ${common.lib_deps_external} diff --git a/firmware/RFM69CW_RF_Demo_ATmega328/RFM69CW_RF12_Demo_ATmega328/RFM69CW_RF12_Demo_ATmega328.ino b/firmware/RFM69CW_RF_Demo_ATmega328/RFM69CW_RF12_Demo_ATmega328/src/src.ino similarity index 85% rename from firmware/RFM69CW_RF_Demo_ATmega328/RFM69CW_RF12_Demo_ATmega328/RFM69CW_RF12_Demo_ATmega328.ino rename to firmware/RFM69CW_RF_Demo_ATmega328/RFM69CW_RF12_Demo_ATmega328/src/src.ino index 480febc..2c1c8cc 100644 --- a/firmware/RFM69CW_RF_Demo_ATmega328/RFM69CW_RF12_Demo_ATmega328/RFM69CW_RF12_Demo_ATmega328.ino +++ b/firmware/RFM69CW_RF_Demo_ATmega328/RFM69CW_RF12_Demo_ATmega328/src/src.ino @@ -1,10 +1,10 @@ -//RFM12Pi V2 with RFM69CW Firmware +//RFM12Pi V2 with RFM69CW Firmware //Based on JCW RF12 Demo: https://github.com/jcw/jeelib/tree/master/examples/RF12/RF12demo -//Edited for RFM12Pi and emonPi operation June 2014 by Glyn Hudson and Trystan Lea +//Edited for RFM12Pi and emonPi operation June 2014 by Glyn Hudson and Trystan Lea //http://OpenEnergyMonitor.org //https://github.com/openenergymonitor/RFM2Pi -// V1.3 July 15 - add RF trace mode debug and fix node ID isse, merge pb66 pull requests +// V1.3 July 15 - add RF trace mode debug and fix node ID isse, merge pb66 pull requests // https://github.com/openenergymonitor/RFM2Pi/pull/2 // https://github.com/openenergymonitor/RFM2Pi/pull/4 @@ -13,7 +13,7 @@ // V0.9 June 2014 // * 210 default network group -// * activity LED to light on startup and each time packet is received +// * activity LED to light on startup and each time packet is received //-------------------------------------------------------------------------------------------------------------------------------------------- @@ -37,18 +37,10 @@ #define MINOR_VERSION 2 // bump on other non-trivial changes #define VERSION "[RF12demo.13]" // keep in sync with the above -#if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny44__) -#define TINY 1 -#define SERIAL_BAUD 38400 // can only be 9600 or 38400 -#define DATAFLASH 0 // do not change -#undef LED_PIN // do not change -#define rf12_configDump() // disabled -#else -#define TINY 0 #define SERIAL_BAUD 38400 // max baud for 8Mhz RFM12Pi http://openenergymonitor.org/emon/node/6244/ #define DATAFLASH 0 // set to 0 for non-JeeLinks, else 4/8/16 (Mbit) #define LED_PIN 9 // activity LED, comment out to disable -#endif + /// Save a few bytes of flash by declaring const if used more than once. const char INVALID1[] PROGMEM = "\rInvalid\n"; @@ -58,33 +50,28 @@ const char INITFAIL[] PROGMEM = "config save failed\n"; byte trace_mode = 0; #endif -#if TINY -// Serial support (output only) for Tiny supported by TinyDebugSerial -// http://www.ernstc.dk/arduino/tinycom.html -// 9600, 38400, or 115200 -// hardware\jeelabs\avr\cores\tiny\TinyDebugSerial.h Modified to -// moveTinyDebugSerial from PB0 to PA3 to match the Jeenode Micro V3 PCB layout -// Connect Tiny84 PA3 to USB-BUB RXD for serial output from sketch. -// Jeenode AIO2 -// -// With thanks for the inspiration by 2006 David A. Mellis and his AFSoftSerial -// code. All right reserved. -// Connect Tiny84 PA2 to USB-BUB TXD for serial input to sketch. -// Jeenode DIO2 -// 9600 or 38400 at present. - -#if SERIAL_BAUD == 9600 -#define BITDELAY 54 // 9k6 @ 8MHz, 19k2 @16MHz -#endif -#if SERIAL_BAUD == 38400 -#define BITDELAY 11 // 38k4 @ 8MHz, 76k8 @16MHz -#endif - #define _receivePin 8 static int _bitDelay; static char _receive_buffer; static byte _receive_buffer_index; +// TODO: replace with code from the std avr libc library: +// http://www.nongnu.org/avr-libc/user-manual/group__util__delay__basic.html +void whackDelay (word delay) { + byte tmp=0; + + asm volatile("sbiw %0, 0x01 \n\t" + "ldi %1, 0xFF \n\t" + "cpi %A0, 0xFF \n\t" + "cpc %B0, %1 \n\t" + "brne .-10 \n\t" + : + "+r" (delay), "+a" (tmp) + : + "0" (delay) +); +} + ISR (PCINT0_vect) { char i, d = 0; if (digitalRead(_receivePin)) // PA2 = Jeenode DIO2 @@ -102,22 +89,6 @@ ISR (PCINT0_vect) { _receive_buffer_index = 1; // got a byte } -// TODO: replace with code from the std avr libc library: -// http://www.nongnu.org/avr-libc/user-manual/group__util__delay__basic.html -void whackDelay (word delay) { - byte tmp=0; - - asm volatile("sbiw %0, 0x01 \n\t" - "ldi %1, 0xFF \n\t" - "cpi %A0, 0xFF \n\t" - "cpc %B0, %1 \n\t" - "brne .-10 \n\t" -: - "+r" (delay), "+a" (tmp) -: - "0" (delay) - ); -} static byte inChar () { byte d; @@ -128,7 +99,6 @@ static byte inChar () { return d; } -#endif static unsigned long now () { // FIXME 49-day overflow @@ -166,7 +136,7 @@ byte spare_flags : word frequency_offset; // used by rf12_config, offset 4 byte pad[RF12_EEPROM_SIZE-8]; word crc; -} +} RF12Config; static RF12Config config; @@ -186,11 +156,22 @@ static void showByte (byte value) { if (config.hex_output) { showNibble(value >> 4); showNibble(value); - } + } else Serial.print((word) value); } +static void showString (PGM_P s) { + for (;;) { + char c = pgm_read_byte(s++); + if (c == 0) + break; + if (c == '\n') + printOneChar('\r'); + printOneChar(c); + } +} + static word calcCrc (const void* ptr, byte len) { word crc = ~0; for (byte i = 0; i < len; ++i) @@ -244,6 +225,7 @@ static void ookPulse(int on, int off) { delayMicroseconds(off - 200); } + static void fs20sendBits(word data, byte bits) { if (bits == 8) { ++bits; @@ -337,27 +319,14 @@ const char helpText2[] PROGMEM = " 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') - printOneChar('\r'); - printOneChar(c); - } -} + static void showHelp () { -#if TINY - showString(PSTR("?\n")); -#else showString(helpText1); if (df_present()) showString(helpText2); showString(PSTR("Current configuration:\n")); rf12_configDump(); -#endif } static void handleInput (char c) { @@ -394,7 +363,7 @@ static void handleInput (char c) { rf12_sendNow(stack[3], stack + 4, top - 4); rf12_sendWait(2); rf12_configSilent(); - } + } else if (c > ' ') { switch (c) { @@ -414,7 +383,7 @@ static void handleInput (char c) { } break; - case 'o': + case 'o': { // Increment frequency within band // Stay within your country's ISM spectrum management guidelines, i.e. // allowable frequencies and their use when selecting operating frequencies. @@ -422,32 +391,6 @@ static void handleInput (char c) { config.frequency_offset = value; saveConfig(); } -#if !TINY - // this code adds about 400 bytes to flash memory use - // display the exact frequency associated with this setting - byte freq = 0, band = config.nodeId >> 6; - switch (band) { - case RF12_433MHZ: - freq = 43; - break; - case RF12_868MHZ: - freq = 86; - break; - case RF12_915MHZ: - freq = 90; - break; - } - uint32_t f1 = freq * 100000L + band * 25L * config.frequency_offset; - Serial.print((word) (f1 / 10000)); - printOneChar('.'); - word f2 = f1 % 10000; - // tedious, but this avoids introducing floating point - printOneChar('0' + f2 / 1000); - printOneChar('0' + (f2 / 100) % 10); - printOneChar('0' + (f2 / 10) % 10); - printOneChar('0' + f2 % 10); - Serial.println(" MHz"); -#endif break; } @@ -518,13 +461,8 @@ static void handleInput (char c) { case 'v': //display the interpreter version and configuration displayVersion(); rf12_configDump(); -#if TINY - Serial.println(); -#endif break; - // the following commands all get optimised away when TINY is set - case 'l': // turn activity LED on or off activityLed(value); break; @@ -581,9 +519,6 @@ static void displayASCII (const byte* data, byte count) { static void displayVersion () { showString(PSTR(VERSION)); -#if TINY - showString(PSTR(" Tiny")); -#endif } void setup () { @@ -591,23 +526,13 @@ void setup () { delay(100); // shortened for now. Handy with JeeNode Micro V1 where ISP // interaction can be upset by RF12B startup process. -#if TINY - PCMSK0 |= (1<>1); @@ -729,10 +647,9 @@ void loop () { } Serial.print(-y); Serial.println("dB"); - + delay(trace_mode*10); - - } + + } #endif } -