Skip to content

Commit

Permalink
EZOpH & EZOORP support
Browse files Browse the repository at this point in the history
This commits adds support for EZOpH and EZOORP to Tasmota
  • Loading branch information
tichris0 committed Oct 18, 2020
1 parent df5538f commit d8b8636
Show file tree
Hide file tree
Showing 12 changed files with 562 additions and 4 deletions.
4 changes: 4 additions & 0 deletions BUILDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@
| USE_DISPLAY_ILI9488 | - | - | - | - | - | - | - |
| USE_DISPLAY_SSD1351 | - | - | - | - | - | - | - |
| USE_DISPLAY_RA8876 | - | - | - | - | - | - | - |
| | | | | | | | |
| Feature or Sensor | minimal | lite | tasmota | knx | sensors | ir | display | Remarks
| USE_EZOPH | - | - | - | - | - | - | - |
| USE_EZOORP | - | - | - | - | - | - | - |

## Additional Features and Sensors on ESP32

Expand Down
2 changes: 2 additions & 0 deletions I2CDEVICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,5 @@ Index | Define | Driver | Device | Address(es) | Description
52 | USE_HP303B | xsns_73 | HP303B | 0x76 - 0x77 | Pressure and temperature sensor
53 | USE_MLX90640 | xdrv_84 | MLX90640 | 0x33 | IR array temperature sensor
54 | USE_VL53L1X | xsns_77 | VL53L1X | 0x29 | Time-of-flight (ToF) distance sensor
55 | USE_EZO,USE_EZO_PH | xsns_78 | EZOPH | 0x61 - 0x70 | pH Sensor
55 | USE_EZO,USE_EZO_ORP | xsns_79 | EZOORP | 0x61 - 0x70 | ORP Sensor
1 change: 1 addition & 0 deletions c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
platformio run -e tasmota --target upload --upload-port /dev/ttyS4
Binary file added tasmota/.my_user_config.h.swp
Binary file not shown.
120 changes: 120 additions & 0 deletions tasmota/ezo.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
ezo.ino - EZO modules base class
Copyright (C) 2020 Christopher Tremblay
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef USE_I2C
#if defined(USE_EZOPH) || defined(USE_EZOORP)

#define D_EZO_DELAY 300 // Minimum delay for any instruction
#define D_EZO_MAX_BUF 40 // Maximum response



// This baseclass provides common functionality for all EZO devices
struct EZOStruct {
void MeasureRequest(void)
{
const uint8_t EZOMeasureCmd[2] = {'R', 0};

if (valid) {
valid--;
}

Wire.beginTransmission(addr);
Wire.write(EZOMeasureCmd, sizeof(EZOMeasureCmd));
Wire.endTransmission();

lastRead = millis();
}

void ProcessMeasurement(char *const data, const uint32_t len, const uint32_t latency)
{
// Wait for the data to arrive first
const int32_t dur = lastRead + latency - millis();

// Wait for the last readout to complete (only when commands are issued)
if (dur > 0) {
delay(dur);
}

Wire.requestFrom(addr, len);
const char code = Wire.read();

if (code == 1) {
for (uint32_t i = 0; (Wire.available() > 0) && (i < len); i++) {
data[i] = Wire.read();
}

valid = SENSOR_MAX_MISS;
}
}

void HandleCommand(uint32_t index) const
{
char *at = XdrvMailbox.data;
uint32_t len = XdrvMailbox.data_len;

// Figure out if we're trying to address a specific device
// PS: This should ideally be done through the Tasmota mailbox
if (at[0] == '-') {
uint32_t idx = atoi(&at[1]);
at = strchr(at, ' ');

if (!at++) {
return;
}

len -= (at - XdrvMailbox.data);

if (idx != index) {
return;
}
}

// Transmit our command verbatim
Wire.beginTransmission(addr);
Wire.write(at, len);
if (Wire.endTransmission() != 0) {
return;
}

// Attempt to read the results
char data[D_EZO_MAX_BUF];
for (uint32_t code = 254; code == 254; code = Wire.read()) {
delay(D_EZO_DELAY);
Wire.requestFrom(addr, sizeof(data));
}

for (uint32_t i = 0; Wire.available() > 0; i++) {
data[i] = Wire.read();
}

ResponseCmndChar((char *)data);
}

public:
uint8_t valid = 0;
uint8_t addr;

private:
uint32_t lastRead = -2000;
};



#endif // USE_EZO*
#endif // USE_I2C
Loading

0 comments on commit d8b8636

Please sign in to comment.