Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
BLE Demo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tag2y19
BLE Demo
Commits
f838504f
Commit
f838504f
authored
4 months ago
by
tag2y19
Committed by
Tom Greig
4 months ago
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
apps/ble-demo/src/main.c
+38
-3
38 additions, 3 deletions
apps/ble-demo/src/main.c
with
38 additions
and
3 deletions
apps/ble-demo/src/main.c
+
38
−
3
View file @
f838504f
...
@@ -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
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment