FreeCalypso > hg > fc-tourmaline
comparison src/cs/services/vibr/vibr_process.c @ 294:e17bdedfbf2b
VIBR SWE initial implementation
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 27 Mar 2022 08:46:10 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
293:2d7d95e7f9c2 | 294:e17bdedfbf2b |
---|---|
1 /* | |
2 * In this module we are going to implement the main process functions | |
3 * for VIBR. | |
4 */ | |
5 | |
6 #include "vibr/vibr_env.h" | |
7 #include "vibr/vibr_func_i.h" | |
8 #include "rv/rv_general.h" | |
9 #include "rvf/rvf_api.h" | |
10 #include "rvm/rvm_use_id_list.h" | |
11 #include "main/sys_types.h" | |
12 #include "buzzer/vibrator.h" | |
13 | |
14 /* duration of "on" and "off" phases of each vibration cycle */ | |
15 #define ON_PHASE_MS 500 | |
16 #define OFF_PHASE_MS 500 | |
17 | |
18 void vibr_process_start_req(struct vibr_start_msg *msg) | |
19 { | |
20 vibr_env->vibr_level = msg->vibr_level; | |
21 /* start the first pulse */ | |
22 HW_vibrator_on(vibr_env->vibr_level); | |
23 vibr_env->on_state = TRUE; | |
24 rvf_start_timer(VIBR_TIMER, RVF_MS_TO_TICKS(ON_PHASE_MS), FALSE); | |
25 if (msg->num_pulses) { | |
26 vibr_env->cont_mode = FALSE; | |
27 vibr_env->remain_cycles = msg->num_pulses; | |
28 } else | |
29 vibr_env->cont_mode = TRUE; | |
30 } | |
31 | |
32 void vibr_process_stop_req(struct vibr_stop_msg *msg) | |
33 { | |
34 HW_vibrator_off(); | |
35 rvf_stop_timer(VIBR_TIMER); | |
36 } | |
37 | |
38 static void on_phase_end(void) | |
39 { | |
40 HW_vibrator_off(); | |
41 /* got more pulses? */ | |
42 if (!vibr_env->cont_mode) { | |
43 vibr_env->remain_cycles--; | |
44 if (!vibr_env->remain_cycles) | |
45 return; /* pulse train finished */ | |
46 } | |
47 /* time the "off" phase before next pulse */ | |
48 vibr_env->on_state = FALSE; | |
49 rvf_start_timer(VIBR_TIMER, RVF_MS_TO_TICKS(OFF_PHASE_MS), FALSE); | |
50 } | |
51 | |
52 static void off_phase_end(void) | |
53 { | |
54 /* start the next pulse */ | |
55 HW_vibrator_on(vibr_env->vibr_level); | |
56 vibr_env->on_state = TRUE; | |
57 rvf_start_timer(VIBR_TIMER, RVF_MS_TO_TICKS(ON_PHASE_MS), FALSE); | |
58 } | |
59 | |
60 void vibr_handle_timer(void) | |
61 { | |
62 if (vibr_env->on_state) | |
63 on_phase_end(); | |
64 else | |
65 off_phase_end(); | |
66 } |