From b865921e5dcf2ae2d6532b88eba1a0a49998eb27 Mon Sep 17 00:00:00 2001 From: ThomasintAnker Date: Fri, 31 May 2024 15:01:11 +0200 Subject: shenanigans --- main/i2c.c | 39 +++++++++++++++++++++++---------------- main/init.c | 4 ++-- main/sock.c | 6 ++++-- 3 files changed, 29 insertions(+), 20 deletions(-) (limited to 'main') diff --git a/main/i2c.c b/main/i2c.c index e42e0b1..5cad081 100644 --- a/main/i2c.c +++ b/main/i2c.c @@ -49,14 +49,16 @@ uint8_t* scan_bus(uint8_t *array) { int i = 0; uint8_t rxdata; - for(int addr = 0; addr < (1<<7); addr++) { + for(int addr = 1; addr < (1<<7); addr++) { // ignore reserved addresses // These are any addresses of the form 000 0xxx or 111 1xxx - if( reserved_addr(addr) ){ - ret = PICO_ERROR_GENERIC; - }else{ - ret = i2c_read_blocking(I2C_PORT, addr, &rxdata, 1, false); - } + + // if( reserved_addr(addr) ){ + // ret = PICO_ERROR_GENERIC; + // }else{ + // + ret = i2c_read_blocking(I2C_PORT, addr, &rxdata, 1, false); + //} // if acknowledged -> ret == number of bytes sent if(ret > 0){ @@ -77,31 +79,36 @@ void bus_task() { int i = 0; uint8_t found[MAX_SLAVES]; init_addr_array(found, MAX_SLAVES); + scan_bus(found); while(1) { // printf("Bus scan!"); - scan_bus(found); uint8_t data; for(int i = 0; i < MAX_SLAVES; i++){ if( found[i] == 0x00 ) - break; + continue; - data = 0x01; - // send data to found slave address - write_i2c(found[i], &data, 1); + read_i2c(found[i], &data, 2); + if(data > 0) { + printf("Data: %d", data); + } + + // data = 0x01; + // // send data to found slave address + // write_i2c(found[i], &data, 1); + + // data = 0x02; + // write_i2c(found[i], &data, 1); - data = 0x02; - write_i2c(found[i], &data, 1); // request update from slave addr at found[i] //write_i2c(); } uint8_t rcvData[2]; - if(xQueueReceive(queue, &rcvData, portMAX_DELAY) == pdPASS){ + if(xQueueReceive(queue, &rcvData, 5) == pdPASS){ + printf("Send to address: %d, datat: %d\n", rcvData[0], rcvData[1]); write_i2c(rcvData[0], &rcvData[1], sizeof(rcvData[1])); - } else { - printf("Something went wrong at queue receive!\n"); } } } diff --git a/main/init.c b/main/init.c index fee3a6a..4ab373e 100644 --- a/main/init.c +++ b/main/init.c @@ -25,8 +25,8 @@ static void init_wifi() { cyw43_arch_enable_sta_mode(); /* WERKT GEWOON NIET MET DEZE LIJNEN CODE */ - // if (cyw43_arch_wifi_connect_timeout_ms(CONF_NET_SSID, CONF_NET_PASS, CONF_NET_AUTH, CONF_NET_CONN_TIMEOUT)) - // panic("cyw43_arch_wifi_connect failed\n"); + if (cyw43_arch_wifi_connect_timeout_ms(CONF_NET_SSID, CONF_NET_PASS, CONF_NET_AUTH, CONF_NET_CONN_TIMEOUT)) + panic("cyw43_arch_wifi_connect failed\n"); /* WERKT GEWOON NIET MET DEZE LIJNEN CODE */ printf("connected to Wi-Fi\n"); diff --git a/main/sock.c b/main/sock.c index 5c8644b..434694f 100644 --- a/main/sock.c +++ b/main/sock.c @@ -55,8 +55,8 @@ void i2c_recv(uint16_t addr, const char * data, size_t data_size) { printf("Sending data over i2c"); uint8_t i2cData[2] = {addr, 0x00}; - if(xQueueSend(queue, &i2cData, portMAX_DELAY) != pdPASS) { - printf("Something went wrong!"); + if(xQueueSend(queue, &i2cData, portMAX_DELAY) == pdPASS) { + printf("Socket send data to address: %d, data: %d", i2cData[0], i2cData[1]); } } @@ -70,8 +70,10 @@ void recv_handler(struct netconn* conn, struct netbuf* buf) { netbuf_data(buf, (void**)&data, &len); // continue early if more data is needed to complete message + printf("yeetus deletus defeatus"); if (!pb_read(&recv_msg, data, len)) continue; + printf("yeetus deletus defeatus v2!"); // forward received message to puzzle bus i2c_recv(recv_msg.addr, recv_msg.data, recv_msg.length); free(recv_msg.data); -- cgit v1.2.3