Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error propagation from the embedded_hal functions #37

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
<!-- next-header -->
## [Unreleased] - ReleaseDate
### Changed

* `Motor::new()` and `Driver::new()` methods now set the outputs upon their
initialisation to the documented defaults.
* `Motor::new()` and `Driver::new()` methods now also return errors if they fail
to set their outputs upon initialisation.
* Breaking: update to `embedded-hal` 1.0
* Renamed error types to their struct names
* Renamed `DriveCommand::Backwards` to `DriveCommand::Backward` to match
`DriveCommand::Forward`

### Removed

* Removed the `drive_forward`, `drive_backward`, `stop` and `brake`
functions as they are duplicates to the `drive` function with the
different enum variants and make the API surface larger

## [0.2.0] - 2023-11-28

### Changed
* Due to dependency updates the MSRV has been updated from 1.60 to 1.63. This should only be relevant if you use the `defmt` feature, but we now only test with 1.63 and not older releases, so it's not guaranteed to work otherwise.

* Due to dependency updates the MSRV has been updated from 1.60 to 1.63. This
should only be relevant if you use the `defmt` feature, but we now only test
with 1.63 and not older releases, so it's not guaranteed to work otherwise.
* Breaking: the API was migrated from `embedded-hal:0.2` to `embedded-hal:1.0.0-rc1`.
If your HAL does not yet implement this, then please use the previous release of the library.

Expand Down
18 changes: 9 additions & 9 deletions examples/stm32f4-single-motor-example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ mod app {
.pwm_hz(Channel3::new(gpiob.pb10), 100.kHz(), &clocks)
.split();
motor_pwm.enable();
let mut motor = Motor::new(motor_in1, motor_in2, motor_pwm);
motor.drive_backwards(0).expect("");
let mut motor = Motor::new(motor_in1, motor_in2, motor_pwm).unwrap();
motor.drive(DriveCommand::Backward(0)).unwrap();

// set up the button
let mut button = gpioc.pc13.into_pull_down_input();
Expand Down Expand Up @@ -103,20 +103,20 @@ mod app {
}
0 => {
*motor_ramp_direction = 1;
DriveCommand::Backwards(1)
DriveCommand::Backward(1)
}
_ => DriveCommand::Forward((*speed as i8 + *motor_ramp_direction) as u8),
},
DriveCommand::Backwards(speed) => match speed {
DriveCommand::Backward(speed) => match speed {
100 => {
*motor_ramp_direction = -1;
DriveCommand::Backwards(99)
DriveCommand::Backward(99)
}
0 => {
*motor_ramp_direction = 1;
DriveCommand::Forward(1)
}
_ => DriveCommand::Backwards((*speed as i8 + *motor_ramp_direction) as u8),
_ => DriveCommand::Backward((*speed as i8 + *motor_ramp_direction) as u8),
},
DriveCommand::Stop | DriveCommand::Brake => {
return;
Expand All @@ -140,16 +140,16 @@ mod app {
.lock(|motor| match motor.current_drive_command() {
DriveCommand::Stop => {
defmt::info!("motor stopped => applying brake");
motor.brake();
motor.drive(DriveCommand::Brake).unwrap();
}
DriveCommand::Brake => {
defmt::info!("brake was on => starting the motor again");
motor.drive_backwards(0).expect("");
motor.drive(DriveCommand::Backward(0)).unwrap();
update_motor_speed::spawn_after(100.millis()).ok();
}
_ => {
defmt::info!("was driving so far => stopping the motor");
motor.stop();
motor.drive(DriveCommand::Stop).unwrap();
}
});
}
Expand Down
Loading