Skip to content

Commit 3f7760e

Browse files
committed
sensors: LEGO EV3 Color: add 4th value on RGB-RAW mode
The LEGO EV3 Color sensor actually sends 4 values in the RGB-RAW mode instead of the reported 3, so add some hacks to enable access to this extra value.
1 parent 89bde52 commit 3f7760e

3 files changed

Lines changed: 11 additions & 5 deletions

File tree

brickpi3/brickpi3_ports_in.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,18 +247,20 @@ static void brickpi3_in_port_poll_work(struct work_struct *work)
247247
break;
248248
case BRICKPI3_SENSOR_TYPE_EV3_COLOR_COLOR_COMPONENTS:
249249
ret = brickpi3_read_sensor(data->bp, data->address, data->index,
250-
data->sensor_type, msg, 6);
250+
data->sensor_type, msg, 8);
251251
if (ret < 0)
252252
return;
253253

254-
// 3 16-bit values
254+
// 4 16-bit values
255255
if (raw_data) {
256256
raw_data[0] = msg[1];
257257
raw_data[1] = msg[0];
258258
raw_data[2] = msg[3];
259259
raw_data[3] = msg[2];
260260
raw_data[4] = msg[5];
261261
raw_data[5] = msg[4];
262+
raw_data[6] = msg[7];
263+
raw_data[7] = msg[6];
262264
}
263265
break;
264266
case BRICKPI3_SENSOR_TYPE_EV3_INFRARED_SEEK:

sensors/ev3_uart_sensor_defs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ const struct ev3_uart_sensor_info ev3_uart_sensor_defs[] = {
100100
* @value0: Red (0 to 1020???)
101101
* @value1: Green (0 to 1020???)
102102
* @value2: Blue (0 to 1020???)
103-
* @units_description: color
103+
* @value3: Ambient? (0 to 1020???)
104104
*/
105105
.name = "RGB-RAW",
106-
.data_sets = 3,
106+
.data_sets = 4,
107107
.data_type = LEGO_SENSOR_DATA_S16,
108108
},
109109
[5] = {

sensors/ev3_uart_sensor_ld.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,11 @@ static int ev3_uart_receive_buf2(struct tty_struct *tty,
834834
port->last_err = "Received duplicate format INFO.";
835835
goto err_invalid_state;
836836
}
837-
port->mode_info[mode].data_sets = message[2];
837+
/* LEGO EV3 Color sensor reports wrong value for RGB-RAW mode */
838+
if (port->type_id == EV3_UART_TYPE_ID_COLOR && mode == 4)
839+
port->mode_info[mode].data_sets = 4;
840+
else
841+
port->mode_info[mode].data_sets = message[2];
838842
if (!port->mode_info[mode].data_sets) {
839843
port->last_err = "Invalid number of data sets.";
840844
goto err_invalid_state;

0 commit comments

Comments
 (0)