#ifndef LatchingSolenoid_h #define LatchingSolenoid_h #ifndef NonLatchingRelay_h #include "NonLatchingRelay.h" #endif #ifndef Arduino_H #include #endif class LatchingSolenoid { private: String name = "Latching Solenoid"; unsigned int onpin; unsigned int onpin_readback; bool onpin_working; unsigned int offpin; unsigned int offpin_readback; bool offpin_working; unsigned int on_voltage_read_pin; unsigned int off_voltage_read_pin; unsigned long on_relay_first_voltage_time; // The millis() time that we first saw a voltage across unsigned long off_relay_first_voltage_time; // The millis() time that we first saw a voltage across const unsigned long set_duration = 1000; // How many ms the relay should be turned on to move the solenoid position const unsigned long set_duration_minimum = 100; // We want to see at least this long to assume the solenoid turned on bool on_relay_actual_state; // The current state of the on relay bool on_relay_working; bool off_relay_actual_state; // The current state of the off relay bool off_relay_working; bool desired_state = false; // The desired state of the solenoid, set by the control program bool expected_state; // The expected state of the solenoid based off of voltage readbacks across the relays bool startup = true; // This is used so that the object knows whether or not to use the normal or startup function to control NonLatchingRelay on_relay; NonLatchingRelay off_relay; void update_first_voltage_times(); void update_relay_actual_states(); void update_if_pins_working(); void update_if_relays_working(); void update_solenoid_expected_state(); void turn_off_relays_after_duration(); void turn_on_solenoid(); void turn_off_solenoid(); void turn_on_solenoid_startup(); void turn_off_solenoid_startup(); public: LatchingSolenoid(String name, unsigned int onpin, unsigned int onpin_readback, unsigned int offpin, unsigned int offpin_readback, unsigned int on_voltage_read_pin, unsigned int off_voltage_read_pin); LatchingSolenoid(unsigned int onpin, unsigned int onpin_readback, unsigned int offpin, unsigned int offpin_readback, unsigned int on_voltage_read_pin, unsigned int off_voltage_read_pin); bool get_onpin_working() const {return onpin_working;} bool get_offpin_working() const {return offpin_working;} bool get_on_relay_actual_state() const {return on_relay_actual_state;} bool get_off_relay_actual_state() const {return off_relay_actual_state;} bool get_desired_state() const {return desired_state;} bool get_expected_state() const {return expected_state;} bool get_on_relay_working() const {return on_relay_working;} bool get_off_relay_working() const {return off_relay_working;} void set_desired_solenoid_state(unsigned char new_desired_state); void control_solenoid(); }; #endif