mirror of
https://github.com/slint-ui/slint.git
synced 2025-12-23 09:19:32 +00:00
Merge 69a0f51c3d into 1a236048c5
This commit is contained in:
commit
e7ece76667
5 changed files with 32 additions and 0 deletions
|
|
@ -21,6 +21,7 @@ name = "home_automation_lib"
|
|||
[dependencies]
|
||||
slint = { path = "../../../api/rs/slint", features = ["backend-android-activity-06"] }
|
||||
chrono = "0.4"
|
||||
kira = "0.10"
|
||||
|
||||
[features]
|
||||
sw-renderer = []
|
||||
|
|
|
|||
|
|
@ -2,6 +2,11 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
use chrono::{Datelike, Local, Timelike};
|
||||
use kira::{
|
||||
AudioManager, AudioManagerSettings, DefaultBackend,
|
||||
sound::static_sound::StaticSoundData,
|
||||
};
|
||||
use std::io::Cursor;
|
||||
use slint::{Timer, TimerMode};
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
|
|
@ -17,6 +22,10 @@ slint::slint! {
|
|||
export { Api, AppWindow } from "../ui/demo.slint";
|
||||
}
|
||||
|
||||
// https://sourceforge.net/projects/sox/
|
||||
// $ sox -n dial-tick.wav synth 0.01 sine 1000 fade t 0 0.01 0.005 gain -1
|
||||
const DIAL_TICK : &[u8] = include_bytes!("../ui/sounds/dial-tick.wav");
|
||||
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen(start))]
|
||||
pub fn main() {
|
||||
// This provides better error messages in debug mode.
|
||||
|
|
@ -27,6 +36,18 @@ pub fn main() {
|
|||
let app = AppWindow::new().expect("AppWindow::new() failed");
|
||||
let app_weak = app.as_weak();
|
||||
|
||||
let mut manager = AudioManager::<DefaultBackend>::new(AudioManagerSettings::default()).unwrap();
|
||||
|
||||
let api = app.global::<Api>();
|
||||
api.on_play_sound(move |sound| {
|
||||
let sound = match sound {
|
||||
SoundEffect::DialTick => DIAL_TICK,
|
||||
};
|
||||
let cursor = Cursor::new(sound);
|
||||
let sound_data = StaticSoundData::from_cursor(cursor).unwrap();
|
||||
let _sound_handle = manager.play(sound_data).unwrap();
|
||||
});
|
||||
|
||||
let timer = Timer::default();
|
||||
timer.start(TimerMode::Repeated, std::time::Duration::from_millis(1000), move || {
|
||||
if let Some(app) = app_weak.upgrade() {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,10 @@ export struct WeatherData {
|
|||
temperature: float,
|
||||
}
|
||||
|
||||
export enum SoundEffect {
|
||||
dial-tick,
|
||||
}
|
||||
|
||||
export global Api {
|
||||
in property <float> indoor-temperature: 22.0;
|
||||
in property <float> outdoor-temperature: 24.0;
|
||||
|
|
@ -95,4 +99,6 @@ export global Api {
|
|||
temperature: 23.0,
|
||||
},
|
||||
];
|
||||
|
||||
callback play-sound(SoundEffect);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright © SixtyFPS GmbH <info@slint.dev>
|
||||
// SPDX-License-Identifier: MIT
|
||||
import { Palette } from "../../common.slint";
|
||||
import { Api, SoundEffect } from "../../api.slint";
|
||||
|
||||
export global DialState {
|
||||
out property <int> totalLights: 60;
|
||||
|
|
@ -19,6 +20,9 @@ export component Dial {
|
|||
property <bool> moving: ta.firstTouch;
|
||||
in-out property <angle> dialAngle: DialState.startAngle;
|
||||
out property <int> volume: ((dialAngle - DialState.startAngle) / DialState.degreesFilledWithLights) * DialState.totalLights;
|
||||
changed volume => {
|
||||
Api.play-sound(SoundEffect.dial-tick);
|
||||
}
|
||||
|
||||
width: 212px;
|
||||
height: 213px;
|
||||
|
|
|
|||
BIN
demos/home-automation/ui/sounds/dial-tick.wav
Normal file
BIN
demos/home-automation/ui/sounds/dial-tick.wav
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue