From 2c31b90877c27366e0c970dd31201858ff3ad7e9 Mon Sep 17 00:00:00 2001 From: Tanja Date: Thu, 7 Sep 2023 18:49:41 +0200 Subject: [PATCH] Generate API URLs on the client during compile time --- src/app/mod.rs | 6 ++--- src/app/projector.rs | 34 ++++++++++++++++++++++++ src/main.rs | 1 + src/projector_commands.rs | 55 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 src/app/projector.rs create mode 100644 src/projector_commands.rs diff --git a/src/app/mod.rs b/src/app/mod.rs index ef5131b..108940e 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -1,3 +1,4 @@ +mod projector; mod sound_button; mod sounds; @@ -5,7 +6,7 @@ use leptos::{ev::close, *}; use leptos_router::*; use crate::app::sound_button::SoundButton; -use crate::app::sounds::Sounds; +use crate::app::{projector::Projector, sounds::Sounds}; use crate::core::{ get_sounds, get_sounds_strings, kill_mplayer, parse_sounds, Sound, HL_SOUNDS_STRING, }; @@ -41,8 +42,6 @@ pub fn App(cx: Scope) -> impl IntoView { - // -
@@ -50,6 +49,7 @@ pub fn App(cx: Scope) -> impl IntoView { // // + impl IntoView { + log!("Projector"); + + log!("{}", projector_commands::power::on); + + view! { cx, +
+ // "Value: " {move || counter.count.get()} + // + // } + // } + // /> +
+ } +} diff --git a/src/main.rs b/src/main.rs index add938f..54d24d7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ mod app; mod core; mod license_notice; +mod projector_commands; // mod components; use leptos::*; diff --git a/src/projector_commands.rs b/src/projector_commands.rs new file mode 100644 index 0000000..a56099d --- /dev/null +++ b/src/projector_commands.rs @@ -0,0 +1,55 @@ +#![allow(non_upper_case_globals)] + +const BASE_URL: &str = "http://licht.realraum.at:4201/api/v1/"; + +#[macro_export] +#[macro_use] +macro_rules! make_api_urls { + // Match the list of identifiers and the module name and assign them to $name and $module + ($($name:ident),*; $module:ident) => { + // For each identifier in the list, expand to a constant declaration + $(pub const $name: &str = concat!("http://licht.realraum.at:4201/api/v1/", stringify!($module), "/", stringify!($name));)* + }; + } + +pub mod input { + // FIXME these may not work on all projectors + + make_api_urls!( + vga_a, + vga_b, + composite, + s_video, + hdmi, + wireless, + usb_display, + usb_viewer; + input + ); +} + +pub mod volume { + make_api_urls!(up, down, mute, un_mute; volume); +} + +pub mod power { + make_api_urls!(on, off; power); +} + +pub mod menu { + make_api_urls!(menu_button, up, down, left, right, ok; menu); +} + +pub mod picture { + make_api_urls!( + blank, + un_blank, + freeze, + un_freeze, + contrast_up, + contrast_down, + brightness_up, + brightness_down; + picture + ); +}