Skip to content

Commit

Permalink
change to use EthernetENC library, replacing UIPEthernet; remove some…
Browse files Browse the repository at this point in the history
… unnecessary code
  • Loading branch information
rayshobby committed Aug 16, 2021
1 parent 97dbfa6 commit 93035cc
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 43 deletions.
35 changes: 6 additions & 29 deletions OpenSprinkler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,15 +512,8 @@ byte OpenSprinkler::start_ether() {
if(hw_rev<2) return 0; // ethernet capability is only available after hw_rev 2
#endif
Ethernet.init(PIN_ETHER_CS); // make sure to call this before any Ethernet calls
Enc28J60Network::initSPI();
if(Ethernet.hardwareStatus()==EthernetNoHardware) return 0;
load_hardware_mac((uint8_t*)tmp_buffer, true);
// detect if Enc28J60 exists
Enc28J60Network::init((uint8_t*)tmp_buffer);
uint8_t erevid = Enc28J60Network::geterevid();
DEBUG_PRINT(F("erevid:"));
DEBUG_PRINTLN(erevid);
// a valid chip must have erevid > 0 and < 255
if(erevid==0 || erevid==255) return 0;

lcd_print_line_clear_pgm(PSTR("Start wired link"), 1);

Expand Down Expand Up @@ -1111,7 +1104,7 @@ void OpenSprinkler::apply_all_station_bits() {
// for DC controller: boost voltage and enable output path
digitalWriteExt(PIN_BOOST_EN, LOW); // disfable output path
digitalWriteExt(PIN_BOOST, HIGH); // enable boost converter
delay_nicely((int)iopts[IOPT_BOOST_TIME]<<2); // wait for booster to charge
delay((int)iopts[IOPT_BOOST_TIME]<<2); // wait for booster to charge
digitalWriteExt(PIN_BOOST, LOW); // disable boost converter
digitalWriteExt(PIN_BOOST_EN, HIGH); // enable output path
engage_booster = 0;
Expand Down Expand Up @@ -1169,7 +1162,7 @@ void OpenSprinkler::apply_all_station_bits() {
// for DC controller: boost voltage
digitalWrite(PIN_BOOST_EN, LOW); // disable output path
digitalWrite(PIN_BOOST, HIGH); // enable boost converter
delay_nicely((int)iopts[IOPT_BOOST_TIME]<<2); // wait for booster to charge
delay((int)iopts[IOPT_BOOST_TIME]<<2); // wait for booster to charge
digitalWrite(PIN_BOOST, LOW); // disable boost converter

digitalWrite(PIN_BOOST_EN, HIGH); // enable output path
Expand Down Expand Up @@ -1336,7 +1329,7 @@ uint16_t OpenSprinkler::read_current() {
uint16_t sum = 0;
for(byte i=0;i<K;i++) {
sum += analogRead(PIN_CURR_SENSE);
delay_nicely(1);
delay(1);
}
return (uint16_t)((sum/K)*scale);
} else {
Expand Down Expand Up @@ -2409,22 +2402,6 @@ void OpenSprinkler::lcd_print_option(int i) {

}

void OpenSprinkler::yield_nicely() {
if(m_server) Ethernet.tick();
#if defined(ESP8266)
delay(0);
#endif
}

/** A delay function that does not stall Ethernet or WiFi */
void OpenSprinkler::delay_nicely(uint32_t ms) {
uint32_t start = millis();
do {
//yield_nicely();
delay(1);
} while(millis()-start < ms);
}

/** Button functions */
/** wait for button */
byte OpenSprinkler::button_read_busy(byte pin_butt, byte waitmode, byte butt, byte is_holding) {
Expand All @@ -2438,7 +2415,7 @@ byte OpenSprinkler::button_read_busy(byte pin_butt, byte waitmode, byte butt, by

while (digitalReadExt(pin_butt) == 0 &&
(waitmode == BUTTON_WAIT_RELEASE || (waitmode == BUTTON_WAIT_HOLD && hold_time<BUTTON_HOLD_MS))) {
delay_nicely(BUTTON_DELAY_MS);
delay(BUTTON_DELAY_MS);
hold_time += BUTTON_DELAY_MS;
}
if (is_holding || hold_time >= BUTTON_HOLD_MS)
Expand All @@ -2454,7 +2431,7 @@ byte OpenSprinkler::button_read(byte waitmode)
byte curr = BUTTON_NONE;
byte is_holding = (old&BUTTON_FLAG_HOLD);

delay_nicely(BUTTON_DELAY_MS);
delay(BUTTON_DELAY_MS);

if (digitalReadExt(PIN_BUTTON_1) == 0) {
curr = button_read_busy(PIN_BUTTON_1, waitmode, BUTTON_1, is_holding);
Expand Down
4 changes: 1 addition & 3 deletions OpenSprinkler.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include <Arduino.h>
#include <Wire.h>
#include <SPI.h>
#include <UIPEthernet.h>
#include <Ethernet.h>
#include "I2CRTC.h"

#if defined(ESP8266)
Expand Down Expand Up @@ -293,8 +293,6 @@ class OpenSprinkler {
// return values are 'OR'ed with flags
// check defines.h for details

static void yield_nicely();
static void delay_nicely(uint32_t ms);
// -- UI functions --
static void ui_set_options(int oid); // ui for setting options (oid-> starting option index)
static void lcd_set_brightness(byte value=1);
Expand Down
6 changes: 4 additions & 2 deletions examples/mainArduino/mainArduino.ino
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <Wire.h>

#if defined(ESP8266)
//#if defined(ESP8266)
#if 0
struct tcp_pcb;
extern struct tcp_pcb* tcp_tw_pcbs;
extern "C" void tcp_abort (struct tcp_pcb* pcb);
Expand All @@ -24,7 +25,8 @@ void setup() {

void loop() {
do_loop();
#if defined(ESP8266)
//#if defined(ESP8266)
#if 0
tcpCleanup();
#endif
}
6 changes: 3 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ void remote_http_callback(char*);

// Small variations have been added to the timing values below
// to minimize conflicting events
#define NTP_SYNC_INTERVAL 86413L // NTP sync interval (in seconds)
#define NTP_SYNC_INTERVAL 864//13L // NTP sync interval (in seconds)
#define CHECK_NETWORK_INTERVAL 601 // Network checking timeout (in seconds)
#define CHECK_WEATHER_TIMEOUT 21613L // Weather check interval (in seconds)
#define CHECK_WEATHER_TIMEOUT 2161//3L // Weather check interval (in seconds)
#define CHECK_WEATHER_SUCCESS_TIMEOUT 86400L // Weather check success interval (in seconds)
#define LCD_BACKLIGHT_TIMEOUT 15 // LCD backlight timeout (in seconds))
#define PING_TIMEOUT 200 // Ping test timeout (in ms)
Expand Down Expand Up @@ -123,7 +123,7 @@ bool ui_confirm(PGM_P str) {
button = os.button_read(BUTTON_WAIT_NONE);
if((button&BUTTON_MASK)==BUTTON_3 && (button&BUTTON_FLAG_DOWN)) return true;
if((button&BUTTON_MASK)==BUTTON_1 && (button&BUTTON_FLAG_DOWN)) return false;
os.delay_nicely(10);
delay(10);
} while(millis() - start < 2500);
return false;
}
Expand Down
6 changes: 4 additions & 2 deletions mainArduino.ino
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <Wire.h>

#if defined(ESP8266)
//#if defined(ESP8266)
#if 0
struct tcp_pcb;
extern struct tcp_pcb* tcp_tw_pcbs;
extern "C" void tcp_abort (struct tcp_pcb* pcb);
Expand All @@ -24,7 +25,8 @@ void setup() {

void loop() {
do_loop();
#if defined(ESP8266)
//#if defined(ESP8266)
#if 0
tcpCleanup();
#endif
}
2 changes: 1 addition & 1 deletion make.os23
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ BOARD_TAG = 1284
MCU = atmega1284p
VARIANT = sanguino
F_CPU = 16000000L
ARDUINO_LIBS = UIPEthernet Wire SdFat SPI pubsubclient
ARDUINO_LIBS = EthernetENC Wire SdFat SPI pubsubclient
MONITOR_PORT = /dev/ttyUSB0
MONITOR_BAUDRATE = 115200
include ./Arduino.mk
2 changes: 1 addition & 1 deletion mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#if defined(ESP8266)
#include <ESP8266WiFi.h>
#endif
#include <UIPEthernet.h>
#include <Ethernet.h>
#include <PubSubClient.h>

struct PubSubClient *mqtt_client = NULL;
Expand Down
3 changes: 3 additions & 0 deletions opensprinkler_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,10 @@ void server_change_options()
}
uint8_t keyfound = 0;
if(findKeyVal(p, tmp_buffer, TMP_BUFFER_SIZE, PSTR("wto"), true)) {
DEBUG_PRINT(F("wto:"));
DEBUG_PRINTLN(tmp_buffer);
urlDecode(tmp_buffer);
DEBUG_PRINTLN(tmp_buffer);
if (os.sopt_save(SOPT_WEATHER_OPTS, tmp_buffer)) {
weather_change = true; // if wto has changed
}
Expand Down
4 changes: 2 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ board = d1_mini_lite
framework = arduino
lib_ldf_mode = deep
lib_deps =
UIPEthernet=https://github.com/OpenSprinkler/UIPEthernet/archive/fixes/dhcp.zip
EthernetENC=https://github.com/jandrassy/EthernetENC/archive/refs/tags/2.0.1.zip
sui77/rc-switch @ ^2.6.3
https://github.com/ThingPulse/esp8266-oled-ssd1306/archive/4.2.0.zip
knolleary/PubSubClient @ ^2.8
Expand All @@ -36,7 +36,7 @@ board_build.variant = sanguino
framework = arduino
lib_ldf_mode = deep
lib_deps =
UIPEthernet=https://github.com/OpenSprinkler/UIPEthernet/archive/fixes/dhcp.zip
EthernetENC=https://github.com/jandrassy/EthernetENC/archive/refs/tags/2.0.1.zip
knolleary/PubSubClient @ ^2.8
greiman/SdFat @ 1.0.7
Wire
Expand Down

0 comments on commit 93035cc

Please sign in to comment.