Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/hal/halmodule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions tests/halmodule/comp-set-get/expected
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions tests/halmodule/comp-set-get/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
Loading