From 6c5c1f033504dfbddb91454d4b11bcf0ac7b1bde Mon Sep 17 00:00:00 2001 From: Laurens Valk Date: Sat, 14 Jun 2025 17:39:29 +0200 Subject: [PATCH 1/2] pbio/port_lump: Send keep-alive right away. It turns out the ColorLightMatrix needs the NACK to get going at all, so make sure we always send one before we start waiting on the timeout. In b17e5033dcc4edd75722839c4832c791f0e698a8, we removed grace period of 6 keep-alive messages to go unanswered, which was essentially masking this issue so the device worked before. --- lib/pbio/src/port_lump.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/pbio/src/port_lump.c b/lib/pbio/src/port_lump.c index 49ea35d41..fdce2b38a 100644 --- a/lib/pbio/src/port_lump.c +++ b/lib/pbio/src/port_lump.c @@ -917,7 +917,9 @@ pbio_error_t pbio_port_lump_data_send_thread(pbio_os_state_t *state, pbio_port_l PBIO_OS_ASYNC_BEGIN(state); - pbio_os_timer_set(timer, EV3_UART_DATA_KEEP_ALIVE_TIMEOUT); + // Some devices need the NACK keep-alive signal before doing anything, so + // initially set the timer to expire soon. + pbio_os_timer_set(timer, 1); for (;;) { @@ -925,8 +927,9 @@ pbio_error_t pbio_port_lump_data_send_thread(pbio_os_state_t *state, pbio_port_l // Handle keep alive timeout if (pbio_os_timer_is_expired(timer)) { - // make sure we are receiving data - if (!lump_dev->data_rec) { + // Make sure we are receiving data. The first time around, we allow + // not having any data yet. + if (!lump_dev->data_rec && timer->duration == EV3_UART_DATA_KEEP_ALIVE_TIMEOUT) { debug_pr("No data since last keepalive\n"); lump_dev->status = PBDRV_LEGODEV_LUMP_STATUS_ERR; return PBIO_ERROR_TIMEDOUT; From 4a4714aa1fb4b4a93803cf00c4af5543e299218a Mon Sep 17 00:00:00 2001 From: Laurens Valk Date: Mon, 16 Jun 2025 09:25:28 +0200 Subject: [PATCH 2/2] pbio/port_lump: Revert setting EV3 Color Sensor ambient mode. This was added in 91acfb321b54ac083e00712f087bb2d6f4c51543 to get the sensor going. Since 6c5c1f033504dfbddb91454d4b11bcf0ac7b1bde, we are doing it by sending a keep-alive message, so we don't need to set any mode on this sensor. It seems better to stick to the default reflection mode. --- lib/pbio/src/port_lump.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/pbio/src/port_lump.c b/lib/pbio/src/port_lump.c index fdce2b38a..cba71058e 100644 --- a/lib/pbio/src/port_lump.c +++ b/lib/pbio/src/port_lump.c @@ -881,8 +881,6 @@ pbio_error_t pbio_port_lump_sync_thread(pbio_os_state_t *state, pbio_port_lump_d default_mode = LEGO_DEVICE_MODE_PUP_REL_MOTOR__POS; } else if (lump_dev->type_id == LEGO_DEVICE_TYPE_ID_COLOR_DIST_SENSOR) { default_mode = LEGO_DEVICE_MODE_PUP_COLOR_DISTANCE_SENSOR__RGB_I; - } else if (lump_dev->type_id == LEGO_DEVICE_TYPE_ID_EV3_COLOR_SENSOR) { - default_mode = LEGO_DEVICE_MODE_EV3_COLOR_SENSOR__AMBIENT; } if (default_mode) { pbio_port_lump_request_mode(lump_dev, default_mode); @@ -1014,7 +1012,7 @@ pbio_error_t pbio_port_lump_data_recv_thread(pbio_os_state_t *state, pbio_port_l lump_dev->rx_msg_size = ev3_uart_get_msg_size(lump_dev->rx_msg[0]); if (lump_dev->rx_msg_size < 3 || lump_dev->rx_msg_size > EV3_UART_MAX_MESSAGE_SIZE) { - debug_pr("Bad data message size %d\n", lump_dev->rx_msg_size); + debug_pr("Bad data message size\n"); continue; }