Skip to content

Commit

Permalink
Merge branch 'master' into websocket-new
Browse files Browse the repository at this point in the history
  • Loading branch information
arfrie22 committed Jun 19, 2024
2 parents f7673aa + e0f567b commit 447b649
Show file tree
Hide file tree
Showing 18 changed files with 158 additions and 137 deletions.
4 changes: 2 additions & 2 deletions I2CRTC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ bool I2CRTC::detect()
}

// PUBLIC FUNCTIONS
time_t I2CRTC::get() // Aquire data from buffer and convert to time_t
time_os_t I2CRTC::get() // Aquire data from buffer and convert to time_os_t
{
tmElements_t tm;
read(tm);
return(makeTime(tm));
}

void I2CRTC::set(time_t t)
void I2CRTC::set(time_os_t t)
{
tmElements_t tm;
breakTime(t, tm);
Expand Down
5 changes: 3 additions & 2 deletions I2CRTC.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define MCP7940_ADDR 0x6F
#define PCF8563_ADDR 0x51

#include "types.h"
#include "TimeLib.h"

// library interface description
Expand All @@ -19,8 +20,8 @@ class I2CRTC
// user-accessible "public" interface
public:
I2CRTC();
static time_t get();
static void set(time_t t);
static time_os_t get();
static void set(time_os_t t);
static void read(tmElements_t &tm);
static void write(tmElements_t &tm);
static bool detect();
Expand Down
69 changes: 36 additions & 33 deletions OpenSprinkler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@ byte OpenSprinkler::station_bits[MAX_NUM_BOARDS];
byte OpenSprinkler::engage_booster;
uint16_t OpenSprinkler::baseline_current;

time_t OpenSprinkler::sensor1_on_timer;
time_t OpenSprinkler::sensor1_off_timer;
time_t OpenSprinkler::sensor1_active_lasttime;
time_t OpenSprinkler::sensor2_on_timer;
time_t OpenSprinkler::sensor2_off_timer;
time_t OpenSprinkler::sensor2_active_lasttime;
time_t OpenSprinkler::raindelay_on_lasttime;
time_os_t OpenSprinkler::sensor1_on_timer;
time_os_t OpenSprinkler::sensor1_off_timer;
time_os_t OpenSprinkler::sensor1_active_lasttime;
time_os_t OpenSprinkler::sensor2_on_timer;
time_os_t OpenSprinkler::sensor2_off_timer;
time_os_t OpenSprinkler::sensor2_active_lasttime;
time_os_t OpenSprinkler::raindelay_on_lasttime;
ulong OpenSprinkler::pause_timer;

ulong OpenSprinkler::flowcount_log_start;
ulong OpenSprinkler::flowcount_rt;
byte OpenSprinkler::button_timeout;
time_t OpenSprinkler::checkwt_lasttime;
time_t OpenSprinkler::checkwt_success_lasttime;
time_t OpenSprinkler::powerup_lasttime;
time_os_t OpenSprinkler::checkwt_lasttime;
time_os_t OpenSprinkler::checkwt_success_lasttime;
time_os_t OpenSprinkler::powerup_lasttime;
uint8_t OpenSprinkler::last_reboot_cause = REBOOT_CAUSE_NONE;
byte OpenSprinkler::weather_update_flag;

Expand Down Expand Up @@ -412,7 +412,7 @@ static const char days_str[] PROGMEM =
"Sun\0";

/** Calculate local time (UTC time plus time zone offset) */
time_t OpenSprinkler::now_tz() {
time_os_t OpenSprinkler::now_tz() {
return now()+(int32_t)3600/4*(int32_t)(iopts[IOPT_TIMEZONE]-48);
}

Expand Down Expand Up @@ -464,6 +464,7 @@ byte OpenSprinkler::start_network() {

if (start_ether()) {
useEth = true;
WiFi.mode(WIFI_OFF);
} else {
useEth = false;
}
Expand Down Expand Up @@ -580,25 +581,26 @@ byte OpenSprinkler::start_ether() {
lcd_print_line_clear_pgm(PSTR("Start wired link"), 1);
lcd_print_line_clear_pgm(eth.isW5500 ? PSTR(" (w5500) ") : PSTR(" (enc28j60) "), 2);

ulong timeout = millis()+30000; // 30 seconds time out
while (!eth.connected()) {
ulong timeout = millis()+60000; // 60 seconds time out
while (!eth.connected() && millis()<timeout) {
DEBUG_PRINT(".");
delay(1000);
if(millis()>timeout) return 0;
}

DEBUG_PRINTLN();
DEBUG_PRINT("eth.ip:");
DEBUG_PRINTLN(eth.localIP());
DEBUG_PRINT("eth.dns:");
DEBUG_PRINTLN(WiFi.dnsIP());

if (iopts[IOPT_USE_DHCP]) {
memcpy(iopts+IOPT_STATIC_IP1, &(eth.localIP()[0]), 4);
memcpy(iopts+IOPT_GATEWAY_IP1, &(eth.gatewayIP()[0]),4);
memcpy(iopts+IOPT_DNS_IP1, &(WiFi.dnsIP()[0]), 4); // todo: lwip need dns ip
memcpy(iopts+IOPT_SUBNET_MASK1, &(eth.subnetMask()[0]), 4);
iopts_save();
// if wired connection is not done at this point, return directly
if(eth.connected()) {
DEBUG_PRINTLN();
DEBUG_PRINT("eth.ip:");
DEBUG_PRINTLN(eth.localIP());
DEBUG_PRINT("eth.dns:");
DEBUG_PRINTLN(WiFi.dnsIP());

if (iopts[IOPT_USE_DHCP]) {
memcpy(iopts+IOPT_STATIC_IP1, &(eth.localIP()[0]), 4);
memcpy(iopts+IOPT_GATEWAY_IP1, &(eth.gatewayIP()[0]),4);
memcpy(iopts+IOPT_DNS_IP1, &(WiFi.dnsIP()[0]), 4); // todo: lwip need dns ip
memcpy(iopts+IOPT_SUBNET_MASK1, &(eth.subnetMask()[0]), 4);
iopts_save();
}
}

return 1;
Expand Down Expand Up @@ -631,7 +633,8 @@ byte OpenSprinkler::start_ether() {

bool OpenSprinkler::network_connected(void) {
#if defined (ESP8266)
if(useEth) return true; // todo: lwip currently does not have a way to check link status
if(useEth)
return eth.connected();
else
return (get_wifi_mode()==WIFI_MODE_STA && WiFi.status()==WL_CONNECTED && state==OS_STATE_CONNECTED);
#else
Expand Down Expand Up @@ -1034,7 +1037,7 @@ void OpenSprinkler::begin() {
RTC.detect();

#else
DEBUG_PRINTLN(get_runtime_path());
//DEBUG_PRINTLN(get_runtime_path());
#endif
}

Expand Down Expand Up @@ -1285,7 +1288,7 @@ void OpenSprinkler::apply_all_station_bits() {
// we refresh the station that's next in line
static byte next_sid_to_refresh = MAX_NUM_STATIONS>>1;
static byte lastnow = 0;
time_t curr_time = now_tz();
time_os_t curr_time = now_tz();
byte _now = (curr_time & 0xFF);
if (lastnow != _now) { // perform this no more than once per second
lastnow = _now;
Expand All @@ -1310,7 +1313,7 @@ void OpenSprinkler::apply_all_station_bits() {
}

/** Read rain sensor status */
void OpenSprinkler::detect_binarysensor_status(time_t curr_time) {
void OpenSprinkler::detect_binarysensor_status(time_os_t curr_time) {
// sensor_type: 0 if normally closed, 1 if normally open
if(iopts[IOPT_SENSOR1_TYPE]==SENSOR_TYPE_RAIN || iopts[IOPT_SENSOR1_TYPE]==SENSOR_TYPE_SOIL) {
if(hw_rev>=2) pinModeExt(PIN_SENSOR1, INPUT_PULLUP); // this seems necessary for OS 3.2
Expand Down Expand Up @@ -1374,7 +1377,7 @@ void OpenSprinkler::detect_binarysensor_status(time_t curr_time) {
}

/** Return program switch status */
byte OpenSprinkler::detect_programswitch_status(time_t curr_time) {
byte OpenSprinkler::detect_programswitch_status(time_os_t curr_time) {
byte ret = 0;
if(iopts[IOPT_SENSOR1_TYPE]==SENSOR_TYPE_PSWITCH) {
static byte sensor1_hist = 0;
Expand Down Expand Up @@ -2443,7 +2446,7 @@ void OpenSprinkler::lcd_print_2digit(int v)
}

/** print time to a given line */
void OpenSprinkler::lcd_print_time(time_t t)
void OpenSprinkler::lcd_print_time(time_os_t t)
{
#if defined(ESP8266)
lcd.setAutoDisplay(false);
Expand Down
29 changes: 15 additions & 14 deletions OpenSprinkler.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#ifndef _OPENSPRINKLER_H
#define _OPENSPRINKLER_H

#include "types.h"
#include "defines.h"
#include "utils.h"
#include "gpio.h"
Expand Down Expand Up @@ -234,21 +235,21 @@ class OpenSprinkler {
static byte masters[NUM_MASTER_ZONES][NUM_MASTER_OPTS];

// variables for time keeping
static time_t sensor1_on_timer; // time when sensor1 is detected on last time
static time_t sensor1_off_timer; // time when sensor1 is detected off last time
static time_t sensor1_active_lasttime; // most recent time sensor1 is activated
static time_t sensor2_on_timer; // time when sensor2 is detected on last time
static time_t sensor2_off_timer; // time when sensor2 is detected off last time
static time_t sensor2_active_lasttime; // most recent time sensor1 is activated
static time_t raindelay_on_lasttime; // time when the most recent rain delay started
static time_os_t sensor1_on_timer; // time when sensor1 is detected on last time
static time_os_t sensor1_off_timer; // time when sensor1 is detected off last time
static time_os_t sensor1_active_lasttime; // most recent time sensor1 is activated
static time_os_t sensor2_on_timer; // time when sensor2 is detected on last time
static time_os_t sensor2_off_timer; // time when sensor2 is detected off last time
static time_os_t sensor2_active_lasttime; // most recent time sensor1 is activated
static time_os_t raindelay_on_lasttime; // time when the most recent rain delay started
static ulong pause_timer; // count down timer in paused state
static ulong flowcount_rt; // flow count (for computing real-time flow rate)
static ulong flowcount_log_start; // starting flow count (for logging)

static byte button_timeout; // button timeout
static time_t checkwt_lasttime; // time when weather was checked
static time_t checkwt_success_lasttime; // time when weather check was successful
static time_t powerup_lasttime; // time when controller is powered up most recently
static time_os_t checkwt_lasttime; // time when weather was checked
static time_os_t checkwt_success_lasttime; // time when weather check was successful
static time_os_t powerup_lasttime; // time when controller is powered up most recently
static uint8_t last_reboot_cause; // last reboot cause
static byte weather_update_flag;
// member functions
Expand All @@ -260,7 +261,7 @@ class OpenSprinkler {
static byte start_ether(); // initialize ethernet with the given mac and port
static bool network_connected(); // check if the network is up
static bool load_hardware_mac(byte* buffer, bool wired=false); // read hardware mac address
static time_t now_tz();
static time_os_t now_tz();
// -- station names and attributes
static void get_station_data(byte sid, StationData* data); // get station data
static void set_station_data(byte sid, StationData* data); // set station data
Expand Down Expand Up @@ -306,8 +307,8 @@ class OpenSprinkler {
static void disable(); // disable controller operation, all stations will be closed immediately
static void raindelay_start(); // start raindelay
static void raindelay_stop(); // stop rain delay
static void detect_binarysensor_status(time_t curr_time);// update binary (rain, soil) sensor status
static byte detect_programswitch_status(time_t curr_time); // get program switch status
static void detect_binarysensor_status(time_os_t curr_time);// update binary (rain, soil) sensor status
static byte detect_programswitch_status(time_os_t curr_time); // get program switch status
static void sensor_resetall();

static uint16_t read_current(); // read current sensing value
Expand All @@ -333,7 +334,7 @@ class OpenSprinkler {
static void lcd_print_pgm(PGM_P PROGMEM str); // print a program memory string
static void lcd_print_line_clear_pgm(PGM_P PROGMEM str, byte line);
#endif
static void lcd_print_time(time_t t); // print current time
static void lcd_print_time(time_os_t t); // print current time
static void lcd_print_ip(const byte *ip, byte endian); // print ip
static void lcd_print_mac(const byte *mac); // print mac
static void lcd_print_screen(char c); // print station bits of the board selected by display_board
Expand Down
Loading

0 comments on commit 447b649

Please sign in to comment.