From b6dabcd16f01f888702e34710f21a1bfd0ee2470 Mon Sep 17 00:00:00 2001 From: Willem Oldemans Date: Tue, 12 Jan 2021 11:16:33 +0100 Subject: [PATCH] intermediate commit --- .DS_Store | Bin 0 -> 6148 bytes include/images.h | 211 ++++++++++++++++++ platformio.ini | 23 ++ src/.DS_Store | Bin 0 -> 6148 bytes src/display.cpp | 150 +++++++++++++ src/display.h | 12 + src/hal.h | 51 +++++ ...envelope-symbol_icon-icons.com_56519-2.xbm | 100 +++++++++ ...-envelope-symbol_icon-icons.com_56519.MONO | 1 + src/img/mail-black.png | Bin 0 -> 1769 bytes src/mailbox.cpp | 46 ++++ src/mailbox.h | 8 + src/main.cpp | 42 +++- src/net.cpp | 33 +++ src/net.h | 9 + src/power.cpp | 171 ++++++++++++++ src/power.h | 10 + src/sensor.cpp | 33 +++ src/sensor.h | 11 + src/sleep.cpp | 71 ++++++ src/sleep.h | 9 + src/workspace.code-workspace | 14 ++ 22 files changed, 999 insertions(+), 6 deletions(-) create mode 100644 .DS_Store create mode 100644 include/images.h create mode 100644 src/.DS_Store create mode 100644 src/display.cpp create mode 100644 src/display.h create mode 100644 src/hal.h create mode 100644 src/img/mail-black-envelope-symbol_icon-icons.com_56519-2.xbm create mode 100644 src/img/mail-black-envelope-symbol_icon-icons.com_56519.MONO create mode 100644 src/img/mail-black.png create mode 100644 src/mailbox.cpp create mode 100644 src/mailbox.h create mode 100644 src/net.cpp create mode 100644 src/net.h create mode 100644 src/power.cpp create mode 100644 src/power.h create mode 100644 src/sensor.cpp create mode 100644 src/sensor.h create mode 100644 src/sleep.cpp create mode 100644 src/sleep.h create mode 100644 src/workspace.code-workspace diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5172429f264de2441865cb4700216d4256da9242 GIT binary patch literal 6148 zcmeH~J!%6%427R!7lt%jx}3%b$PET#pTHLgIFQEJ;E>dF^gR7ES*H$5cmnB-G%I%Z zD|S`@Z2$T80!#olbXV*=%*>dt@PRwdU#I)^a=X5>;#J@&VrHyNnC;iLL0pQvfVyTmjO&;ssLc!1UOG})p;=82 zR;?Ceh}WZ?+UmMqI#RP8R>OzYoz15hnq@nzF`-!xQ4j$Um=RcIKKc27r2jVm&svm< zfC&6E0=7P!4tu^-ovjbA=k?dB`g+i*aXG_}p8zI)6mRKa+;6_1_R^8c3Qa!(fk8n8 H{*=HsM+*^= literal 0 HcmV?d00001 diff --git a/include/images.h b/include/images.h new file mode 100644 index 0000000..3f2393c --- /dev/null +++ b/include/images.h @@ -0,0 +1,211 @@ +#define WiFi_Logo_width 60 +#define WiFi_Logo_height 36 +const unsigned char WiFi_Logo_bits[] PROGMEM = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0x07, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xE0, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF, + 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, + 0xFF, 0x03, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, + 0x00, 0xFF, 0xFF, 0xFF, 0x07, 0xC0, 0x83, 0x01, 0x80, 0xFF, 0xFF, 0xFF, + 0x01, 0x00, 0x07, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x0C, 0x00, + 0xC0, 0xFF, 0xFF, 0x7C, 0x00, 0x60, 0x0C, 0x00, 0xC0, 0x31, 0x46, 0x7C, + 0xFC, 0x77, 0x08, 0x00, 0xE0, 0x23, 0xC6, 0x3C, 0xFC, 0x67, 0x18, 0x00, + 0xE0, 0x23, 0xE4, 0x3F, 0x1C, 0x00, 0x18, 0x00, 0xE0, 0x23, 0x60, 0x3C, + 0x1C, 0x70, 0x18, 0x00, 0xE0, 0x03, 0x60, 0x3C, 0x1C, 0x70, 0x18, 0x00, + 0xE0, 0x07, 0x60, 0x3C, 0xFC, 0x73, 0x18, 0x00, 0xE0, 0x87, 0x70, 0x3C, + 0xFC, 0x73, 0x18, 0x00, 0xE0, 0x87, 0x70, 0x3C, 0x1C, 0x70, 0x18, 0x00, + 0xE0, 0x87, 0x70, 0x3C, 0x1C, 0x70, 0x18, 0x00, 0xE0, 0x8F, 0x71, 0x3C, + 0x1C, 0x70, 0x18, 0x00, 0xC0, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0x08, 0x00, + 0xC0, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0x0C, 0x00, 0x80, 0xFF, 0xFF, 0x1F, + 0x00, 0x00, 0x06, 0x00, 0x80, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0x07, 0x00, + 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0xF8, 0xFF, 0xFF, + 0xFF, 0x7F, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x01, 0x00, 0x00, + 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF, + 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFF, 0x1F, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x80, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }; + +#define hhlogo_width 128 +#define hhlogo_height 64 +const unsigned char hhlogo_bits[] PROGMEM = { + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,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0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x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 0xff, + 0xf0, 0xff, 0x07, 0x00, 0x78, 0xf0, 0x87, 0x3f, 0x03, 0x00, 0xf8, 0x0f, + 0x00, 0x80, 0xff, 0x7f, 0xf0, 0xff, 0x03, 0x00, 0x78, 0xf8, 0x87, 0x3f, + 0x01, 0x00, 0xfc, 0x0f, 0x00, 0xc0, 0xff, 0x7f, 0xf8, 0xff, 0x43, 0x15, + 0x78, 0xf8, 0x83, 0x3f, 0x03, 0x00, 0xff, 0x0f, 0x00, 0xf8, 0xff, 0x7f, + 0xf8, 0xff, 0xe1, 0x3f, 0x38, 0xf8, 0xc1, 0x3f, 0x1f, 0xe0, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x3f, 0x00, 0xc0, 0xf0, 0x3f, 0x38, 0x00, 0xc0, 0x3f, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x40, 0xf8, 0x3f, + 0x38, 0x00, 0xf0, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, + 0x00, 0x60, 0xf8, 0x3f, 0x18, 0x00, 0xf8, 0x3f, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x3f, 0x00, 0x20, 0xfc, 0x7f, 0x18, 0x00, 0xff, 0x3f, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x3f }; + +//Added by Sloeber +#pragma once \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 6123a70..058aeb3 100644 --- a/platformio.ini +++ b/platformio.ini @@ -8,7 +8,30 @@ ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html +[platformio] +default_envs = heltec_wifi_lora_32_V2 + [env:heltec_wifi_lora_32_V2] platform = espressif32 board = heltec_wifi_lora_32_V2 +tasks = framework = arduino +build_flags = -D ENVIRONMENT=1 +lib_deps = + #heltecautomation/Heltec ESP32 Dev-Boards@^1.1.0 + ericksimoes/Ultrasonic@^3.0.0 + 256dpi/MQTT@^2.4.8 + http://192.168.2.3/Bonobo.Git.Server/OLEDDisplay.git +monitor_speed = 115200 + + +[env:lolin32] +platform = espressif32 +board = lolin32 +framework = arduino +build_flags = -D ENVIRONMENT=2 +lib_deps = + ericksimoes/Ultrasonic@^3.0.0 + 256dpi/MQTT@^2.4.8 + http://192.168.2.3/Bonobo.Git.Server/OLEDDisplay.git +monitor_speed = 115200 \ No newline at end of file diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f98683afb324179aa403fd5f6d4fb249c2fc7219 GIT binary patch literal 6148 zcmeHK%}T>S5Z-O8rihq>P>*}@)P}(V4RQ&FswVWIxm z)-S?v`k}ktr9Vpg=H5vd#I7HV7Bbl%jv(ab$`6KNVu#CM7|D4Y<-m2SeY2LP-F98H zyRED)(xXy8gqqm>wpfg&*-lpqJWNX2}GgM z(wHj*4+vMOfGU;iCk9vPFfMeQr7>5i(ixX4!#sNB;_<@e>M$;3IOCQ=>WKkjV3mQg zGEF@HPvI}K_L0AuLKZPV4E!+$c%|p`Y$!^ftzXK+vsOSGKtsW}92F4IS1tiy;6Ac1 eoyspzhd4`Pt`KLzahVQC7Xe8Kb;Q6AFz^lvuuqEs literal 0 HcmV?d00001 diff --git a/src/display.cpp b/src/display.cpp new file mode 100644 index 0000000..94fd73f --- /dev/null +++ b/src/display.cpp @@ -0,0 +1,150 @@ +#include "Arduino.h" +#include "display.h" +#include "sensor.h" +#include "net.h" +#include +#include "SSD1306wire.h" +#include +#include "hal.h" +#include "power.h" + +SSD1306Wire *display; +bool initOK = false; +char buf[128]; + +void displayDrawBatt(uint16_t voltage, bool sleep) +{ + voltage = powerGetVbatt(); + uint16_t xstart = 104; + uint16_t ystart = 30; + display->setColor(BLACK); + display->fillRect(xstart - 5, ystart, 29, 24); + + display->setColor(WHITE); + display->drawRect(xstart, ystart, 12, 6); + display->fillRect(xstart + 1, xstart + 2, 1, 2); + + uint16_t v = voltage; + if (v < MINBATT) + { + v = MINBATT; + } + if (v > MAXBATT) + { + v = MAXBATT; + } + double pct = map(v, MINBATT, MAXBATT, 0, 100); + uint8_t bars = round(pct / 10.0); + display->fillRect(xstart + 1, ystart + 1, bars, 4); + display->setFont(ArialMT_Plain_10); + display->setTextAlignment(TEXT_ALIGN_RIGHT); + + display->drawString(127, 5, String((int)round(pct)) + "%"); + display->drawString(127, 14, String(round(voltage / 10.0) / 100.0) + "V"); + Serial.printf("battery = %i mv\n", voltage); + +#if defined(__DEBUG) && __DEBUG > 0 + static uint8_t c = 0; + if ((c++ % 10) == 0) + { + c = 1; + Serial.printf("VBAT: %dmV [%4.1f%%] %d bars\n", voltage, pct, bars); + } +#endif +} + +void displayDrawShutdown(void) +{ + display->clear(); + display->setColor(WHITE); + display->setFont(ArialMT_Plain_10); + display->setTextAlignment(TEXT_ALIGN_CENTER); + display->drawString(64, 24, "Shutdown!!"); + display->display(); +} + +void displayDrawNet(void) +{ + if (netIsConnected()) + { + display->drawString(0, 0, "WiFi connected."); + } + else + { + display->drawString(0, 0, "WiFi Disconnected."); + } + display->drawString(0, 15, "IP: "); + display->drawString(20, 15, WiFi.localIP().toString()); +} + +void displayDrawSensor(void) +{ + sprintf(buf, "Dist: %i cm", sensorGetDistance()); + display->drawString(0, 45, buf); +} + +void displayDrawMailbox(void) +{ + if (mailboxGetMailDetected()) + { + uint8_t xstart = 6; + uint8_t ystart = 6; + uint8_t width = 64; + uint8_t height = 40; + display->setColor(WHITE); + display->fillRect(xstart, ystart, width, height); + display->setColor(BLACK); + display->drawLine(xstart, ystart, (width / 2) + xstart - 1, (height / 5 * 3) + ystart - 1); + display->drawLine(xstart + width - 1, ystart, (width / 2) + xstart, (height / 5 * 3) + ystart - 1); + display->drawLine(xstart, ystart + height - 1, (width / 5 * 2), (height / 2)); + display->drawLine(xstart + width - 1, ystart + height - 1, width / 5 * 4 + 3, height / 2); + } +} + +void displayUpdate(void) +{ + if (!initOK) + { + Serial.println("display update FAILED"); + return; + } + + display->clear(); + //displayDrawNet(); + displayDrawBatt(0, false); + displayDrawSensor(); + displayDrawMailbox(); + display->display(); + + delay(10); +} + +void displayInit(void) +{ + Serial.print("display Init"); + display = new SSD1306Wire(0x3c, SDA_OLED, SCL_OLED, RST_OLED, GEOMETRY_128_64); + + if (display == NULL) + { + Serial.println("Failed to init display, NULL ptr"); + return; + } + initOK = display->init(); + display->setBrightness(255); + display->flipScreenVertically(); + display->setFont(ArialMT_Plain_10); + display->drawString(0, 0, "OLED initial done!"); + display->display(); + delay(1000); + Serial.print("."); + + display->clear(); + display->display(); + + if (!initOK) + { + Serial.println("display Init FAILED"); + return; + } + Serial.println(" done"); +} diff --git a/src/display.h b/src/display.h new file mode 100644 index 0000000..4f7d097 --- /dev/null +++ b/src/display.h @@ -0,0 +1,12 @@ +#ifndef DISPLAYH +#define DISPLAYH + + +void displayInit(void); +void displayUpdate(void); +void displayDrawBatt(uint16_t voltage, bool sleep); +void displayDrawShutdown(void); + + + +#endif //DISPLAYH \ No newline at end of file diff --git a/src/hal.h b/src/hal.h new file mode 100644 index 0000000..1a84868 --- /dev/null +++ b/src/hal.h @@ -0,0 +1,51 @@ +#ifndef HALH +#define HALH + +#define MAXBATT 4200 // The default Lipo is 4200mv when the battery is fully charged. +#define LIGHT_SLEEP_VOLTAGE 3750 // Point where start light sleep +#define MINBATT 3200 // The default Lipo is 3200mv when the battery is empty...this WILL be low on the 3.3v rail specs!!! + + +#ifndef ENVIRONMENT +#error "Must define ENVIRONMENT..." +#endif + +#define HELTECv2 1 +#define LOLIN32 2 +#define HELTECv21 3 + + +#if ENVIRONMENT == HELTECv2 //HELTEC WIFI LORA V2 + +#define TRIGGER 27 +#define ECHO 14 + +#define VBATT ADC2_CHANNEL_4 +#define VEXT 21 + +#endif + +#if ENVIRONMENT == LOLIN32 //LOLIN32 + +#define SDA_OLED 15 +#define SCL_OLED 4 +#define RST_OLED 17 + +#define TRIGGER 13 +#define ECHO 14 + +#define VBATT ADC2_CHANNEL_1 +#define VEXT 21 +#endif + +#if ENVIRONMENT == HELTECv21 // + +#define TRIGGER 27 +#define ECHO 14 + +#define VBATT ADC2_CHANNEL_1 +#define VEXT 21 + +#endif + +#endif //HALH \ No newline at end of file diff --git a/src/img/mail-black-envelope-symbol_icon-icons.com_56519-2.xbm b/src/img/mail-black-envelope-symbol_icon-icons.com_56519-2.xbm new file mode 100644 index 0000000..4426dbb --- /dev/null +++ b/src/img/mail-black-envelope-symbol_icon-icons.com_56519-2.xbm @@ -0,0 +1,100 @@ +#define 30884_7a5aa225e163575300dd0301e8bbff692538a943f474f800a4a291b956fc794e_width 96 +#define 30884_7a5aa225e163575300dd0301e8bbff692538a943f474f800a4a291b956fc794e_height 96 +static char 30884_7a5aa225e163575300dd0301e8bbff692538a943f474f800a4a291b956fc794e_bits[] = { + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 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a/src/img/mail-black-envelope-symbol_icon-icons.com_56519.MONO b/src/img/mail-black-envelope-symbol_icon-icons.com_56519.MONO new file mode 100644 index 0000000..1034fa6 --- /dev/null +++ b/src/img/mail-black-envelope-symbol_icon-icons.com_56519.MONO @@ -0,0 +1 @@ +ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ \ No newline at end of file diff --git a/src/img/mail-black.png b/src/img/mail-black.png new file mode 100644 index 0000000000000000000000000000000000000000..2b20de8944f67dc695a888fb832f4eef2c34c037 GIT binary patch literal 1769 zcmVZ68VjgNcO- zE+i5JUC2VB3Du26HK+(TRjF$ZYcaXM3vU6_9vD+KnbzE8f>(es4~(jcjA_oC@c^(uxaL{lng_=DF4r_y zHY`AK{yz=@L%>p@;iJH?2S)lT!@z2R!=)&$4@Dm=2PSj}=Ycgs2M+>+9vJJJ3~6p` zSPh)h*H56hXHQc{SAagDqeZ{~Awr5|KyzY4ABx+?cKrayTXZ;%9J_WB!qh0t>=d}# ztT}CNe;nYVq4OzJ7-d^6cL4kJwPll0v`lH+C4Tl=__+x7@Ujkkg6!cfwDxej%7nJr zhECvP>@&m|!Ud5NjsgpX0iQwTK*}a3Z@H>%wPB&=%!OO$fd_$JVc<2WNUCg-@)DOQ zu^0F;MxU`17)GrHBn5u*fUKCLn?{9L682HeZ0fYuT|z(U!tlcGkSb+U$B@I!te)^p6du5Bj;um9 zHO@OOi}5m3+%-(SPy(s0asfHaT#5=avwF8>YQV6A0lg?^`Sx-iLcW1klYKfqb3w2ypN`nee7`VuQUo9bFL&vS=JZpOKWab*?#U5n;<>zDf-<`SkBUG#S; zn%97Xth|f}iSTff3>r{o|~(M^NY8OsG-Z z3b=3w{DA!qd=j{>uZ>gmcg;0L+01|SSSBpcy0(=Aeg}FiMn8hOI~&`$7X2mcWp*}m zM2~4g4@&2@aKK-{!xm$g0A~$tU9+jJP}6Nq)5$qKwh1eM%Ytp*JK#F%e6b0OaNEY` zGRHTsWJJVw2954ZFuozbZj>YJ25cvod`kFX3=VQP;OMe@wd^K+(fl^>hM@aLIq;QPM|I#!?5W>Pz^x3&Ym_Ydyal{u(Z3V; zD#P(Ib-+nrzD4=N~|&WM2%N_JGW!avJ-S{W$5jD<*C@hJCKQ7x>l#64S~_ zZHo!(Nw=viQKOrvh{l92vX2(ZlDf8~%VO^)l9x4OH@FS#v?v4cfd|B8Ezg^C!qZZ|;*^*EXB52=@)X;ss~1mlIb|Oy$ToxvXtBp$BuN&)ESZz)E3| zGaispmYl(UbFO4|t=riFH-L4P&bujg_kgb=?eg7qIZTB6fKwhA zQFS?`xr~K*zzGkOZx=ZM+|!C^(= MAILCOUNTERFILTER) + { + mailDetected = true; + } + } + else + { + mailcounter = 0; + } + } + else if (currentDistance < (previousDistance - MAILCOUNTERTHRESHOLT)) + { + mailFlag = true; + mailcounter = 0; + } + else + { + mailFlag = false; + } + previousDistance = currentDistance; +} + +bool mailboxGetMailDetected(void) +{ + return mailDetected; +} \ No newline at end of file diff --git a/src/mailbox.h b/src/mailbox.h new file mode 100644 index 0000000..03d07b8 --- /dev/null +++ b/src/mailbox.h @@ -0,0 +1,8 @@ +#ifndef MAILBOXH +#define MAILBOXH + +bool mailboxGetMailDetected(void); +void mailboxhandler(void); + + +#endif //MAILBOXH \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 58b344c..7da367f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,9 +1,39 @@ -#include +#include "arduino.h" +#include "time.h" +#include "sleep.h" +#include "net.h" +#include "sensor.h" +#include "display.h" +#include "power.h" +#include "mailbox.h" -void setup() { - // put your setup code here, to run once: +#define TIME_TO_SLEEP 1 /* Time ESP32 will go to sleep (in seconds) */ + +void serialInit(void) +{ + Serial.begin(115200); + Serial.flush(); + delay(50); + Serial.print("Serial initial done\r\n"); } -void loop() { - // put your main code here, to run repeatedly: -} \ No newline at end of file +void setup() +{ + serialInit(); + displayInit(); + sensorInit(); + //netInit(); + powerInit(); + //sleepInit(TIME_TO_SLEEP); + displayUpdate(); +} + +void loop() +{ + powerHandler(); + sensorUpdateDistance(); + displayUpdate(); + mailboxhandler(); + //sleepStart(); + delay(1000); +} diff --git a/src/net.cpp b/src/net.cpp new file mode 100644 index 0000000..5c82b97 --- /dev/null +++ b/src/net.cpp @@ -0,0 +1,33 @@ +#include "Arduino.h" +#include "net.h" +#include + + +// Replace with your network credentials +const char *ssid = "poes"; +const char *password = "Rijnstraat214"; + + +void netInit(void) +{ + Serial.print("Inet init "); + WiFi.begin(ssid, password); + delay(10); + int counter = 30; + while (WiFi.status() != WL_CONNECTED && counter) + { + Serial.print("."); + delay(500); + } + Serial.println("done"); +} + +bool netIsConnected( void ) +{ + return (WiFi.status() == WL_CONNECTED); +} + +const char* netGetSSID( void ) +{ + return ssid; +} diff --git a/src/net.h b/src/net.h new file mode 100644 index 0000000..b06931a --- /dev/null +++ b/src/net.h @@ -0,0 +1,9 @@ +#ifndef NETH +#define NETH + +void netInit(void); +bool netIsConnected( void ); +const char* netGetSSID( void ); + + +#endif //NETH \ No newline at end of file diff --git a/src/power.cpp b/src/power.cpp new file mode 100644 index 0000000..66bc41a --- /dev/null +++ b/src/power.cpp @@ -0,0 +1,171 @@ +#include "arduino.h" +#include "power.h" +#include "hal.h" +#include +#include +#include "display.h" + +#define VOLTAGE_DIVIDER 2.08 // Lora has 220k/100k voltage divider so need to reverse that reduction via (220k+100k)/100k on vbat GPIO37 or ADC1_1 (early revs were GPIO13 or ADC2_4 but do NOT use with WiFi.begin()) +#define DEFAULT_VREF 1100 // Default VREF use if no e-fuse calibration +#define VBATT_SAMPLE 500 // Battery sample rate in ms +#define VBATT_SMOOTH 20 // Number of averages in sample +#define ADC_READ_STABILIZE 50 // in ms (delay from GPIO control and ADC connections times) +#define LO_BATT_SLEEP_TIME 10 * 60 * 1000 * 1000 // How long when low batt to stay in sleep (us) +#define __DEBUG 0 // DEBUG Serial output + +uint16_t Sample(); + + +esp_adc_cal_characteristics_t *adc_chars; + +uint16_t voltage = 666; + +void powerInit(void) +{ +#if (ENVIRONMENT == HELTECv21) + adc_chars = (esp_adc_cal_characteristics_t *)calloc(1, sizeof(esp_adc_cal_characteristics_t)); + esp_adc_cal_value_t val_type = esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_6, ADC_WIDTH_BIT_12, DEFAULT_VREF, adc_chars); + adc1_config_width(ADC_WIDTH_BIT_12); + adc1_config_channel_atten(VBATT, ADC_ATTEN_DB_6); +#else + // Use this for older V2.0 with VBatt reading wired to GPIO13 + adc_chars = (esp_adc_cal_characteristics_t *)calloc(1, sizeof(esp_adc_cal_characteristics_t)); + esp_adc_cal_value_t val_type = esp_adc_cal_characterize(ADC_UNIT_2, ADC_ATTEN_DB_6, ADC_WIDTH_BIT_12, DEFAULT_VREF, adc_chars); + adc2_config_channel_atten(VBATT, ADC_ATTEN_DB_6); +#endif + + if (val_type) + ; // Suppress warning + + Serial.printf("ADC Calibration: "); + if (val_type == ESP_ADC_CAL_VAL_EFUSE_VREF) + { + Serial.printf("eFuse Vref\n"); + } + else if (val_type == ESP_ADC_CAL_VAL_EFUSE_TP) + { + Serial.printf("Two Point\n"); + } + else + { + Serial.printf("Default[%dmV]\n", DEFAULT_VREF); + } + + Serial.println("Power init: ADC done"); + // Prime the Sample register + for (uint8_t i = 0; i < VBATT_SMOOTH; i++) + { + Sample(); + } + Serial.println("Power init: buffer done"); + pinMode(VEXT, OUTPUT); + //digitalWrite(VEXT, LOW); // ESP32 Lora v2.1 reads on GPIO37 when GPIO21 is low + //delay(ADC_READ_STABILIZE); // let GPIO stabilize + Serial.println("Power init done"); +} + + +uint16_t powerGetVbatt(void) +{ + return voltage; +} + +void powerHandler(void) +{ + voltage = Sample(); + //displayDrawBatt(voltage, voltage < LIGHT_SLEEP_VOLTAGE); + + if (voltage < MINBATT) + { // Low Voltage cut off shut down to protect battery as long as possible + displayDrawShutdown(); + delay(2000); +#if defined(__DEBUG) && __DEBUG > 0 + Serial.printf(" !! Shutting down...low battery volotage: %dmV.\n", voltage); + delay(10); +#endif + esp_sleep_enable_timer_wakeup(LO_BATT_SLEEP_TIME); + esp_deep_sleep_start(); + } + else if (voltage < LIGHT_SLEEP_VOLTAGE) + { // Use light sleep once on battery + uint64_t s = VBATT_SAMPLE; +#if defined(__DEBUG) && __DEBUG > 0 + Serial.printf(" - Light Sleep (%dms)...battery volotage: %dmV.\n", (int)s, voltage); + delay(20); +#endif + esp_sleep_enable_timer_wakeup(s * 1000); // Light Sleep does not flush buffer + esp_light_sleep_start(); + } + delay(ADC_READ_STABILIZE); +} + + +// Heltec WiFi LoRa V2 battery read example +// by Jeff McClain jeff@themcclains.net +// + +// Poll the proper ADC for VBatt on Heltec Lora 32 with GPIO21 toggled +uint16_t ReadVBatt() +{ + int reading = 666; + + digitalWrite(VEXT, LOW); // ESP32 Lora v2.1 reads on GPIO37 when GPIO21 is low + delay(ADC_READ_STABILIZE); // let GPIO stabilize +#if (defined(HELTEC_V2_1)) + pinMode(VBATT, OPEN_DRAIN); // ADC GPIO37 + reading = adc1_get_raw(VBATT); + pinMode(VBATT, INPUT); // Disconnect ADC before GPIO goes back high so we protect ADC from direct connect to VBATT (i.e. no divider) +#else + pinMode(VBATT, OPEN_DRAIN); // ADC GPIO13 + adc2_get_raw(VBATT, ADC_WIDTH_BIT_12, &reading); + pinMode(VBATT, INPUT); // Disconnect ADC before GPIO goes back high so we protect ADC from direct connect to VBATT (i.e. no divider +#endif + uint16_t rawVoltage = esp_adc_cal_raw_to_voltage(reading, adc_chars); + //Serial.printf("battery rawvoltage = %i\n", rawVoltage); + rawVoltage *= VOLTAGE_DIVIDER; + //Serial.printf("battery sample = %i\n", rawVoltage); + //digitalWrite(VEXT, HIGH); // ESP32 Lora v2.1 reads on GPIO37 when GPIO21 is low + + return rawVoltage; + +} + +// Use a buffer to average/sample ADC +uint16_t Sample() +{ + static uint8_t i = 0; + static uint16_t samp[VBATT_SMOOTH]; + static int32_t t = 0; + static bool f = true; + if (f) + { + for (uint8_t c = 0; c < VBATT_SMOOTH; c++) + { + samp[c] = 0; + } + f = false; + } // Initialize the sample array first time + t -= samp[i]; // doing a rolling recording, so remove the old rolled around value out of total and get ready to put new one in. + if (t < 0) + { + t = 0; + } + + // ADC read + samp[i] = ReadVBatt(); +#if defined(__DEBUG) && __DEBUG > 0 + Serial.printf("ADC Raw Reading[%d]: %d", i, voltage); +#endif + t += samp[i]; + + if (++i >= VBATT_SMOOTH) + { + i = 0; + } + uint16_t s = round(((float)t / (float)VBATT_SMOOTH)); +#if defined(__DEBUG) && __DEBUG > 0 + Serial.printf(" Smoothed of %d/%d = %d\n", t, VBATT_S MOOTH, s); +#endif + + return s; +} diff --git a/src/power.h b/src/power.h new file mode 100644 index 0000000..b9fffa5 --- /dev/null +++ b/src/power.h @@ -0,0 +1,10 @@ +#ifndef POWERH +#define POWERH + +void powerInit(void); +void powerHandler(void); +uint16_t powerGetVbatt(void); + + + +#endif //POWERH \ No newline at end of file diff --git a/src/sensor.cpp b/src/sensor.cpp new file mode 100644 index 0000000..4d05d4b --- /dev/null +++ b/src/sensor.cpp @@ -0,0 +1,33 @@ +#include "Arduino.h" +#include "sensor.h" +#include +#include "hal.h" + + +RTC_DATA_ATTR int prevDistance = 0; + +Ultrasonic ultrasonic(TRIGGER, ECHO); +int distance; + +void sensorInit(void) +{ + sensorUpdateDistance(); + Serial.println("sensor Init done"); +} + + +void sensorUpdateDistance(void) +{ + distance = ultrasonic.read(); + Serial.printf("distance= %i CM\n",distance); +} + +int sensorGetDistance(void) +{ + return distance; +} + +int sensorGetPreviousDistance(void) +{ + return prevDistance; +} \ No newline at end of file diff --git a/src/sensor.h b/src/sensor.h new file mode 100644 index 0000000..d992a9f --- /dev/null +++ b/src/sensor.h @@ -0,0 +1,11 @@ +#ifndef SENSORH +#define SENSORH + +void sensorInit(void); +void sensorUpdateDistance(void); +int sensorGetDistance(void); +int sensorGetPreviousDistance(void); + + + +#endif //SENSORH \ No newline at end of file diff --git a/src/sleep.cpp b/src/sleep.cpp new file mode 100644 index 0000000..a2551b7 --- /dev/null +++ b/src/sleep.cpp @@ -0,0 +1,71 @@ +#include "arduino.h" +#include "sleep.h" + +#define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds */ + +RTC_DATA_ATTR int bootCount = 0; + +/* +Method to print the reason by which ESP32 +has been awaken from sleep +*/ +void print_wakeup_reason() +{ + esp_sleep_wakeup_cause_t wakeup_reason; + + wakeup_reason = esp_sleep_get_wakeup_cause(); + + switch (wakeup_reason) + { + case ESP_SLEEP_WAKEUP_EXT0: + Serial.println("Wakeup caused by external signal using RTC_IO"); + break; + case ESP_SLEEP_WAKEUP_EXT1: + Serial.println("Wakeup caused by external signal using RTC_CNTL"); + break; + case ESP_SLEEP_WAKEUP_TIMER: + Serial.println("Wakeup caused by timer"); + break; + case ESP_SLEEP_WAKEUP_TOUCHPAD: + Serial.println("Wakeup caused by touchpad"); + break; + case ESP_SLEEP_WAKEUP_ULP: + Serial.println("Wakeup caused by ULP program"); + break; + default: + Serial.printf("Wakeup was not caused by deep sleep: %d\n", wakeup_reason); + break; + } +} + +void sleepInit(unsigned int duration) +{ + //set wakeup sources + ++bootCount; + Serial.println("Boot number: " + String(bootCount)); + + //Print the wakeup reason for ESP32 + print_wakeup_reason(); + + /* + First we configure the wake up source + We set our ESP32 to wake up every 5 seconds + */ + esp_sleep_enable_timer_wakeup(duration * uS_TO_S_FACTOR); + Serial.println("Setup ESP32 to sleep for every " + String(duration) + + " Seconds"); +} + +void sleepCallback(void) +{ +} + +void sleepStart() +{ + Serial.flush(); + Serial.println("Going to sleep now"); + Serial.flush(); + delay(100); + esp_light_sleep_start(); + Serial.println("Woke"); +} \ No newline at end of file diff --git a/src/sleep.h b/src/sleep.h new file mode 100644 index 0000000..72325a1 --- /dev/null +++ b/src/sleep.h @@ -0,0 +1,9 @@ +#ifndef SLEEPH +#define SLEEPH + +void sleepInit(unsigned int duration ); +void sleepCallback(void); +void sleepStart(); + + +#endif //SLEEPH diff --git a/src/workspace.code-workspace b/src/workspace.code-workspace new file mode 100644 index 0000000..1d086ac --- /dev/null +++ b/src/workspace.code-workspace @@ -0,0 +1,14 @@ +{ + "folders": [ + { + "path": ".." + } + ], + "settings": { + "files.associations": { + "*.tcc": "cpp", + "cmath": "cpp", + "random": "cpp" + } + } +} \ No newline at end of file