diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-06-03 11:25:23 +0200 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-06-03 11:25:23 +0200 |
commit | 3a8fcd3a27cc39a360e367a0492878e2e9aa8f28 (patch) | |
tree | 28e28be08d5e63a3473bd65f8635f9605e1c7af6 | |
parent | 5a096a31cab585c1a0d938d64ebcc651900fbf42 (diff) |
demo working kinda
-rw-r--r-- | main/i2c.c | 11 | ||||
-rw-r--r-- | main/sock.c | 1 | ||||
-rw-r--r-- | shared/pb/types.h | 4 |
3 files changed, 13 insertions, 3 deletions
@@ -75,7 +75,8 @@ int write_read_i2c(uint8_t addr, uint8_t *input, size_t input_len, uint8_t *outp uint8_t* scan_bus(uint8_t *array) { int ret; int i = 0; - uint8_t* rxdata, handshake_data; + uint8_t * rxdata; + uint8_t * handshake_data; init_addr_array(array, MAX_SLAVES); for(int addr = 1; addr < (1<<7); addr++) { @@ -85,15 +86,19 @@ uint8_t* scan_bus(uint8_t *array) { if ( ret <= 0 ) continue; - printf("found possible i2c slave on addr: %d\n", addr); + char buf[80]; + size_t s = snprintf(buf, 80,"found i2c puzzle module at address: 0x%02x\n", addr); + netconn_write(current_connection, buf, s, NETCONN_COPY); + printf("%.*s", s, buf); // do handshake - ret = write_read_i2c(addr, (uint8_t*)pb_magic_msg, sizeof(pb_magic_msg), &handshake_data, sizeof(pb_magic_res)); // fix data + length + everything + ret = write_read_i2c(addr, (uint8_t*)pb_magic_msg, sizeof(pb_magic_msg), handshake_data, sizeof(pb_magic_res)); // fix data + length + everything if ( ret != sizeof(pb_magic_res)) continue; if ( ret > 0 && (memcmp(handshake_data, pb_magic_res, sizeof(pb_magic_res)) == 0)) { + printf("this was an actual device!!!1111!\n"); char buf[80]; size_t s = snprintf(buf, 80,"found i2c puzzle module at address: 0x%02x\n"); netconn_write(current_connection, buf, s, NETCONN_COPY); diff --git a/main/sock.c b/main/sock.c index 1913698..af25d97 100644 --- a/main/sock.c +++ b/main/sock.c @@ -53,6 +53,7 @@ void recv_handler(struct netconn* conn, struct netbuf* buf) { 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 diff --git a/shared/pb/types.h b/shared/pb/types.h index f2e2078..d4a65ed 100644 --- a/shared/pb/types.h +++ b/shared/pb/types.h @@ -6,9 +6,13 @@ extern "C" { #endif #ifdef __GNUC__ +#ifndef __packed #define __packed __attribute__((packed)) +#endif +#ifndef __weak #define __weak __attribute__((weak)) #endif +#endif #ifndef __packed #error Could not determine packed attribute for current compiler #define __packed |