Skip to content

Commit

Permalink
try-fix Zone Expander Latch
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Schmaltz committed Jun 12, 2024
1 parent 5c99958 commit e1ce4de
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
28 changes: 20 additions & 8 deletions OpenSprinkler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ void OpenSprinkler::latch_setallzonepins(byte value) {
}
}

void OpenSprinkler::latch_disable_alloutputs_v2() {
void OpenSprinkler::latch_disable_alloutputs_v2(byte expvalue) {
digitalWriteExt(PIN_LATCH_COMA, LOW);
digitalWriteExt(PIN_LATCH_COMK, LOW);

Expand All @@ -1144,7 +1144,12 @@ void OpenSprinkler::latch_disable_alloutputs_v2() {
// latch v2 has a 74hc595 which controls all h-bridge cathode pins
drio->shift_out(V2_PIN_SRLAT, V2_PIN_SRCLK, V2_PIN_SRDAT, 0x00);

// todo: handle expander
// Handle all expansion boards
for(byte i=0;i<MAX_EXT_BOARDS/2;i++) {
if(expanders[i]->type==IOEXP_TYPE_9555) {
expanders[i]->i2c_write(NXP_OUTPUT_REG, expvalue?0xFFFF:0x0000);
}
}
}

/** Set one zone (for LATCH controller)
Expand Down Expand Up @@ -1183,8 +1188,15 @@ void OpenSprinkler::latch_setzoneoutput_v2(byte sid, byte A, byte K) {

drio->shift_out(V2_PIN_SRLAT, V2_PIN_SRCLK, V2_PIN_SRDAT, K ? (1<<sid) : 0);

} else { // on expander
// todo: handle expander
} else { // for expander
byte bid=(sid-8)>>4;
uint16_t s=(sid-8)&0x0F;
if(expanders[bid]->type==IOEXP_TYPE_9555) {
uint16_t reg = expanders[bid]->i2c_read(NXP_OUTPUT_REG); // read current output reg value
if(A==HIGH && K==LOW) reg |= (1<<s);
else if(K==HIGH && A==LOW) reg &= (~(1<<s));
expanders[bid]->i2c_write(NXP_OUTPUT_REG, reg);
}
}
}

Expand All @@ -1194,14 +1206,14 @@ void OpenSprinkler::latch_setzoneoutput_v2(byte sid, byte A, byte K) {
void OpenSprinkler::latch_open(byte sid) {
if(hw_rev>=2) {
DEBUG_PRINTLN(F("latch_open_v2"));
latch_disable_alloutputs_v2(); // disable all output pins
latch_disable_alloutputs_v2(HIGH); // disable all output pins; set expanders all to HIGH
latch_boost(); // generate boost voltage
digitalWriteExt(PIN_LATCH_COMA, HIGH); // enable COM+
latch_setzoneoutput_v2(sid, LOW, HIGH); // enable sid-
digitalWriteExt(PIN_BOOST_EN, HIGH); // enable output path
delay(150);
digitalWriteExt(PIN_BOOST_EN, LOW); // disabled output boosted voltage path
latch_disable_alloutputs_v2(); // disable all output pins
latch_disable_alloutputs_v2(HIGH); // disable all output pins; set expanders all to HIGH
} else {
latch_boost(); // boost voltage
latch_setallzonepins(HIGH); // set all switches to HIGH, including COM
Expand All @@ -1217,14 +1229,14 @@ void OpenSprinkler::latch_open(byte sid) {
void OpenSprinkler::latch_close(byte sid) {
if(hw_rev>=2) {
DEBUG_PRINTLN(F("latch_close_v2"));
latch_disable_alloutputs_v2(); // disable all output pins
latch_disable_alloutputs_v2(LOW); // disable all output pins; set expanders all to LOW
latch_boost(); // generate boost voltage
latch_setzoneoutput_v2(sid, HIGH, LOW); // enable sid+
digitalWriteExt(PIN_LATCH_COMK, HIGH); // enable COM-
digitalWriteExt(PIN_BOOST_EN, HIGH); // enable output path
delay(150);
digitalWriteExt(PIN_BOOST_EN, LOW); // disable output boosted voltage path
latch_disable_alloutputs_v2(); // disable all output pins
latch_disable_alloutputs_v2(HIGH); // disable all output pins; set expanders all to HIGH
} else {
latch_boost(); // boost voltage
latch_setallzonepins(LOW); // set all switches to LOW, including COM
Expand Down
2 changes: 1 addition & 1 deletion OpenSprinkler.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ class OpenSprinkler {
static void latch_close(byte sid);
static void latch_setzonepin(byte sid, byte value);
static void latch_setallzonepins(byte value);
static void latch_disable_alloutputs_v2();
static void latch_disable_alloutputs_v2(byte expvalue);
static void latch_setzoneoutput_v2(byte sid, byte A, byte K);
static void latch_apply_all_station_bits();
static byte prev_station_bits[];
Expand Down
6 changes: 3 additions & 3 deletions defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#ifndef _DEFINES_H
#define _DEFINES_H

#define ENABLE_DEBUG // enable serial debug
#define SERIAL_DEBUG
//#define ENABLE_DEBUG // enable serial debug
//#define SERIAL_DEBUG

typedef unsigned char byte;
typedef unsigned long ulong;
Expand All @@ -37,7 +37,7 @@ typedef unsigned long ulong;
// if this number is different from the one stored in non-volatile memory
// a device reset will be automatically triggered

#define OS_FW_MINOR 162 // Firmware minor version
#define OS_FW_MINOR 163 // Firmware minor version

/** Hardware version base numbers */
#define OS_HW_VERSION_BASE 0x00 // OpenSprinkler
Expand Down
4 changes: 2 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ uint32_t ping_ok = 0;

void flow_poll() {
#if defined(ESP8266)
if(os.hw_rev == 2) pinModeExt(PIN_SENSOR1, INPUT_PULLUP); // this seems necessary for OS 3.2
if(os.hw_rev >= 2) pinModeExt(PIN_SENSOR1, INPUT_PULLUP); // this seems necessary for OS 3.2
#endif
byte curr_flow_state = digitalReadExt(PIN_SENSOR1);
if(!(prev_flow_state==HIGH && curr_flow_state==LOW)) { // only record on falling edge
Expand Down Expand Up @@ -641,7 +641,7 @@ void do_loop()
if (curr_time != last_time) {

#if defined(ESP8266)
if(os.hw_rev==2) {
if(os.hw_rev>=2) {
pinModeExt(PIN_SENSOR1, INPUT_PULLUP); // this seems necessary for OS 3.2
pinModeExt(PIN_SENSOR2, INPUT_PULLUP);
}
Expand Down

0 comments on commit e1ce4de

Please sign in to comment.