Simplify type check in tick and init last
This commit is contained in:
parent
6132a05fd9
commit
190bdf8117
@ -49,6 +49,7 @@ void common_hal_gamepad_gamepad_init(gamepad_obj_t *gamepad,
|
||||
}
|
||||
gamepad->pins[i] = pin;
|
||||
}
|
||||
gamepad->last = 0;
|
||||
}
|
||||
|
||||
void common_hal_gamepad_gamepad_deinit(gamepad_obj_t *self) {
|
||||
|
@ -38,12 +38,11 @@ void gamepad_tick(void) {
|
||||
uint8_t bit = 1;
|
||||
|
||||
void* singleton = MP_STATE_VM(gamepad_singleton);
|
||||
if (!singleton) {
|
||||
if (singleton == NULL || !MP_OBJ_IS_TYPE(MP_OBJ_FROM_PTR(singleton), &gamepad_type)) {
|
||||
return;
|
||||
}
|
||||
if (MP_OBJ_IS_TYPE(MP_OBJ_FROM_PTR(singleton), &gamepad_type)) {
|
||||
// buttons connected directly to pins
|
||||
gamepad_obj_t *self = singleton;
|
||||
|
||||
gamepad_obj_t *self = MP_OBJ_TO_PTR(singleton);
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
digitalio_digitalinout_obj_t* pin = self->pins[i];
|
||||
if (!pin) {
|
||||
@ -58,7 +57,6 @@ void gamepad_tick(void) {
|
||||
self->pressed |= self->last & current;
|
||||
self->last = current;
|
||||
}
|
||||
}
|
||||
|
||||
void gamepad_reset(void) {
|
||||
MP_STATE_VM(gamepad_singleton) = NULL;
|
||||
|
@ -40,6 +40,8 @@ void common_hal_gamepadshift_gamepadshift_init(gamepadshift_obj_t *gamepadshift,
|
||||
common_hal_digitalio_digitalinout_switch_to_output(latch_pin, 1,
|
||||
DRIVE_MODE_PUSH_PULL);
|
||||
gamepadshift->latch_pin = latch_pin;
|
||||
|
||||
gamepadshift->last = 0;
|
||||
}
|
||||
|
||||
void common_hal_gamepadshift_gamepadshift_deinit(gamepadshift_obj_t *gamepadshift) {
|
||||
|
@ -31,12 +31,10 @@
|
||||
|
||||
void gamepadshift_tick(void) {
|
||||
void* singleton = MP_STATE_VM(gamepad_singleton);
|
||||
if (!singleton) {
|
||||
if (singleton == NULL || !MP_OBJ_IS_TYPE(MP_OBJ_FROM_PTR(singleton), &gamepadshift_type)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (MP_OBJ_IS_TYPE(MP_OBJ_FROM_PTR(singleton), &gamepadshift_type)) {
|
||||
// buttons connected to a shift register
|
||||
gamepadshift_obj_t *self = MP_OBJ_TO_PTR(singleton);
|
||||
uint8_t current = 0;
|
||||
uint8_t bit = 1;
|
||||
@ -53,7 +51,6 @@ void gamepadshift_tick(void) {
|
||||
self->pressed |= self->last & current;
|
||||
self->last = current;
|
||||
}
|
||||
}
|
||||
|
||||
void gamepadshift_reset(void) {
|
||||
MP_STATE_VM(gamepad_singleton) = NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user