浏览代码

display: Display the data received from the base station.

父节点
当前提交
ddf7753ec6

+ 30
- 0
display/firmware/Cargo.lock 查看文件

@@ -59,6 +59,15 @@ name = "cc"
59 59
 version = "1.0.52"
60 60
 source = "registry+https://github.com/rust-lang/crates.io-index"
61 61
 
62
+[[package]]
63
+name = "chrono"
64
+version = "0.4.11"
65
+source = "registry+https://github.com/rust-lang/crates.io-index"
66
+dependencies = [
67
+ "num-integer 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
68
+ "num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
69
+]
70
+
62 71
 [[package]]
63 72
 name = "cmake"
64 73
 version = "0.1.42"
@@ -137,6 +146,7 @@ name = "display-firmware"
137 146
 version = "0.0.1"
138 147
 dependencies = [
139 148
  "bme280 0.2.1 (git+https://github.com/mgottschlag/bme280-rs?branch=destroy)",
149
+ "chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
140 150
  "cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
141 151
  "cortex-m-rt 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
142 152
  "cortex-m-rtfm 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -294,6 +304,23 @@ name = "nb"
294 304
 version = "0.1.2"
295 305
 source = "registry+https://github.com/rust-lang/crates.io-index"
296 306
 
307
+[[package]]
308
+name = "num-integer"
309
+version = "0.1.42"
310
+source = "registry+https://github.com/rust-lang/crates.io-index"
311
+dependencies = [
312
+ "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
313
+ "num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
314
+]
315
+
316
+[[package]]
317
+name = "num-traits"
318
+version = "0.2.11"
319
+source = "registry+https://github.com/rust-lang/crates.io-index"
320
+dependencies = [
321
+ "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
322
+]
323
+
297 324
 [[package]]
298 325
 name = "panic-semihosting"
299 326
 version = "0.5.3"
@@ -469,6 +496,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
469 496
 "checksum bme280 0.2.1 (git+https://github.com/mgottschlag/bme280-rs?branch=destroy)" = "<none>"
470 497
 "checksum byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
471 498
 "checksum cc 1.0.52 (registry+https://github.com/rust-lang/crates.io-index)" = "c3d87b23d6a92cd03af510a5ade527033f6aa6fa92161e2d5863a907d4c5e31d"
499
+"checksum chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "80094f509cf8b5ae86a4966a39b3ff66cd7e2a3e594accec3743ff3fabeab5b2"
472 500
 "checksum cmake 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "81fb25b677f8bf1eb325017cb6bb8452f87969db0fedb4f757b297bee78a7c62"
473 501
 "checksum cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2954942fbbdd49996704e6f048ce57567c3e1a4e2dc59b41ae9fde06a01fc763"
474 502
 "checksum cortex-m-rt 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "00d518da72bba39496024b62607c1d8e37bcece44b2536664f1132a73a499a28"
@@ -493,6 +521,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
493 521
 "checksum mkl25z4 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "91f9b185f1346b1fdc8337481e2fdf5f282d0e884e2c59e4ddea5328105017d7"
494 522
 "checksum mkl25z4-hal 0.1.0 (git+https://github.com/mgottschlag/mkl25z4-hal)" = "<none>"
495 523
 "checksum nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b1411551beb3c11dedfb0a90a0fa256b47d28b9ec2cdff34c25a2fa59e45dbdc"
524
+"checksum num-integer 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "3f6ea62e9d81a77cd3ee9a2a5b9b609447857f3d358704331e4ef39eb247fcba"
525
+"checksum num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096"
496 526
 "checksum panic-semihosting 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c03864ac862876c16a308f5286f4aa217f1a69ac45df87ad3cd2847f818a642c"
497 527
 "checksum pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)" = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677"
498 528
 "checksum proc-macro2 1.0.12 (registry+https://github.com/rust-lang/crates.io-index)" = "8872cf6f48eee44265156c111456a700ab3483686b3f96df4cf5481c89157319"

+ 2
- 4
display/firmware/Cargo.toml 查看文件

@@ -25,10 +25,8 @@ embedded-nrf24l01 = { git = "https://github.com/mgottschlag/embedded-nrf24l01",
25 25
 epd-waveshare = { git = "https://github.com/mgottschlag/epd-waveshare", branch = "wip" }
26 26
 tinygfx = { git = "https://github.com/mgottschlag/tinygfx" }
27 27
 protocol = { path = "../../common/rust-protocol" }
28
-
29
-[dependencies.void]
30
-default-features = false
31
-version = "1.0.2"
28
+chrono = { version = "0.4.11", default-features = false }
29
+void = { version = "1.0.2", default-features = false }
32 30
 
33 31
 [build-dependencies]
34 32
 tinygfx-assets = { git = "https://github.com/mgottschlag/tinygfx" }

+ 1
- 1
display/firmware/src/information.rs 查看文件

@@ -4,7 +4,7 @@ use super::sensors::BME280Data;
4 4
 
5 5
 #[derive(Clone)]
6 6
 pub struct Information {
7
-    pub time: u32,
7
+    pub time: u64,
8 8
     pub valid: bool,
9 9
 
10 10
     pub inside: Option<TemperatureHumidity>,

+ 45
- 6
display/firmware/src/main.rs 查看文件

@@ -104,6 +104,9 @@ const APP: () = {
104 104
         ctx.resources.update_timer.start(10.s());
105 105
         ctx.resources.update_timer.enable_interrupt();
106 106
 
107
+        // Update the time.
108
+        // TODO
109
+
107 110
         // Trigger an update of the displayed values.
108 111
         ctx.spawn.fetch_update().ok();
109 112
     }
@@ -144,14 +147,50 @@ const APP: () = {
144 147
             &[ValueType::Temperature, ValueType::Humidity],
145 148
             &mut balcony,
146 149
         );
147
-        // TODO
150
+        let mut bathroom = [None; 2];
151
+        radio.request_values(
152
+            Location::Bathroom,
153
+            &[ValueType::Temperature, ValueType::Humidity],
154
+            &mut bathroom,
155
+        );
156
+        let mut general = [None; 2];
157
+        radio.request_values(
158
+            Location::Livingroom,
159
+            &[ValueType::Time, ValueType::Pressure],
160
+            &mut general,
161
+        );
148 162
 
149 163
         ctx.resources.info.lock(|info| {
150
-            info.inside = Some(TemperatureHumidity {
151
-                temperature: values.temperature,
152
-                humidity: values.humidity,
153
-            });
154
-            info.pressure = Some(values.pressure);
164
+            if livingroom[0].is_some() && livingroom[1].is_some() {
165
+                info.inside = Some(TemperatureHumidity {
166
+                    temperature: livingroom[0].unwrap() as i32,
167
+                    humidity: livingroom[1].unwrap() as u32,
168
+                });
169
+            } else {
170
+                info.inside = None;
171
+            }
172
+            if balcony[0].is_some() && balcony[1].is_some() {
173
+                info.outside = Some(TemperatureHumidity {
174
+                    temperature: balcony[0].unwrap() as i32,
175
+                    humidity: balcony[1].unwrap() as u32,
176
+                });
177
+            } else {
178
+                info.outside = None;
179
+            }
180
+            if bathroom[0].is_some() && bathroom[1].is_some() {
181
+                info.bathroom = Some(TemperatureHumidity {
182
+                    temperature: bathroom[0].unwrap() as i32,
183
+                    humidity: bathroom[1].unwrap() as u32,
184
+                });
185
+            } else {
186
+                info.bathroom = None;
187
+            }
188
+            if general[1].is_some() {
189
+                info.pressure = Some(general[1].unwrap() as u32);
190
+            }
191
+            if general[0].is_some() {
192
+                info.time = general[0].unwrap() as u64;
193
+            }
155 194
             info.local = Some(values);
156 195
         });
157 196
 

+ 44
- 7
display/firmware/src/ui/tiles.rs 查看文件

@@ -1,5 +1,7 @@
1 1
 use core::fmt::Write;
2 2
 
3
+use chrono::naive::NaiveDateTime;
4
+use chrono::{Datelike, Timelike, Weekday};
3 5
 use tinygfx::color::BlackWhite::{self, Black, White};
4 6
 use tinygfx::image::{MonoBitmapImage, MonoImageData};
5 7
 use tinygfx::{Clip, MonoImage, Rectangle, Renderer, Text, TextAlignment};
@@ -18,20 +20,55 @@ impl TileView {
18 20
     }
19 21
 
20 22
     pub fn draw(&self, renderer: &mut Renderer<BlackWhite>) {
21
-        // TODO: Insert values.
22
-        let date = Text::new(8, 8, "Samstag, 25.04.2020", &ROBOTO_22, Black);
23
-        let mut time = Text::new(392, 8, "12:34", &ROBOTO_22, Black);
24
-        time.align(TextAlignment::Right);
25
-        let top_bar = Rectangle::new(0, 34, 400, 1, Black);
23
+        // Format the time.
24
+        let datetime = NaiveDateTime::from_timestamp(self.info.time as i64, 0);
25
+        let date = datetime.date();
26
+        let time = datetime.time();
26 27
 
27
-        let tile_width = 400 / 2 - 1;
28
-        let tile_height = (300 - 35) / 2 - 1;
28
+        let mut date_buffer = WriteBuffer {
29
+            buffer: [0u8; 32],
30
+            length: 0,
31
+        };
32
+        write!(
33
+            date_buffer,
34
+            "{}, {:02}.{:02}.{:04}",
35
+            match date.weekday() {
36
+                Weekday::Mon => "Montag",
37
+                Weekday::Tue => "Dienstag",
38
+                Weekday::Wed => "Mittwoch",
39
+                Weekday::Thu => "Donnerstag",
40
+                Weekday::Fri => "Freitag",
41
+                Weekday::Sat => "Samstag",
42
+                Weekday::Sun => "Sonntag",
43
+            },
44
+            date.day(),
45
+            date.month(),
46
+            date.year()
47
+        )
48
+        .ok();
29 49
 
50
+        let mut time_buffer = WriteBuffer {
51
+            buffer: [0u8; 8],
52
+            length: 0,
53
+        };
54
+        write!(time_buffer, "{:02}:{:02}", time.hour(), time.minute(),).ok();
55
+
56
+        // Format everything else.
30 57
         let outside_strings = self.info.outside.map(|x| TempHumStrings::new(x));
31 58
         let inside_strings = self.info.inside.map(|x| TempHumStrings::new(x));
32 59
         let bathroom_strings = self.info.bathroom.map(|x| TempHumStrings::new(x));
33 60
         let pressure_string = self.info.pressure.map(|x| PressureString::new(x));
34 61
 
62
+        // Create the UI.
63
+        // TODO: Insert values.
64
+        let date = Text::new(8, 8, date_buffer.to_str(), &ROBOTO_22, Black);
65
+        let mut time = Text::new(392, 8, time_buffer.to_str(), &ROBOTO_22, Black);
66
+        time.align(TextAlignment::Right);
67
+        let top_bar = Rectangle::new(0, 34, 400, 1, Black);
68
+
69
+        let tile_width = 400 / 2 - 1;
70
+        let tile_height = (300 - 35) / 2 - 1;
71
+
35 72
         let inside_tile = TempHumTile::new(
36 73
             "Innen",
37 74
             inside_strings.as_ref(),

正在加载...
取消
保存