Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
card10
firmware
Commits
25626ba3
Commit
25626ba3
authored
4 years ago
by
schneider
Browse files
Options
Downloads
Patches
Plain Diff
fix(ble): Correctly switch between ADV modes
parent
8458ce6e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!390
Bonding dialog
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
epicardium/ble/ble_main.c
+45
-16
45 additions, 16 deletions
epicardium/ble/ble_main.c
with
45 additions
and
16 deletions
epicardium/ble/ble_main.c
+
45
−
16
View file @
25626ba3
...
...
@@ -44,6 +44,8 @@
#include
"modules/log.h"
static
bool
active
;
static
uint8_t
advertising_mode
=
APP_MODE_NONE
;
static
uint8_t
advertising_mode_target
=
APP_MODE_NONE
;
static
enum
ble_event_type
ble_event
;
/**************************************************************************************************
...
...
@@ -355,15 +357,9 @@ static void bleSetup(bleMsg_t *pMsg)
AppAdvSetData
(
APP_ADV_DATA_CONNECTABLE
,
0
,
NULL
);
AppAdvSetData
(
APP_SCAN_DATA_CONNECTABLE
,
0
,
NULL
);
/* We only want to be bondable when the appropriate dialog is open */
AppSetBondable
(
FALSE
);
/* TODO: Sadly, not advertising leads to a higher current consumption... */
if
(
AppDbCheckBonded
()
==
FALSE
)
{
AppAdvStop
();
}
else
{
AppAdvStart
(
APP_MODE_CONNECTABLE
);
}
active
=
true
;
/* TODO: Sadly, not advertising leads to a higher current consumption... */
epic_ble_set_bondable
(
false
);
}
void
epic_ble_set_bondable
(
bool
bondable
)
...
...
@@ -373,18 +369,47 @@ void epic_ble_set_bondable(bool bondable)
}
if
(
bondable
)
{
LOG_INFO
(
"ble"
,
"Making bondable and discoverable"
);
/* We need to stop advertising in between or the
* adv set will not be changed... */
AppAdvStop
();
* adv set will not be changed.
* Also need to wait for the stop operation to finish
* before we can start again
* Also need to set the variables first as we don't
* have a lock on the stack.*/
AppSetBondable
(
TRUE
);
AppAdvStart
(
APP_MODE_DISCOVERABLE
);
if
(
advertising_mode
!=
APP_MODE_DISCOVERABLE
)
{
LOG_INFO
(
"ble"
,
"Making bondable and discoverable"
);
if
(
advertising_mode
!=
APP_MODE_NONE
)
{
advertising_mode_target
=
APP_MODE_DISCOVERABLE
;
advertising_mode
=
APP_MODE_NONE
;
AppAdvStop
();
}
else
{
advertising_mode
=
APP_MODE_DISCOVERABLE
;
advertising_mode_target
=
APP_MODE_DISCOVERABLE
;
AppAdvStart
(
advertising_mode
);
}
}
}
else
{
LOG_INFO
(
"ble"
,
"Making connectable"
);
AppAdvStop
();
AppSetBondable
(
FALSE
);
if
(
AppDbCheckBonded
())
{
AppAdvStart
(
APP_MODE_CONNECTABLE
);
if
(
advertising_mode
!=
APP_MODE_CONNECTABLE
)
{
LOG_INFO
(
"ble"
,
"Bonded. Making connectable"
);
if
(
advertising_mode
!=
APP_MODE_NONE
)
{
advertising_mode_target
=
APP_MODE_CONNECTABLE
;
advertising_mode
=
APP_MODE_NONE
;
AppAdvStop
();
}
else
{
advertising_mode
=
APP_MODE_CONNECTABLE
;
advertising_mode_target
=
APP_MODE_CONNECTABLE
;
AppAdvStart
(
advertising_mode
);
}
}
}
else
{
if
(
advertising_mode
!=
APP_MODE_NONE
)
{
LOG_INFO
(
"ble"
,
"Not bonded. Stop advertising"
);
advertising_mode
=
APP_MODE_NONE
;
advertising_mode_target
=
APP_MODE_NONE
;
AppAdvStop
();
}
}
}
}
...
...
@@ -475,7 +500,11 @@ static void bleProcMsg(bleMsg_t *pMsg)
break
;
case
DM_ADV_STOP_IND
:
LOG_INFO
(
"ble"
,
"Advertisement stopped"
);
LOG_INFO
(
"ble"
,
"Advertisement stopped %u %u"
,
advertising_mode
,
advertising_mode_target
);
if
(
advertising_mode
!=
advertising_mode_target
)
{
advertising_mode
=
advertising_mode_target
;
AppAdvStart
(
advertising_mode
);
}
break
;
case
DM_CONN_OPEN_IND
:
...
...
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