diff --git a/avrrfm.c b/avrrfm.c index 39b1d44..6b32992 100644 --- a/avrrfm.c +++ b/avrrfm.c @@ -33,11 +33,11 @@ #include "dejavu.h" #include "unifont.h" -#define MEASURE_INTS 8 +#define MEASURE_INTS 4 #define LABEL_OFFSET 10 #ifndef RECEIVER - #define RECEIVER 1 + #define RECEIVER 0 #endif /* 1 int = 8 seconds */ @@ -161,17 +161,17 @@ int16_t tempx10 = convertTSens(raw); div_t temp = div(tempx10, 10); static char buf[16]; - + snprintf(buf, sizeof (buf), "%d.%d°C\r\n", temp.quot, abs(temp.rem)); printString(buf); snprintf(buf, sizeof (buf), "%4d.%d°", temp.quot, abs(temp.rem)); - + x_t x; const __flash Font *unifont = &unifontFont; x = writeString(0, yu, unifont, buf); yu += unifont->height; - if (yu + unifont->height > DISPLAY_HEIGHT) yu = 0; + if (yu + unifont->height > DISPLAY_HEIGHT) yu = 0; if (xl == 0) xl = x; const __flash Font *dejaVu = &dejaVuFont; @@ -222,7 +222,7 @@ initSPI(); initI2C(); initRadioInt(); - if (! RECEIVER) { + if (!RECEIVER) { // used only for tx initWatchdog(); } @@ -233,10 +233,11 @@ printString("Hello Radio!\r\n"); initRadio(868600); - initDisplay(); - - setFrame(0xffff); if (RECEIVER) { + initDisplay(); + + setFrame(0xffff); + // initial rx mode startReceive(); } @@ -245,8 +246,8 @@ // do something else besides tx/rx // printString("Running...\r\n"); // _delay_ms(10); - - if (! RECEIVER) { + + if (!RECEIVER) { if (ints % MEASURE_INTS == 0) { ints = 0; @@ -265,7 +266,7 @@ startReceive(); } } - + // power down until woken up by watchdog (tx) // or "PayloadReady" (rx) interrupt set_sleep_mode(SLEEP_MODE_PWR_DOWN); diff --git a/mcp9808.c b/mcp9808.c index 124ab63..bbb8ee2 100644 --- a/mcp9808.c +++ b/mcp9808.c @@ -46,7 +46,7 @@ uint16_t value = 0; value |= upper << 8; value |= lower; - + return value; } @@ -60,7 +60,7 @@ uint16_t conf = regRead(MCP9808_CONF); conf &= ~(1 << 8); regWrite(MCP9808_CONF, conf); - + // TODO need to wait for first conversion result after wake up // can use an alert irq to wake up sleeping MCU instead? _delay_ms(300); @@ -68,14 +68,14 @@ uint16_t readTSens(void) { uint16_t raw = regRead(MCP9808_TEMP); - + return raw; } int16_t convertTSens(uint16_t raw) { uint8_t upper = raw >> 8; uint8_t lower = raw & 0x00ff; - + // check flags if ((upper & 0x80) == 0x80) { // T >= TA CRIT @@ -99,6 +99,6 @@ // TA >= 0°C temp = (upper * 160 + lower * 10 / 16); } - + return temp; } \ No newline at end of file diff --git a/rfm69.c b/rfm69.c index bf4c2aa..2f27059 100644 --- a/rfm69.c +++ b/rfm69.c @@ -238,8 +238,8 @@ loop_until_bit_is_set(irqFlags2, 3); clearIrqFlags(); - + setMode(MODE_STDBY); - + return len; } diff --git a/rfm69.h b/rfm69.h index 01d7d03..04d7113 100644 --- a/rfm69.h +++ b/rfm69.h @@ -48,6 +48,7 @@ #define PCK_CFG1 0x37 #define NODE_ADDR 0x39 #define CAST_ADDR 0x3a +#define AUTO_MODES 0x3b #define FIFO_THRESH 0x3c #define TEST_LNA 0x58 #define TEST_PA1 0x5a