• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pybricks / pybricks-micropython / 9659196825

25 Jun 2024 08:35AM UTC coverage: 56.592% (+10.5%) from 46.065%
9659196825

push

github

laurensvalk
pybricks.hubs: Add update_heading_correction method to imu.

3760 of 6644 relevant lines covered (56.59%)

20292085.46 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/pybricks/common/pb_type_lightarray.c
1
// SPDX-License-Identifier: MIT
2
// Copyright (c) 2018-2023 The Pybricks Authors
3

4
#include "py/mpconfig.h"
5

6
#if PYBRICKS_PY_COMMON_LIGHT_ARRAY
7

8
#include "py/obj.h"
9

10
#include <pybricks/common.h>
11

12
#include <pybricks/pupdevices.h>
13
#include <pybricks/common/pb_type_device.h>
14

15
#include <pybricks/util_pb/pb_error.h>
16
#include <pybricks/util_mp/pb_obj_helper.h>
17
#include <pybricks/util_mp/pb_kwarg_helper.h>
18
#include <pybricks/util_mp/pb_obj_helper.h>
19

20
// pybricks._common.Light class object
21
typedef struct _common_LightArray_obj_t {
22
    mp_obj_base_t base;
23
    pb_type_device_obj_base_t *sensor;
24
    uint8_t light_mode;
25
    uint8_t number_of_lights;
26
} common_LightArray_obj_t;
27

28
// pybricks._common.LightArray.on
29
STATIC mp_obj_t common_LightArray_on(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
×
30
    PB_PARSE_ARGS_METHOD(n_args, pos_args, kw_args,
×
31
        common_LightArray_obj_t, self,
32
        PB_ARG_DEFAULT_INT(brightness, 100));
×
33

34
    int8_t brightness_values[4];
×
35
    pb_obj_get_pct_or_array(brightness_in, self->number_of_lights, brightness_values);
×
36

37
    // Set the brightness values and wait or await it.
38
    return pb_type_device_set_data(self->sensor, self->light_mode, brightness_values, self->number_of_lights);
×
39
}
40
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(common_LightArray_on_obj, 1, common_LightArray_on);
41

42
// pybricks._common.LightArray.off
43
STATIC mp_obj_t common_LightArray_off(mp_obj_t self_in) {
×
44
    common_LightArray_obj_t *self = MP_OBJ_TO_PTR(self_in);
×
45
    int8_t brightness_values[4] = { };
×
46
    return pb_type_device_set_data(self->sensor, self->light_mode, brightness_values, self->number_of_lights);
×
47
}
48
STATIC MP_DEFINE_CONST_FUN_OBJ_1(common_LightArray_off_obj, common_LightArray_off);
49

50
// dir(pybricks.builtins.LightArray)
51
STATIC const mp_rom_map_elem_t common_LightArray_locals_dict_table[] = {
52
    { MP_ROM_QSTR(MP_QSTR_on), MP_ROM_PTR(&common_LightArray_on_obj) },
53
    { MP_ROM_QSTR(MP_QSTR_off), MP_ROM_PTR(&common_LightArray_off_obj) },
54
};
55
STATIC MP_DEFINE_CONST_DICT(common_LightArray_locals_dict, common_LightArray_locals_dict_table);
56

57
// type(pybricks.builtins.LightArray)
58
STATIC MP_DEFINE_CONST_OBJ_TYPE(pb_type_LightArray,
59
    MP_QSTRnull,
60
    MP_TYPE_FLAG_NONE,
61
    locals_dict, &common_LightArray_locals_dict);
62

63
// pybricks._common.LightArray.__init__
64
mp_obj_t common_LightArray_obj_make_new(pb_type_device_obj_base_t *sensor, uint8_t light_mode, uint8_t number_of_lights) {
×
65
    common_LightArray_obj_t *light = mp_obj_malloc(common_LightArray_obj_t, &pb_type_LightArray);
×
66
    light->sensor = sensor;
×
67
    light->light_mode = light_mode;
×
68
    light->number_of_lights = number_of_lights;
×
69
    return MP_OBJ_FROM_PTR(light);
×
70
}
71

72
#endif // PYBRICKS_PY_COMMON_LIGHT_ARRAY
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc