Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support relays for switching valves #175

Merged
merged 16 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion main/devices/Device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class ConsoleProvider : public LogConsumer {
: logRecords(logRecords)
, recordedLevel(recordedLevel) {
Serial.begin(115200);
Serial1.begin(115200, SERIAL_8N1, pins::RXD0, pins::TXD0);
Serial1.begin(115200, SERIAL_8N1, pins::RXD0->getGpio(), pins::TXD0->getGpio());
#if Serial != Serial0
Serial0.begin(115200);
#endif
Expand Down
8 changes: 6 additions & 2 deletions main/devices/DeviceDefinition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <peripherals/fence/ElectricFenceMonitor.hpp>
#include <peripherals/light_sensor/Bh1750.hpp>
#include <peripherals/light_sensor/Tsl2591.hpp>
#include <peripherals/multiplexer/Xl9535.hpp>

using namespace farmhub::kernel;
using namespace farmhub::kernel::drivers;
Expand Down Expand Up @@ -64,7 +65,7 @@ class DeviceConfiguration : public ConfigurationSection {
template <typename TDeviceConfiguration>
class DeviceDefinition {
public:
DeviceDefinition(gpio_num_t statusPin, gpio_num_t bootPin)
DeviceDefinition(PinPtr statusPin, InternalPinPtr bootPin)
: statusLed("status", statusPin)
, bootPin(bootPin) {
}
Expand All @@ -78,6 +79,7 @@ class DeviceDefinition {
peripheralManager.registerFactory(electricFenceMonitorFactory);
peripheralManager.registerFactory(bh1750Factory);
peripheralManager.registerFactory(tsl2591Factory);
peripheralManager.registerFactory(xl9535Factory);
registerDeviceSpecificPeripheralFactories(peripheralManager);
}

Expand All @@ -99,7 +101,7 @@ class DeviceDefinition {
LedDriver statusLed;
PcntManager pcnt;
PwmManager pwm;
const gpio_num_t bootPin;
const InternalPinPtr bootPin;

private:
ConfigurationFile<TDeviceConfiguration> configFile { FileSystem::get(), "/device-config.json" };
Expand All @@ -121,6 +123,8 @@ class DeviceDefinition {

farmhub::peripherals::light_sensor::Bh1750Factory bh1750Factory;
farmhub::peripherals::light_sensor::Tsl2591Factory tsl2591Factory;

farmhub::peripherals::multiplexer::Xl9535Factory xl9535Factory;
};

} // namespace farmhub::devices
83 changes: 0 additions & 83 deletions main/devices/Pin.hpp

This file was deleted.

44 changes: 22 additions & 22 deletions main/devices/UglyDucklingMk4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <kernel/FileSystem.hpp>
#include <kernel/Kernel.hpp>
#include <kernel/Pin.hpp>
#include <kernel/Service.hpp>
#include <kernel/drivers/BatteryDriver.hpp>
#include <kernel/drivers/Drv8801Driver.hpp>
Expand All @@ -15,7 +16,6 @@
#include <peripherals/valve/Valve.hpp>

#include <devices/DeviceDefinition.hpp>
#include <devices/Pin.hpp>

using namespace farmhub::kernel;
using namespace farmhub::peripherals::chicken_door;
Expand All @@ -34,33 +34,33 @@ class Mk4Config
};

namespace pins {
static gpio_num_t BOOT = Pin::registerPin("BOOT", GPIO_NUM_0);
static gpio_num_t STATUS = Pin::registerPin("STATUS", GPIO_NUM_26);

static gpio_num_t SOIL_MOISTURE = Pin::registerPin("SOIL_MOISTURE", GPIO_NUM_6);
static gpio_num_t SOIL_TEMP = Pin::registerPin("SOIL_TEMP", GPIO_NUM_7);

static gpio_num_t VALVE_EN = Pin::registerPin("VALVE_EN", GPIO_NUM_10);
static gpio_num_t VALVE_PH = Pin::registerPin("VALVE_PH", GPIO_NUM_11);
static gpio_num_t VALVE_FAULT = Pin::registerPin("VALVE_FAULT", GPIO_NUM_12);
static gpio_num_t VALVE_SLEEP = Pin::registerPin("VALVE_SLEEP", GPIO_NUM_13);
static gpio_num_t VALVE_MODE1 = Pin::registerPin("VALVE_MODE1", GPIO_NUM_14);
static gpio_num_t VALVE_MODE2 = Pin::registerPin("VALVE_MODE2", GPIO_NUM_15);
static gpio_num_t VALVE_CURRENT = Pin::registerPin("VALVE_CURRENT", GPIO_NUM_16);
static gpio_num_t FLOW = Pin::registerPin("FLOW", GPIO_NUM_17);

static gpio_num_t SDA = Pin::registerPin("SDA", GPIO_NUM_8);
static gpio_num_t SCL = Pin::registerPin("SCL", GPIO_NUM_9);
static gpio_num_t RXD0 = Pin::registerPin("RXD0", GPIO_NUM_44);
static gpio_num_t TXD0 = Pin::registerPin("TXD0", GPIO_NUM_43);
static InternalPinPtr BOOT = InternalPin::registerPin("BOOT", GPIO_NUM_0);
static InternalPinPtr STATUS = InternalPin::registerPin("STATUS", GPIO_NUM_26);

static InternalPinPtr SOIL_MOISTURE = InternalPin::registerPin("SOIL_MOISTURE", GPIO_NUM_6);
static InternalPinPtr SOIL_TEMP = InternalPin::registerPin("SOIL_TEMP", GPIO_NUM_7);

static InternalPinPtr VALVE_EN = InternalPin::registerPin("VALVE_EN", GPIO_NUM_10);
static InternalPinPtr VALVE_PH = InternalPin::registerPin("VALVE_PH", GPIO_NUM_11);
static InternalPinPtr VALVE_FAULT = InternalPin::registerPin("VALVE_FAULT", GPIO_NUM_12);
static InternalPinPtr VALVE_SLEEP = InternalPin::registerPin("VALVE_SLEEP", GPIO_NUM_13);
static InternalPinPtr VALVE_MODE1 = InternalPin::registerPin("VALVE_MODE1", GPIO_NUM_14);
static InternalPinPtr VALVE_MODE2 = InternalPin::registerPin("VALVE_MODE2", GPIO_NUM_15);
static InternalPinPtr VALVE_CURRENT = InternalPin::registerPin("VALVE_CURRENT", GPIO_NUM_16);
static InternalPinPtr FLOW = InternalPin::registerPin("FLOW", GPIO_NUM_17);

static InternalPinPtr SDA = InternalPin::registerPin("SDA", GPIO_NUM_8);
static InternalPinPtr SCL = InternalPin::registerPin("SCL", GPIO_NUM_9);
static InternalPinPtr RXD0 = InternalPin::registerPin("RXD0", GPIO_NUM_44);
static InternalPinPtr TXD0 = InternalPin::registerPin("TXD0", GPIO_NUM_43);
} // namespace pins

class UglyDucklingMk4 : public DeviceDefinition<Mk4Config> {
public:
UglyDucklingMk4()
: DeviceDefinition<Mk4Config>(
pins::STATUS,
pins::BOOT) {
pins::STATUS,
pins::BOOT) {
}

void registerDeviceSpecificPeripheralFactories(PeripheralManager& peripheralManager) override {
Expand Down
86 changes: 43 additions & 43 deletions main/devices/UglyDucklingMk5.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <kernel/FileSystem.hpp>
#include <kernel/Kernel.hpp>
#include <kernel/Pin.hpp>
#include <kernel/Service.hpp>
#include <kernel/drivers/BatteryDriver.hpp>
#include <kernel/drivers/Drv8874Driver.hpp>
Expand All @@ -13,7 +14,6 @@
#include <peripherals/valve/Valve.hpp>

#include <devices/DeviceDefinition.hpp>
#include <devices/Pin.hpp>

using namespace farmhub::kernel;
using namespace farmhub::peripherals::chicken_door;
Expand All @@ -33,54 +33,54 @@ class Mk5Config
};

namespace pins {
static gpio_num_t BOOT = Pin::registerPin("BOOT", GPIO_NUM_0);
static gpio_num_t BATTERY = Pin::registerPin("BATTERY", GPIO_NUM_1);
static gpio_num_t STATUS = Pin::registerPin("STATUS", GPIO_NUM_2);
static gpio_num_t AIPROPI = Pin::registerPin("AIPROPI", GPIO_NUM_4);

static gpio_num_t IOA1 = Pin::registerPin("A1", GPIO_NUM_5);
static gpio_num_t IOA2 = Pin::registerPin("A2", GPIO_NUM_6);
static gpio_num_t BIPROPI = Pin::registerPin("BIPROPI", GPIO_NUM_7);
static gpio_num_t IOB1 = Pin::registerPin("B1", GPIO_NUM_15);
static gpio_num_t AIN1 = Pin::registerPin("AIN1", GPIO_NUM_16);
static gpio_num_t AIN2 = Pin::registerPin("AIN2", GPIO_NUM_17);
static gpio_num_t BIN1 = Pin::registerPin("BIN1", GPIO_NUM_18);
static gpio_num_t BIN2 = Pin::registerPin("BIN2", GPIO_NUM_8);

static gpio_num_t DMINUS = Pin::registerPin("D-", GPIO_NUM_19);
static gpio_num_t DPLUS = Pin::registerPin("D+", GPIO_NUM_20);

static gpio_num_t IOB2 = Pin::registerPin("B2", GPIO_NUM_9);

static gpio_num_t NSLEEP = Pin::registerPin("NSLEEP", GPIO_NUM_10);
static gpio_num_t NFault = Pin::registerPin("NFault", GPIO_NUM_11);
static gpio_num_t IOC4 = Pin::registerPin("C4", GPIO_NUM_12);
static gpio_num_t IOC3 = Pin::registerPin("C3", GPIO_NUM_13);
static gpio_num_t IOC2 = Pin::registerPin("C2", GPIO_NUM_14);
static gpio_num_t IOC1 = Pin::registerPin("C1", GPIO_NUM_21);
static gpio_num_t IOD4 = Pin::registerPin("D4", GPIO_NUM_47);
static gpio_num_t IOD3 = Pin::registerPin("D3", GPIO_NUM_48);

static gpio_num_t SDA = Pin::registerPin("SDA", GPIO_NUM_35);
static gpio_num_t SCL = Pin::registerPin("SCL", GPIO_NUM_36);

static gpio_num_t IOD1 = Pin::registerPin("D1", GPIO_NUM_37);
static gpio_num_t IOD2 = Pin::registerPin("D2", GPIO_NUM_38);

static gpio_num_t TCK = Pin::registerPin("TCK", GPIO_NUM_39);
static gpio_num_t TDO = Pin::registerPin("TDO", GPIO_NUM_40);
static gpio_num_t TDI = Pin::registerPin("TDI", GPIO_NUM_41);
static gpio_num_t TMS = Pin::registerPin("TMS", GPIO_NUM_42);
static gpio_num_t RXD0 = Pin::registerPin("RXD0", GPIO_NUM_44);
static gpio_num_t TXD0 = Pin::registerPin("TXD0", GPIO_NUM_43);
static InternalPinPtr BOOT = InternalPin::registerPin("BOOT", GPIO_NUM_0);
static InternalPinPtr BATTERY = InternalPin::registerPin("BATTERY", GPIO_NUM_1);
static InternalPinPtr STATUS = InternalPin::registerPin("STATUS", GPIO_NUM_2);
static InternalPinPtr AIPROPI = InternalPin::registerPin("AIPROPI", GPIO_NUM_4);

static InternalPinPtr IOA1 = InternalPin::registerPin("A1", GPIO_NUM_5);
static InternalPinPtr IOA2 = InternalPin::registerPin("A2", GPIO_NUM_6);
static InternalPinPtr BIPROPI = InternalPin::registerPin("BIPROPI", GPIO_NUM_7);
static InternalPinPtr IOB1 = InternalPin::registerPin("B1", GPIO_NUM_15);
static InternalPinPtr AIN1 = InternalPin::registerPin("AIN1", GPIO_NUM_16);
static InternalPinPtr AIN2 = InternalPin::registerPin("AIN2", GPIO_NUM_17);
static InternalPinPtr BIN1 = InternalPin::registerPin("BIN1", GPIO_NUM_18);
static InternalPinPtr BIN2 = InternalPin::registerPin("BIN2", GPIO_NUM_8);

static InternalPinPtr DMINUS = InternalPin::registerPin("D-", GPIO_NUM_19);
static InternalPinPtr DPLUS = InternalPin::registerPin("D+", GPIO_NUM_20);

static InternalPinPtr IOB2 = InternalPin::registerPin("B2", GPIO_NUM_9);

static InternalPinPtr NSLEEP = InternalPin::registerPin("NSLEEP", GPIO_NUM_10);
static InternalPinPtr NFault = InternalPin::registerPin("NFault", GPIO_NUM_11);
static InternalPinPtr IOC4 = InternalPin::registerPin("C4", GPIO_NUM_12);
static InternalPinPtr IOC3 = InternalPin::registerPin("C3", GPIO_NUM_13);
static InternalPinPtr IOC2 = InternalPin::registerPin("C2", GPIO_NUM_14);
static InternalPinPtr IOC1 = InternalPin::registerPin("C1", GPIO_NUM_21);
static InternalPinPtr IOD4 = InternalPin::registerPin("D4", GPIO_NUM_47);
static InternalPinPtr IOD3 = InternalPin::registerPin("D3", GPIO_NUM_48);

static InternalPinPtr SDA = InternalPin::registerPin("SDA", GPIO_NUM_35);
static InternalPinPtr SCL = InternalPin::registerPin("SCL", GPIO_NUM_36);

static InternalPinPtr IOD1 = InternalPin::registerPin("D1", GPIO_NUM_37);
static InternalPinPtr IOD2 = InternalPin::registerPin("D2", GPIO_NUM_38);

static InternalPinPtr TCK = InternalPin::registerPin("TCK", GPIO_NUM_39);
static InternalPinPtr TDO = InternalPin::registerPin("TDO", GPIO_NUM_40);
static InternalPinPtr TDI = InternalPin::registerPin("TDI", GPIO_NUM_41);
static InternalPinPtr TMS = InternalPin::registerPin("TMS", GPIO_NUM_42);
static InternalPinPtr RXD0 = InternalPin::registerPin("RXD0", GPIO_NUM_44);
static InternalPinPtr TXD0 = InternalPin::registerPin("TXD0", GPIO_NUM_43);
} // namespace pins

class UglyDucklingMk5 : public DeviceDefinition<Mk5Config> {
public:
UglyDucklingMk5()
: DeviceDefinition<Mk5Config>(
pins::STATUS,
pins::BOOT) {
pins::STATUS,
pins::BOOT) {
}

void registerDeviceSpecificPeripheralFactories(PeripheralManager& peripheralManager) override {
Expand Down
Loading
Loading