use crate::extern_functions::*;
use serde::{Deserialize, Serialize};
use crate::helpers::*;
use crate::{error::Error};
pub struct Haptics;
impl Haptics {
pub async fn impact(options: impl Into<ImpactOptions>) -> Result<(), Error> {
run_value_unit(options, haptics_impact).await
}
pub async fn vibrate(options: impl Into<VibrateOptions>) -> Result<(), Error> {
run_value_unit(options, haptics_vibrate).await
}
pub async fn notification(options: impl Into<NotificationOptions>) -> Result<(), Error> {
run_value_unit(options, haptics_notification).await
}
pub async fn selection_start() -> Result<(), Error> {
run_unit_unit(haptics_selectionStart).await
}
pub async fn selection_changed() -> Result<(), Error> {
run_unit_unit(haptics_selectionChanged).await
}
pub async fn selection_end() -> Result<(), Error> {
run_unit_unit(haptics_selectionEnd).await
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct VibrateOptions {
pub duration: f64,
}
impl From<f64> for VibrateOptions {
fn from(duration: f64) -> Self {
Self { duration }
}
}
impl Default for VibrateOptions {
fn default() -> Self {
Self { duration: 300.0 }
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct NotificationOptions {
#[serde(rename = "type")]
pub notification_type: NotificationType,
}
impl From<NotificationType> for NotificationOptions {
fn from(notification_type: NotificationType) -> Self {
Self { notification_type }
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "UPPERCASE")]
pub enum NotificationType {
Success,
Warning,
Error,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct ImpactOptions {
pub style: ImpactStyle,
}
impl From<ImpactStyle> for ImpactOptions {
fn from(style: ImpactStyle) -> Self {
Self { style }
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "UPPERCASE")]
pub enum ImpactStyle {
Heavy,
Medium,
Light,
}