Skip to content

Commit

Permalink
Merge pull request #48 from KaiseiYokoyama/dev/0.4.4
Browse files Browse the repository at this point in the history
Dev/0.4.4
  • Loading branch information
KaiseiYokoyama authored May 6, 2020
2 parents f3c0b82 + e7dd10c commit fb29b26
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "joycon-rs"
version = "0.4.3"
version = "0.4.4"
authors = ["Kaisei Yokoyama <[email protected]>"]
repository = "https://github.com/KaiseiYokoyama/joycon-rs"
edition = "2018"
Expand Down
6 changes: 5 additions & 1 deletion examples/rumble.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ fn main() -> JoyConResult<()> {

driver.enable_feature(JoyConFeature::Vibration)?;

// let rumble = Rumble::new(80.0,0.2);
let rumble = Rumble::new(300.0,0.9);
driver.rumble((Some(rumble), Some(rumble)))?;

std::thread::sleep(std::time::Duration::from_millis(60));

let stop = Rumble::stop();
driver.rumble((Some(stop),Some(stop)))?;

Ok(())
})?;

Expand Down
13 changes: 6 additions & 7 deletions src/joycon/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,18 @@ impl Into<[u8; 4]> for Rumble {
let encoded_hex_freq = f32::round(f32::log2(self.frequency / 10.0) * 32.0) as u8;

let hf_freq: u16 = (encoded_hex_freq as u16).saturating_sub(0x60) * 4;
let lf_freq: u8 = encoded_hex_freq.saturating_sub(0x40);
let lf_freq: u8 = encoded_hex_freq.saturating_sub(0x41) + 1;

let encoded_hex_amp = if self.amplitude > 0.23 {
f32::round(f32::log2(self.amplitude * 8.7) * 32.0) as u8
} else if self.amplitude > 0.12 {
f32::round(f32::log2(self.amplitude * 17.0) * 16.0) as u8
} else {
// todo study
f32::round(f32::log2(self.amplitude * 17.0) * 16.0) as u8
f32::round(((f32::log2(self.amplitude) * 32.0) - 96.0) / (4.0 - 2.0 * self.amplitude)) as u8
};

let hf_amp: u16 = {
let hf_amp: u16 = (encoded_hex_freq as u16 - 0x60) * 4;
let hf_amp: u16 = encoded_hex_amp as u16 * 2;
if hf_amp > 0x01FC {
0x01FC
} else { hf_amp }
Expand Down Expand Up @@ -1129,7 +1128,7 @@ pub mod input_report_mode {

fn new(driver: D) -> JoyConResult<Self> {
let mut driver = driver;
driver.send_sub_command(Self::SUB_COMMAND,Self::ARGS.as_ref())?;
driver.send_sub_command(Self::SUB_COMMAND, Self::ARGS.as_ref())?;

Ok(SubCommandMode {
driver,
Expand Down Expand Up @@ -1300,7 +1299,7 @@ pub mod input_report_mode {
driver.enable_feature(JoyConFeature::IMUFeature(IMUConfig::default()))?;
}

driver.send_sub_command(Self::SUB_COMMAND,Self::ARGS.as_ref())?;
driver.send_sub_command(Self::SUB_COMMAND, Self::ARGS.as_ref())?;

Ok(StandardFullMode {
driver
Expand Down Expand Up @@ -1774,7 +1773,7 @@ pub mod lights {
/// see the [new](#method.new) and [add_phase](#method.add_phase).
pub fn once(global_mini_cycle_duration: u8, led_start_intensity: u8,
led_intensity: u8, fading_transition_duration: u16, led_duration: u16) -> Self {
let mut pattern = LightEmittingPattern::new(global_mini_cycle_duration,led_start_intensity, 0u8.into());
let mut pattern = LightEmittingPattern::new(global_mini_cycle_duration, led_start_intensity, 0u8.into());
pattern.phases_len = Some(0u8.into());

pattern.add_phase(led_intensity, fading_transition_duration, led_duration)
Expand Down

0 comments on commit fb29b26

Please sign in to comment.