2 #include <twr_onewire_relay.h>
8 memset(
self, 0,
sizeof(*
self));
9 self->_device_number = device_number;
10 self->_onewire = onewire;
12 if (!_twr_onewire_relay_read_state(
self))
22 if (!self->_state_valid && !_twr_onewire_relay_read_state(
self))
32 uint8_t new_state =
self->_state;
36 new_state |= (1 << relay_channel);
40 new_state &= ~(1 << relay_channel);
45 uint8_t buffer[] = { 0x5A, new_state, ~new_state };
59 self->_state = new_state;
66 if (!self->_state_valid)
71 *state = ((
self->_state >> relay_channel) & 0x01) == 0x00;
78 self->_state_valid =
false;
91 self->_state_valid =
true;
bool twr_onewire_relay_set_state(twr_onewire_relay_t *self, twr_onewire_relay_channel_t relay_channel, bool state)
Set relay to specified state.
bool twr_onewire_relay_get_state(twr_onewire_relay_t *self, twr_onewire_relay_channel_t relay_channel, bool *state)
Get current relay state.
bool twr_onewire_relay_init(twr_onewire_relay_t *self, twr_onewire_t *onewire, uint64_t device_number)
Initialize relay.
void twr_onewire_write(twr_onewire_t *self, const void *buffer, size_t length)
Select device.
void twr_onewire_write_byte(twr_onewire_t *self, uint8_t data)
Select device.
struct twr_onewire_t twr_onewire_t
1-Wire instance
bool twr_onewire_reset(twr_onewire_t *self)
Reset the 1-Wire bus and return the presence of any device.
void twr_onewire_select(twr_onewire_t *self, uint64_t *device_number)
Select device.
uint8_t twr_onewire_read_byte(twr_onewire_t *self)
Select device.
HARDWARIO 1-wire relay instance.