Skip to content

Commit c4ce631

Browse files
authored
Update docu with uint16_t as void * (#56)
* Update docu with uint16_t as void * This trips up experienced programmers let alone beginners!
1 parent 26106b8 commit c4ce631

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

mongoose-os/api/core/mgos_timers.h.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ mgos_timer_id mgos_set_timer(int msecs, int flags, timer_callback cb,
6363
> However, number of software timers is not limited.
6464
> If you need intervals < 10ms, use mgos_set_hw_timer.
6565
>
66-
> Example:
66+
> Basic example:
6767
> ```c
6868
> static void my_timer_cb(void *arg) {
6969
> bool val = mgos_gpio_toggle(mgos_sys_config_get_pins_led());
@@ -76,6 +76,19 @@ mgos_timer_id mgos_set_timer(int msecs, int flags, timer_callback cb,
7676
> return MGOS_APP_INIT_SUCCESS;
7777
> }
7878
> ```
79+
> Example passing unsigned int as an argument to void *
80+
> ```c
81+
> static void my_timer_cb(void *arg) {
82+
> uint16_t conn_id = (uintptr_t) arg;
83+
> LOG(LL_INFO, ("my_timer_cb value: %u", conn_id));
84+
> }
85+
>
86+
> enum mgos_app_init_result mgos_app_init(void) {
87+
> uint16_t conn_id = 99;
88+
> mgos_set_timer(15000, 0, my_timer_cb, (void *) (uintptr_t) conn_id);
89+
> return MGOS_APP_INIT_SUCCESS;
90+
> }
91+
> ```
7992
>
8093
#### mgos_set_hw_timer
8194

0 commit comments

Comments
 (0)