This commit is contained in:
6
.vscode/settings.json
vendored
Normal file
6
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"iostream": "cpp",
|
||||||
|
"random": "cpp"
|
||||||
|
}
|
||||||
|
}
|
||||||
1
lib/infinityPV_INA233_Arduino-library
Submodule
1
lib/infinityPV_INA233_Arduino-library
Submodule
Submodule lib/infinityPV_INA233_Arduino-library added at bc68e03c01
@@ -19,5 +19,5 @@ lib_deps =
|
|||||||
bblanchon/ArduinoJson@^6.21.3
|
bblanchon/ArduinoJson@^6.21.3
|
||||||
ArduinoLog
|
ArduinoLog
|
||||||
upload_protocol = espota
|
upload_protocol = espota
|
||||||
upload_port = 192.168.5.181
|
upload_port = 192.168.5.242
|
||||||
lib_extra_dirs = libs
|
lib_extra_dirs = libs
|
||||||
|
|||||||
96
src/external_interfacing/leds.cpp
Normal file
96
src/external_interfacing/leds.cpp
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
#include "leds.h"
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <ArduinoLog.h>
|
||||||
|
#include "tools/tools.h"
|
||||||
|
|
||||||
|
extern ActiveErrors active_errors;
|
||||||
|
extern WaterData water_data;
|
||||||
|
|
||||||
|
void display_percentage(float percentage)
|
||||||
|
{
|
||||||
|
digitalWrite(LED_RED, 0);
|
||||||
|
|
||||||
|
if (percentage > 0) {
|
||||||
|
digitalWrite(LED_1, 1);
|
||||||
|
} else {
|
||||||
|
digitalWrite(LED_1, 0);
|
||||||
|
}
|
||||||
|
if (percentage > 20) {
|
||||||
|
digitalWrite(LED_2, 1);
|
||||||
|
} else {
|
||||||
|
digitalWrite(LED_2, 0);
|
||||||
|
}
|
||||||
|
if (percentage > 40) {
|
||||||
|
digitalWrite(LED_3, 1);
|
||||||
|
} else {
|
||||||
|
digitalWrite(LED_3, 0);
|
||||||
|
}
|
||||||
|
if (percentage > 60) {
|
||||||
|
digitalWrite(LED_4, 1);
|
||||||
|
} else {
|
||||||
|
digitalWrite(LED_4, 0);
|
||||||
|
}
|
||||||
|
if (percentage > 80) {
|
||||||
|
digitalWrite(LED_5, 1);
|
||||||
|
} else {
|
||||||
|
digitalWrite(LED_5, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (percentage > 10) {
|
||||||
|
delay(3000);
|
||||||
|
} else if (percentage > 0) {
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
digitalWrite(LED_1, 1);
|
||||||
|
delay(500);
|
||||||
|
digitalWrite(LED_1, 0);
|
||||||
|
delay(500);
|
||||||
|
}
|
||||||
|
} else if (percentage <= 0) {
|
||||||
|
for (int i = 0; i < 15; i++) {
|
||||||
|
digitalWrite(LED_1, 1);
|
||||||
|
delay(100);
|
||||||
|
digitalWrite(LED_1, 0);
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void display_error_code(byte err_code)
|
||||||
|
{
|
||||||
|
digitalWrite(LED_RED, 1);
|
||||||
|
digitalWrite(LED_1, bitRead(err_code, 0));
|
||||||
|
digitalWrite(LED_2, bitRead(err_code, 1));
|
||||||
|
digitalWrite(LED_3, bitRead(err_code, 2));
|
||||||
|
digitalWrite(LED_4, bitRead(err_code, 3));
|
||||||
|
digitalWrite(LED_5, bitRead(err_code, 4));
|
||||||
|
}
|
||||||
|
|
||||||
|
void display_task(void* parameter)
|
||||||
|
{
|
||||||
|
while (true) {
|
||||||
|
if (!is_error(active_errors)) {
|
||||||
|
// We have no error, refresh status display and wait half a second
|
||||||
|
display_percentage(water_data.percentage);
|
||||||
|
} else {
|
||||||
|
Log.verbose("Error detected");
|
||||||
|
|
||||||
|
// We have an error, display error code for 3 seconds and then water level for 3 seconds
|
||||||
|
if (active_errors.voltage_low) {
|
||||||
|
display_error_code(1);
|
||||||
|
delay(3000);
|
||||||
|
} else if (active_errors.voltage_high) {
|
||||||
|
display_error_code(2);
|
||||||
|
delay(3000);
|
||||||
|
} else if (active_errors.current_low) {
|
||||||
|
display_error_code(3);
|
||||||
|
delay(3000);
|
||||||
|
} else if (active_errors.current_high) {
|
||||||
|
display_error_code(4);
|
||||||
|
delay(3000);
|
||||||
|
} else {
|
||||||
|
delay(3000);
|
||||||
|
}
|
||||||
|
display_percentage(water_data.percentage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
12
src/external_interfacing/leds.h
Normal file
12
src/external_interfacing/leds.h
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#define LED_1 4
|
||||||
|
#define LED_2 2
|
||||||
|
#define LED_3 15
|
||||||
|
#define LED_4 13
|
||||||
|
#define LED_5 12
|
||||||
|
#define LED_RED 14
|
||||||
|
|
||||||
|
void display_percentage(float percentage);
|
||||||
|
void display_error_code(byte err_code);
|
||||||
|
void display_task(void* parameter);
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "global_data.h"
|
#include "global_data/global_data.h"
|
||||||
|
|
||||||
NetworkData wifi_data;
|
NetworkData wifi_data;
|
||||||
NetworkData ethernet_data;
|
NetworkData ethernet_data;
|
||||||
|
|||||||
135
src/main.cpp
135
src/main.cpp
@@ -20,140 +20,24 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <Preferences.h>
|
#include <Preferences.h>
|
||||||
#include "global_data/global_data.h"
|
|
||||||
#include "sensor/sensor.h"
|
#include "sensor/sensor.h"
|
||||||
|
#include "external_interfacing/leds.h"
|
||||||
|
#include "tools/tools.h"
|
||||||
|
|
||||||
#define LED_1 4
|
Preferences prefs;
|
||||||
#define LED_2 2
|
|
||||||
#define LED_3 15
|
extern WaterData water_data;
|
||||||
#define LED_4 13
|
extern DeviceTelemetry telemetry;
|
||||||
#define LED_5 12
|
extern NetworkData wifi_data;
|
||||||
#define LED_RED 14
|
extern NetworkData ethernet_data;
|
||||||
|
extern SensorData shunt_data;
|
||||||
|
|
||||||
extern "C" int rom_phy_get_vdd33();
|
extern "C" int rom_phy_get_vdd33();
|
||||||
|
|
||||||
|
|
||||||
extern NetworkData wifi_data;
|
|
||||||
extern NetworkData ethernet_data;
|
|
||||||
extern DeviceTelemetry telemetry;
|
|
||||||
|
|
||||||
extern SensorData shunt_data;
|
|
||||||
extern WaterData water_data;
|
|
||||||
|
|
||||||
extern ActiveErrors active_errors;
|
|
||||||
|
|
||||||
Preferences prefs;
|
|
||||||
|
|
||||||
AsyncWebServer server(80);
|
AsyncWebServer server(80);
|
||||||
#define FORMAT_LITTLEFS_IF_FAILED true
|
#define FORMAT_LITTLEFS_IF_FAILED true
|
||||||
|
|
||||||
void display_percentage(float percentage)
|
|
||||||
{
|
|
||||||
digitalWrite(LED_RED, 0);
|
|
||||||
|
|
||||||
if (percentage > 0) {
|
|
||||||
digitalWrite(LED_1, 1);
|
|
||||||
} else {
|
|
||||||
digitalWrite(LED_1, 0);
|
|
||||||
}
|
|
||||||
if (percentage > 20) {
|
|
||||||
digitalWrite(LED_2, 1);
|
|
||||||
} else {
|
|
||||||
digitalWrite(LED_2, 0);
|
|
||||||
}
|
|
||||||
if (percentage > 40) {
|
|
||||||
digitalWrite(LED_3, 1);
|
|
||||||
} else {
|
|
||||||
digitalWrite(LED_3, 0);
|
|
||||||
}
|
|
||||||
if (percentage > 60) {
|
|
||||||
digitalWrite(LED_4, 1);
|
|
||||||
} else {
|
|
||||||
digitalWrite(LED_4, 0);
|
|
||||||
}
|
|
||||||
if (percentage > 80) {
|
|
||||||
digitalWrite(LED_5, 1);
|
|
||||||
} else {
|
|
||||||
digitalWrite(LED_5, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (percentage > 10) {
|
|
||||||
delay(3000);
|
|
||||||
} else if (percentage > 0) {
|
|
||||||
for (int i = 0; i < 3; i++) {
|
|
||||||
digitalWrite(LED_1, 1);
|
|
||||||
delay(500);
|
|
||||||
digitalWrite(LED_1, 0);
|
|
||||||
delay(500);
|
|
||||||
}
|
|
||||||
} else if (percentage <= 0) {
|
|
||||||
for (int i = 0; i < 15; i++) {
|
|
||||||
digitalWrite(LED_1, 1);
|
|
||||||
delay(100);
|
|
||||||
digitalWrite(LED_1, 0);
|
|
||||||
delay(100);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void display_error_code(byte err_code)
|
|
||||||
{
|
|
||||||
digitalWrite(LED_RED, 1);
|
|
||||||
digitalWrite(LED_1, bitRead(err_code, 0));
|
|
||||||
digitalWrite(LED_2, bitRead(err_code, 1));
|
|
||||||
digitalWrite(LED_3, bitRead(err_code, 2));
|
|
||||||
digitalWrite(LED_4, bitRead(err_code, 3));
|
|
||||||
digitalWrite(LED_5, bitRead(err_code, 4));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool is_error()
|
|
||||||
{
|
|
||||||
return active_errors.voltage_high || active_errors.voltage_low || active_errors.current_high || active_errors.current_low;
|
|
||||||
}
|
|
||||||
|
|
||||||
void printSuffix(Print* _logOutput, int logLevel)
|
|
||||||
{
|
|
||||||
_logOutput->print(CR);
|
|
||||||
}
|
|
||||||
|
|
||||||
void print_prefix(Print* _logOutput, int logLevel)
|
|
||||||
{
|
|
||||||
_logOutput->print("WATERMETER - C");
|
|
||||||
_logOutput->print(xPortGetCoreID());
|
|
||||||
_logOutput->print(" - ");
|
|
||||||
_logOutput->print(pcTaskGetName(xTaskGetCurrentTaskHandle()));
|
|
||||||
_logOutput->print(" - ");
|
|
||||||
}
|
|
||||||
|
|
||||||
void display_task(void* parameter)
|
|
||||||
{
|
|
||||||
while (true) {
|
|
||||||
if (!is_error()) {
|
|
||||||
// We have no error, refresh status display and wait half a second
|
|
||||||
display_percentage(water_data.percentage);
|
|
||||||
} else {
|
|
||||||
Log.verbose("Error detected");
|
|
||||||
|
|
||||||
// We have an error, display error code for 3 seconds and then water level for 3 seconds
|
|
||||||
if (active_errors.voltage_low) {
|
|
||||||
display_error_code(1);
|
|
||||||
delay(3000);
|
|
||||||
} else if (active_errors.voltage_high) {
|
|
||||||
display_error_code(2);
|
|
||||||
delay(3000);
|
|
||||||
} else if (active_errors.current_low) {
|
|
||||||
display_error_code(3);
|
|
||||||
delay(3000);
|
|
||||||
} else if (active_errors.current_high) {
|
|
||||||
display_error_code(4);
|
|
||||||
delay(3000);
|
|
||||||
} else {
|
|
||||||
delay(3000);
|
|
||||||
}
|
|
||||||
display_percentage(water_data.percentage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void collect_internal_telemetry_task(void* parameter)
|
void collect_internal_telemetry_task(void* parameter)
|
||||||
{
|
{
|
||||||
@@ -168,7 +52,6 @@ void collect_internal_telemetry_task(void* parameter)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
String processor(const String& var)
|
String processor(const String& var)
|
||||||
{
|
{
|
||||||
if (var == level_sensor_range_key) {
|
if (var == level_sensor_range_key) {
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
#include <ETH.h>
|
#include <ETH.h>
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#include "../global_data/defines.h"
|
#include "../global_data/defines.h"
|
||||||
#include "../global_data/global_data.h"
|
|
||||||
#include <Preferences.h>
|
#include <Preferences.h>
|
||||||
|
#include <global_data/global_data.h>
|
||||||
|
|
||||||
int64_t mac_address = ESP.getEfuseMac();
|
int64_t mac_address = ESP.getEfuseMac();
|
||||||
uint8_t failed_connection_attempts = 0;
|
uint8_t failed_connection_attempts = 0;
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
#include <INA233.h>
|
#include <INA233.h>
|
||||||
#include <Preferences.h>
|
#include <Preferences.h>
|
||||||
#include <ArduinoLog.h>
|
#include <ArduinoLog.h>
|
||||||
#include "../global_data/global_data.h"
|
|
||||||
#include "Wire.h"
|
#include "Wire.h"
|
||||||
|
#include <global_data/global_data.h>
|
||||||
|
|
||||||
|
|
||||||
#ifdef USE_INA226s
|
#ifdef USE_INA226s
|
||||||
|
|||||||
21
src/tools/tools.cpp
Normal file
21
src/tools/tools.cpp
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
#include "tools.h"
|
||||||
|
#include <ArduinoLog.h>
|
||||||
|
|
||||||
|
void printSuffix(Print* _logOutput, int logLevel)
|
||||||
|
{
|
||||||
|
_logOutput->print(CR);
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_prefix(Print* _logOutput, int logLevel)
|
||||||
|
{
|
||||||
|
_logOutput->print("WATERMETER - C");
|
||||||
|
_logOutput->print(xPortGetCoreID());
|
||||||
|
_logOutput->print(" - ");
|
||||||
|
_logOutput->print(pcTaskGetName(xTaskGetCurrentTaskHandle()));
|
||||||
|
_logOutput->print(" - ");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_error(ActiveErrors active_errors) {
|
||||||
|
return active_errors.current_high || active_errors.current_low || active_errors.level_high || active_errors.level_low || active_errors.voltage_high || active_errors.voltage_low;
|
||||||
|
}
|
||||||
6
src/tools/tools.h
Normal file
6
src/tools/tools.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
#include <global_data/global_data.h>
|
||||||
|
|
||||||
|
void printSuffix(Print* _logOutput, int logLevel);
|
||||||
|
void print_prefix(Print* _logOutput, int logLevel);
|
||||||
|
bool is_error(ActiveErrors active_errors);
|
||||||
Reference in New Issue
Block a user