diff --git a/src/hal/halmodule.cc b/src/hal/halmodule.cc index 3f581d7de4b..9c354a30aa8 100644 --- a/src/hal/halmodule.cc +++ b/src/hal/halmodule.cc @@ -147,7 +147,7 @@ bool from_python(PyObject *o, bool *b) if(PyFloat_Check(o)) { // Floating point is false *only* when it is 0.0 double v = PyFloat_AsDouble(o); - *b = 0.0 == v; + *b = 0.0 != v; return true; } @@ -913,7 +913,7 @@ static bool check_port(const pyhalitem *item, const char *pfx) return false; } if(item->pin.type != HAL_PORT) { - PyErr_Format(PyExc_RuntimeError, "%s: %s: Pin type not HAL_PORT but '%d'", pfx, (int)item->pin.type); + PyErr_Format(PyExc_RuntimeError, "%s: %s: Pin type not HAL_PORT but '%d'", pfx, item->name, (int)item->pin.type); return false; } return true; @@ -2239,6 +2239,7 @@ static const halenum_member_t halenum_rt_members[] = { {"LXRT", REALTIME_TYPE_LXRT}, {"XENOMAI", REALTIME_TYPE_XENOMAI}, {"XENOMAI_EVL", REALTIME_TYPE_XENOMAI_EVL}, + {} }; // Build an enum.IntEnum subclass from a member table. The class claims diff --git a/tests/halmodule/comp-set-get/expected b/tests/halmodule/comp-set-get/expected index 37c7b48be8d..34009b990ec 100644 --- a/tests/halmodule/comp-set-get/expected +++ b/tests/halmodule/comp-set-get/expected @@ -35,3 +35,8 @@ pincheck s True True True pincheck param False True True set u 0 0 set u -1 fail +set param 0.0 ok +set param 1.0 ok +set param -0.5 True +set param 0 ok +set param 2 True diff --git a/tests/halmodule/comp-set-get/test.py b/tests/halmodule/comp-set-get/test.py index 46d6d36b0f3..9a10f2a60e3 100755 --- a/tests/halmodule/comp-set-get/test.py +++ b/tests/halmodule/comp-set-get/test.py @@ -88,6 +88,13 @@ def pin_validate(i, t, d): try_set_pin(pu, 0) try_set_pin(pu, -1) + + # A float into a bool is false only when it is 0.0 + try_set("param", 0.0) + try_set("param", 1.0) + try_set("param", -0.5) + try_set("param", 0) + try_set("param", 2) except: import traceback print("Exception: {}".format(traceback.format_exc()))