From 0440e536dde6835aee727ef2c12742a997633b20 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Tue, 1 Oct 2019 18:06:49 +0200 Subject: [PATCH] scalefactor for curve plotter --- include/cyclic.h | 5 +++++ include/display.h | 2 +- include/senddata.h | 7 ++++++- src/cyclic.cpp | 4 ++++ src/display.cpp | 41 +++++++++++++++++++++-------------------- src/senddata.cpp | 4 ++++ 6 files changed, 41 insertions(+), 22 deletions(-) diff --git a/include/cyclic.h b/include/cyclic.h index b9512c53..4b402360 100644 --- a/include/cyclic.h +++ b/include/cyclic.h @@ -5,6 +5,7 @@ #include "senddata.h" #include "rcommand.h" #include "spislave.h" + #if(HAS_LORA) #include #endif @@ -13,6 +14,10 @@ #include "bmesensor.h" #endif +#ifdef HAS_DISPLAY +#include "display.h" +#endif + extern Ticker housekeeper; void housekeeping(void); diff --git a/include/display.h b/include/display.h index a2a20eff..7c90a968 100644 --- a/include/display.h +++ b/include/display.h @@ -18,6 +18,6 @@ void oledScrollBufferLeft(uint8_t *buf, const uint16_t width, const uint16_t height); int oledDrawPixel(uint8_t *buf, const uint16_t x, const uint16_t y, const uint8_t dot); -void oledPlotCurve(uint16_t count); +void oledPlotCurve(uint16_t count, bool reset); #endif \ No newline at end of file diff --git a/include/senddata.h b/include/senddata.h index 4a748445..0151f7e2 100644 --- a/include/senddata.h +++ b/include/senddata.h @@ -2,10 +2,15 @@ #define _SENDDATA_H #include "spislave.h" +#include "cyclic.h" + #if(HAS_LORA) #include "lorawan.h" #endif -#include "cyclic.h" + +#ifdef HAS_DISPLAY +#include "display.h" +#endif extern Ticker sendcycler; diff --git a/src/cyclic.cpp b/src/cyclic.cpp index ef2ce200..9b75ecef 100644 --- a/src/cyclic.cpp +++ b/src/cyclic.cpp @@ -128,5 +128,9 @@ void reset_counters() { macs_total = 0; // reset all counters macs_wifi = 0; macs_ble = 0; +#ifdef HAS_DISPLAY + oledPlotCurve(0, true); +#endif + #endif } \ No newline at end of file diff --git a/src/display.cpp b/src/display.cpp index 9662dc3f..01057745 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -47,9 +47,8 @@ static const char TAG[] = __FILE__; #define QR_SCALEFACTOR 2 // 29 -> 58x < 64px // settings for curve plotter -#define PLOT_SCALEFACTOR 1 // downscales pax numbers to display rows -#define DISPLAY_WIDTH 128 // Width in pixels of OLED-display, must be 32X -#define DISPLAY_HEIGHT 64 // Height in pixels of OLED-display, must be 16X +#define DISPLAY_WIDTH 128 // Width in pixels of OLED-display, must be 32X +#define DISPLAY_HEIGHT 64 // Height in pixels of OLED-display, must be 16X // helper array for converting month values to text const char *printmonth[] = {"xxx", "Jan", "Feb", "Mar", "Apr", "May", "Jun", @@ -185,7 +184,7 @@ void draw_page(time_t t, uint8_t page) { macs.size()); // display number of unique macs total Wifi + BLE // update histogram if we have a display - oledPlotCurve(macs.size()); + oledPlotCurve(macs.size(), false); switch (page % DISPLAY_PAGES) { @@ -424,31 +423,33 @@ void oledScrollBufferLeft(uint8_t *buf, const uint16_t width, } } -void oledPlotCurve(uint16_t count) { +void oledPlotCurve(uint16_t count, bool reset) { - uint8_t level; - static uint16_t last_count = 0, col = 0, row = 0; + static uint16_t last_count = 0, col = 0, row = 0, scalefactor = 1; - if (last_count == count) + if ((last_count == count) && !reset) return; - // next count cycle? - if (count == 0) { - - // matrix full? then scroll left 1 dot, else increment column - if (col < DISPLAY_WIDTH - 1) + if (reset) { // next count cycle? + if (col < DISPLAY_WIDTH - 1) // matrix not full -> increment column col++; - else + else // matrix full -> scroll left 1 dot oledScrollBufferLeft(displaybuf, DISPLAY_WIDTH, DISPLAY_HEIGHT); - } else - oledDrawPixel(displaybuf, col, row, 0); // clear current dot + } else // clear current dot + oledDrawPixel(displaybuf, col, row, 0); - // scale and set new dot + // re-scale, if necessary + while (((count / scalefactor) <= DISPLAY_HEIGHT) && (scalefactor > 1)) { + scalefactor--; + } + while ((count / scalefactor) > DISPLAY_HEIGHT) { + scalefactor++; + } + + // set new dot + row = DISPLAY_HEIGHT - 1 - (count / scalefactor) % DISPLAY_HEIGHT; last_count = count; - level = count / PLOT_SCALEFACTOR; - row = - level <= DISPLAY_HEIGHT ? DISPLAY_HEIGHT - 1 - level % DISPLAY_HEIGHT : 0; oledDrawPixel(displaybuf, col, row, 1); } diff --git a/src/senddata.cpp b/src/senddata.cpp index 76d412e2..11b0d81a 100644 --- a/src/senddata.cpp +++ b/src/senddata.cpp @@ -75,6 +75,10 @@ void sendData() { get_salt(); // get new salt for salting hashes ESP_LOGI(TAG, "Counter cleared"); } +#ifdef HAS_DISPLAY + else + oledPlotCurve(macs.size(), true); +#endif break; #endif