diff options
Diffstat (limited to 'main')
-rw-r--r-- | main/i2c.c | 1 | ||||
-rw-r--r-- | main/i2c.h | 2 | ||||
-rw-r--r-- | main/main.c | 7 | ||||
-rw-r--r-- | main/sock.c | 24 |
4 files changed, 23 insertions, 11 deletions
@@ -3,6 +3,7 @@ #include <stdio.h> #include <stddef.h> #include <stdint.h> +#include <string.h> #include <pico/stdlib.h> #include <hardware/i2c.h> @@ -1,7 +1,9 @@ #pragma once // https://github.com/raspberrypi/pico-examples/tree/master/i2c +// https://www.raspberrypi.com/documentation/microcontrollers/raspberry-pi-pico.html #define MAX_SLAVES 10 +#define MAX_TIMEOUT_TIME 50 //ms //! looking for slave addresses and requesting updates void bus_task(); diff --git a/main/main.c b/main/main.c index 1c615fc..7c1bb6a 100644 --- a/main/main.c +++ b/main/main.c @@ -6,5 +6,12 @@ int main() { init(); vTaskStartScheduler(); + + while(1) { + // we should have never gotten here + printf("Why are we here?!\n"); + } + + return 0; } diff --git a/main/sock.c b/main/sock.c index 6a5ff72..5d75e8f 100644 --- a/main/sock.c +++ b/main/sock.c @@ -9,7 +9,10 @@ #include "config.h" #include "i2ctcpv1.h" #include "sock.h" +#include "i2c.h" +#include <hardware/i2c.h> +extern uint8_t found[MAX_SLAVES]; struct netconn* current_connection = NULL; i2ctcp_msg_t recv_msg; @@ -35,31 +38,30 @@ void i2c_send(uint16_t addr, const char * data, size_t data_size) { } void i2c_recv(uint16_t addr, const char * data, size_t data_size) { - printf("address: 0x%02x\n", addr); - printf("data: \"%.*s\"\n", data_size, data); - - // send message back - char reply[] = "Test message back!"; - i2c_send(0x69, reply, strlen(reply)); - // TODO: this function should forward the recieved message onto the puzzle // bus instead of printing/replying + + printf("Addr: %lu, Data: %c, Data_size: %lu\n", addr, data[0], data_size); + i2c_write_blocking(i2c0, addr, data, data_size, false); } void recv_handler(struct netconn* conn, struct netbuf* buf) { - i2ctcp_read_reset(&recv_msg); + // i2ctcp_read_reset(&recv_msg); do { char* data; uint16_t len; netbuf_data(buf, (void**)&data, &len); + + printf("now scanning the bus!!!!\n"); + scan_bus(found); // continue early if more data is needed to complete message - if (!i2ctcp_read(&recv_msg, data, len)) continue; + // if (i2ctcp_read(&recv_msg, data, len) > 0) continue; // forward received message to puzzle bus - i2c_recv(recv_msg.addr, recv_msg.data, recv_msg.length); - free(recv_msg.data); + // i2c_recv(recv_msg.addr, recv_msg.data, recv_msg.length); + // free(recv_msg.data); } while (netbuf_next(buf) >= 0); netbuf_delete(buf); |