Skip to content

Commit 0dcfcb1

Browse files
committed
Added feature to show if Frame is paired or not on the display
1 parent f9ba6bf commit 0dcfcb1

File tree

5 files changed

+28
-9
lines changed

5 files changed

+28
-9
lines changed

source/application/bluetooth.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ void SD_EVT_IRQHandler(void)
356356
}
357357
}
358358

359-
void bluetooth_setup(bool factory_reset)
359+
void bluetooth_setup(bool factory_reset, bool *is_paired)
360360
{
361361
// Enable the softdevice using internal RC oscillator
362362
check_error(sd_softdevice_enable(NULL, softdevice_assert_handler));
@@ -439,6 +439,15 @@ void bluetooth_setup(bool factory_reset)
439439
flash_wait_until_complete();
440440
}
441441

442+
// Check if already paired
443+
ble_gap_enc_info_t zero_struct;
444+
memset(&zero_struct, 0xFF, sizeof(ble_gap_enc_info_t));
445+
if (memcmp((void *)bond_storage, &zero_struct, sizeof(ble_gap_enc_info_t)))
446+
{
447+
LOG("Device is paired");
448+
*is_paired = true;
449+
}
450+
442451
// Read stored encryption key from memory
443452
memcpy(&bond.own_key.enc_info,
444453
(void *)bond_storage,

source/application/bluetooth.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#define BLE_PREFERRED_MAX_MTU 185
3232
extern uint16_t ble_negotiated_mtu;
3333

34-
void bluetooth_setup(bool factory_reset);
34+
void bluetooth_setup(bool factory_reset, bool *is_paired);
3535

3636
bool bluetooth_is_connected(void);
3737

source/application/luaport.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void lua_break_signal_interrupt(void)
6363
1);
6464
}
6565

66-
void run_lua(bool factory_reset)
66+
void run_lua(bool factory_reset, bool is_paired)
6767
{
6868
lua_State *L = luaL_newstate();
6969
L_global = L; // Only used for interrupts
@@ -125,9 +125,18 @@ void run_lua(bool factory_reset)
125125
}
126126

127127
// Show splash screen
128-
status = luaL_dostring(L, "frame.display.text('Ready to Pair', 200, 140);"
129-
"frame.display.text('Frame '..frame.bluetooth.address():sub(-2, -1), 245, 210, { color = 'ORANGE' });"
130-
"frame.display.show();");
128+
if (!is_paired)
129+
{
130+
status = luaL_dostring(L, "frame.display.text('Ready to Pair', 200, 140);"
131+
"frame.display.text('Frame '..frame.bluetooth.address():sub(-2, -1), 245, 210, { color = 'GREEN' });"
132+
"frame.display.show();");
133+
}
134+
else
135+
{
136+
status = luaL_dostring(L, "frame.display.text('Frame is Paired', 185, 140);"
137+
"frame.display.text('Frame '..frame.bluetooth.address():sub(-2, -1), 245, 210, { color = 'ORANGE' });"
138+
"frame.display.show();");
139+
}
131140

132141
if (status != LUA_OK)
133142
{

source/application/luaport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ void lua_write_to_repl(uint8_t *buffer, uint8_t length);
3838

3939
void lua_break_signal_interrupt(void);
4040

41-
void run_lua(bool factory_reset);
41+
void run_lua(bool factory_reset, bool is_paired);

source/application/main.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,16 +402,17 @@ int main(void)
402402
LOG("Frame firmware " BUILD_VERSION " (" GIT_COMMIT ")");
403403

404404
bool factory_reset = false;
405+
bool is_paired = false;
405406

406407
hardware_setup(&factory_reset);
407408

408-
bluetooth_setup(factory_reset);
409+
bluetooth_setup(factory_reset, &is_paired);
409410

410411
while (1)
411412
{
412413
reload_watchdog(NULL, NULL);
413414

414-
run_lua(factory_reset);
415+
run_lua(factory_reset, is_paired);
415416

416417
factory_reset = false;
417418
}

0 commit comments

Comments
 (0)