File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -1070,13 +1070,26 @@ void pbdrv_bluetooth_peripheral_disconnect(pbio_task_t *task) {
10701070static PT_THREAD (broadcast_task (struct pt * pt , pbio_task_t * task )) {
10711071 pbdrv_bluetooth_value_t * value = task -> context ;
10721072
1073+ static struct {
1074+ pbdrv_bluetooth_value_t v ;
1075+ uint8_t d [31 ];
1076+ } previous_value ;
1077+
10731078 PT_BEGIN (pt );
10741079
10751080 if (value -> size > B_MAX_ADV_LEN ) {
10761081 task -> status = PBIO_ERROR_INVALID_ARG ;
10771082 PT_EXIT (pt );
10781083 }
10791084
1085+ // Avoid I/O operations if the user tries to broadcast the same data
1086+ // over and over in a tight loop.
1087+ if (is_broadcasting && !memcmp ((void * )& previous_value , (void * )value , sizeof (pbdrv_bluetooth_value_t ) + value -> size )) {
1088+ task -> status = PBIO_SUCCESS ;
1089+ PT_EXIT (pt );
1090+ }
1091+ memcpy ((void * )& previous_value , (void * )value , sizeof (pbdrv_bluetooth_value_t ) + value -> size );
1092+
10801093 // HACK: calling GAP_updateAdvertisingData() repeatedly will cause the
10811094 // Bluetooth chips on Technic and City hubs to eventually lock up. So we
10821095 // call the standard Bluetooth command instead. We still get the vendor-
You can’t perform that action at this time.
0 commit comments