Merge pull request #732 from pewpew-game/gamepad-typecheck
Add a type check to the gamepad module
This commit is contained in:
commit
630352c25d
@ -27,6 +27,7 @@
|
||||
#include "py/runtime.h"
|
||||
#include "py/mphal.h"
|
||||
#include "shared-module/gamepad/GamePad.h"
|
||||
#include "shared-bindings/digitalio/DigitalInOut.h"
|
||||
#include "GamePad.h"
|
||||
|
||||
|
||||
@ -96,6 +97,12 @@ STATIC mp_obj_t gamepad_make_new(const mp_obj_type_t *type, size_t n_args,
|
||||
gamepad_singleton = m_new_obj(gamepad_obj_t);
|
||||
gamepad_singleton->base.type = &gamepad_type;
|
||||
}
|
||||
for (size_t i = 0; i < n_args; ++i) {
|
||||
if (!MP_OBJ_IS_TYPE(args[i], &digitalio_digitalinout_type)) {
|
||||
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
|
||||
"Expected a %q", digitalio_digitalinout_type.name));
|
||||
}
|
||||
}
|
||||
gamepad_init(n_args, args);
|
||||
return MP_OBJ_FROM_PTR(gamepad_singleton);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user