Release 0.1 - without LORA
This commit is contained in:
parent
bab9d3e5d2
commit
da2f84482e
|
|
@ -48,13 +48,26 @@ void Eink::show_temp(float temperature)
|
||||||
{
|
{
|
||||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "EINK", "Show temp: %f", temperature);
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "EINK", "Show temp: %f", temperature);
|
||||||
|
|
||||||
int textX = 40;
|
int textX = 50;
|
||||||
//u8g2Fonts.setFont(u8g2_font_fur42_tf);
|
//u8g2Fonts.setFont(u8g2_font_fur42_tf);
|
||||||
u8g2Fonts.setFont(u8g2_font_inr46_mf);
|
u8g2Fonts.setFont(u8g2_font_inb46_mf);
|
||||||
|
|
||||||
drawString(textX, 70, String(temperature, 1) + "°", LEFT);
|
drawString(textX, 70, String(temperature, 1) + "°", LEFT);
|
||||||
drawMercury(temperature);
|
drawMercury(temperature);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Eink::show_internal_temp(int x, int y, float temperature)
|
||||||
|
{
|
||||||
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "EINK", "Show internal temp: %f", temperature);
|
||||||
|
u8g2Fonts.setFont(u8g2_font_7x13_tf);
|
||||||
|
drawString(x + 60, y - 11, String(temperature, 1) + "°", LEFT);
|
||||||
|
}
|
||||||
|
void Eink::show_count(int x, int y, float cnt, String unit)
|
||||||
|
{
|
||||||
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "EINK", "Show cnt: %f", cnt);
|
||||||
|
u8g2Fonts.setFont(u8g2_font_7x13_tf);
|
||||||
|
drawString(x + 60, y - 11, unit + String(cnt, 1), LEFT);
|
||||||
|
}
|
||||||
void Eink::drawSignalBars(int x, int y, int percentage)
|
void Eink::drawSignalBars(int x, int y, int percentage)
|
||||||
{
|
{
|
||||||
// Define stapler properties
|
// Define stapler properties
|
||||||
|
|
@ -99,7 +112,9 @@ void Eink::drawMercury(float temperature)
|
||||||
int y = 30;
|
int y = 30;
|
||||||
int height = 60;
|
int height = 60;
|
||||||
int width = 10;
|
int width = 10;
|
||||||
int mercuryLevel = map(temperature, 0.0, 100.0, 20, height);
|
int mercuryLevel = map(temperature, 5.0, 35.0, 10, height);
|
||||||
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "EINK", "mercuryLevel: %d", mercuryLevel);
|
||||||
|
|
||||||
int radius = 14;
|
int radius = 14;
|
||||||
eink.drawRect(x, y - radius + 2, width, height, GxEPD_BLACK);
|
eink.drawRect(x, y - radius + 2, width, height, GxEPD_BLACK);
|
||||||
|
|
||||||
|
|
@ -125,9 +140,6 @@ void Eink::drawBattery(int x, int y, int percentage)
|
||||||
|
|
||||||
void Eink::drawString(int x, int y, String text, alignmentType alignment)
|
void Eink::drawString(int x, int y, String text, alignmentType alignment)
|
||||||
{
|
{
|
||||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "EINK drawstring", "x: %d", y);
|
|
||||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "EINK drawstring", "y: %d", x);
|
|
||||||
|
|
||||||
int16_t x1, y1; // the bounds of x,y and w and h of the variable 'text' in pixels.
|
int16_t x1, y1; // the bounds of x,y and w and h of the variable 'text' in pixels.
|
||||||
uint16_t w, h;
|
uint16_t w, h;
|
||||||
eink.setTextWrap(false);
|
eink.setTextWrap(false);
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,10 @@
|
||||||
class Eink {
|
class Eink {
|
||||||
public:
|
public:
|
||||||
Eink(int csPin = EPD_CS, int dcPin = EPD_DC, int rstPin = EPD_RSET, int busyPin = EPD_BUSY);
|
Eink(int csPin = EPD_CS, int dcPin = EPD_DC, int rstPin = EPD_RSET, int busyPin = EPD_BUSY);
|
||||||
|
|
||||||
void setup_eink();
|
void setup_eink();
|
||||||
void show_temp(float temperature);
|
void show_temp(float temperature);
|
||||||
|
void show_internal_temp(int x, int y, float temperature);
|
||||||
|
void show_count(int x, int y, float cnt, String unit);
|
||||||
void show_display(String header, int wait=100);
|
void show_display(String header, int wait=100);
|
||||||
void drawBattery(int x, int y, int percentage=100);
|
void drawBattery(int x, int y, int percentage=100);
|
||||||
void drawSignalBars(int x, int y, int numBars);
|
void drawSignalBars(int x, int y, int numBars);
|
||||||
|
|
@ -20,13 +21,10 @@ public:
|
||||||
private:
|
private:
|
||||||
U8G2_FOR_ADAFRUIT_GFX u8g2Fonts;
|
U8G2_FOR_ADAFRUIT_GFX u8g2Fonts;
|
||||||
enum alignmentType {LEFT, RIGHT, CENTER};
|
enum alignmentType {LEFT, RIGHT, CENTER};
|
||||||
|
|
||||||
void drawMercury(float temperature);
|
void drawMercury(float temperature);
|
||||||
void drawString(int x, int y, String text, alignmentType alignment);
|
void drawString(int x, int y, String text, alignmentType alignment);
|
||||||
void drawCircleSegment(int x0, int y0, int radius, int startAngle, int endAngle);
|
void drawCircleSegment(int x0, int y0, int radius, int startAngle, int endAngle);
|
||||||
// GxEPD2_213_BN epd;
|
|
||||||
GxEPD2_BW<GxEPD2_213_BN, GxEPD2_213_BN::HEIGHT> eink;
|
GxEPD2_BW<GxEPD2_213_BN, GxEPD2_213_BN::HEIGHT> eink;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,64 +2,96 @@
|
||||||
#include "io.hpp"
|
#include "io.hpp"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "pins.hpp"
|
#include "pins.hpp"
|
||||||
#include "WiFi.h"
|
#include "WiFi.h"
|
||||||
#include "driver/adc.h"
|
#include "driver/adc.h"
|
||||||
#include <esp_wifi.h>
|
#include <esp_wifi.h>
|
||||||
#include <esp_bt.h>
|
#include <esp_bt.h>
|
||||||
|
|
||||||
|
|
||||||
extern logging::Logger logger;
|
extern logging::Logger logger;
|
||||||
|
|
||||||
IO::IO() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void IO::setup_io() {
|
IO::IO() : oneWire(DI_DALLAS), sensors(&oneWire) {
|
||||||
oneWire.begin(DI_DALLAS);
|
// Constructor body (if needed)
|
||||||
sensors.begin();
|
|
||||||
sensors.setResolution(10);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void IO::set_low_power() {
|
#define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds */
|
||||||
digitalWrite ( DI_LED, LOW );
|
#define TIME_TO_SLEEP 600
|
||||||
setCpuFrequencyMhz(80);
|
|
||||||
WiFi.mode(WIFI_OFF);
|
|
||||||
btStop();
|
|
||||||
|
|
||||||
|
void IO::setup_io()
|
||||||
|
{
|
||||||
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "IO", "SETUP IO");
|
||||||
|
oneWire.begin(DI_DALLAS);
|
||||||
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "IO", "oneWire.begin");
|
||||||
|
sensors.begin();
|
||||||
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "IO", "sensors.begi");
|
||||||
|
sensors.setResolution(12);
|
||||||
|
}
|
||||||
|
|
||||||
|
void IO::set_low_power()
|
||||||
|
{
|
||||||
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "IO", "Set lower power attrs");
|
||||||
|
|
||||||
|
pinMode(DI_LED, OUTPUT);
|
||||||
|
digitalWrite(DI_LED, LOW); // TODO check if pin 22(ledbuiltin 2) is a led
|
||||||
|
setCpuFrequencyMhz(80);
|
||||||
|
WiFi.mode(WIFI_OFF);
|
||||||
|
btStop();
|
||||||
esp_wifi_stop();
|
esp_wifi_stop();
|
||||||
esp_bt_controller_disable();
|
esp_bt_controller_disable();
|
||||||
|
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
|
||||||
|
adc_power_on();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t IO::read_battery() {
|
void IO::set_deep_sleep()
|
||||||
|
{
|
||||||
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "IO", "Going to sleep");
|
||||||
|
esp_deep_sleep_start();
|
||||||
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "IO", "Will not reach");
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t IO::read_battery()
|
||||||
|
{
|
||||||
uint8_t percentage = 100;
|
uint8_t percentage = 100;
|
||||||
|
|
||||||
float voltage = analogRead(ADC_BATTERY) / 4096.0 * 7.46;
|
float voltage = analogRead(ADC_BATTERY) / 4096.0 * 7.46;
|
||||||
//float voltage = analogRead(35) / 4096.0 * 7.46;
|
// float voltage = analogRead(35) / 4096.0 * 7.46;
|
||||||
if (voltage > 1 ) { // Only display if there is a valid reading
|
if (voltage > 1)
|
||||||
|
{ // Only display if there is a valid reading
|
||||||
percentage = 2836.9625 * pow(voltage, 4) - 43987.4889 * pow(voltage, 3) + 255233.8134 * pow(voltage, 2) - 656689.7123 * voltage + 632041.7303;
|
percentage = 2836.9625 * pow(voltage, 4) - 43987.4889 * pow(voltage, 3) + 255233.8134 * pow(voltage, 2) - 656689.7123 * voltage + 632041.7303;
|
||||||
if (voltage >= 4.20) percentage = 100;
|
if (voltage >= 4.20)
|
||||||
if (voltage <= 3.50) percentage = 0;
|
percentage = 100;
|
||||||
|
if (voltage <= 3.50)
|
||||||
|
percentage = 0;
|
||||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "io", "Voltage: %f", voltage);
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "io", "Voltage: %f", voltage);
|
||||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "io", "Percentage: %d", percentage);
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "io", "Percentage: %d", percentage);
|
||||||
}
|
}
|
||||||
|
|
||||||
return percentage;
|
return percentage;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float IO::read_temp() {
|
float IO::read_temp()
|
||||||
|
{
|
||||||
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "IO", "read_temp");
|
||||||
sensors.requestTemperatures(); // Request temperature readings
|
sensors.requestTemperatures(); // Request temperature readings
|
||||||
|
delay(1000);
|
||||||
float tempC = sensors.getTempCByIndex(0);
|
float tempC = sensors.getTempCByIndex(0);
|
||||||
if (tempC != DEVICE_DISCONNECTED_C)
|
if (tempC != DEVICE_DISCONNECTED_C)
|
||||||
{
|
{
|
||||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "io", "Temp: %f", tempC);
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "io", "Temp: %f", tempC);
|
||||||
}else{
|
|
||||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "io", "Couldn't read temp");
|
|
||||||
}
|
}
|
||||||
|
else if(tempC == -127.00) {
|
||||||
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "io", "Couldn't read temp");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "io", "Couldn't read temp");
|
||||||
|
}
|
||||||
|
return tempC;
|
||||||
|
}
|
||||||
|
|
||||||
|
float IO::read_internal_temp()
|
||||||
|
{
|
||||||
float chipTemp = temperatureRead();
|
float chipTemp = temperatureRead();
|
||||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "io", "chipTemp: %f", chipTemp);
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "io", "chipTemp: %f", chipTemp);
|
||||||
return tempC;
|
return chipTemp;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -11,12 +11,13 @@ public:
|
||||||
IO();
|
IO();
|
||||||
void setup_io();
|
void setup_io();
|
||||||
void set_low_power();
|
void set_low_power();
|
||||||
|
void set_deep_sleep();
|
||||||
float read_temp();
|
float read_temp();
|
||||||
|
float read_internal_temp();
|
||||||
uint8_t read_battery();
|
uint8_t read_battery();
|
||||||
private:
|
private:
|
||||||
OneWire oneWire;
|
OneWire oneWire;
|
||||||
DallasTemperature sensors;
|
DallasTemperature sensors;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* IO_H */
|
#endif /* IO_H */
|
||||||
|
|
@ -7,35 +7,60 @@ logging::Logger logger;
|
||||||
Eink eink;
|
Eink eink;
|
||||||
IO io;
|
IO io;
|
||||||
|
|
||||||
|
RTC_DATA_ATTR int bootCount = 0;
|
||||||
|
RTC_DATA_ATTR int updateCount = 0;
|
||||||
|
RTC_DATA_ATTR float last_temp = 20;
|
||||||
|
RTC_DATA_ATTR int last_battery = 0;
|
||||||
|
bool update = false;
|
||||||
|
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
// TODO check if pin 22(ledbuiltin 2) is a led
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "MAIN", "Boot number: %i", bootCount);
|
||||||
|
update = false;
|
||||||
#ifndef DEBUG
|
#ifndef DEBUG
|
||||||
logger.setDebugLevel(logging::LoggerLevel::LOGGER_LEVEL_INFO);
|
logger.setDebugLevel(logging::LoggerLevel::LOGGER_LEVEL_INFO);
|
||||||
#endif
|
#endif
|
||||||
//delay(100);
|
|
||||||
io.set_low_power();
|
|
||||||
io.setup_io();
|
io.setup_io();
|
||||||
|
io.set_low_power();
|
||||||
|
|
||||||
uint8_t battery = io.read_battery();
|
uint8_t battery = io.read_battery();
|
||||||
|
if (abs(battery - last_battery) >= 2)
|
||||||
|
{
|
||||||
|
last_battery = battery;
|
||||||
|
update = true;
|
||||||
|
}
|
||||||
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "MAIN", "Battery: %i", battery);
|
||||||
|
|
||||||
float temp = io.read_temp();
|
float temp = io.read_temp();
|
||||||
eink.setup_eink();
|
|
||||||
// delay(100);
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "MAIN", "TEMP: %f", temp);
|
||||||
|
if (abs(temp - last_temp) >= 0.5 && temp > -120)
|
||||||
|
{
|
||||||
|
last_temp = temp;
|
||||||
|
update = true;
|
||||||
|
}
|
||||||
|
|
||||||
eink.drawBattery(186, 14, battery); // eink width 250 - drawbattery width
|
float internal_temp = io.read_internal_temp();
|
||||||
eink.drawSignalBars(180 - 24 - 4, 12, 84); // drawbattery width - drawsignal
|
eink.setup_eink();
|
||||||
eink.show_temp(30.0);
|
|
||||||
eink.display();
|
++bootCount;
|
||||||
|
if (update)
|
||||||
|
{
|
||||||
|
++updateCount;
|
||||||
|
eink.drawBattery(186, 14, battery); // eink width 250 - drawbattery width
|
||||||
|
eink.drawSignalBars(180 - 24 - 4, 12, 84); // drawbattery width - drawsignal
|
||||||
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "MAIN", "TEMP: %f", temp);
|
||||||
|
eink.show_temp(temp);
|
||||||
|
eink.show_internal_temp(180 - 24 - 4 - 100, 12, internal_temp);
|
||||||
|
eink.show_count(180 - 24 - 4 - 100 - 60, 12, (float)bootCount, "c: ");
|
||||||
|
eink.show_count(180 - 24 - 4 - 100 - 60 - 50, 12, (float)bootCount, "u: ");
|
||||||
|
eink.display(true);
|
||||||
|
}
|
||||||
|
io.set_deep_sleep();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
eink.show_temp(30.0);
|
|
||||||
eink.display(true);
|
|
||||||
sleep(10);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,9 @@ const int RADIO_RST = 14;
|
||||||
const int RADIO_IRQ = 26; // IRQ --> DIO0
|
const int RADIO_IRQ = 26; // IRQ --> DIO0
|
||||||
|
|
||||||
// Battery pin
|
// Battery pin
|
||||||
const int ADC_BATTERY = 12; //builtin = 35
|
const int ADC_BATTERY = 35; //builtin = 35
|
||||||
|
|
||||||
const int DI_DALLAS = 32;
|
const int DI_DALLAS = 32;
|
||||||
// Builtin LED
|
// Builtin LED
|
||||||
const int DI_LED = 22;
|
const int DI_LED = LED_BUILTIN;
|
||||||
#endif /* PINS_H */
|
#endif /* PINS_H */
|
||||||
Loading…
Reference in New Issue