Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions lib/pbio/src/port_lump.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -917,16 +915,19 @@ 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 (;;) {

PBIO_OS_AWAIT_UNTIL(state, pbio_os_timer_is_expired(timer) || lump_dev->mode_switch.requested || lump_dev->data_set->size > 0);

// 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;
Expand Down Expand Up @@ -1011,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;
}

Expand Down