_protomatter: move get/set paused into shared-module

This commit is contained in:
Jeff Epler 2020-04-03 10:52:50 -05:00
parent caea4e010f
commit a663a7dd30
3 changed files with 17 additions and 8 deletions

View File

@ -193,7 +193,7 @@ static void check_for_deinit(protomatter_protomatter_obj_t *self) {
STATIC mp_obj_t protomatter_protomatter_get_paused(mp_obj_t self_in) {
protomatter_protomatter_obj_t *self = (protomatter_protomatter_obj_t*)self_in;
check_for_deinit(self);
return mp_obj_new_bool(self->paused);
return mp_obj_new_bool(common_hal_protomatter_protomatter_get_paused(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(protomatter_protomatter_get_paused_obj, protomatter_protomatter_get_paused);
@ -201,12 +201,7 @@ STATIC mp_obj_t protomatter_protomatter_set_paused(mp_obj_t self_in, mp_obj_t va
protomatter_protomatter_obj_t *self = (protomatter_protomatter_obj_t*)self_in;
check_for_deinit(self);
bool paused = mp_obj_is_true(value_in);
if (paused && !self->paused) {
_PM_stop(&self->core);
} else if (!paused && self->paused) {
_PM_resume(&self->core);
}
self->paused = paused;
common_hal_protomatter_protomatter_set_paused(self, paused);
return mp_const_none;
}
@ -262,7 +257,7 @@ STATIC void protomatter_protomatter_deinit_void(mp_obj_t self_in) {
}
STATIC void protomatter_protomatter_set_brightness(mp_obj_t self_in, mp_float_t value) {
protomatter_protomatter_set_paused(self_in, mp_obj_new_bool(value <= 0));
common_hal_protomatter_protomatter_set_paused(self_in, value <= 0);
}
STATIC const framebuffer_p_t protomatter_protomatter_proto = {

View File

@ -52,5 +52,7 @@ void common_hal_protomatter_protomatter_construct(protomatter_protomatter_obj_t*
void common_hal_protomatter_protomatter_deinit(protomatter_protomatter_obj_t*);
void protomatter_protomatter_collect_ptrs(protomatter_protomatter_obj_t*);
void common_hal_protomatter_protomatter_reconstruct(protomatter_protomatter_obj_t* self, mp_obj_t framebuffer);
void common_hal_protomatter_protomatter_set_paused(protomatter_protomatter_obj_t* self, bool paused);
bool common_hal_protomatter_protomatter_get_paused(protomatter_protomatter_obj_t* self);
#endif

View File

@ -180,3 +180,15 @@ void protomatter_protomatter_collect_ptrs(protomatter_protomatter_obj_t* self) {
gc_collect_ptr(self->core.screenData);
}
void common_hal_protomatter_protomatter_set_paused(protomatter_protomatter_obj_t* self, bool paused) {
if (paused && !self->paused) {
_PM_stop(&self->core);
} else if (!paused && self->paused) {
_PM_resume(&self->core);
}
self->paused = paused;
}
bool common_hal_protomatter_protomatter_get_paused(protomatter_protomatter_obj_t* self) {
return self->paused;
}