Skip to content

Commit

Permalink
pybricks/parameters: add brick colors
Browse files Browse the repository at this point in the history
These are some standard brick colors measured using the
ColorDistance sensor
  • Loading branch information
Novakasa committed Sep 5, 2022
1 parent b4ef683 commit 03b1e24
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pybricks/parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ extern const pb_type_Color_obj_t pb_Color_NONE_obj;
extern const pb_type_Color_obj_t pb_Color_BLACK_obj;
extern const pb_type_Color_obj_t pb_Color_GRAY_obj;
extern const pb_type_Color_obj_t pb_Color_WHITE_obj;
extern const pb_type_Color_obj_t pb_Color_BRICK_YELLOW_obj;
extern const pb_type_Color_obj_t pb_Color_BRICK_GREEN_obj;
extern const pb_type_Color_obj_t pb_Color_BRICK_RED_obj;
extern const pb_type_Color_obj_t pb_Color_BRICK_BLACK_obj;
extern const pb_type_Color_obj_t pb_Color_BRICK_WHITE_obj;
extern const pb_type_Color_obj_t pb_Color_BRICK_BLUE_obj;

extern const mp_obj_type_t pb_enum_type_Direction;

Expand Down
36 changes: 36 additions & 0 deletions pybricks/parameters/pb_type_color.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,36 @@ const pb_type_Color_obj_t pb_Color_WHITE_obj = {
.hsv = {0, 0, 100}
};

const pb_type_Color_obj_t pb_Color_BRICK_YELLOW_obj = {
{&pb_type_Color},
.hsv = {52, 96, 90}
};

const pb_type_Color_obj_t pb_Color_BRICK_GREEN_obj = {
{&pb_type_Color},
.hsv = {140, 89, 48}
};

const pb_type_Color_obj_t pb_Color_BRICK_RED_obj = {
{&pb_type_Color},
.hsv = {357, 96, 71}
};

const pb_type_Color_obj_t pb_Color_BRICK_BLACK_obj = {
{&pb_type_Color},
.hsv = {189, 49, 17}
};

const pb_type_Color_obj_t pb_Color_BRICK_WHITE_obj = {
{&pb_type_Color},
.hsv = {0, 5, 95}
};

const pb_type_Color_obj_t pb_Color_BRICK_BLUE_obj = {
{&pb_type_Color},
.hsv = {221, 96, 67}
};

/**
* Gets the pointer to the hsv type from a Color type.
*
Expand Down Expand Up @@ -139,6 +169,12 @@ void pb_type_Color_reset(void) {
mp_obj_dict_store(MP_OBJ_FROM_PTR(colors), MP_ROM_QSTR(MP_QSTR_GRAY), MP_OBJ_FROM_PTR(&pb_Color_GRAY_obj));
mp_obj_dict_store(MP_OBJ_FROM_PTR(colors), MP_ROM_QSTR(MP_QSTR_WHITE), MP_OBJ_FROM_PTR(&pb_Color_WHITE_obj));
mp_obj_dict_store(MP_OBJ_FROM_PTR(colors), MP_ROM_QSTR(MP_QSTR_NONE), MP_OBJ_FROM_PTR(&pb_Color_NONE_obj));
mp_obj_dict_store(MP_OBJ_FROM_PTR(colors), MP_ROM_QSTR(MP_QSTR_BRICK_RED), MP_OBJ_FROM_PTR(&pb_Color_BRICK_RED_obj));
mp_obj_dict_store(MP_OBJ_FROM_PTR(colors), MP_ROM_QSTR(MP_QSTR_BRICK_YELLOW), MP_OBJ_FROM_PTR(&pb_Color_BRICK_YELLOW_obj));
mp_obj_dict_store(MP_OBJ_FROM_PTR(colors), MP_ROM_QSTR(MP_QSTR_BRICK_GREEN), MP_OBJ_FROM_PTR(&pb_Color_BRICK_GREEN_obj));
mp_obj_dict_store(MP_OBJ_FROM_PTR(colors), MP_ROM_QSTR(MP_QSTR_BRICK_BLACK), MP_OBJ_FROM_PTR(&pb_Color_BRICK_BLACK_obj));
mp_obj_dict_store(MP_OBJ_FROM_PTR(colors), MP_ROM_QSTR(MP_QSTR_BRICK_WHITE), MP_OBJ_FROM_PTR(&pb_Color_BRICK_WHITE_obj));
mp_obj_dict_store(MP_OBJ_FROM_PTR(colors), MP_ROM_QSTR(MP_QSTR_BRICK_BLUE), MP_OBJ_FROM_PTR(&pb_Color_BRICK_BLUE_obj));
MP_STATE_VM(pb_type_Color_dict) = colors;
}

Expand Down

0 comments on commit 03b1e24

Please sign in to comment.