Skip to main content

OpenAppMessages

Struct OpenAppMessages 

Source
pub struct OpenAppMessages<'handle> { /* private fields */ }

Implementations§

Source§

impl<'open> OpenAppMessages<'open>

Source

pub fn send( &self, f: impl for<'dictionary> FnOnce(&mut DictionaryWriter<'dictionary>) -> Result<(), DictionaryResult>, ) -> Result<(), AppMessageSendResult>

Examples found in repository?
example/src/lib.rs (line 64)
43async fn async_main_(mut services: bordstein::PebbleServices, _spawner: embassy_executor::Spawner) {
44    bordstein::info!("Async main called!");
45
46    with_window(async |mut h| {
47        let app_messages = services.app_messages.open(1024, 512);
48        stack_pin_init!(let _app_message_listener = app_messages.listen(
49            |_d| {},
50            |_| {},
51            |_| {},
52            |_, _| {},
53        ));
54        stack_pin_init!(let _app_message_listener = app_messages.listen(
55            |_d| {},
56            |_| {},
57            |_| {},
58            |_, _| {},
59        ));
60        stack_pin_init!(let _app_message_listener = app_messages.listen_received(
61            |_d| {},
62        ));
63
64        let _ = app_messages.send(|d| d.u8(10001, 123));
65
66        h.set_background_colour(GColor8::RED);
67
68        let window_bounds = h.root_layer().bounds();
69        bordstein::info!("Window bounds: {:?}", window_bounds);
70
71        stack_pin_init!(let timer_minutes = TickService::listen(TimeUnits::MINUTE_UNIT, |time, _| {
72            bordstein::info!("minute timer tick: {:?}", time);
73        }));
74
75        {
76            stack_pin_init!(let timer_seconds = TickService::listen(TimeUnits::SECOND_UNIT, |time, _| {
77                bordstein::info!("second timer tick: {:?}", time);
78            }));
79
80            let root_layer = h.root_layer();
81            let status_bar = root_layer.new_child::<StatusBarLayer>(()).unwrap();
82
83            let remaining_space =
84                window_bounds.shrink_to_avoid(status_bar.layer().bounds(), shapes::Edge::Top, 0);
85
86            let mut child_layer = root_layer
87                .new_child::<ScrollLayer>(remaining_space)
88                .unwrap();
89
90            child_layer.set_click_config_onto_window(&mut h);
91
92            let mut num_taps: u32 = 0;
93
94            let mut accelerometer_service = services.accelerometer.enable();
95            stack_pin_init!(let tap_events = accelerometer_service.subscribe_to_tap_service(|axis, dir| {
96                num_taps += 1;
97                bordstein::info!("Tap! {}, {:?}, {}", num_taps, axis, dir);
98            }));
99
100            let mut text_layer = child_layer
101                .new_child::<TextLayer>(child_layer.layer().bounds().with_height(100))
102                .unwrap();
103            text_layer.set_text_alignment(GTextAlignment::GTextAlignmentCenter);
104
105            let mut fill_layer = child_layer
106                .new_child::<TextLayer>(child_layer.layer().bounds().translate(0, text_layer.layer().bounds().size.h))
107                .unwrap();
108
109            child_layer.set_content_size(GSize::total_bounds_of_rects([
110                text_layer.layer().frame(),
111                fill_layer.layer().frame(),
112            ]));
113            // child_layer.set_content_size(GSize::new(200, 500));
114
115            bordstein::info!("Scroll bounds: {:?}", child_layer.get_content_size());
116
117            let _guard = fill_layer.set_text(cr#"
118foo
119bar
120baz
121hello
122this
123is
124some
125text
126lorem
127ipsum
128dolor
129sit
130amet
131"#);
132
133            let mut text_content: CString<64>;
134            for i in 0..100 {
135                text_content = CString::<64>::new();
136                let _ = ufmt::uwrite!(&mut text_content, "{}", i);
137                let _guard = text_layer.set_text(&text_content);
138
139                embassy_time::Timer::after_secs(1).await;
140
141                // app_messages
142                //     .send(|d| {
143                //         d.u16(10001, 1234)?;
144
145                //         Ok(())
146                //     })
147                //     .unwrap();
148
149                child_layer.set_content_offset(GPoint::new(0, i * -10), true);
150
151                bordstein::info!("Scroll offset: {:?}", child_layer.get_content_offset());
152            }
153
154            bordstein::info!("Child bounds: {:?}", child_layer.layer().bounds());
155        }
156
157        stack_pin_init!(let timer_seconds_stream = TickService::stream(TimeUnits::SECOND_UNIT));
158        while let Some(t) = timer_seconds_stream.next().await {
159            bordstein::info!("second tick stream: {}", t.0.secs);
160        }
161
162        // layers now destroyed, app should show just the window with its red background
163
164        // if you have nothing else to do, but want to wait until the system
165        // closes the window, you can use core::future::pending.
166        core::future::pending::<()>().await;
167    })
168    .await
169    .unwrap();
170}
Source

pub fn listen<'env, 'this, FInboxReceived, FInboxDropped, FOutboxSent, FOutboxFailed>( &'this self, inbox_received: FInboxReceived, inbox_dropped: FInboxDropped, outbox_sent: FOutboxSent, outbox_failed: FOutboxFailed, ) -> impl PinInit<Handle<'this, AppMessageListener<'open, FInboxReceived, FInboxDropped, FOutboxSent, FOutboxFailed>>>
where FInboxReceived: for<'message> FnMut(DictionaryRef<'message>) + 'env, FInboxDropped: FnMut(AppMessageResult) + 'env, FOutboxSent: for<'message> FnMut(DictionaryRef<'message>) + 'env, FOutboxFailed: for<'message> FnMut(DictionaryRef<'message>, AppMessageResult) + 'env,

Register callbacks to listen on app message events.

These closures are capable of borrowing references to local variables.

NOTE: You can create multiple app message event listeners from multiple locations, the library handles this elegantly using an intrusive linked list of stack-allocated nodes.

This returns a [PinInit] as we need to pass the pebble SDK a pointer to the stack allocated closures passed in. If Handle could move, it would invalidate this reference.

Use [pin_init::stack_pin_init] to allocate the result of this method in your stack frame.

Examples found in repository?
src/app_message.rs (lines 243-248)
225    pub fn listen_received<'this, 'env, FInboxReceived>(
226        &'this self,
227        inbox_received: FInboxReceived,
228    ) -> impl PinInit<
229        Handle<
230            'this,
231            AppMessageListener<
232                'open,
233                FInboxReceived,
234                EmptyInboxDroppedHandler<'env>,
235                EmptyOutboxSentHandler<'env>,
236                EmptyOutboxFailedHandler<'env>,
237            >,
238        >,
239    >
240    where
241        FInboxReceived: for<'message> FnMut(DictionaryRef<'message>) + 'env,
242    {
243        self.listen(
244            inbox_received,
245            empty_inbox_dropped_handler(),
246            empty_outbox_sent_handler(),
247            empty_outbox_failed_handler(),
248        )
249    }
More examples
Hide additional examples
example/src/lib.rs (lines 48-53)
43async fn async_main_(mut services: bordstein::PebbleServices, _spawner: embassy_executor::Spawner) {
44    bordstein::info!("Async main called!");
45
46    with_window(async |mut h| {
47        let app_messages = services.app_messages.open(1024, 512);
48        stack_pin_init!(let _app_message_listener = app_messages.listen(
49            |_d| {},
50            |_| {},
51            |_| {},
52            |_, _| {},
53        ));
54        stack_pin_init!(let _app_message_listener = app_messages.listen(
55            |_d| {},
56            |_| {},
57            |_| {},
58            |_, _| {},
59        ));
60        stack_pin_init!(let _app_message_listener = app_messages.listen_received(
61            |_d| {},
62        ));
63
64        let _ = app_messages.send(|d| d.u8(10001, 123));
65
66        h.set_background_colour(GColor8::RED);
67
68        let window_bounds = h.root_layer().bounds();
69        bordstein::info!("Window bounds: {:?}", window_bounds);
70
71        stack_pin_init!(let timer_minutes = TickService::listen(TimeUnits::MINUTE_UNIT, |time, _| {
72            bordstein::info!("minute timer tick: {:?}", time);
73        }));
74
75        {
76            stack_pin_init!(let timer_seconds = TickService::listen(TimeUnits::SECOND_UNIT, |time, _| {
77                bordstein::info!("second timer tick: {:?}", time);
78            }));
79
80            let root_layer = h.root_layer();
81            let status_bar = root_layer.new_child::<StatusBarLayer>(()).unwrap();
82
83            let remaining_space =
84                window_bounds.shrink_to_avoid(status_bar.layer().bounds(), shapes::Edge::Top, 0);
85
86            let mut child_layer = root_layer
87                .new_child::<ScrollLayer>(remaining_space)
88                .unwrap();
89
90            child_layer.set_click_config_onto_window(&mut h);
91
92            let mut num_taps: u32 = 0;
93
94            let mut accelerometer_service = services.accelerometer.enable();
95            stack_pin_init!(let tap_events = accelerometer_service.subscribe_to_tap_service(|axis, dir| {
96                num_taps += 1;
97                bordstein::info!("Tap! {}, {:?}, {}", num_taps, axis, dir);
98            }));
99
100            let mut text_layer = child_layer
101                .new_child::<TextLayer>(child_layer.layer().bounds().with_height(100))
102                .unwrap();
103            text_layer.set_text_alignment(GTextAlignment::GTextAlignmentCenter);
104
105            let mut fill_layer = child_layer
106                .new_child::<TextLayer>(child_layer.layer().bounds().translate(0, text_layer.layer().bounds().size.h))
107                .unwrap();
108
109            child_layer.set_content_size(GSize::total_bounds_of_rects([
110                text_layer.layer().frame(),
111                fill_layer.layer().frame(),
112            ]));
113            // child_layer.set_content_size(GSize::new(200, 500));
114
115            bordstein::info!("Scroll bounds: {:?}", child_layer.get_content_size());
116
117            let _guard = fill_layer.set_text(cr#"
118foo
119bar
120baz
121hello
122this
123is
124some
125text
126lorem
127ipsum
128dolor
129sit
130amet
131"#);
132
133            let mut text_content: CString<64>;
134            for i in 0..100 {
135                text_content = CString::<64>::new();
136                let _ = ufmt::uwrite!(&mut text_content, "{}", i);
137                let _guard = text_layer.set_text(&text_content);
138
139                embassy_time::Timer::after_secs(1).await;
140
141                // app_messages
142                //     .send(|d| {
143                //         d.u16(10001, 1234)?;
144
145                //         Ok(())
146                //     })
147                //     .unwrap();
148
149                child_layer.set_content_offset(GPoint::new(0, i * -10), true);
150
151                bordstein::info!("Scroll offset: {:?}", child_layer.get_content_offset());
152            }
153
154            bordstein::info!("Child bounds: {:?}", child_layer.layer().bounds());
155        }
156
157        stack_pin_init!(let timer_seconds_stream = TickService::stream(TimeUnits::SECOND_UNIT));
158        while let Some(t) = timer_seconds_stream.next().await {
159            bordstein::info!("second tick stream: {}", t.0.secs);
160        }
161
162        // layers now destroyed, app should show just the window with its red background
163
164        // if you have nothing else to do, but want to wait until the system
165        // closes the window, you can use core::future::pending.
166        core::future::pending::<()>().await;
167    })
168    .await
169    .unwrap();
170}
Source

pub fn listen_received<'this, 'env, FInboxReceived>( &'this self, inbox_received: FInboxReceived, ) -> impl PinInit<Handle<'this, AppMessageListener<'open, FInboxReceived, EmptyInboxDroppedHandler<'env>, EmptyOutboxSentHandler<'env>, EmptyOutboxFailedHandler<'env>>>>
where FInboxReceived: for<'message> FnMut(DictionaryRef<'message>) + 'env,

Register callbacks to listen on app message receive events.

These closures are capable of borrowing references to local variables.

NOTE: You can create multiple app message event listeners from multiple locations, the library handles this elegantly using an intrusive linked list of stack-allocated nodes.

This returns a [PinInit] as we need to pass the pebble SDK a pointer to the stack allocated closures passed in. If Handle could move, it would invalidate this reference.

Use [pin_init::stack_pin_init] to allocate the result of this method in your stack frame.

Examples found in repository?
example/src/lib.rs (lines 60-62)
43async fn async_main_(mut services: bordstein::PebbleServices, _spawner: embassy_executor::Spawner) {
44    bordstein::info!("Async main called!");
45
46    with_window(async |mut h| {
47        let app_messages = services.app_messages.open(1024, 512);
48        stack_pin_init!(let _app_message_listener = app_messages.listen(
49            |_d| {},
50            |_| {},
51            |_| {},
52            |_, _| {},
53        ));
54        stack_pin_init!(let _app_message_listener = app_messages.listen(
55            |_d| {},
56            |_| {},
57            |_| {},
58            |_, _| {},
59        ));
60        stack_pin_init!(let _app_message_listener = app_messages.listen_received(
61            |_d| {},
62        ));
63
64        let _ = app_messages.send(|d| d.u8(10001, 123));
65
66        h.set_background_colour(GColor8::RED);
67
68        let window_bounds = h.root_layer().bounds();
69        bordstein::info!("Window bounds: {:?}", window_bounds);
70
71        stack_pin_init!(let timer_minutes = TickService::listen(TimeUnits::MINUTE_UNIT, |time, _| {
72            bordstein::info!("minute timer tick: {:?}", time);
73        }));
74
75        {
76            stack_pin_init!(let timer_seconds = TickService::listen(TimeUnits::SECOND_UNIT, |time, _| {
77                bordstein::info!("second timer tick: {:?}", time);
78            }));
79
80            let root_layer = h.root_layer();
81            let status_bar = root_layer.new_child::<StatusBarLayer>(()).unwrap();
82
83            let remaining_space =
84                window_bounds.shrink_to_avoid(status_bar.layer().bounds(), shapes::Edge::Top, 0);
85
86            let mut child_layer = root_layer
87                .new_child::<ScrollLayer>(remaining_space)
88                .unwrap();
89
90            child_layer.set_click_config_onto_window(&mut h);
91
92            let mut num_taps: u32 = 0;
93
94            let mut accelerometer_service = services.accelerometer.enable();
95            stack_pin_init!(let tap_events = accelerometer_service.subscribe_to_tap_service(|axis, dir| {
96                num_taps += 1;
97                bordstein::info!("Tap! {}, {:?}, {}", num_taps, axis, dir);
98            }));
99
100            let mut text_layer = child_layer
101                .new_child::<TextLayer>(child_layer.layer().bounds().with_height(100))
102                .unwrap();
103            text_layer.set_text_alignment(GTextAlignment::GTextAlignmentCenter);
104
105            let mut fill_layer = child_layer
106                .new_child::<TextLayer>(child_layer.layer().bounds().translate(0, text_layer.layer().bounds().size.h))
107                .unwrap();
108
109            child_layer.set_content_size(GSize::total_bounds_of_rects([
110                text_layer.layer().frame(),
111                fill_layer.layer().frame(),
112            ]));
113            // child_layer.set_content_size(GSize::new(200, 500));
114
115            bordstein::info!("Scroll bounds: {:?}", child_layer.get_content_size());
116
117            let _guard = fill_layer.set_text(cr#"
118foo
119bar
120baz
121hello
122this
123is
124some
125text
126lorem
127ipsum
128dolor
129sit
130amet
131"#);
132
133            let mut text_content: CString<64>;
134            for i in 0..100 {
135                text_content = CString::<64>::new();
136                let _ = ufmt::uwrite!(&mut text_content, "{}", i);
137                let _guard = text_layer.set_text(&text_content);
138
139                embassy_time::Timer::after_secs(1).await;
140
141                // app_messages
142                //     .send(|d| {
143                //         d.u16(10001, 1234)?;
144
145                //         Ok(())
146                //     })
147                //     .unwrap();
148
149                child_layer.set_content_offset(GPoint::new(0, i * -10), true);
150
151                bordstein::info!("Scroll offset: {:?}", child_layer.get_content_offset());
152            }
153
154            bordstein::info!("Child bounds: {:?}", child_layer.layer().bounds());
155        }
156
157        stack_pin_init!(let timer_seconds_stream = TickService::stream(TimeUnits::SECOND_UNIT));
158        while let Some(t) = timer_seconds_stream.next().await {
159            bordstein::info!("second tick stream: {}", t.0.secs);
160        }
161
162        // layers now destroyed, app should show just the window with its red background
163
164        // if you have nothing else to do, but want to wait until the system
165        // closes the window, you can use core::future::pending.
166        core::future::pending::<()>().await;
167    })
168    .await
169    .unwrap();
170}

Trait Implementations§

Source§

impl Drop for OpenAppMessages<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<'open> MultiRegistrationService for OpenAppMessages<'open>

Source§

type CallbackData = AppMessagesPointers

Source§

fn list(&self) -> &SingleCoreCell<List<Entry<Self::CallbackData>>>

Retrieve the intrusive list root for this service.

Auto Trait Implementations§

§

impl<'handle> !UnwindSafe for OpenAppMessages<'handle>

§

impl<'handle> Freeze for OpenAppMessages<'handle>

§

impl<'handle> RefUnwindSafe for OpenAppMessages<'handle>

§

impl<'handle> Send for OpenAppMessages<'handle>

§

impl<'handle> Sync for OpenAppMessages<'handle>

§

impl<'handle> Unpin for OpenAppMessages<'handle>

§

impl<'handle> UnsafeUnpin for OpenAppMessages<'handle>

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.