3
3
#![ feature( alloc_error_handler) ]
4
4
#![ feature( trait_alias) ]
5
5
6
- mod common;
7
6
mod dashboard;
8
- mod input_scanner;
9
- mod run_loop;
7
+ mod ssd1306_terminal;
10
8
mod uptime;
11
9
mod uptime_delay;
12
10
@@ -16,15 +14,9 @@ use alloc::rc::Rc;
16
14
use alloc_cortex_m:: CortexMHeap ;
17
15
use core:: { alloc:: Layout , cell:: RefCell } ;
18
16
use cortex_m_rt:: entry;
19
- use dashboard:: Dashboard ;
20
17
use embedded_hal:: digital:: v2:: InputPin ;
21
18
use embedded_time:: rate:: Extensions ;
22
19
use panic_probe as _;
23
- use stuff:: {
24
- mq:: { MessageProcessingStatus , MessageQueue } ,
25
- scale:: Scale ,
26
- } ;
27
- use uptime:: Uptime ;
28
20
29
21
use rp_pico as bsp;
30
22
@@ -38,12 +30,23 @@ use bsp::hal::{
38
30
39
31
use nau7802:: { Gain , Ldo , Nau7802 , SamplesPerSecond } ;
40
32
use ssd1306:: {
41
- mode:: { TerminalDisplaySize , TerminalMode } ,
42
- prelude:: { WriteOnlyDataCommand , * } ,
43
- I2CDisplayInterface , Ssd1306 ,
33
+ mode:: DisplayConfig , rotation:: DisplayRotation , size:: DisplaySize128x64 , I2CDisplayInterface ,
34
+ Ssd1306 ,
44
35
} ;
45
36
46
- use crate :: { input_scanner:: * , run_loop:: * } ;
37
+ use app_core:: {
38
+ common:: { AppContext , AppMessage } ,
39
+ input_scanner:: InputScanner ,
40
+ scale:: Scale ,
41
+ terminal:: Terminal ,
42
+ } ;
43
+ use dashboard:: Dashboard ;
44
+ use ssd1306_terminal:: Ssd1306Terminal ;
45
+ use stuff:: {
46
+ mq:: MessageProcessingStatus ,
47
+ run_loop:: { Schedule , Task } ,
48
+ } ;
49
+ use uptime:: Uptime ;
47
50
48
51
#[ alloc_error_handler]
49
52
fn oom ( _: Layout ) -> ! {
@@ -103,12 +106,12 @@ fn _main() -> ! {
103
106
) ;
104
107
105
108
let interface = I2CDisplayInterface :: new ( i2c) ;
106
- let shared_terminal = Rc :: new ( RefCell :: new (
107
- Ssd1306 :: new ( interface, DisplaySize128x64 , DisplayRotation :: Rotate0 ) . into_terminal_mode ( ) ,
108
- ) ) ;
109
+ let mut ssd1306 =
110
+ Ssd1306 :: new ( interface, DisplaySize128x64 , DisplayRotation :: Rotate0 ) . into_terminal_mode ( ) ;
111
+ ssd1306. init ( ) . unwrap ( ) ;
112
+ let shared_terminal = Rc :: new ( RefCell :: new ( Ssd1306Terminal :: new ( ssd1306) ) ) ;
109
113
{
110
114
let mut terminal = shared_terminal. borrow_mut ( ) ;
111
- terminal. init ( ) . unwrap ( ) ;
112
115
terminal. clear ( ) . unwrap ( ) ;
113
116
}
114
117
@@ -170,23 +173,6 @@ fn _main() -> ! {
170
173
}
171
174
}
172
175
173
- #[ derive( Default ) ]
174
- struct AppContext {
175
- mq : MessageQueue < AppMessage > ,
176
- state : AppState ,
177
- }
178
-
179
- enum AppMessage {
180
- InputEvent ( InputEvent ) ,
181
- Tare ,
182
- Calibrate ,
183
- }
184
-
185
- #[ derive( Default ) ]
186
- struct AppState {
187
- weight : f32 ,
188
- }
189
-
190
176
enum AppTask {
191
177
InputScanner ( InputScanner ) ,
192
178
Dashboard ( Dashboard ) ,
@@ -200,22 +186,3 @@ impl<'a> AsMut<dyn Task<AppContext> + 'a> for AppTask {
200
186
}
201
187
}
202
188
}
203
-
204
- pub trait Terminal : core:: fmt:: Write {
205
- fn clear ( & mut self ) -> core:: fmt:: Result ;
206
- fn set_position ( & mut self , column : u8 , row : u8 ) -> core:: fmt:: Result ;
207
- }
208
-
209
- impl < DI , SIZE > Terminal for Ssd1306 < DI , SIZE , TerminalMode >
210
- where
211
- DI : WriteOnlyDataCommand ,
212
- SIZE : TerminalDisplaySize ,
213
- {
214
- fn clear ( & mut self ) -> core:: fmt:: Result {
215
- self . clear ( ) . map_err ( |_| core:: fmt:: Error )
216
- }
217
-
218
- fn set_position ( & mut self , column : u8 , row : u8 ) -> core:: fmt:: Result {
219
- self . set_position ( column, row) . map_err ( |_| core:: fmt:: Error )
220
- }
221
- }
0 commit comments