Skip to content

Commit bf8f389

Browse files
jgoppertbperseghetti
authored andcommitted
Add lighting for SIL.
Co-authored-by: James Goppert <james.goppert@gmail.com> Signed-off-by: Benjamin Perseghetti <bperseghetti@rudislabs.com>
1 parent 2eab16e commit bf8f389

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

app/b3rb/src/lighting.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,8 @@ static void lighting_work_handler(struct k_work* work)
160160
const double* color = NULL;
161161
if (ctx->safety.status == synapse_msgs_Safety_Status_SAFETY_SAFE) {
162162
color = color_safe;
163-
} else if (ctx->safety.status == synapse_msgs_Safety_Status_SAFETY_UNSAFE) {
164-
color = color_unsafe;
165163
} else {
166-
color = color_unknown;
164+
color = color_unsafe;
167165
}
168166
set_led(safety_leds[i], color, brightness, &ctx->led_array.led[led_msg_index]);
169167
led_msg_index++;

lib/dream/sil/zephyr_main.c

+21-1
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ static struct k_thread my_thread_data;
3535
static void zephyr_sim_entry_point(void* p0, void* p1, void* p2)
3636
{
3737
struct zros_node node;
38-
struct zros_sub sub_actuators;
38+
struct zros_sub sub_actuators, sub_led_array;
3939
synapse_msgs_Actuators actuators;
40+
synapse_msgs_LEDArray led_array;
4041

4142
zros_node_init(&node, "dream_sil");
4243
zros_sub_init(&sub_actuators, &node, &topic_actuators, &actuators, 10);
44+
zros_sub_init(&sub_led_array, &node, &topic_led_array, &led_array, 10);
4345

4446
sil_context_t* ctx = p0;
4547
ARG_UNUSED(p1);
@@ -103,6 +105,24 @@ static void zephyr_sim_entry_point(void* p0, void* p1, void* p2)
103105
}
104106
}
105107

108+
// send led array if subscription updated
109+
if (zros_sub_update_available(&sub_led_array)) {
110+
zros_sub_update(&sub_led_array);
111+
TF_Msg msg;
112+
TF_ClearMsg(&msg);
113+
uint8_t buf[synapse_msgs_LEDArray_size];
114+
pb_ostream_t stream = pb_ostream_from_buffer((pu8)buf, sizeof(buf));
115+
int status = pb_encode(&stream, synapse_msgs_LEDArray_fields, &led_array);
116+
if (status) {
117+
msg.type = SYNAPSE_LED_ARRAY_TOPIC;
118+
msg.data = buf;
119+
msg.len = stream.bytes_written;
120+
TF_Send(&ctx->tf, &msg);
121+
} else {
122+
LOG_ERR("encoding failed: %s", PB_GET_ERROR(&stream));
123+
}
124+
}
125+
106126
// compute board time
107127
uint64_t uptime = k_uptime_get();
108128
struct timespec ts_board;

0 commit comments

Comments
 (0)