Skip to main content

AppMessages

Struct AppMessages 

Source
pub struct AppMessages { /* private fields */ }
Expand description

This struct provides access to app messages. You must use AppMessages::open to be able to register handlers and send messages.

You receive an instance of this from crate::main.

Implementations§

Source§

impl AppMessages

Source

pub fn open<'handle>( &'handle mut self, size_inbound: u32, size_outbound: u32, ) -> OpenAppMessages<'handle>

Open the app message service with the given buffer sizes.

Returns an OpenAppMessages that can be used to send messages and register event listeners via OpenAppMessages::listen.

When the returned OpenAppMessages is dropped, the app message service is closed and SDK callbacks are deregistered.

Examples found in repository?
example/src/lib.rs (line 46)
42async fn async_main_(mut services: bordstein::PebbleServices, _spawner: embassy_executor::Spawner) {
43    bordstein::info!("Async main called!");
44
45    with_window(async |mut h| {
46        let app_messages = services.app_messages.open(1024, 512);
47        stack_pin_init!(let _app_message_listener = app_messages.listen(
48            |_d| {},
49            |_| {},
50            |_| {},
51            |_, _| {},
52        ));
53        stack_pin_init!(let _app_message_listener = app_messages.listen(
54            |_d| {},
55            |_| {},
56            |_| {},
57            |_, _| {},
58        ));
59        stack_pin_init!(let _app_message_listener = app_messages.listen_received(
60            |_d| {},
61        ));
62
63        let _ = app_messages.send(|d| d.u8(10001, 123));
64
65        h.set_background_colour(GColor8::RED);
66
67        let window_bounds = h.root_layer().bounds();
68        bordstein::info!("Window bounds: {:?}", window_bounds);
69
70        stack_pin_init!(let timer_minutes = TickService::listen(TimeUnits::MINUTE_UNIT, |time, _| {
71            bordstein::info!("minute timer tick: {:?}", time);
72        }));
73
74        let mut foo = 123;
75
76        {
77            stack_pin_init!(let timer_seconds = TickService::listen(TimeUnits::SECOND_UNIT, |time, _| {
78                bordstein::info!("second timer tick: {:?}", time);
79            }));
80
81            let root_layer = h.root_layer();
82            let status_bar = root_layer.new_child::<StatusBarLayer>(()).unwrap();
83
84            let remaining_space =
85                window_bounds.shrink_to_avoid(status_bar.layer().bounds(), shapes::Edge::Top, 0);
86
87            stack_pin_init! {
88                let child_layer = root_layer
89                    .new_child::<Layer>(remaining_space)
90                    .unwrap()
91                    .with_update_proc(|_layer, _ctx| {
92                        bordstein::debug!("Hello from layer callback: {}", foo);
93                        foo += 1;
94                    })
95            };
96
97            let mut num_taps: u32 = 0;
98
99            let mut accelerometer_service = services.accelerometer.enable();
100            stack_pin_init!(let tap_events = accelerometer_service.subscribe_to_tap_service(|axis, dir| {
101                num_taps += 1;
102                bordstein::info!("Tap! {}, {:?}, {}", num_taps, axis, dir);
103            }));
104
105            let mut text_layer: TextLayer<'_> = child_layer
106                .new_child::<TextLayer>(child_layer.bounds())
107                .unwrap();
108            text_layer.set_text_alignment(GTextAlignment::GTextAlignmentCenter);
109
110            let mut text_content: CString<64>;
111            for i in 0..10 {
112                text_content = CString::<64>::new();
113                let _ = ufmt::uwrite!(&mut text_content, "{}", i);
114                let _guard = text_layer.set_text(&text_content);
115
116                embassy_time::Timer::after_secs(1).await;
117
118                app_messages
119                    .send(|d| {
120                        d.u16(10001, 1234)?;
121
122                        Ok(())
123                    })
124                    .unwrap();
125            }
126
127            bordstein::info!("Child bounds: {:?}", child_layer.bounds());
128        }
129
130        stack_pin_init!(let timer_seconds_stream = TickService::stream(TimeUnits::SECOND_UNIT));
131        while let Some(t) = timer_seconds_stream.next().await {
132            bordstein::info!("second tick stream: {}", t.0.secs);
133        }
134
135        // layers now destroyed, app should show just the window with its red background
136
137        // if you have nothing else to do, but want to wait until the system
138        // closes the window, you can use core::future::pending.
139        core::future::pending::<()>().await;
140    })
141    .await
142    .unwrap();
143}

Auto Trait Implementations§

§

impl Freeze for AppMessages

§

impl RefUnwindSafe for AppMessages

§

impl Send for AppMessages

§

impl Sync for AppMessages

§

impl Unpin for AppMessages

§

impl UnsafeUnpin for AppMessages

§

impl UnwindSafe for AppMessages

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Init<T> for T

§

unsafe fn __init(self, slot: *mut T) -> Result<(), Infallible>

Initializes slot. Read more
§

fn chain<F>(self, f: F) -> ChainInit<Self, F, T, E>
where F: FnOnce(&mut T) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T> PinInit<T> for T

§

unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>

Initializes slot. Read more
§

fn pin_chain<F>(self, f: F) -> ChainPinInit<Self, F, T, E>
where F: FnOnce(Pin<&mut T>) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.