diff --git a/firmware/ble113_rfspy/gatt.xml b/firmware/ble113_rfspy/gatt.xml index dc7e450..062a312 100644 --- a/firmware/ble113_rfspy/gatt.xml +++ b/firmware/ble113_rfspy/gatt.xml @@ -48,7 +48,7 @@ Version - ble_rfspy 0.9 + ble_rfspy 2.0 LED Mode diff --git a/firmware/ble113_rfspy/main.bgs b/firmware/ble113_rfspy/main.bgs index 7b6a370..4b28bee 100644 --- a/firmware/ble113_rfspy/main.bgs +++ b/firmware/ble113_rfspy/main.bgs @@ -8,6 +8,7 @@ dim spi_out_buf_len # 1 = waiting for ble client to read bytes from data attr. # We halt spi comms until this happens. Crude flow control. dim waiting_for_client +dim connected dim slave_bytes_avail dim spi_xfer_size dim spi_batch_size @@ -94,6 +95,10 @@ procedure set_led_mode(value) end procedure do_spi() + if in_spi = 1 then + return + end if + in_spi = 1 call hardware_io_port_write(0, $10, 0) @@ -153,13 +158,14 @@ event attributes_value(connection, reason, handle, offset, value_len, value_data if handle = xgatt_data then if offset = 0 then expected_length = value_data(0:1) + 1 + waiting_for_client = 0 end if spi_out_buf(offset:value_len) = value_data(0:value_len) # Write to SPI if finished if offset + value_len = expected_length then spi_out_buf_len = expected_length - if waiting_for_client != 1 && in_spi = 0 + if waiting_for_client != 1 call do_spi() end if end if @@ -200,9 +206,9 @@ event attributes_user_read_request(connection, handle, offset, maxsize) if waiting_for_client = 0 call set_data_led(0) + call do_spi() end if - end if if handle = xgatt_led_mode then @@ -240,7 +246,7 @@ end # Timer event listener to poll data from spi event hardware_soft_timer(handle) - if waiting_for_client != 1 && in_spi = 0 + if waiting_for_client != 1 && connected = 1 then call do_spi() end if @@ -258,6 +264,7 @@ end event connection_status(connection, flags, address, address_type, conn_interval, timeout, latency, bonding) # Device is connected. Turn on green led call hardware_io_port_write(0, $1, $1) + connected = 1 # Drop any data what was waiting to go to client from # previous connection. @@ -272,6 +279,7 @@ event connection_disconnected(handle,res) call gap_set_mode(gap_general_discoverable,gap_undirected_connectable) # Device disconnected. Turn off green led call hardware_io_port_write(0, $1, $0) + connected = 0 # Save name if name_len > 0 diff --git a/firmware/ble113_rfspy/variable_memory_usage.txt b/firmware/ble113_rfspy/variable_memory_usage.txt index e0364a4..7fc2b9b 100644 --- a/firmware/ble113_rfspy/variable_memory_usage.txt +++ b/firmware/ble113_rfspy/variable_memory_usage.txt @@ -1,4 +1,4 @@ -644 +648 0:0 GAP_AD_FLAG_BREDR_NOT_SUPPORTED 0:0 GAP_AD_FLAG_GENERAL_DISCOVERABLE 0:0 GAP_AD_FLAG_LIMITED_DISCOVERABLE @@ -89,26 +89,27 @@ 261:255 spi_out_buf 516:4 spi_out_buf_len 520:4 waiting_for_client -524:4 slave_bytes_avail -528:4 spi_xfer_size -532:4 spi_batch_size -536:4 spi_batch_offset -540:32 name -572:4 name_len -576:4 result -580:4 channel -584:4 continue -588:4 escaping -592:4 bytes_to_send -596:4 tlen -600:4 idx -604:4 response_count -608:4 expected_length -612:4 send_idx -616:4 chunk_size -620:4 in_spi -624:4 timer_tick_count -628:4 timer_update_count -632:4 led_mode -636:4 batconn_handle -640:4 batresult +524:4 connected +528:4 slave_bytes_avail +532:4 spi_xfer_size +536:4 spi_batch_size +540:4 spi_batch_offset +544:32 name +576:4 name_len +580:4 result +584:4 channel +588:4 continue +592:4 escaping +596:4 bytes_to_send +600:4 tlen +604:4 idx +608:4 response_count +612:4 expected_length +616:4 send_idx +620:4 chunk_size +624:4 in_spi +628:4 timer_tick_count +632:4 timer_update_count +636:4 led_mode +640:4 batconn_handle +644:4 batresult