SignalK now with thread, and updated REAME
This commit is contained in:
12
src/forms.rs
12
src/forms.rs
@@ -142,6 +142,18 @@ impl Screen {
|
||||
draw_text_mut(&mut self.image, Rgb([255, 255, 255]), x as u32 - width as u32, y as u32, scale, &font, text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Text, Horisontally justified at x
|
||||
*/
|
||||
pub fn text_c (&mut self, font: &Font, text: &str, scale: f32, x: u16, y: u16) {
|
||||
let scale = rusttype::Scale { x: scale, y: scale };
|
||||
let last_glyph = font.layout (text, scale, rusttype::Point::<f32> { x: 0.0, y: 0.0 }).last().unwrap();
|
||||
let half_width = last_glyph.pixel_bounding_box().unwrap().max.x as u16 / 2;
|
||||
let offset = { if x < half_width { 0 } else { x-half_width }};
|
||||
draw_text_mut(&mut self.image, Rgb([255, 255, 255]), offset as u32, y as u32, scale, &font, text);
|
||||
}
|
||||
|
||||
|
||||
pub fn render (&mut self, form: &Form, angle: f32, x: u16, y: u16) {
|
||||
let transform : Transform2D<f32, ModelSpace, ModelSpace> = Transform2D::create_rotation(Angle::radians(angle)).post_translate(Vector2D::new(500.0, 500.0));
|
||||
let tx_points = form.points.iter().map(|p| transform.transform_point(*p)).collect::<Vec<_>>();
|
||||
|
||||
50
src/main.rs
50
src/main.rs
@@ -4,6 +4,8 @@ use std::error::Error;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use std::f32::consts::PI;
|
||||
use chrono::{DateTime, Utc};
|
||||
use chrono_tz::Tz;
|
||||
|
||||
|
||||
use image::{
|
||||
@@ -15,11 +17,14 @@ use imageproc::drawing::draw_filled_rect_mut;
|
||||
|
||||
mod ilidisplay;
|
||||
mod forms;
|
||||
mod signalk;
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
|
||||
let mut course_screen = forms::Screen::new(200, 200);
|
||||
let mut navigation_screen = forms::Screen::new(160,320);
|
||||
let mut sog_screen = forms::Screen::new(160,60);
|
||||
let mut gps_screen = forms::Screen::new(400, 40);
|
||||
let mut time_screen = forms::Screen::new(200, 60);
|
||||
|
||||
let mut loader = forms::Loader::new("/root/helms-display".to_string());
|
||||
|
||||
@@ -51,18 +56,47 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
course_screen.render(&b, 0.0, 500, 500);
|
||||
e.put_image(&(course_screen.image), (160, (160-100)));
|
||||
|
||||
navigation_screen.clear();
|
||||
navigation_screen.text(&font, "SOG", 32.0, 5, 5);
|
||||
navigation_screen.text(&font, "speed over ground", 12.0, 5, 38);
|
||||
sog_screen.clear();
|
||||
sog_screen.text(&font, "SOG", 32.0, 5, 5);
|
||||
sog_screen.text(&font, "speed over ground", 12.0, 5, 38);
|
||||
let speed_over_ground = 5.0; // in m/s
|
||||
let speed_over_ground = speed_over_ground * 1.9438612860586; // now in nautic miles per hour
|
||||
navigation_screen.text_rj(&font, &format!("{:.1}", speed_over_ground).as_str(), 32.0, 138, 5);
|
||||
navigation_screen.fraction(&font, "nm", "h", 14.0, 140, 6);
|
||||
e.put_image(&(navigation_screen.image), (0, 0));
|
||||
sog_screen.text_rj(&font, format!("{:.1}", speed_over_ground).as_str(), 32.0, 138, 5);
|
||||
sog_screen.fraction(&font, "nm", "h", 14.0, 140, 6);
|
||||
e.put_image(&(sog_screen.image), (0, 0));
|
||||
|
||||
navigation_screen.save();
|
||||
gps_screen.clear();
|
||||
// format with unicodes for degrees, minutes and seconds.
|
||||
let longitude: f32 = 55.658863;
|
||||
let latitude: f32 = 12.480960;
|
||||
|
||||
let long_d: u8 = longitude.trunc() as u8;
|
||||
let longitude = longitude.fract() * 60.0;
|
||||
let long_m: u8 = longitude.trunc() as u8;
|
||||
let longitude = longitude.fract() * 60.0;
|
||||
let long_s: u8 = longitude.round() as u8;
|
||||
let long_ns: char = 'N';
|
||||
|
||||
let lat_d: u8 = latitude.trunc() as u8;
|
||||
let latitude = latitude.fract() * 60.0;
|
||||
let lat_m: u8 = latitude.trunc() as u8;
|
||||
let latitude = latitude.fract() * 60.0;
|
||||
let lat_s: u8 = latitude.round() as u8;
|
||||
let lat_ew: char = 'E';
|
||||
gps_screen.text_c(&font, format!("{}{:02}\u{00B0}{:02}\u{2032}{:02}\u{2033} {}{:02}\u{00B0}{:02}\u{2032}{:02}\u{2033}", long_ns, long_d, long_m, long_s, lat_ew, lat_d, lat_m, lat_s).as_str(), 32.0, 200, 5);
|
||||
e.put_image(&(gps_screen.image), (240,370));
|
||||
|
||||
time_screen.clear();
|
||||
let tz: Tz = "Europe/Copenhagen".parse().unwrap();
|
||||
let now = Utc::now().with_timezone(&tz);
|
||||
time_screen.text_c(&font, now.format("%H:%M:%S %Z").to_string().as_str(), 24.0, 100, 1);
|
||||
time_screen.text_c(&font, "Europe/Copenhagen", 16.0, 100, 25);
|
||||
time_screen.text_c(&font, now.format("%Y-%m-%d").to_string().as_str(), 16.0, 100, 43);
|
||||
time_screen.save();
|
||||
|
||||
|
||||
println!("Display has been rendered now, sleeping for 5s");
|
||||
signalk::SignalKData::connect();
|
||||
thread::sleep(Duration::from_millis(5000));
|
||||
e.turn_off();
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user