Compare commits

..

No commits in common. "502afc9a5f5aba8e331b656394fb08ff3d35cba2" and "443da0edcf78c37a65ba1f0a4435dc7e051c2ea5" have entirely different histories.

3 changed files with 18 additions and 40 deletions

View file

@ -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);
}
}
}

View file

@ -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;
}

View file

@ -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<usize, RxError> {
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);