Skip to content
Snippets Groups Projects
Commit f838504f authored by tag2y19's avatar tag2y19 Committed by Tom Greig
Browse files

Add periodic time message on notify characteristic

Both up and down buttons prompt indicate messages now.
parent 0f848747
No related branches found
No related tags found
No related merge requests found
...@@ -53,6 +53,8 @@ static int ble_in_callback( uint16_t connection_handle, ...@@ -53,6 +53,8 @@ static int ble_in_callback( uint16_t connection_handle,
static void gpio_init( void ); static void gpio_init( void );
static void button_handler( void* data ); static void button_handler( void* data );
static void timeout( struct os_event* event );
/* GLOBALS!!! */ /* GLOBALS!!! */
static struct { static struct {
...@@ -68,6 +70,7 @@ static struct { ...@@ -68,6 +70,7 @@ static struct {
uint8_t frame_buffer[128 / 8 * 64 + 1] = { 0x40, 0, }; uint8_t frame_buffer[128 / 8 * 64 + 1] = { 0x40, 0, };
uint8_t* frame = &frame_buffer[1]; uint8_t* frame = &frame_buffer[1];
const size_t frame_size = 128 / 8 * 64; const size_t frame_size = 128 / 8 * 64;
uint32_t t = 0;
/* DATA!!! */ /* DATA!!! */
...@@ -145,6 +148,12 @@ int main( void ) { ...@@ -145,6 +148,12 @@ int main( void ) {
gpio_init(); gpio_init();
t = 0;
static struct os_callout timer;
os_callout_init( &timer, os_eventq_dflt_get(),
&timeout, &timer );
os_callout_reset( &timer, OS_TICKS_PER_SEC );
while ( 1 ) { while ( 1 ) {
os_eventq_run( os_eventq_dflt_get() ); os_eventq_run( os_eventq_dflt_get() );
...@@ -573,13 +582,13 @@ static void button_handler( void* data ) { ...@@ -573,13 +582,13 @@ static void button_handler( void* data ) {
ble_state.count--; ble_state.count--;
if ( ble_state.notify_status ) { if ( ble_state.indicate_status ) {
struct os_mbuf* om = struct os_mbuf* om =
ble_hs_mbuf_from_flat( &( ble_state.count ), 1 ); ble_hs_mbuf_from_flat( &( ble_state.count ), 1 );
assert( 0 == ble_gatts_notify_custom( assert( 0 == ble_gatts_indicate_custom(
ble_state.connection_handle, ble_state.connection_handle,
ble_state.notify_handle, om ) ); ble_state.indicate_handle, om ) );
} }
...@@ -606,3 +615,29 @@ static void button_handler( void* data ) { ...@@ -606,3 +615,29 @@ static void button_handler( void* data ) {
i2c_write( frame_buffer, sizeof frame_buffer ); i2c_write( frame_buffer, sizeof frame_buffer );
} }
static void timeout( struct os_event* event ) {
t++;
char str[32];
snprintf( str, sizeof str,
"Time: %lu:%02lu", t / 60, t % 60 );
memset( frame + frame_size / 2, 0, frame_size / 8 );
text8( str, frame, 4, 0 );
i2c_write( frame_buffer, sizeof frame_buffer );
if ( ble_state.notify_status ) {
struct os_mbuf* om =
ble_hs_mbuf_from_flat( str, strlen( str ) );
assert( 0 == ble_gatts_notify_custom(
ble_state.connection_handle,
ble_state.notify_handle, om ) );
}
struct os_callout* timer = (struct os_callout*) event->ev_arg;
os_callout_reset( timer, OS_TICKS_PER_SEC );
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment