Skip to content

Commit

Permalink
Merge branch 'main' into feature/LEAF-charger
Browse files Browse the repository at this point in the history
  • Loading branch information
dalathegreat authored Feb 2, 2024
2 parents 3117852 + 38524e2 commit 82379dd
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 79 deletions.
46 changes: 46 additions & 0 deletions Software/Software.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* Only change battery specific settings in "USER_SETTINGS.h" */

#include <Arduino.h>
#include <Preferences.h>
#include "HardwareSerial.h"
#include "USER_SETTINGS.h"
#include "src/battery/BATTERIES.h"
Expand All @@ -19,6 +20,8 @@
#include "src/devboard/webserver/webserver.h"
#endif

Preferences settings; // Store user settings

// Interval settings
int intervalUpdateValues = 4800; // Interval at which to update inverter values / Modbus registers
const int interval10 = 10; // Interval for 10ms tasks
Expand Down Expand Up @@ -119,6 +122,8 @@ bool inverterAllowsContactorClosing = true;
void setup() {
init_serial();

init_stored_settings();

#ifdef WEBSERVER
init_webserver();
#endif
Expand Down Expand Up @@ -186,6 +191,37 @@ void init_serial() {
Serial.println("__ OK __");
}

void init_stored_settings() {
settings.begin("batterySettings", false);

#ifndef LOAD_SAVED_SETTINGS_ON_BOOT
settings.clear(); // If this clear function is executed, no settings will be read from storage
#endif

static uint16_t temp = 0;
temp = settings.getUInt("BATTERY_WH_MAX", false);
if (temp != 0) {
BATTERY_WH_MAX = temp;
}
temp = settings.getUInt("MAXPERCENTAGE", false);
if (temp != 0) {
MAXPERCENTAGE = temp;
}
temp = settings.getUInt("MINPERCENTAGE", false);
if (temp != 0) {
MINPERCENTAGE = temp;
}
temp = settings.getUInt("MAXCHARGEAMP", false);
if (temp != 0) {
MAXCHARGEAMP = temp;
}
temp = settings.getUInt("MAXDISCHARGEAMP", false);
if (temp != 0) {
MAXDISCHARGEAMP = temp;
}
settings.end();
}

void init_CAN() {
// CAN pins
pinMode(CAN_SE_PIN, OUTPUT);
Expand Down Expand Up @@ -699,3 +735,13 @@ void init_serialDataLink() {
Serial2.begin(9600, SERIAL_8N1, RS485_RX_PIN, RS485_TX_PIN);
#endif
}

void storeSettings() {
settings.begin("batterySettings", false);
settings.putUInt("BATTERY_WH_MAX", BATTERY_WH_MAX);
settings.putUInt("MAXPERCENTAGE", MAXPERCENTAGE);
settings.putUInt("MINPERCENTAGE", MINPERCENTAGE);
settings.putUInt("MAXCHARGEAMP", MAXCHARGEAMP);
settings.putUInt("MAXDISCHARGEAMP", MAXDISCHARGEAMP);
settings.end();
}
2 changes: 1 addition & 1 deletion Software/USER_SETTINGS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ const char* ssid = "REPLACE_WITH_YOUR_SSID"; // Maximum of 63 character
const char* password = "REPLACE_WITH_YOUR_PASSWORD"; // Minimum of 8 characters;
const char* ssidAP = "Battery Emulator"; // Maximum of 63 characters;
const char* passwordAP = "123456789"; // Minimum of 8 characters; set to NULL if you want the access point to be open
const char* versionNumber = "4.4.0"; // The current software version, shown on webserver
const char* versionNumber = "4.5.0"; // The current software version, shown on webserver
#endif
3 changes: 2 additions & 1 deletion Software/USER_SETTINGS.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
//#define DUAL_CAN //Enable this line to activate an isolated secondary CAN Bus using add-on MCP2515 controller (Needed for FoxESS inverters)
//#define SERIAL_LINK_RECEIVER //Enable this line to receive battery data over RS485 pins from another Lilygo (This LilyGo interfaces with inverter)
//#define SERIAL_LINK_TRANSMITTER //Enable this line to send battery data over RS485 pins to another Lilygo (This LilyGo interfaces with battery)
//#define WEBSERVER //Enable this line to enable WiFi, and to run the webserver. See USER_SETTINGS.cpp for the Wifi settings.
#define WEBSERVER //Enable this line to enable WiFi, and to run the webserver. See USER_SETTINGS.cpp for the Wifi settings.
#define LOAD_SAVED_SETTINGS_ON_BOOT //Enable this line to read settings stored via the webserver on boot

/* Select charger used (Optional) */
//#define CHEVYVOLT_CHARGER //Enable this line to control a Chevrolet Volt charger connected to battery - for example, when generator charging or using an inverter without a charging function.
Expand Down
Loading

0 comments on commit 82379dd

Please sign in to comment.