@@ -19,8 +19,6 @@ const CONNECTIONS_MAX: usize = 1;
19
19
/// Max number of L2CAP channels.
20
20
const L2CAP_CHANNELS_MAX : usize = 2 ; // Signal + att
21
21
22
- type Resources < C > = HostResources < C , CONNECTIONS_MAX , L2CAP_CHANNELS_MAX , L2CAP_MTU > ;
23
-
24
22
// GATT Server definition
25
23
#[ gatt_server]
26
24
struct Server {
@@ -64,10 +62,11 @@ where
64
62
let address = Address :: random ( [ 0x42 , 0x6A , 0xE3 , 0x1E , 0x83 , 0xE7 ] ) ;
65
63
info ! ( "Our address = {:?}" , address) ;
66
64
67
- let mut resources = Resources :: new ( PacketQos :: None ) ;
68
- let ( stack, mut peripheral, _, runner) = trouble_host:: new ( controller, & mut resources)
69
- . set_random_address ( address)
70
- . build ( ) ;
65
+ let mut resources: HostResources < CONNECTIONS_MAX , L2CAP_CHANNELS_MAX , L2CAP_MTU > = HostResources :: new ( ) ;
66
+ let stack = trouble_host:: new ( controller, & mut resources) . set_random_address ( address) ;
67
+ let Host {
68
+ mut peripheral, runner, ..
69
+ } = stack. build ( ) ;
71
70
72
71
info ! ( "Starting advertising and GATT service" ) ;
73
72
let server = Server :: new_with_config ( GapConfig :: Peripheral ( PeripheralConfig {
82
81
Ok ( conn) => {
83
82
// set up tasks when the connection is established to a central, so they don't run when no one is connected.
84
83
let a = gatt_events_task ( & server, & conn) ;
85
- let b = custom_task ( & server, & conn, stack) ;
84
+ let b = custom_task ( & server, & conn, & stack) ;
86
85
// run until any task ends (usually because the connection has been closed),
87
86
// then return to advertising state.
88
87
select ( a, b) . await ;
@@ -180,7 +179,7 @@ async fn advertise<'a, C: Controller>(
180
179
/// This task will notify the connected central of a counter value every 2 seconds.
181
180
/// It will also read the RSSI value every 2 seconds.
182
181
/// and will stop when the connection is closed by the central or an error occurs.
183
- async fn custom_task < C : Controller > ( server : & Server < ' _ > , conn : & Connection < ' _ > , stack : Stack < ' _ , C > ) {
182
+ async fn custom_task < C : Controller > ( server : & Server < ' _ > , conn : & Connection < ' _ > , stack : & Stack < ' _ , C > ) {
184
183
let mut tick: u8 = 0 ;
185
184
let level = server. battery_service . level ;
186
185
loop {
0 commit comments