Github Repo | C Header | C source | JS source |
---|---|---|---|
mongoose-os-libs/onewire | mgos_onewire.h |
This library provides support for 1-wire protocol for Mongoose OS.
uint8_t mgos_onewire_crc8(const uint8_t *rom, int len);
Calculate CRC8 of the given chunk of memory.
struct mgos_onewire *mgos_onewire_create(int pin);
Create onewire instance on a given pin.
bool mgos_onewire_reset(struct mgos_onewire *ow);
Reset onewire bus. Usually this is needed before communicating with any device.
void mgos_onewire_target_setup(struct mgos_onewire *ow,
const uint8_t family_code);
/*
* Search for the next device. The given `rom` should point to a chunk of at
* least 8 bytes; result will be written there. `mode` is as follows:
* 0 - normal search, 1 - conditional search.
*/
bool mgos_onewire_next(struct mgos_onewire *ow, uint8_t *rom, int mode);
Setup the search to find the device type 'family_code' on the next call mgos_onewire_next() if it is present Note if no devices of the desired family are currently on the 1-Wire, then another type will be found.
void mgos_onewire_select(struct mgos_onewire *ow, const uint8_t *rom);
Select a device based on is address
rom
, which is a 8-byte string. After a reset, this is needed to choose which device you will use, and then all communication will be with that device, until another reset.
void mgos_onewire_skip(struct mgos_onewire *ow);
Skip the device selection. This only works if you have a single device, but you can avoid searching and use this to immediately access your device.
void mgos_onewire_search_clean(struct mgos_onewire *ow);
Reset a search. Next use of
mgos_onewire_next
will begin at the first device.
bool mgos_onewire_read_bit(struct mgos_onewire *ow);
Read a single bit from the onewire bus. Returned value is
true
for 1, orfalse
for 0.
uint8_t mgos_onewire_read(struct mgos_onewire *ow);
Read a byte from the onewire bus.
void mgos_onewire_read_bytes(struct mgos_onewire *ow, uint8_t *buf, int len);
Read
len
bytes from the onewire bus to the bufferbuf
.
void mgos_onewire_write_bit(struct mgos_onewire *ow, int bit);
Write a single bit to the onewire bus; given
bit
should be either0
or1
.
void mgos_onewire_write(struct mgos_onewire *ow, const uint8_t data);
Write a byte to the onewire bus.
void mgos_onewire_write_bytes(struct mgos_onewire *ow, const uint8_t *buf,
int len);
Write
len
bytes to the onewire bus frombuf
.
void mgos_onewire_close(struct mgos_onewire *ow);
edit this docClose onewire instance and free the occupied memory.