Skip to content
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

## [Unreleased]

### Fixed

- Fixed overflow in saturation and value for ambient color measurement. This
can occur with very bright screens.

## [3.6.0] - 2024-03-02

### Changed
Expand Down
12 changes: 4 additions & 8 deletions pybricks/pupdevices/pb_type_pupdevices_colorsensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include "py/mphal.h"

#include <pbio/int_math.h>

#include <pybricks/common.h>
#include <pybricks/parameters.h>
#include <pybricks/pupdevices.h>
Expand Down Expand Up @@ -76,14 +78,8 @@ static void get_hsv_reflected(mp_obj_t self_in, pbio_color_hsv_t *hsv) {
static void get_hsv_ambient(mp_obj_t self_in, pbio_color_hsv_t *hsv) {
int16_t *data = pb_type_device_get_data(self_in, PBDRV_LEGODEV_MODE_PUP_COLOR_SENSOR__SHSV);
hsv->h = data[0];
hsv->s = data[1] / 10;
if (hsv->s > 100) {
hsv->s = 100;
}
hsv->v = data[2] / 10;
if (hsv->v > 100) {
hsv->v = 100;
}
hsv->s = pbio_int_math_min(data[1] / 10, 100);
hsv->v = pbio_int_math_min(data[2] / 10, 100);
}

// pybricks.pupdevices.ColorSensor.hsv(surface=True)
Expand Down