@@ -149,17 +149,13 @@ void mperror_heartbeat_switch_off (void) {
149149void mperror_heartbeat_signal (void ) {
150150 if (mperror_heart_beat .do_disable ) {
151151 mperror_heart_beat .do_disable = false;
152- mperror_heartbeat_switch_off ();
153- mperror_heart_beat .enabled = false;
154- }
155- else if (mperror_heart_beat .enabled ) {
152+ } else if (mperror_heart_beat .enabled ) {
156153 if (!mperror_heart_beat .beating ) {
157154 if ((mperror_heart_beat .on_time = HAL_GetTick ()) - mperror_heart_beat .off_time > MPERROR_HEARTBEAT_OFF_MS ) {
158155 MAP_GPIOPinWrite (MICROPY_SYS_LED_PORT , MICROPY_SYS_LED_PORT_PIN , MICROPY_SYS_LED_PORT_PIN );
159156 mperror_heart_beat .beating = true;
160157 }
161- }
162- else {
158+ } else {
163159 if ((mperror_heart_beat .off_time = HAL_GetTick ()) - mperror_heart_beat .on_time > MPERROR_HEARTBEAT_ON_MS ) {
164160 MAP_GPIOPinWrite (MICROPY_SYS_LED_PORT , MICROPY_SYS_LED_PORT_PIN , 0 );
165161 mperror_heart_beat .beating = false;
@@ -199,48 +195,17 @@ void nlr_jump_fail(void *val) {
199195#endif
200196}
201197
202- #ifndef BOOTLOADER
203- /******************************************************************************/
204- // Micro Python bindings
205-
206- /// \classmethod \constructor()
207- ///
208- /// Return the heart beat object
209- STATIC mp_obj_t pyb_heartbeat_make_new (mp_obj_t type_in , mp_uint_t n_args , mp_uint_t n_kw , const mp_obj_t * args ) {
210- // check arguments
211- mp_arg_check_num (n_args , n_kw , 0 , 0 , false);
212-
213- // return constant object
214- return (mp_obj_t )& pyb_heartbeat_obj ;
215- }
216-
217- /// \function enable()
218- /// Enables the heartbeat signal
219- STATIC mp_obj_t pyb_enable_heartbeat (mp_obj_t self ) {
220- mperror_heart_beat .enabled = true;
221- return mp_const_none ;
198+ void mperror_enable_heartbeat (bool enable ) {
199+ if (enable ) {
200+ mperror_heart_beat .enabled = true;
201+ mperror_heart_beat .do_disable = false;
202+ mperror_heartbeat_switch_off ();
203+ } else {
204+ mperror_heart_beat .do_disable = true;
205+ mperror_heart_beat .enabled = false;
206+ }
222207}
223- STATIC MP_DEFINE_CONST_FUN_OBJ_1 (pyb_enable_heartbeat_obj , pyb_enable_heartbeat );
224208
225- /// \function disable()
226- /// Disables the heartbeat signal
227- STATIC mp_obj_t pyb_disable_heartbeat (mp_obj_t self ) {
228- mperror_heart_beat .do_disable = true;
229- return mp_const_none ;
209+ bool mperror_is_heartbeat_enabled (void ) {
210+ return mperror_heart_beat .enabled ;
230211}
231- STATIC MP_DEFINE_CONST_FUN_OBJ_1 (pyb_disable_heartbeat_obj , pyb_disable_heartbeat );
232-
233- STATIC const mp_map_elem_t pyb_heartbeat_locals_dict_table [] = {
234- { MP_OBJ_NEW_QSTR (MP_QSTR_enable ), (mp_obj_t )& pyb_enable_heartbeat_obj },
235- { MP_OBJ_NEW_QSTR (MP_QSTR_disable ), (mp_obj_t )& pyb_disable_heartbeat_obj },
236- };
237- STATIC MP_DEFINE_CONST_DICT (pyb_heartbeat_locals_dict , pyb_heartbeat_locals_dict_table );
238-
239- const mp_obj_type_t pyb_heartbeat_type = {
240- { & mp_type_type },
241- .name = MP_QSTR_HeartBeat ,
242- .make_new = pyb_heartbeat_make_new ,
243- .locals_dict = (mp_obj_t )& pyb_heartbeat_locals_dict ,
244- };
245-
246- #endif
0 commit comments