Skip to content

Conversation

@nivekmai
Copy link
Contributor

Summary:
Credit to @brent113 for finding this originally.

The issue is that we are allowed to call ToolHeadLaser::SetPower with
any value, and it will attempt to do the conversion through the
power_table_ using that value.

This means that calling ToolHeadLaser::SetPower with any value above
100 will result in reading random data and attempting to set that as the
PWM value.

To fix, we should clamp power to the size of the power_table_ when
doing any lookups.

Test Plan:
pio run
I also wrote a test of sorts (http://tpcg.io/AMS3HP), but it'd be better
if I could write a proper test for this method.

@nivekmai nivekmai force-pushed the limit_laser_power branch 4 times, most recently from 0f1a27a to afac282 Compare February 12, 2022 20:59
@nivekmai
Copy link
Contributor Author

One day I'll get this right...

Summary:
Credit to @brent113 for finding this originally.

The issue is that we are allowed to call `ToolHeadLaser::SetPower` with
any value, and it will attempt to do the conversion through the
`power_table_` using that value.

This means that calling `ToolHeadLaser::SetPower` with any value above
100 will result in reading random data and attempting to set that as the
PWM value.

To fix, we should clamp `power` to the size of the `power_table_` when
doing any lookups.

Test Plan:
`pio run`
I also wrote a test of sorts (http://tpcg.io/AMS3HP), but it'd be better
if I could write a proper test for this method.
@nivekmai nivekmai marked this pull request as ready for review February 20, 2022 16:49
@scotthsl scotthsl merged commit 481af57 into Snapmaker:main Jun 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants