Squashed commit of the following:

commit a4632bb7ad
Author: A.M. Rowsell <amrowsell@frozenelectronics.ca>
Date:   Mon Jan 21 20:13:12 2019 -0500

    Sanitizing key and wifi

    Signed-off-by: A.M. Rowsell <amrowsell@frozenelectronics.ca>

commit 5e3be0f561
Author: A.M. Rowsell <amrowsell@frozenelectronics.ca>
Date:   Mon Jan 21 19:53:42 2019 -0500

    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>

commit 48702bf328
Author: A.M. Rowsell <amrowsell@frozenelectronics.ca>
Date:   Sun Jan 20 21:13:04 2019 -0500

    First version that compiles with new file layout.

    Had to make many changes to get it to compile across many files,
    including removing the LOCAL specifier from almost all functions.
    Edited the Makefile to compile all three files and link them.
    Haven't tested on hardware yet, that's the next step.

    Lots of small changes to avoid warnings, now that I have turned
    -Wall on. This makes the code a bit "better".

    Signed-off-by: A.M. Rowsell <amrowsell@frozenelectronics.ca>

commit 1cd8191682
Author: A.M. Rowsell <amrowsell@frozenelectronics.ca>
Date:   Sat Jan 19 15:25:44 2019 -0500

    New branch for my new AIO key.

    Will have to remember to sanitize before committing to master.

    Signed-off-by: A.M. Rowsell <amrowsell@frozenelectronics.ca>

Signed-off-by: A.M. Rowsell <amrowsell@frozenelectronics.ca>
This commit is contained in:
A.M. Rowsell 2019-01-21 20:14:09 -05:00
commit 627df20e53
Signed by: amr
GPG key ID: 0B6E2D8375CF79A9
8 changed files with 317 additions and 106 deletions

109
onewire.c
View file

@ -1,38 +1,105 @@
#include <stdint.h>
#include "os_type.h"
#include "osapi.h"
#include "user_interface.h"
#include "gpio.h"
#include "hw_timer.c"
#include "onewire.h"
LOCAL void timerISR(void) {
return;
}
#define OWBUS BIT5
LOCAL void reset(oneWire_t *owDev) {
sint8 ICACHE_FLASH_ATTR reset(void) {
uint32_t time;
// reset the ow line, check for presence?
time = system_get_time() + 500;
gpio_output_set(0, OWBUS, OWBUS, 0); // pull GPIO4 low
while(system_get_time() < time); // delay 500uS
gpio_output_set(0, 0, 0, OWBUS); // let go of GPIO4
time = system_get_time() + 60;
while(system_get_time() < time);
uint8_t presence = (uint8_t)(gpio_input_get() >> 5) & 0x1;
// give a 480uS pause so the next onewire event doesn't get trampled
time = system_get_time() + 480;
while(system_get_time() < time);
if(!presence) {
return 1;
} else {
return -1;
}
}
LOCAL void ICACHE_FLASH_ATTR transact(oneWire_t *owDev, ds18b20_cmds cmd) {
void ICACHE_FLASH_ATTR transact(oneWire_t *owDev, ds18b20_cmds cmd) {
uint32_t time;
uint8_t sendBit;
uint8_t inBit = 0x00;
uint8_t inByte = 0x00;
switch(cmd) {
case READ_ROM:
break;
case MATCH_ROM:
break;
case SEARCH_ROM:
break;
case ALARM_SEARCH:
break;
os_printf("\nOnewire command: %d\n", cmd);
case SKIP_ROM:
break;
case CONVERT_T:
for(uint8_t i = 0; i < 8; i++) {
sendBit = (cmd >> i) & 0x1;
//os_printf("\nThe bit is: %d \t i is %d\n", sendBit, i);
if(sendBit == 1) {
//os_printf("\nWe are in sendBit == 1\n");
time = system_get_time() + 10;
gpio_output_set(0, OWBUS, OWBUS, 0); // pull low
while(system_get_time() < time);
gpio_output_set(0, 0, 0, OWBUS); // let go
time = system_get_time() + 50;
while(system_get_time() < time);
} else {
//os_printf("\nWe are in the sendBit else\n");
time = system_get_time() + 100;
gpio_output_set(0, OWBUS, OWBUS, 0); //pull low
while(system_get_time() < time);
gpio_output_set(0, 0, 0, OWBUS); // let go
time = system_get_time() + 10;
while(system_get_time() < time);
}
}
break;
case SCRATCH_READ:
for(uint8_t i = 0; i < 8; i++) {
sendBit = (cmd >> i) & 0x1;
if(sendBit == 1) {
//os_printf("\nWe are in sendBit == 1\n");
time = system_get_time() + 10;
gpio_output_set(0, OWBUS, OWBUS, 0); // pull low
while(system_get_time() < time);
gpio_output_set(0, 0, 0, OWBUS); // let go
time = system_get_time() + 50;
while(system_get_time() < time);
} else {
//os_printf("\nWe are in the sendBit else\n");
time = system_get_time() + 100;
gpio_output_set(0, OWBUS, OWBUS, 0); //pull low
while(system_get_time() < time);
gpio_output_set(0, 0, 0, OWBUS); // let go
time = system_get_time() + 10;
while(system_get_time() < time);
}
}
// now read the scratchpad
for(uint8_t i = 0; i < 2; i++) {
for(uint8_t j = 0; j < 8; j++) {
time = system_get_time() + 8;
gpio_output_set(0, OWBUS, OWBUS, 0);
while(system_get_time() < time);
gpio_output_set(0, 0, 0, OWBUS);
time = system_get_time() + 15;
while(system_get_time() < time);
inBit = (uint8_t)(gpio_input_get() >> 5) & 0x01;
inByte |= inBit << j;
time = system_get_time() + 45;
while(system_get_time() < time);
}
owDev->scratchpad[i] = inByte;
inByte = 0; // clear inByte
}
break;
case SCRATCH_WRITE:
break;
case SCRATCH_COPY:
break;
case E2_RECALL:
default:
os_printf("\nIncorrect command\n");
break;
}
}