|
31 | 31 | #include "shared-bindings/util.h" |
32 | 32 |
|
33 | 33 | #include "lib/utils/context_manager_helpers.h" |
| 34 | +#include "lib/utils/interrupt_char.h" |
34 | 35 |
|
35 | 36 | #include "py/ioctl.h" |
36 | 37 | #include "py/objproperty.h" |
|
56 | 57 | //| :param int bits: the number of bits per byte, 7, 8 or 9. |
57 | 58 | //| :param Parity parity: the parity used for error checking. |
58 | 59 | //| :param int stop: the number of stop bits, 1 or 2. |
59 | | -//| :param int timeout: the timeout in seconds to wait for the first character and between subsequent characters. |
| 60 | +//| :param int timeout: the timeout in seconds to wait for the first character and between subsequent characters. Raises ``ValueError`` if timeout >100 seconds. |
60 | 61 | //| :param int receiver_buffer_size: the character length of the read buffer (0 to disable). (When a character is 9 bits the buffer will be 2 * receiver_buffer_size bytes.) |
61 | 62 | //| |
62 | 63 | //| *New in CircuitPython 4.0:* ``timeout`` has incompatibly changed units from milliseconds to seconds. |
| 64 | +//| The new upper limit on ``timeout`` is meant to catch mistaken use of milliseconds. |
63 | 65 |
|
64 | 66 | typedef struct { |
65 | 67 | mp_obj_base_t base; |
@@ -116,9 +118,13 @@ STATIC mp_obj_t busio_uart_make_new(const mp_obj_type_t *type, size_t n_args, si |
116 | 118 | mp_raise_ValueError(translate("stop must be 1 or 2")); |
117 | 119 | } |
118 | 120 |
|
| 121 | + mp_float_t timeout = mp_obj_get_float(args[ARG_timeout].u_obj); |
| 122 | + if (timeout > 100.0f) { |
| 123 | + mp_raise_ValueError(translate("timeout >100 (units are now seconds, not msecs)")); |
| 124 | + } |
| 125 | + |
119 | 126 | common_hal_busio_uart_construct(self, tx, rx, |
120 | | - args[ARG_baudrate].u_int, bits, parity, stop, |
121 | | - mp_obj_get_float(args[ARG_timeout].u_obj), |
| 127 | + args[ARG_baudrate].u_int, bits, parity, stop, timeout, |
122 | 128 | args[ARG_receiver_buffer_size].u_int); |
123 | 129 | return (mp_obj_t)self; |
124 | 130 | } |
|
0 commit comments