22extern crate log;
33extern crate env_logger;
44
5+ use std:: {
6+ collections:: VecDeque ,
7+ process:: Command ,
8+ sync:: {
9+ atomic:: { AtomicBool , Ordering } ,
10+ Mutex ,
11+ } ,
12+ thread:: sleep,
13+ time:: Duration ,
14+ } ;
15+
516use atomic:: Atomic ;
6- use chrono:: DateTime ;
7- use chrono:: Local ;
8- use libremarkable:: appctx;
9- use libremarkable:: appctx:: ApplicationContext ;
10- use libremarkable:: battery;
11- use libremarkable:: framebuffer:: cgmath;
12- use libremarkable:: framebuffer:: cgmath:: EuclideanSpace ;
13- use libremarkable:: framebuffer:: common:: * ;
14- use libremarkable:: framebuffer:: refresh:: PartialRefreshMode ;
15- use libremarkable:: framebuffer:: storage;
16- use libremarkable:: framebuffer:: FramebufferDraw ;
17- use libremarkable:: framebuffer:: FramebufferIO ;
18- use libremarkable:: framebuffer:: FramebufferRefresh ;
19- use libremarkable:: image;
20- use libremarkable:: image:: GenericImage ;
21- use libremarkable:: input:: gpio;
22- use libremarkable:: input:: multitouch;
23- use libremarkable:: input:: wacom;
24- use libremarkable:: input:: InputDevice ;
25- use libremarkable:: input:: InputEvent ;
26- use libremarkable:: ui_extensions:: element:: UIConstraintRefresh ;
27- use libremarkable:: ui_extensions:: element:: UIElement ;
28- use libremarkable:: ui_extensions:: element:: UIElementHandle ;
29- use libremarkable:: ui_extensions:: element:: UIElementWrapper ;
30- use once_cell:: sync:: Lazy ;
17+ use chrono:: { DateTime , Local } ;
18+ use libremarkable:: {
19+ appctx,
20+ appctx:: ApplicationContext ,
21+ battery,
22+ framebuffer:: {
23+ cgmath, cgmath:: EuclideanSpace , common:: * , storage, FramebufferDraw , FramebufferIO ,
24+ FramebufferRefresh , PartialRefreshMode ,
25+ } ,
26+ image,
27+ image:: GenericImage ,
28+ input:: {
29+ GPIOEvent , InputDevice , InputEvent , MultitouchEvent , PhysicalButton , WacomEvent , WacomPen ,
30+ } ,
31+ ui_extensions:: element:: { UIConstraintRefresh , UIElement , UIElementHandle , UIElementWrapper } ,
32+ } ;
3133// use rand::Rng;
3234use marauder:: modes:: draw:: DrawMode ;
33- use marauder:: modes:: touch:: TouchMode ;
34- use marauder:: strokes:: Strokes ;
35- use marauder:: unipen;
36- use std:: collections:: VecDeque ;
37- use std:: process:: Command ;
38- use std:: sync:: atomic:: AtomicBool ;
39- use std:: sync:: atomic:: Ordering ;
40- use std:: sync:: Mutex ;
41- use std:: thread:: sleep;
42- use std:: time:: Duration ;
35+ use marauder:: { modes:: touch:: TouchMode , strokes:: Strokes , unipen} ;
36+ use once_cell:: sync:: Lazy ;
4337// use marauder::shapes::*;
4438
4539// This region will have the following size at rest:
@@ -150,10 +144,8 @@ fn on_zoom_out(app: &mut ApplicationContext, _element: UIElementHandle) {
150144 . copy_from ( & resized, CANVAS_REGION . width / 8 , CANVAS_REGION . height / 8 )
151145 . unwrap ( ) ;
152146
153- framebuffer. draw_image (
154- new_image. as_rgb8 ( ) . unwrap ( ) ,
155- CANVAS_REGION . top_left ( ) . cast ( ) . unwrap ( ) ,
156- ) ;
147+ framebuffer
148+ . draw_image ( new_image. as_rgb8 ( ) . unwrap ( ) , CANVAS_REGION . top_left ( ) . cast ( ) . unwrap ( ) ) ;
157149 framebuffer. partial_refresh (
158150 & CANVAS_REGION ,
159151 PartialRefreshMode :: Async ,
@@ -182,10 +174,8 @@ fn on_blur_canvas(app: &mut ApplicationContext, _element: UIElementHandle) {
182174 )
183175 . blur ( 0.6f32 ) ;
184176
185- framebuffer. draw_image (
186- dynamic. as_rgb8 ( ) . unwrap ( ) ,
187- CANVAS_REGION . top_left ( ) . cast ( ) . unwrap ( ) ,
188- ) ;
177+ framebuffer
178+ . draw_image ( dynamic. as_rgb8 ( ) . unwrap ( ) , CANVAS_REGION . top_left ( ) . cast ( ) . unwrap ( ) ) ;
189179 framebuffer. partial_refresh (
190180 & CANVAS_REGION ,
191181 PartialRefreshMode :: Async ,
@@ -325,13 +315,9 @@ fn loop_companion(app: &mut ApplicationContext) {
325315// ## Input Handlers
326316// ####################
327317
328- fn on_wacom_input ( app : & mut ApplicationContext , input : wacom :: WacomEvent ) {
318+ fn on_wacom_input ( app : & mut ApplicationContext , input : WacomEvent ) {
329319 match input {
330- wacom:: WacomEvent :: Draw {
331- position,
332- pressure,
333- tilt : _,
334- } => {
320+ WacomEvent :: Draw { position, pressure, tilt : _ } => {
335321 // debug!("{} {} {}", position.x, position.y, pressure);
336322
337323 let mut wacom_stack = WACOM_HISTORY . lock ( ) . unwrap ( ) ;
@@ -361,7 +347,7 @@ fn on_wacom_input(app: &mut ApplicationContext, input: wacom::WacomEvent) {
361347 DrawMode :: Erase ( s) => ( color:: WHITE , s * 3 ) ,
362348 } ;
363349
364- wacom_stack. push_back ( ( position. cast ( ) . unwrap ( ) , pressure as i32 ) ) ;
350+ wacom_stack. push_back ( ( position. cast ( ) . unwrap ( ) , i32:: from ( pressure ) ) ) ;
365351 while wacom_stack. len ( ) >= 3 {
366352 let framebuffer = app. get_framebuffer_ref ( ) ;
367353 let points = vec ! [
@@ -400,14 +386,14 @@ fn on_wacom_input(app: &mut ApplicationContext, input: wacom::WacomEvent) {
400386 ) ;
401387 }
402388 }
403- wacom :: WacomEvent :: InstrumentChange { pen, state } => {
389+ WacomEvent :: InstrumentChange { pen, state } => {
404390 match pen {
405- wacom :: WacomPen :: ToolPen => {
391+ WacomPen :: ToolPen => {
406392 // Whether the pen is in range
407393 let in_range = state;
408394 WACOM_IN_RANGE . store ( in_range, Ordering :: Relaxed ) ;
409395 }
410- wacom :: WacomPen :: Touch => {
396+ WacomPen :: Touch => {
411397 // Whether the pen is actually making contact
412398 let making_contact = state;
413399 if !making_contact {
@@ -422,11 +408,7 @@ fn on_wacom_input(app: &mut ApplicationContext, input: wacom::WacomEvent) {
422408 _ => unreachable ! ( ) ,
423409 }
424410 }
425- wacom:: WacomEvent :: Hover {
426- position : _,
427- distance,
428- tilt : _,
429- } => {
411+ WacomEvent :: Hover { position : _, distance, tilt : _ } => {
430412 // If the pen is hovering, don't record its coordinates as the origin of the next line
431413 if distance > 1 {
432414 let mut wacom_stack = WACOM_HISTORY . lock ( ) . unwrap ( ) ;
@@ -438,11 +420,9 @@ fn on_wacom_input(app: &mut ApplicationContext, input: wacom::WacomEvent) {
438420 } ;
439421}
440422
441- fn on_touch_handler ( app : & mut ApplicationContext , input : multitouch :: MultitouchEvent ) {
423+ fn on_touch_handler ( app : & mut ApplicationContext , input : MultitouchEvent ) {
442424 let framebuffer = app. get_framebuffer_ref ( ) ;
443- if let multitouch:: MultitouchEvent :: Press { finger }
444- | multitouch:: MultitouchEvent :: Move { finger } = input
445- {
425+ if let MultitouchEvent :: Press { finger } | MultitouchEvent :: Move { finger } = input {
446426 let position = finger. pos ;
447427 if !CANVAS_REGION . contains_point ( & position. cast ( ) . unwrap ( ) ) {
448428 return ;
@@ -508,11 +488,11 @@ fn on_touch_handler(app: &mut ApplicationContext, input: multitouch::MultitouchE
508488 }
509489}
510490
511- fn on_button_press ( app : & mut ApplicationContext , input : gpio :: GPIOEvent ) {
491+ fn on_button_press ( app : & mut ApplicationContext , input : GPIOEvent ) {
512492 let ( btn, new_state) = match input {
513- gpio :: GPIOEvent :: Press { button } => ( button, true ) ,
514- gpio :: GPIOEvent :: Unpress { button } => ( button, false ) ,
515- _ => return ,
493+ GPIOEvent :: Press { button } => ( button, true ) ,
494+ GPIOEvent :: Unpress { button } => ( button, false ) ,
495+ GPIOEvent :: Unknown => return ,
516496 } ;
517497
518498 // Ignoring the unpressed event
@@ -526,7 +506,7 @@ fn on_button_press(app: &mut ApplicationContext, input: gpio::GPIOEvent) {
526506 }
527507
528508 match btn {
529- gpio :: PhysicalButton :: RIGHT => {
509+ PhysicalButton :: RIGHT => {
530510 let new_state = if app. is_input_device_active ( InputDevice :: Multitouch ) {
531511 app. deactivate_input_device ( InputDevice :: Multitouch ) ;
532512 "Enable Touch"
@@ -536,31 +516,23 @@ fn on_button_press(app: &mut ApplicationContext, input: gpio::GPIOEvent) {
536516 } ;
537517
538518 if let Some ( ref elem) = app. get_element_by_name ( "tooltipRight" ) {
539- if let UIElement :: Text {
540- ref mut text,
541- scale : _,
542- foreground : _,
543- border_px : _,
544- } = elem. write ( ) . inner
519+ if let UIElement :: Text { ref mut text, scale : _, foreground : _, border_px : _ } =
520+ elem. write ( ) . inner
545521 {
546- * text = new_state. to_string ( ) ;
522+ * text = new_state. to_owned ( ) ;
547523 }
548524 }
549525 app. draw_element ( "tooltipRight" ) ;
550526 }
551- gpio :: PhysicalButton :: MIDDLE | gpio :: PhysicalButton :: LEFT => {
552- app. clear ( btn == gpio :: PhysicalButton :: MIDDLE ) ;
527+ PhysicalButton :: MIDDLE | PhysicalButton :: LEFT => {
528+ app. clear ( btn == PhysicalButton :: MIDDLE ) ;
553529 app. draw_elements ( ) ;
554530 }
555- gpio:: PhysicalButton :: POWER => {
556- Command :: new ( "systemctl" )
557- . arg ( "start" )
558- . arg ( "xochitl" )
559- . spawn ( )
560- . unwrap ( ) ;
531+ PhysicalButton :: POWER => {
532+ Command :: new ( "systemctl" ) . arg ( "start" ) . arg ( "xochitl" ) . spawn ( ) . unwrap ( ) ;
561533 std:: process:: exit ( 0 ) ;
562534 }
563- gpio :: PhysicalButton :: WAKEUP => {
535+ PhysicalButton :: WAKEUP => {
564536 info ! ( "WAKEUP button(?) pressed(?)" ) ;
565537 }
566538 } ;
0 commit comments