Initialise esp32 pwm, fix esp32 initial setup as it uses 2 bytes

This commit is contained in:
Piv
2023-01-22 15:05:32 +10:30
parent 40e5269c35
commit 34fbc40ebb
3 changed files with 7 additions and 6 deletions

View File

@@ -99,12 +99,14 @@ pub struct Esp32SerialPwmServo<T: SerialPort> {
impl<T: SerialPort> Esp32SerialPwmServo<T> {
pub fn new(serial_port: Arc<Mutex<T>>, channel: u8, pin: u8) -> Esp32SerialPwmServo<T> {
Esp32SerialPwmServo {
let mut servo = Esp32SerialPwmServo {
serial_port,
value: 0.,
channel,
pin,
}
};
servo.init_pwm();
servo
}
}
@@ -115,7 +117,7 @@ impl<T: SerialPort> Esp32SerialPwmServo<T> {
.lock()
.unwrap()
.write(&[0, 1, self.channel, self.pin]);
// TODO: Better error handling
// TODO: Better error handling (even anyhow would be better)
match bytes_written {
Ok(size) => println!("{}", size),
Err(err) => eprintln!("{}", err),

View File

@@ -13,7 +13,6 @@ mod grpcserver;
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let addr = "[::1]:10000".parse().unwrap();
// TODO: Do these actually need to be shared since they're both on one port?
let serial_port = serialport::new("", 32400)
.open_native()
.expect("Could not open serial port");

View File

@@ -19,8 +19,8 @@ void setup()
void setupServos(uint8_t size, uint8_t *calibrationValues)
{
// We assume there are 3 bytes per servo. Ignore if there aren't.
if (size % 3 == 0)
// We assume there are 2 bytes per servo [channel number, pin number]. Ignore if there aren't.
if (size % 2 == 0)
{
for (int i = 0; i < size; i += 2)
{