99#include "shared-bindings/countio/Counter.h"
1010#include "shared-bindings/util.h"
1111
12- //| .. currentmodule:: countio
12+ //| class Counter:
13+ //| """Counter will keep track of the number of falling edge transistions (pulses) on a
14+ //| given pin"""
1315//|
14- //| :class:`Counter` -- Track the count of falling edge transistions (pulses) on a given pin
15- //| ========================================================================================
16+ //| def __init__(self, pin_a):
17+ //| """Create a Counter object associated with the given pin. It tracks the number of
18+ //| falling pulses relative when the object is constructed.
1619//|
17- //| Counter will keep track of the number of falling edge transistions (pulses) on a given pin
20+ //| :param ~microcontroller.Pin pin_a: Pin to read pulses from.
1821//|
19- //| .. class:: Counter(pin_a)
2022//|
21- //| Create a Counter object associated with the given pin. It tracks the number of
22- //| falling pulses relative when the object is constructed.
23+ //| For example::
2324//|
24- //| :param ~microcontroller.Pin pin_a: Pin to read pulses from.
25- //|
25+ //| import countio
26+ //| import time
27+ //| from board import *
2628//|
27- //| For example::
28- //|
29- //| import countio
30- //| import time
31- //| from board import *
32- //|
33- //| pin_counter = countio.Counter(board.D1)
34- //| #reset the count after 100 counts
35- //| while True:
36- //| if pin_counter.count == 100:
37- //| pin_counter.reset()
38- //| print(pin_counter.count)
29+ //| pin_counter = countio.Counter(board.D1)
30+ //| #reset the count after 100 counts
31+ //| while True:
32+ //| if pin_counter.count == 100:
33+ //| pin_counter.reset()
34+ //| print(pin_counter.count)"""
3935//|
4036STATIC mp_obj_t countio_counter_make_new (const mp_obj_type_t * type , size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
4137 enum { ARG_pin_a };
4238 static const mp_arg_t allowed_args [] = {
4339 { MP_QSTR_pin_a , MP_ARG_REQUIRED | MP_ARG_OBJ }
44-
40+
4541 };
4642 mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
4743 mp_arg_parse_all (n_args , pos_args , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
4844
4945 const mcu_pin_obj_t * pin_a = validate_obj_is_free_pin (args [ARG_pin_a ].u_obj );
50-
46+
5147
5248 countio_counter_obj_t * self = m_new_obj (countio_counter_obj_t );
5349 self -> base .type = & countio_counter_type ;
@@ -57,9 +53,8 @@ STATIC mp_obj_t countio_counter_make_new(const mp_obj_type_t *type, size_t n_arg
5753 return MP_OBJ_FROM_PTR (self );
5854}
5955
60- //| .. method:: deinit()
61- //|
62- //| Deinitializes the Counter and releases any hardware resources for reuse.
56+ //| def deinit(self):
57+ //| """Deinitializes the Counter and releases any hardware resources for reuse."""
6358//|
6459STATIC mp_obj_t countio_counter_deinit (mp_obj_t self_in ) {
6560 countio_counter_obj_t * self = MP_OBJ_TO_PTR (self_in );
@@ -74,16 +69,14 @@ STATIC void check_for_deinit(countio_counter_obj_t *self) {
7469 }
7570}
7671
77- //| .. method:: __enter__()
78- //|
79- //| No-op used by Context Managers.
72+ //| def __enter__(self):
73+ //| """No-op used by Context Managers."""
8074//|
8175// Provided by context manager helper.
8276
83- //| .. method:: __exit__()
84- //|
85- //| Automatically deinitializes the hardware when exiting a context. See
86- //| :ref:`lifetime-and-contextmanagers` for more info.
77+ //| def __exit__(self):
78+ //| """Automatically deinitializes the hardware when exiting a context. See
79+ //| :ref:`lifetime-and-contextmanagers` for more info."""
8780//|
8881STATIC mp_obj_t countio_counter_obj___exit__ (size_t n_args , const mp_obj_t * args ) {
8982 (void )n_args ;
@@ -93,10 +86,8 @@ STATIC mp_obj_t countio_counter_obj___exit__(size_t n_args, const mp_obj_t *args
9386STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (countio_counter___exit___obj , 4 , 4 , countio_counter_obj___exit__ );
9487
9588
96- //| .. attribute:: count
97- //|
98- //| The current count in terms of pulses.
99- //|
89+ //| count: int = ...
90+ //| """The current count in terms of pulses."""
10091//|
10192STATIC mp_obj_t countio_counter_obj_get_count (mp_obj_t self_in ) {
10293 countio_counter_obj_t * self = MP_OBJ_TO_PTR (self_in );
@@ -122,14 +113,17 @@ const mp_obj_property_t countio_counter_count_obj = {
122113 (mp_obj_t )& mp_const_none_obj },
123114};
124115
116+ //| def reset(self):
117+ //| """Resets the count back to 0."""
118+ //|
125119STATIC mp_obj_t countio_counter_reset (mp_obj_t self_in ){
126120 countio_counter_obj_t * self = MP_OBJ_TO_PTR (self_in );
127121 check_for_deinit (self );
128122 //set the position to zero for reset
129123 common_hal_countio_counter_reset (self );
130124 return mp_const_none ;
131125}
132-
126+
133127
134128MP_DEFINE_CONST_FUN_OBJ_1 (countio_counter_reset_obj , countio_counter_reset );
135129
0 commit comments