Skip to content

Commit

Permalink
pybricks.common.IMU: pass axes from hub
Browse files Browse the repository at this point in the history
When initializing the hub, the user can specify its orientation by saying along which axes the top and front sides point.
  • Loading branch information
laurensvalk committed Jan 5, 2021
1 parent 2d3410a commit da9bd26
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pybricks/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const mp_obj_type_t pb_type_Speaker;

#if PYBRICKS_PY_COMMON_IMU

mp_obj_t pb_type_IMU_obj_new(void);
mp_obj_t pb_type_IMU_obj_new(mp_obj_t top_side_axis, mp_obj_t front_side_axis);

#endif // PYBRICKS_PY_COMMON_IMU

Expand Down
2 changes: 1 addition & 1 deletion pybricks/common/pb_type_imu.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ STATIC const mp_obj_type_t pb_type_IMU = {
STATIC common_IMU_obj_t singleton_obj;

// pybricks._common.IMU.__init__
mp_obj_t pb_type_IMU_obj_new(void) {
mp_obj_t pb_type_IMU_obj_new(mp_obj_t top_side_axis, mp_obj_t front_side_axis) {

// Get singleton instance
common_IMU_obj_t *self = &singleton_obj;
Expand Down
9 changes: 8 additions & 1 deletion pybricks/hubs/pb_type_primehub.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
#include "py/runtime.h"
#include "py/obj.h"

#include <pybricks/util_mp/pb_kwarg_helper.h>

#include <pybricks/common.h>
#include <pybricks/geometry.h>
#include <pybricks/hubs.h>

typedef struct _hubs_PrimeHub_obj_t {
Expand All @@ -34,11 +37,15 @@ static const pb_obj_enum_member_t *primehub_buttons[] = {
};

STATIC mp_obj_t hubs_PrimeHub_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
PB_PARSE_ARGS_CLASS(n_args, n_kw, args,
PB_ARG_DEFAULT_OBJ(top_side, pb_Axis_Z_obj),
PB_ARG_DEFAULT_OBJ(front_side, pb_Axis_X_obj));

hubs_PrimeHub_obj_t *self = m_new_obj(hubs_PrimeHub_obj_t);
self->base.type = (mp_obj_type_t *)type;
self->buttons = pb_type_Keypad_obj_new(PBIO_ARRAY_SIZE(primehub_buttons), primehub_buttons);
self->display = pb_type_Lightmatrix_obj_new(pbsys_hub_light_matrix);
self->imu = pb_type_IMU_obj_new();
self->imu = pb_type_IMU_obj_new(top_side_in, front_side_in);
self->light = common_ColorLight_internal_obj_new(pbsys_status_light);
self->speaker = mp_call_function_0(MP_OBJ_FROM_PTR(&pb_type_Speaker));
return MP_OBJ_FROM_PTR(self);
Expand Down
9 changes: 8 additions & 1 deletion pybricks/hubs/pb_type_technichub.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
#include <pbdrv/reset.h>
#include <pbsys/light.h>

#include <pybricks/util_mp/pb_kwarg_helper.h>

#include <pybricks/common.h>
#include <pybricks/geometry.h>
#include <pybricks/hubs.h>

typedef struct _hubs_TechnicHub_obj_t {
Expand All @@ -18,9 +21,13 @@ typedef struct _hubs_TechnicHub_obj_t {
} hubs_TechnicHub_obj_t;

STATIC mp_obj_t hubs_TechnicHub_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
PB_PARSE_ARGS_CLASS(n_args, n_kw, args,
PB_ARG_DEFAULT_OBJ(top_side, pb_Axis_Z_obj),
PB_ARG_DEFAULT_OBJ(front_side, pb_Axis_X_obj));

hubs_TechnicHub_obj_t *self = m_new_obj(hubs_TechnicHub_obj_t);
self->base.type = (mp_obj_type_t *)type;
self->imu = pb_type_IMU_obj_new();
self->imu = pb_type_IMU_obj_new(top_side_in, front_side_in);
self->light = common_ColorLight_internal_obj_new(pbsys_status_light);
return MP_OBJ_FROM_PTR(self);
}
Expand Down

0 comments on commit da9bd26

Please sign in to comment.