Skip to content

Commit

Permalink
rename battery_level to toy_power
Browse files Browse the repository at this point in the history
  • Loading branch information
TuTiDore committed Dec 10, 2023
1 parent 2e5d4b4 commit ffcda9f
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src-tauri/bindings/FeVCToy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ import type { FeVCToyAnatomy } from "./FeVCToyAnatomy";
import type { FeVCToyFeature } from "./FeVCToyFeature";
import type { ToyPower } from "./ToyPower";

export interface FeVCToy { toy_id: number | null, toy_name: string, toy_anatomy: FeVCToyAnatomy, battery_level: ToyPower, toy_connected: boolean, features: Array<FeVCToyFeature>, listening: boolean, osc_data: boolean, sub_id: number, }
export interface FeVCToy { toy_id: number | null, toy_name: string, toy_anatomy: FeVCToyAnatomy, toy_power: ToyPower, toy_connected: boolean, features: Array<FeVCToyFeature>, listening: boolean, osc_data: boolean, sub_id: number, }
2 changes: 1 addition & 1 deletion src-tauri/src/frontend/frontend_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub struct FeVCToy {
pub toy_id: Option<u32>,
pub toy_name: String,
pub toy_anatomy: FeVCToyAnatomy,
pub battery_level: ToyPower,
pub toy_power: ToyPower,
pub toy_connected: bool,
pub features: Vec<FeVCToyFeature>,
pub listening: bool,
Expand Down
16 changes: 6 additions & 10 deletions src-tauri/src/osc/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,6 @@ pub fn recv_osc_cmd(sock: &UdpSocket) -> Option<OscMessage> {
* Toy update loop every 1 sec maybe 5
* How to do parameter structure
* /avatar/parameters/toy_name
* INT SIGS:
* 0 - 100: toy.battery_level
* -1: connected
* -2: disconnected
*
* ATM this only sends a battery life OSC address/value.
*/
Expand Down Expand Up @@ -219,19 +215,19 @@ pub async fn toy_refresh(
sock.connect(remote).await.unwrap();
for (.., mut toy) in toys {
// Can use this to differ between toys with batteries and toys without!
let battery_level = if toy.device_handle.has_battery_level() {
let toy_power = if toy.device_handle.has_battery_level() {
match toy.device_handle.battery_level().await {
Ok(battery_lvl) => ToyPower::Battery(battery_lvl),
Err(_e) => {
warn!("Device battery_level error: {:?}", _e);
warn!("Device battery_level() error: {:?}", _e);
ToyPower::Pending
}
}
} else {
ToyPower::NoBattery
};

toy.battery_level = battery_level.clone();
toy.toy_power = toy_power.clone();

let _ = app_handle.emit_all(
"fe_toy_event",
Expand All @@ -240,7 +236,7 @@ pub async fn toy_refresh(
toy_id: Some(toy.toy_id),
toy_name: toy.toy_name.clone(),
toy_anatomy: toy.config.as_ref().unwrap().anatomy.to_fe(),
battery_level: battery_level.clone(),
toy_power: toy_power.clone(),
toy_connected: toy.toy_connected,
features: toy.parsed_toy_features.features.to_frontend(),
listening: toy.listening,
Expand All @@ -262,7 +258,7 @@ pub async fn toy_refresh(
.to_lowercase(),
toy.sub_id
),
args: vec![OscType::Float(battery_level.to_float() as f32)],
args: vec![OscType::Float(toy_power.to_float() as f32)],
}))
.unwrap();

Expand All @@ -272,7 +268,7 @@ pub async fn toy_refresh(
} else {
info!(
"Sent battery_level: {} to {}",
battery_level.to_float() as f32,
toy_power.to_float() as f32,
toy.toy_name
);
}
Expand Down
10 changes: 5 additions & 5 deletions src-tauri/src/toy_handling/handling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ pub async fn client_event_handler(
Delay::new(Duration::from_secs(3)).await;

// Can use this to differ between toys with batteries and toys without!
let battery_level = if dev.has_battery_level() {
let toy_power = if dev.has_battery_level() {
match dev.battery_level().await {
Ok(battery_lvl) => ToyPower::Battery(battery_lvl),
Err(_e) => {
warn!("Device battery_level error: {:?}", _e);
warn!("Device battery_level() error: {:?}", _e);
ToyPower::Pending
}
}
Expand Down Expand Up @@ -116,7 +116,7 @@ pub async fn client_event_handler(
let mut toy = VCToy {
toy_id: dev.index(),
toy_name: dev.name().clone(),
battery_level: battery_level.clone(),
toy_power: toy_power.clone(),
toy_connected: dev.connected(),
toy_features: dev.message_attributes().clone(),
parsed_toy_features: VCToyFeatures::new(),
Expand Down Expand Up @@ -168,7 +168,7 @@ pub async fn client_event_handler(
toy_id: Some(toy.toy_id),
toy_name: toy.toy_name.clone(),
toy_anatomy: toy.config.as_ref().unwrap().anatomy.to_fe(),
battery_level,
toy_power,
toy_connected: toy.toy_connected,
features: toy.parsed_toy_features.features.to_frontend(),
listening: toy.listening,
Expand All @@ -184,7 +184,7 @@ pub async fn client_event_handler(
let _ = Notification::new(identifier.clone())
.title("Toy Connected")
.body(
format!("{} ({})", toy.toy_name, toy.battery_level.to_string())
format!("{} ({})", toy.toy_name, toy.toy_power.to_string())
.as_str(),
)
.show();
Expand Down
33 changes: 1 addition & 32 deletions src-tauri/src/toy_handling/toy_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,6 @@ impl ToyManager {
}

pub fn sync_frontend(&mut self, refresh_toys: bool) -> Vec<FeVCToy> {
/*
let _res = self.app_handle.emit_all("fe_toy_event",
FeToyEvent::OfflineSyncAll({
offline_fetoy_vec
}),
);*/

if refresh_toys {
info!("Clearing toy manager configs map and repopulating from disk..");
self.configs.clear();
Expand Down Expand Up @@ -120,7 +113,7 @@ impl ToyManager {
toy_id: None,
toy_name: config.toy_name.clone(),
toy_anatomy: config.anatomy.to_fe(),
battery_level: super::ToyPower::Offline,
toy_power: super::ToyPower::Offline,
toy_connected: false,
features: config.features.features.to_frontend(),
listening: false,
Expand All @@ -131,28 +124,4 @@ impl ToyManager {

offline_toy_vec
}

/*
fn fetoy_vec_from_online_toys(&self) -> Vec<FeVCToy> {
let mut online_toy_vec = Vec::new();
self.online_toys.iter().for_each(|(_toy_id, online_toy)| {
online_toy_vec.push(
FeVCToy {
toy_id: Some(online_toy.toy_id),
toy_name: online_toy.toy_name.clone(),
toy_anatomy: online_toy.config.as_ref().unwrap().anatomy.to_fe(),
battery_level: online_toy.battery_level,
toy_connected: online_toy.toy_connected,
features: online_toy.param_feature_map.to_fe(),
listening: online_toy.listening,
osc_data: online_toy.osc_data,
sub_id: online_toy.sub_id,
});
});
online_toy_vec
}
*/
}
2 changes: 1 addition & 1 deletion src-tauri/src/toy_handling/toyops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use super::ToyPower;
pub struct VCToy {
pub toy_id: u32,
pub toy_name: String,
pub battery_level: ToyPower,
pub toy_power: ToyPower,
pub toy_connected: bool,
pub toy_features: ClientDeviceMessageAttributes,
pub parsed_toy_features: VCToyFeatures,
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/vcore/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ pub fn native_alter_toy(
toy_id: Some(alter_clone.toy_id),
toy_name: alter_clone.toy_name,
toy_anatomy: alter_clone.config.as_ref().unwrap().anatomy.to_fe(),
battery_level: alter_clone.battery_level,
toy_power: alter_clone.toy_power,
toy_connected: alter_clone.toy_connected,
features: alter_clone.parsed_toy_features.features.to_frontend(),
listening: alter_clone.listening,
Expand Down
2 changes: 1 addition & 1 deletion src/features/Toy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function Toy({ toy }: { toy: FeVCToy }) {
<div className="w-full h-full">
<div className="text-4xl flex justify-between items-center px-6">
<div>{nameInfo.shortName}</div>
<ToyInfo nameInfo={nameInfo} toyPower={toy.battery_level} />
<ToyInfo nameInfo={nameInfo} toyPower={toy.toy_power} />
</div>
<div className="m-4 overflow-hidden h-full">
<ToySettings toy={toy} />
Expand Down

0 comments on commit ffcda9f

Please sign in to comment.