File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 53
53
//| """Not used. Access the sole instance through `alarm.sleep_memory`."""
54
54
//| ...
55
55
//|
56
+ //| def __bool__(self) -> bool:
57
+ //| """``sleep_memory`` is ``True`` if its length is greater than zero.
58
+ //| This is an easy way to check for its existence.
59
+ //| """
60
+ //| ...
61
+ //|
62
+ //| def __len__(self) -> int:
63
+ //| """Return the length. This is used by (`len`)"""
64
+ //| ...
65
+ //|
66
+ STATIC mp_obj_t alarm_sleep_memory_unary_op (mp_unary_op_t op , mp_obj_t self_in ) {
67
+ alarm_sleep_memory_obj_t * self = MP_OBJ_TO_PTR (self_in );
68
+ uint16_t len = common_hal_alarm_sleep_memory_get_length (self );
69
+ switch (op ) {
70
+ case MP_UNARY_OP_BOOL : return mp_obj_new_bool (len != 0 );
71
+ case MP_UNARY_OP_LEN : return MP_OBJ_NEW_SMALL_INT (len );
72
+ default : return MP_OBJ_NULL ; // op not supported
73
+ }
74
+ }
56
75
57
76
STATIC const mp_rom_map_elem_t alarm_sleep_memory_locals_dict_table [] = {
58
77
};
@@ -154,6 +173,7 @@ const mp_obj_type_t alarm_sleep_memory_type = {
154
173
{ & mp_type_type },
155
174
.name = MP_QSTR_SleepMemory ,
156
175
.subscr = alarm_sleep_memory_subscr ,
176
+ .unary_op = alarm_sleep_memory_unary_op ,
157
177
.print = NULL ,
158
178
.locals_dict = (mp_obj_t )& alarm_sleep_memory_locals_dict ,
159
179
};
You can’t perform that action at this time.
0 commit comments