Firmware SDK
twr_module_relay.h
1 #ifndef _TWR_MODULE_RELAY_H
2 #define _TWR_MODULE_RELAY_H
3 
4 #include <twr_tca9534a.h>
5 #include <twr_scheduler.h>
6 
7 #define TWR_MODULE_RELAY_I2C_ADDRESS_DEFAULT 0x3B
8 #define TWR_MODULE_RELAY_I2C_ADDRESS_ALTERNATE 0x3F
9 
33 
35 
36 typedef enum
37 {
40 
43 
46 
48 
50 
52 
54 
55 typedef enum
56 {
57  TWR_MODULE_RELAY_TASK_STATE_IDLE,
58  TWR_MODULE_RELAY_TASK_STATE_SET,
59  TWR_MODULE_RELAY_TASK_STATE_SET_DEMAGNETIZE,
60  TWR_MODULE_RELAY_TASK_STATE_PULSE,
61  TWR_MODULE_RELAY_TASK_STATE_PULSE_DEMAGNETIZE,
62  TWR_MODULE_RELAY_TASK_STATE_PULSE_REVERSE,
63  TWR_MODULE_RELAY_TASK_STATE_PULSE_DEMAGNETIZE_2
64 
65 } twr_module_relay_task_state_t;
66 
67 typedef enum
68 {
69  TWR_MODULE_RELAY_COMMAND_NONE = 0,
70  TWR_MODULE_RELAY_COMMAND_SET = 1,
71  TWR_MODULE_RELAY_COMMAND_PULSE = 2
72 
73 } twr_module_relay_command_t;
74 
75 struct twr_module_relay_t
76 {
77  uint8_t _i2c_address;
78  twr_tca9534a_t _tca9534a;
79  twr_module_relay_state_t _relay_state;
80  twr_tick_t _timestamp;
81  twr_scheduler_task_id_t _task_id;
82  twr_module_relay_task_state_t _state;
83  twr_module_relay_command_t _command;
84  twr_module_relay_state_t _desired_state;
85  twr_tick_t _pulse_duration;
86  bool _task_is_active;
87  bool _error;
88 };
89 
91 
94 
95 bool twr_module_relay_init(twr_module_relay_t *self, uint8_t i2c_address);
96 
100 
101 void twr_module_relay_set_state(twr_module_relay_t *self, bool state);
102 
106 
108 
113 
114 void twr_module_relay_pulse(twr_module_relay_t *self, bool direction, twr_tick_t duration);
115 
118 
120 
122 
123 #endif // _TWR_MODULE_RELAY_H
twr_module_relay_state_t
Reported relay states.
void twr_module_relay_set_state(twr_module_relay_t *self, bool state)
Set relay to specified state.
struct twr_module_relay_t twr_module_relay_t
HARDWARIO Relay Module instance.
void twr_module_relay_toggle(twr_module_relay_t *self)
Toggle relay to opposite state.
void twr_module_relay_pulse(twr_module_relay_t *self, bool direction, twr_tick_t duration)
Generate pulse to specified state for given duration.
bool twr_module_relay_init(twr_module_relay_t *self, uint8_t i2c_address)
Initialize HARDWARIO Relay Module.
twr_module_relay_state_t twr_module_relay_get_state(twr_module_relay_t *self)
Get current relay state.
@ TWR_MODULE_RELAY_STATE_UNKNOWN
State is unknown.
@ TWR_MODULE_RELAY_STATE_FALSE
State is false.
@ TWR_MODULE_RELAY_STATE_TRUE
State is true.
size_t twr_scheduler_task_id_t
Task ID assigned by scheduler.
Definition: twr_scheduler.h:22
uint64_t twr_tick_t
Timestamp data type.
Definition: twr_tick.h:16
Pin state.
Definition: twr_tca9534a.h:43