diff --git a/avrrfm.c b/avrrfm.c index cbe33af..bb9b95d 100644 --- a/avrrfm.c +++ b/avrrfm.c @@ -43,9 +43,6 @@ /* 1 int = 8 seconds */ static volatile uint8_t ints = 0; -/* Temp. "log" */ -static y_t yu = 0; - /* Temp. label coordinates */ static x_t xl = 0; static y_t yl = 0; @@ -157,32 +154,32 @@ * * @param raw temperature */ -static void displayTemp(uint16_t raw) { +static void displayTemp(uint8_t rssi, uint16_t raw) { + uint8_t _rssi = divRoundNearest(rssi, 2); int16_t tempx10 = convertTSens(raw); div_t temp = div(tempx10, 10); - static char buf[16]; + + static char buf[32]; - snprintf(buf, sizeof (buf), "%d.%d°C\r\n", temp.quot, abs(temp.rem)); + snprintf(buf, sizeof (buf), "RSSI: -%d dBm, %d.%d°C\r\n", + _rssi, temp.quot, abs(temp.rem)); printString(buf); + + snprintf(buf, sizeof (buf), "RSSI: -%d dBm", _rssi); + const __flash Font *unifont = &unifontFont; + writeString(0, 0, unifont, buf, 0xffff, 0x0000); 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, 0xffff, 0x001f); - yu += unifont->height; - if (yu + unifont->height > DISPLAY_HEIGHT) yu = 0; - - if (xl == 0) xl = x; const __flash Font *dejaVu = &dejaVuFont; if (width > 0) fillArea(xo, yo, width, dejaVu->height, 0xffff); + if (yl == 0) yl = unifont->height; width = writeString(xl, yl, dejaVu, buf, 0xffff, 0x0000); xo = xl; yo = yl; xl += LABEL_OFFSET; yl += LABEL_OFFSET; - if (xl > DISPLAY_WIDTH - width) xl = x; - if (yl > DISPLAY_HEIGHT - dejaVu->height) yl = 0; + if (xl > DISPLAY_WIDTH - width) xl = 0; + if (yl > DISPLAY_HEIGHT - dejaVu->height) yl = unifont->height; } /** @@ -261,8 +258,9 @@ } } else { if (payloadReady()) { + uint8_t rssi = readRssi(); uint16_t raw = readTemp(); - displayTemp(raw); + displayTemp(rssi, raw); startReceive(); } } diff --git a/rfm69.c b/rfm69.c index b7d0dd1..ad82edf 100644 --- a/rfm69.c +++ b/rfm69.c @@ -183,6 +183,10 @@ setMode(MODE_RX); } +uint8_t readRssi(void) { + return regRead(RSSI_VALUE); +} + bool payloadReady(void) { if (irqFlags2 & (1 << 2)) { clearIrqFlags(); diff --git a/rfm69.h b/rfm69.h index 04d7113..ed0570f 100644 --- a/rfm69.h +++ b/rfm69.h @@ -29,6 +29,8 @@ #define LNA 0x18 #define RX_BW 0x19 #define AFC_BW 0x20 +#define RSSI_CONFIG 0x23 +#define RSSI_VALUE 0x24 #define DIO_MAP1 0x25 #define DIO_MAP2 0x26 #define IRQ_FLAGS1 0x27 @@ -89,6 +91,13 @@ void startReceive(void); /** + * Returns the current RSSI value. + * + * @return rssi value + */ +uint8_t readRssi(void); + +/** * Returns true if a "PayloadReady" interrupt arrived and clears the * interrupt state. * diff --git a/utils.h b/utils.h index 993a696..8c0a340 100644 --- a/utils.h +++ b/utils.h @@ -40,11 +40,11 @@ * rounds to the nearest int and returns it. * http://stackoverflow.com/a/18067292/709426 */ -#define divRoundNearest(num, den) \ -({ \ - return ((num < 0) ^ (den < 0)) ? \ - ((num - den / 2) / den) : \ - ((num + den / 2) / den); \ +#define divRoundNearest(num, den) \ +({ \ + ((num < 0) ^ (den < 0)) ? \ + ((num - den / 2) / den) : \ + ((num + den / 2) / den); \ }) #endif /* UTILS_H */