weather icon initial
This commit is contained in:
parent
9cc39ab295
commit
8c26252aeb
10
.vscode/extensions.json
vendored
Normal file
10
.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||||
|
// for the documentation about the extensions.json format
|
||||||
|
"recommendations": [
|
||||||
|
"platformio.platformio-ide"
|
||||||
|
],
|
||||||
|
"unwantedRecommendations": [
|
||||||
|
"ms-vscode.cpptools-extension-pack"
|
||||||
|
]
|
||||||
|
}
|
@ -9,3 +9,5 @@ edition = "2021"
|
|||||||
bit = "0.1.1"
|
bit = "0.1.1"
|
||||||
embedded-graphics = "0.8.0"
|
embedded-graphics = "0.8.0"
|
||||||
openweathermap = "0.2.4"
|
openweathermap = "0.2.4"
|
||||||
|
substring = "1.4.5"
|
||||||
|
tinybmp = "0.5.0"
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
use bit::BitIndex;
|
use bit::BitIndex;
|
||||||
|
use substring::Substring;
|
||||||
|
use tinybmp::Bmp;
|
||||||
use core::time;
|
use core::time;
|
||||||
use embedded_graphics::{
|
use embedded_graphics::{
|
||||||
image::{Image, ImageRaw},
|
image::{Image, ImageRaw},
|
||||||
@ -8,7 +10,7 @@ use embedded_graphics::{
|
|||||||
primitives::{Line, PrimitiveStyle},
|
primitives::{Line, PrimitiveStyle},
|
||||||
text::Text,
|
text::Text,
|
||||||
};
|
};
|
||||||
use openweathermap::{self, CurrentWeather};
|
use openweathermap::{self, CurrentWeather, Weather};
|
||||||
use std::net::UdpSocket;
|
use std::net::UdpSocket;
|
||||||
use std::{env, sync::mpsc::Receiver, thread};
|
use std::{env, sync::mpsc::Receiver, thread};
|
||||||
|
|
||||||
@ -21,6 +23,11 @@ const IMAGE_HEIGHT_BYTE: u32 = 40;
|
|||||||
const IMAGE_LENGTH: usize = (IMAGE_WIDTH_BYTE * IMAGE_HEIGHT_BYTE) as usize;
|
const IMAGE_LENGTH: usize = (IMAGE_WIDTH_BYTE * IMAGE_HEIGHT_BYTE) as usize;
|
||||||
const PACKAGE_LENGTH: usize = (IMAGE_LENGTH + 1) as usize;
|
const PACKAGE_LENGTH: usize = (IMAGE_LENGTH + 1) as usize;
|
||||||
|
|
||||||
|
const PRIMITIVE_STYLE:PrimitiveStyle<BinaryColor> = PrimitiveStyle::with_stroke(BinaryColor::On, 1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct UdpDisplay {
|
struct UdpDisplay {
|
||||||
image: [u8; IMAGE_SIZE_BYTE],
|
image: [u8; IMAGE_SIZE_BYTE],
|
||||||
}
|
}
|
||||||
@ -98,6 +105,53 @@ impl DrawTarget for UdpDisplay {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn renderWeather(display: &mut UdpDisplay ,data: &Option<Result<CurrentWeather, String>>){
|
||||||
|
let text_style = MonoTextStyle::new(&FONT_6X10, BinaryColor::On);
|
||||||
|
|
||||||
|
match data {
|
||||||
|
Some(v) => match v {
|
||||||
|
Err(error) => {
|
||||||
|
Text::new(&error, Point::new(0, 5), text_style)
|
||||||
|
.draw(display)
|
||||||
|
.unwrap();
|
||||||
|
println!("{}", &error);
|
||||||
|
}
|
||||||
|
Ok(result) => {
|
||||||
|
if(!result.weather.is_empty()){
|
||||||
|
let condition = &result.weather[0];
|
||||||
|
let short_icon_code = condition.icon.substring(0,2);
|
||||||
|
|
||||||
|
println!("Weather info: {} desc: {} icon {}", condition.main, condition.description, condition.icon);
|
||||||
|
|
||||||
|
match short_icon_code {
|
||||||
|
"01" => {
|
||||||
|
let sun_icon = include_bytes!("sun.bmp");
|
||||||
|
let sun_icon_image = Bmp::from_slice(sun_icon).unwrap();
|
||||||
|
Image::new(&sun_icon_image, Point::new((IMAGE_WIDTH-40) as i32, 0)).draw(display).unwrap();
|
||||||
|
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
println!("Missing icon for {short_icon_code}");
|
||||||
|
Text::new(&condition.description, Point::new(0, 0), text_style)
|
||||||
|
.draw(display)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None => {
|
||||||
|
Text::new("Waiting for data", Point::new(0, 0), text_style)
|
||||||
|
.draw(display)
|
||||||
|
.unwrap();
|
||||||
|
println!("{}", "no result");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
fn send_package(ipaddress: String, data: &Option<Result<CurrentWeather, String>>) {
|
fn send_package(ipaddress: String, data: &Option<Result<CurrentWeather, String>>) {
|
||||||
let mut package: [u8; PACKAGE_LENGTH] = [0; PACKAGE_LENGTH];
|
let mut package: [u8; PACKAGE_LENGTH] = [0; PACKAGE_LENGTH];
|
||||||
|
|
||||||
@ -108,43 +162,16 @@ fn send_package(ipaddress: String, data: &Option<Result<CurrentWeather, String>>
|
|||||||
image: [0; IMAGE_SIZE_BYTE],
|
image: [0; IMAGE_SIZE_BYTE],
|
||||||
};
|
};
|
||||||
|
|
||||||
let style = PrimitiveStyle::with_stroke(BinaryColor::On, 1);
|
|
||||||
let text_style = MonoTextStyle::new(&FONT_6X10, BinaryColor::On);
|
|
||||||
|
|
||||||
Line::new(Point::new(0, 0), Point::new((IMAGE_WIDTH - 1) as i32, 0))
|
// Line::new(Point::new(0, 0), Point::new((IMAGE_WIDTH - 1) as i32, 0))
|
||||||
.into_styled(style)
|
// .into_styled(PRIMITIVE_STYLE)
|
||||||
.draw(&mut display)
|
// .draw(&mut display)
|
||||||
.unwrap();
|
// .unwrap();
|
||||||
|
|
||||||
|
|
||||||
match data {
|
renderWeather(&mut display, data);
|
||||||
Some(v) => match v {
|
|
||||||
Err(error) => {
|
|
||||||
Text::new(&error, Point::new(0, 5), text_style)
|
|
||||||
.draw(&mut display)
|
|
||||||
.unwrap();
|
|
||||||
println!("{}", &error);
|
|
||||||
}
|
|
||||||
Ok(result) => {
|
|
||||||
let mut y = 10;
|
|
||||||
for condition in result.weather.as_slice() {
|
|
||||||
|
|
||||||
let text = condition.main.to_owned() + " " + &condition.description + " " + &condition.icon;
|
|
||||||
Text::new(&text, Point::new(0, y), text_style)
|
|
||||||
.draw(&mut display)
|
|
||||||
.unwrap();
|
|
||||||
println!("{}", &condition.main);
|
|
||||||
y += 10;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
None => {
|
|
||||||
Text::new("Waiting for data", Point::new(20, 30), text_style)
|
|
||||||
.draw(&mut display)
|
|
||||||
.unwrap();
|
|
||||||
println!("{}", "no result");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
package[1..PACKAGE_LENGTH].copy_from_slice(&display.image);
|
package[1..PACKAGE_LENGTH].copy_from_slice(&display.image);
|
||||||
|
|
||||||
@ -185,6 +212,8 @@ fn main() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let mut lastData = Option::None;
|
let mut lastData = Option::None;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let delay = time::Duration::from_millis(10000);
|
let delay = time::Duration::from_millis(10000);
|
||||||
|
BIN
client/src/sun.bmp
Normal file
BIN
client/src/sun.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.8 KiB |
Loading…
Reference in New Issue
Block a user