diff --git a/spinnyboy_rust/src/bin/dc_driver/afroesc.rs b/spinnyboy_rust/src/bin/dc_driver/afroesc.rs index 9dcf89d..e0aa2b5 100644 --- a/spinnyboy_rust/src/bin/dc_driver/afroesc.rs +++ b/spinnyboy_rust/src/bin/dc_driver/afroesc.rs @@ -1,9 +1,14 @@ +#![no_std] + +use esp_hal::aes::Operation; +use esp_hal::mcpwm::PwmPeripheral; use esp_hal::mcpwm::operator::PwmPin; +use esp_hal::mcpwm::operator::Operator; +use esp_hal::mcpwm::McPwm; +use esp_hal::peripherals::MCPWM0; use esp_hal::delay::Delay; -use crate::dc_driver::EscState; pub struct AfroEsc<'a>{ - pub pwm_pin: &'a mut PwmPin<'a, esp_hal::peripherals::MCPWM0<'a>, 0,true>, - state: crate::dc_driver::EscState, + pub pwm_pin: &'a mut PwmPin<'a, esp_hal::peripherals::MCPWM0<'a>, 0,true> } const ARMING_SEQUENCE:u16 = 1055; @@ -14,14 +19,13 @@ const GAP:u16 = (MAX_THROTTLE - MIN_THROTTLE)/100; impl AfroEsc<'_>{ //this is a little hacky tbh pub fn new<'a>(pwm_pin:&'a mut PwmPin<'a, esp_hal::peripherals::MCPWM0<'a>, 0,true>)-> AfroEsc<'a> { - let mut esc = AfroEsc{pwm_pin:pwm_pin,state:EscState::Starting}; + let mut esc = AfroEsc{pwm_pin:pwm_pin}; let delay = Delay::new(); - esc.send_arming_sequence(); + esc.set_arming_sequence(); delay.delay_millis(3000); esc } pub fn set_timestamp(&mut self,value:u16){ - self.pwm_pin.set_timestamp(value); } //range is from 1121 till 1421 @@ -33,24 +37,8 @@ impl AfroEsc<'_>{ let new_timestamp = MIN_THROTTLE+value*GAP; self.pwm_pin.set_timestamp(new_timestamp); } - pub fn send_arming_sequence(&mut self){ + pub fn set_arming_sequence(&mut self){ self.set_timestamp(1055); } - fn set_state(&mut self, state:EscState){ - self.state = state; - } - pub fn get_state(self) -> EscState{ - self.state - } - pub fn map_duty(&mut self, x:i32){ - if x <=0 { - self.pwm_pin.set_timestamp(1055); - } - else{ - let duty:u16 = crate::dc_driver::arduino_map(x, 0, 100, MIN_THROTTLE.into(), MAX_THROTTLE.into()).try_into().expect("INTEGER TOO LARGE"); - self.pwm_pin.set_timestamp(duty); - - } - } } \ No newline at end of file diff --git a/spinnyboy_rust/src/bin/dc_driver/mod.rs b/spinnyboy_rust/src/bin/dc_driver/mod.rs index 5ebbfd5..c2a351f 100644 --- a/spinnyboy_rust/src/bin/dc_driver/mod.rs +++ b/spinnyboy_rust/src/bin/dc_driver/mod.rs @@ -1,17 +1 @@ -pub mod afroesc; - -pub enum EscState { - Starting, - Running, - Stopping, - Stop - -} -//taken from: https://docs.arduino.cc/language-reference/en/functions/math/map/ -//used for the ramp up of the spincoater -pub fn arduino_map(x:i32, in_min:i32, in_max:i32, out_min:i32, out_max:i32) -> i32 { - - return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; - -} - +pub mod afroesc; \ No newline at end of file diff --git a/spinnyboy_rust/src/bin/peripherals/nextion.rs b/spinnyboy_rust/src/bin/peripherals/nextion.rs index 4827b0e..a9fa346 100644 --- a/spinnyboy_rust/src/bin/peripherals/nextion.rs +++ b/spinnyboy_rust/src/bin/peripherals/nextion.rs @@ -29,6 +29,11 @@ impl<'a> Nextion<'a> { let _ = &self.interface.write(b"\xff\xff\xff"); } fn read_frame(&mut self, buf: &mut [u8]) -> Result { + let size: usize = 0; + let mut tmp_buf: [u8; 20] = [0; 20]; + let mut cmd_end_ctr = 0; + let mut i = 0; + let mut read_header = false; loop { if !self.interface.read_ready() { continue; @@ -65,6 +70,7 @@ impl<'a> Nextion<'a> { UartStatemachine::Terminator(n) => { if byte == b'\xff' { if n >= 2 { + rprintln!("SENDING {:?}",buf); let idx = self.idx; self.reset(); return Ok(idx);