diff --git a/src/demo_tasks.rs b/src/demo_tasks.rs
index 21ae538eba775b85273d04bcbbb0e5bcf55149e0..9dbc431aee797aa8a9a98bb1e9df0e459fc2514b 100644
--- a/src/demo_tasks.rs
+++ b/src/demo_tasks.rs
@@ -6,14 +6,13 @@ use embassy_executor::Spawner;
use embassy_futures::select::{select, select3, Either, Either3};
use embassy_net::{
udp::{UdpSocket, PacketMetadata},
- tcp::{TcpSocket},
- Ipv6Address, Stack, StaticConfigV6, Config, Ipv6Cidr, Ipv4Address, driver::Driver};
+ Ipv6Address, Stack, StaticConfigV6, Config, Ipv6Cidr};
use embassy_net_badgelink::Device;
use embassy_time::{Duration, Timer};
use embedded_graphics::{
image::Image,
mono_font::{ascii::FONT_6X10, MonoTextStyle},
- pixelcolor::{Rgb565, Rgb888},
+ pixelcolor::Rgb565,
prelude::*,
primitives::{Circle, PrimitiveStyle, Rectangle, StyledDrawable},
text::Text,
@@ -21,10 +20,10 @@ use embedded_graphics::{
use esp_backtrace as _;
use esp_println::println;
use esp_wifi::EspWifiInitialization;
-use hal::{Rng, uart, radio::Wifi};
-use heapless::{Vec, String};
-use smoltcp::{wire::{IpEndpoint, TcpOption}, phy};
+use hal::{Rng, radio::Wifi};
+use heapless::Vec;
use tinybmp::Bmp;
+use smoltcp::wire::IpEndpoint;
use smart_leds::SmartLedsWrite;
@@ -434,268 +433,3 @@ async fn send_task(network_stack: &'static Stack<Device<'static>>, addr_left: Ip
}
}
-
-struct SocketWrapper<'a> where
-{
- pub socket: TcpSocket<'a>,
-}
-
-struct LightClient<'a>
-{
- // rx_buffer: &'b mut [u8; 1024],
- // tx_buffer: &'b mut [u8; 1024],
- socket: TcpSocket<'a>,
- // socketwrapper: Option<SocketWrapper<'a>>,
- // a: &'b str,
-}
-
-struct LightBuffer {
- pub rx: [u8; 1024],
- pub tx: [u8; 1024],
-}
-
-impl<'a> LightClient<'a>
-{
-
- pub async fn new<D>(stack: &'a Stack<D>, rx_buffer: &'a mut [u8; 1024], tx_buffer: &'a mut [u8; 1024]) // , buffer: &'b mut LightBuffer
- ->Result<LightClient<'a>, &'static str>
- where D: Driver
- {
-
- let mut s = Self {
- // socketwrapper: None,
- socket: TcpSocket::new(&stack, rx_buffer, tx_buffer),
- // a: "dsf".as_ref(),
- };
-
- let socket = &mut s.socket;
- let endpoint = IpEndpoint{
- addr: Ipv4Address::new(151, 216, 192, 14).into(),
- port: 80
- };
- socket.connect(endpoint).await.map_err(|err| "ConnectError")?;
- socket.write("GET / HTTP/1.1\r\nServer: domelights.i.eta.st\r\n\r\n".as_bytes()).await.map_err(|err| "write error")?;
- socket.flush().await.map_err(|err| "flush error")?;
-
- Ok(s)
- }
-
- pub async fn http_get(&mut self, path: &str) -> Result<(), &'static str> {
- let socket = &mut self.socket;
- socket.write("GET ".as_ref()).await.map_err(|e| "write error")?;
- socket.write(path.as_bytes()).await.map_err(|e| "write error")?;
- socket.write(" HTTP/1.1\r\nServer: domelights.i.eta.st\r\n\r\n".as_bytes()).await.map_err(|err| "write error")?;
- socket.flush().await.map_err(|err| "flush error")?;
-
- Ok(())
- }
-}
-
-impl<'a> Drop for LightClient<'a>
-{
- fn drop(&mut self) {
- self.socket.close();
- }
-}
-
-
-
-async fn set_color(client: &mut LightClient<'_>, i: usize, color: Rgb888) -> Result<(),&'static str>
-{
-
- let mut buf = [0; 7];
- // let a = String::new().;
- let mut buf: String<128> =String::new();
- buf.write_fmt(format_args!("/illuminate?colour=%23{:02x}{:02x}{:02x}&light-{}={}", color.r(), color.g(), color.b(), i*10, i*10)).unwrap();
-
- client.http_get(buf.as_str()).await?;
- Ok(())
-}
-// curl 'http://domelights.i.eta.st/illuminate?colour=%23a1ff89&light-0=0&light-10=10&light-20=20&light-30=30&light-40=40&light-50=50&light-60=60&light-70=70&light-80=80&light-90=90' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8' -H 'Accept-Language: en-US,en;q=0.5' -H 'Accept-Encoding: gzip, deflate' -H 'Referer: http://domelights.i.eta.st/' -H 'DNT: 1' -H 'Connection: keep-alive' -H 'Upgrade-Insecure-Requests: 1'
-
-// #[embassy_executor::task]
-pub async fn dome_demo(display: &mut Display , wifi: Wifi, init: EspWifiInitialization, mut rng: Rng) -> ! {
- println!("dome_demo starting....");
- let config = Config::dhcpv4(Default::default());
- let mut wifi = start_wifi(wifi, init, config, rng.random().into(), "Camp2023-open", "").await;
-
- let mut buffer = LightBuffer{rx:[0; 1024], tx: [0; 1024]};
-
-
- let input = InputHandler;
- let mut inputs = input.split();
-
- let captouch = CaptouchHandler;
- let top = captouch.top_petals();
- let bot = captouch.bottom_petals();
-
-
- let circle_top_style = PrimitiveStyle::with_fill(Rgb565::YELLOW);
- let circle_bot_style = PrimitiveStyle::with_fill(Rgb565::GREEN);
-
- let bmp_data = include_bytes!("../img/milliways.bmp");
- let bmp = Bmp::from_slice(bmp_data).unwrap();
- let logo = Image::with_center(&bmp, display.bounding_box().center());
-
- println!("dome_demo started");
- let colors = [Rgb888::CSS_BLUE, Rgb888::CSS_RED, Rgb888::CSS_GREEN];
-
- let mut state = [0; 10];
-
- loop {
- loop {
- if wifi.is_link_up() {
- break;
- }
- Timer::after(Duration::from_millis(500)).await;
- }
-
- println!("Waiting to get IP address...");
- loop {
- if let Some(config) = wifi.config_v4() {
- println!("Got IP: {}", config.address);
- break;
- }else {
- Timer::after(Duration::from_millis(500)).await;
- }
- }
- println!("got ip!");
-
- let client = LightClient::new(&mut wifi, &mut buffer.rx, &mut buffer.tx).await;
- if client.is_err() {
- continue;
- }
- let mut client = client.unwrap();
-
- loop {
-
- macro_rules! set_and_inc_color {
- ($i:expr) => {
- state[$i] = (state[$i]+ 1) % colors.len();
- let color = colors[state[$i]];
- println!("DEBUG: i {} color_id: {}",$i, state[$i]);
- let _ = set_color(&mut client, $i,color).await;
- };
- }
-
- match select(inputs.sw2_center.wait_for_press(), async {
- display
- .fill_solid(&display.bounding_box(), Rgb565::BLACK)
- .unwrap();
- logo.draw(display).unwrap();
- if top.petal0.pressed().await {
- set_and_inc_color!(0);
-
- Circle::with_center(Point::new(120, 20), 20)
- .draw_styled(&circle_top_style, display)
- .unwrap();
- } else {
- Circle::with_center(Point::new(120, 20), 10)
- .draw_styled(&circle_top_style, display)
- .unwrap();
- }
- if top.petal2.pressed().await {
- set_and_inc_color!(1);
- Circle::with_center(Point::new(215, 90), 20)
- .draw_styled(&circle_top_style, display)
- .unwrap();
- } else {
- Circle::with_center(Point::new(215, 90), 10)
- .draw_styled(&circle_top_style, display)
- .unwrap();
- }
- if top.petal4.pressed().await {
- set_and_inc_color!(2);
- Circle::with_center(Point::new(178, 200), 20)
- .draw_styled(&circle_top_style, display)
- .unwrap();
- } else {
- Circle::with_center(Point::new(178, 200), 10)
- .draw_styled(&circle_top_style, display)
- .unwrap();
- }
- if top.petal6.pressed().await {
- set_and_inc_color!(3);
- Circle::with_center(Point::new(61, 200), 20)
- .draw_styled(&circle_top_style, display)
- .unwrap();
- } else {
- Circle::with_center(Point::new(61, 200), 10)
- .draw_styled(&circle_top_style, display)
- .unwrap();
- }
- if top.petal8.pressed().await {
- set_and_inc_color!(4);
- Circle::with_center(Point::new(25, 90), 20)
- .draw_styled(&circle_top_style, display)
- .unwrap();
- } else {
- Circle::with_center(Point::new(25, 90), 10)
- .draw_styled(&circle_top_style, display)
- .unwrap();
- }
-
- if bot.petal1.pressed().await {
- set_and_inc_color!(6);
- Circle::with_center(Point::new(178, 39), 20)
- .draw_styled(&circle_bot_style, display)
- .unwrap();
- } else {
- Circle::with_center(Point::new(178, 39), 10)
- .draw_styled(&circle_bot_style, display)
- .unwrap();
- }
- if bot.petal3.pressed().await {
- set_and_inc_color!(5);
- Circle::with_center(Point::new(215, 150), 20)
- .draw_styled(&circle_bot_style, display)
- .unwrap();
- } else {
- Circle::with_center(Point::new(215, 150), 10)
- .draw_styled(&circle_bot_style, display)
- .unwrap();
- }
- if bot.petal5.pressed().await {
- set_and_inc_color!(9);
- Circle::with_center(Point::new(120, 220), 20)
- .draw_styled(&circle_bot_style, display)
- .unwrap();
- } else {
- Circle::with_center(Point::new(120, 220), 10)
- .draw_styled(&circle_bot_style, display)
- .unwrap();
- }
- if bot.petal7.pressed().await {
- set_and_inc_color!(8);
- Circle::with_center(Point::new(24, 150), 20)
- .draw_styled(&circle_bot_style, display)
- .unwrap();
- } else {
- Circle::with_center(Point::new(24, 150), 10)
- .draw_styled(&circle_bot_style, display)
- .unwrap();
- }
- if bot.petal9.pressed().await {
- set_and_inc_color!(7);
- Circle::with_center(Point::new(61, 29), 20)
- .draw_styled(&circle_bot_style, display)
- .unwrap();
- } else {
- Circle::with_center(Point::new(61, 29), 10)
- .draw_styled(&circle_bot_style, display)
- .unwrap();
- }
- display.flush().await.unwrap();
- Timer::after(Duration::from_millis(50)).await;
- })
- .await
- {
- Either::First(_) => break,
- Either::Second(_) => (),
- }
- }
- }
- loop{
- println!("ended");
- }
-}
diff --git a/src/dome_lights.rs b/src/dome_lights.rs
new file mode 100644
index 0000000000000000000000000000000000000000..c91e6da76df4b1d1d82b35591fce0e195b6bb053
--- /dev/null
+++ b/src/dome_lights.rs
@@ -0,0 +1,278 @@
+
+use core::fmt::Write;
+
+use embassy_futures::select::{select, Either};
+use embassy_net::{
+ tcp::TcpSocket, Stack, driver::Driver,
+ Ipv6Address, StaticConfigV6, Config, Ipv6Cidr, Ipv4Address
+};
+use embassy_time::{Timer, Duration};
+use embedded_graphics::{primitives::*, pixelcolor::{Rgb888, Rgb565}, prelude::{WebColors, RgbColor, Dimensions, DrawTarget, Point}, image::Image, Drawable};
+use esp_println::println;
+use esp_wifi::EspWifiInitialization;
+use hal::{Rng, radio::Wifi};
+use heapless::String;
+use smoltcp::wire::{IpEndpoint, TcpOption};
+use tinybmp::Bmp;
+
+use crate::flow3r::{display::Display, wifi::start_wifi, input::InputHandler, captouch::CaptouchHandler};
+
+struct LightClient<'a>
+{
+ // rx_buffer: &'b mut [u8; 1024],
+ // tx_buffer: &'b mut [u8; 1024],
+ socket: TcpSocket<'a>,
+ // socketwrapper: Option<SocketWrapper<'a>>,
+ // a: &'b str,
+}
+
+struct LightBuffer {
+ pub rx: [u8; 1024],
+ pub tx: [u8; 1024],
+}
+
+impl<'a> LightClient<'a>
+{
+
+ pub async fn new<D>(stack: &'a Stack<D>, rx_buffer: &'a mut [u8; 1024], tx_buffer: &'a mut [u8; 1024]) // , buffer: &'b mut LightBuffer
+ ->Result<LightClient<'a>, &'static str>
+ where D: Driver
+ {
+
+ let mut s = Self {
+ // socketwrapper: None,
+ socket: TcpSocket::new(&stack, rx_buffer, tx_buffer),
+ // a: "dsf".as_ref(),
+ };
+
+ let socket = &mut s.socket;
+ let endpoint = IpEndpoint{
+ addr: Ipv4Address::new(151, 216, 192, 14).into(),
+ port: 80
+ };
+ socket.connect(endpoint).await.map_err(|err| "ConnectError")?;
+ socket.write("GET / HTTP/1.1\r\nServer: domelights.i.eta.st\r\n\r\n".as_bytes()).await.map_err(|err| "write error")?;
+ socket.flush().await.map_err(|err| "flush error")?;
+
+ Ok(s)
+ }
+
+ pub async fn http_get(&mut self, path: &str) -> Result<(), &'static str> {
+ let socket = &mut self.socket;
+ socket.write("GET ".as_ref()).await.map_err(|e| "write error")?;
+ socket.write(path.as_bytes()).await.map_err(|e| "write error")?;
+ socket.write(" HTTP/1.1\r\nServer: domelights.i.eta.st\r\n\r\n".as_bytes()).await.map_err(|err| "write error")?;
+ socket.flush().await.map_err(|err| "flush error")?;
+
+ Ok(())
+ }
+}
+
+impl<'a> Drop for LightClient<'a>
+{
+ fn drop(&mut self) {
+ self.socket.close();
+ }
+}
+
+
+
+async fn set_color(client: &mut LightClient<'_>, i: usize, color: Rgb888) -> Result<(),&'static str>
+{
+
+ let mut buf = [0; 7];
+ // let a = String::new().;
+ let mut buf: String<128> =String::new();
+ buf.write_fmt(format_args!("/illuminate?colour=%23{:02x}{:02x}{:02x}&light-{}={}", color.r(), color.g(), color.b(), i*10, i*10)).unwrap();
+
+ client.http_get(buf.as_str()).await?;
+ Ok(())
+}
+// curl 'http://domelights.i.eta.st/illuminate?colour=%23a1ff89&light-0=0&light-10=10&light-20=20&light-30=30&light-40=40&light-50=50&light-60=60&light-70=70&light-80=80&light-90=90' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8' -H 'Accept-Language: en-US,en;q=0.5' -H 'Accept-Encoding: gzip, deflate' -H 'Referer: http://domelights.i.eta.st/' -H 'DNT: 1' -H 'Connection: keep-alive' -H 'Upgrade-Insecure-Requests: 1'
+
+// #[embassy_executor::task]
+pub async fn dome_demo(display: &mut Display , wifi: Wifi, init: EspWifiInitialization, mut rng: Rng) -> ! {
+ println!("dome_demo starting....");
+ let config = Config::dhcpv4(Default::default());
+ let mut wifi = start_wifi(wifi, init, config, rng.random().into(), "Camp2023-open", "").await;
+
+ let mut buffer = LightBuffer{rx:[0; 1024], tx: [0; 1024]};
+
+
+ let input = InputHandler;
+ let mut inputs = input.split();
+
+ let captouch = CaptouchHandler;
+ let top = captouch.top_petals();
+ let bot = captouch.bottom_petals();
+
+
+ let circle_top_style = PrimitiveStyle::with_fill(Rgb565::YELLOW);
+ let circle_bot_style = PrimitiveStyle::with_fill(Rgb565::GREEN);
+
+ let bmp_data = include_bytes!("../img/milliways.bmp");
+ let bmp = Bmp::from_slice(bmp_data).unwrap();
+ let logo = Image::with_center(&bmp, display.bounding_box().center());
+
+ println!("dome_demo started");
+ let colors = [Rgb888::CSS_BLUE, Rgb888::CSS_RED, Rgb888::CSS_GREEN];
+
+ let mut state = [0; 10];
+
+ loop {
+ loop {
+ if wifi.is_link_up() {
+ break;
+ }
+ Timer::after(Duration::from_millis(500)).await;
+ }
+
+ println!("Waiting to get IP address...");
+ loop {
+ if let Some(config) = wifi.config_v4() {
+ println!("Got IP: {}", config.address);
+ break;
+ }else {
+ Timer::after(Duration::from_millis(500)).await;
+ }
+ }
+ println!("got ip!");
+
+ let client = LightClient::new(&mut wifi, &mut buffer.rx, &mut buffer.tx).await;
+ if client.is_err() {
+ continue;
+ }
+ let mut client = client.unwrap();
+
+ loop {
+
+ macro_rules! set_and_inc_color {
+ ($i:expr) => {
+ state[$i] = (state[$i]+ 1) % colors.len();
+ let color = colors[state[$i]];
+ println!("DEBUG: i {} color_id: {}",$i, state[$i]);
+ let _ = set_color(&mut client, $i,color).await;
+ };
+ }
+
+ match select(inputs.sw2_center.wait_for_press(), async {
+ display
+ .fill_solid(&display.bounding_box(), Rgb565::BLACK)
+ .unwrap();
+ logo.draw(display).unwrap();
+ if top.petal0.pressed().await {
+ set_and_inc_color!(0);
+
+ Circle::with_center(Point::new(120, 20), 20)
+ .draw_styled(&circle_top_style, display)
+ .unwrap();
+ } else {
+ Circle::with_center(Point::new(120, 20), 10)
+ .draw_styled(&circle_top_style, display)
+ .unwrap();
+ }
+ if top.petal2.pressed().await {
+ set_and_inc_color!(1);
+ Circle::with_center(Point::new(215, 90), 20)
+ .draw_styled(&circle_top_style, display)
+ .unwrap();
+ } else {
+ Circle::with_center(Point::new(215, 90), 10)
+ .draw_styled(&circle_top_style, display)
+ .unwrap();
+ }
+ if top.petal4.pressed().await {
+ set_and_inc_color!(2);
+ Circle::with_center(Point::new(178, 200), 20)
+ .draw_styled(&circle_top_style, display)
+ .unwrap();
+ } else {
+ Circle::with_center(Point::new(178, 200), 10)
+ .draw_styled(&circle_top_style, display)
+ .unwrap();
+ }
+ if top.petal6.pressed().await {
+ set_and_inc_color!(3);
+ Circle::with_center(Point::new(61, 200), 20)
+ .draw_styled(&circle_top_style, display)
+ .unwrap();
+ } else {
+ Circle::with_center(Point::new(61, 200), 10)
+ .draw_styled(&circle_top_style, display)
+ .unwrap();
+ }
+ if top.petal8.pressed().await {
+ set_and_inc_color!(4);
+ Circle::with_center(Point::new(25, 90), 20)
+ .draw_styled(&circle_top_style, display)
+ .unwrap();
+ } else {
+ Circle::with_center(Point::new(25, 90), 10)
+ .draw_styled(&circle_top_style, display)
+ .unwrap();
+ }
+
+ if bot.petal1.pressed().await {
+ set_and_inc_color!(6);
+ Circle::with_center(Point::new(178, 39), 20)
+ .draw_styled(&circle_bot_style, display)
+ .unwrap();
+ } else {
+ Circle::with_center(Point::new(178, 39), 10)
+ .draw_styled(&circle_bot_style, display)
+ .unwrap();
+ }
+ if bot.petal3.pressed().await {
+ set_and_inc_color!(5);
+ Circle::with_center(Point::new(215, 150), 20)
+ .draw_styled(&circle_bot_style, display)
+ .unwrap();
+ } else {
+ Circle::with_center(Point::new(215, 150), 10)
+ .draw_styled(&circle_bot_style, display)
+ .unwrap();
+ }
+ if bot.petal5.pressed().await {
+ set_and_inc_color!(9);
+ Circle::with_center(Point::new(120, 220), 20)
+ .draw_styled(&circle_bot_style, display)
+ .unwrap();
+ } else {
+ Circle::with_center(Point::new(120, 220), 10)
+ .draw_styled(&circle_bot_style, display)
+ .unwrap();
+ }
+ if bot.petal7.pressed().await {
+ set_and_inc_color!(8);
+ Circle::with_center(Point::new(24, 150), 20)
+ .draw_styled(&circle_bot_style, display)
+ .unwrap();
+ } else {
+ Circle::with_center(Point::new(24, 150), 10)
+ .draw_styled(&circle_bot_style, display)
+ .unwrap();
+ }
+ if bot.petal9.pressed().await {
+ set_and_inc_color!(7);
+ Circle::with_center(Point::new(61, 29), 20)
+ .draw_styled(&circle_bot_style, display)
+ .unwrap();
+ } else {
+ Circle::with_center(Point::new(61, 29), 10)
+ .draw_styled(&circle_bot_style, display)
+ .unwrap();
+ }
+ display.flush().await.unwrap();
+ Timer::after(Duration::from_millis(50)).await;
+ })
+ .await
+ {
+ Either::First(_) => break,
+ Either::Second(_) => (),
+ }
+ }
+ }
+ loop{
+ println!("ended");
+ }
+}