mqtt/onewire.h
A.M. Rowsell 5e3be0f561
It's alive! New code all working.
The OneWire library works. It's a bit hacked together, as neither
the software timer or hardware timer APIs would have worked well,
because they are implemented terribly by Espressif. The easiest
way to get around this was to just use system_get_time() and work
off of that for timing in one-wire comms.

Split the publish function into two separate functions: one to
publish floating point numbers, and one to publish integers. In
a language like Lua or C++ you could have these as one function,
but in C it's easier to just split them.

The main.c has a new function called dataLog that deals with
getting the DS18B20 data and then handing that off to pubfloat().

I updated the timer names to be more descriptive.

I grabbed some code to convert integers and floats to strings, as
I can't be bothered to write that code myself for the millionth
time.

If something goes wrong and we are disconnected from our TCP
connection, all timers are halted so we don't blindly keep
trying to send packets over a non-existent link.

Unfortunately the onewire library is hardcoded to use pin 5.
That will be the next update.

Signed-off-by: A.M. Rowsell <amrowsell@frozenelectronics.ca>
2019-01-21 19:53:42 -05:00

33 lines
847 B
C

#include <stdint.h>
#include "os_type.h"
#include "gpio.h"
/**
* @struct oneWire_t
* Structure that holds all the information about onewire connections, including the 64-bit ROM address for each device and some buffer memory to read out the scratchpad
*/
typedef struct {
uint8_t address[8];
uint8_t scratchpad[9];
float temperature;
} oneWire_t;
/**
* @enum ds18b20_cmds
* This enum simply gives easy to read names to all the various one-wire commands that the DS18B20 can accept
*/
typedef enum {
READ_ROM = 0x33,
MATCH_ROM = 0x55,
SEARCH_ROM = 0xF0,
ALARM_SEARCH = 0xEC,
SKIP_ROM = 0xCC,
CONVERT_T = 0x44,
SCRATCH_READ = 0xBE,
SCRATCH_WRITE = 0x4E,
SCRATCH_COPY = 0x48,
E2_RECALL = 0xB8
} ds18b20_cmds;
sint8 ICACHE_FLASH_ATTR reset(void);
void ICACHE_FLASH_ATTR transact(oneWire_t *owDev, ds18b20_cmds cmd);