File tree Expand file tree Collapse file tree 5 files changed +73
-79
lines changed
examples/companion_radio/ui-new Expand file tree Collapse file tree 5 files changed +73
-79
lines changed Original file line number Diff line number Diff line change 1212 #include < helpers/ui/buzzer.h>
1313#endif
1414#ifdef PIN_VIBRATION
15- #include < helpers/ui/vibration .h>
15+ #include < helpers/ui/GenericVibration .h>
1616#endif
1717
1818#include " ../AbstractUITask.h"
@@ -25,7 +25,7 @@ class UITask : public AbstractUITask {
2525 genericBuzzer buzzer;
2626#endif
2727#ifdef PIN_VIBRATION
28- genericVibration vibration;
28+ GenericVibration vibration;
2929#endif
3030 unsigned long _next_refresh, _auto_off;
3131 NodePrefs* _node_prefs;
Original file line number Diff line number Diff line change 1+ #ifdef PIN_VIBRATION
2+ #include " GenericVibration.h"
3+
4+ void GenericVibration::begin () {
5+ pinMode (PIN_VIBRATION, OUTPUT);
6+ digitalWrite (PIN_VIBRATION, LOW);
7+ duration = 0 ;
8+ }
9+
10+ void GenericVibration::trigger () {
11+ duration = millis ();
12+ digitalWrite (PIN_VIBRATION, HIGH);
13+ }
14+
15+ void GenericVibration::loop () {
16+ if (isVibrating ()) {
17+ if ((millis () / 1000 ) % 2 == 0 ) {
18+ digitalWrite (PIN_VIBRATION, LOW);
19+ } else {
20+ digitalWrite (PIN_VIBRATION, HIGH);
21+ }
22+
23+ if (millis () - duration > VIBRATION_TIMEOUT) {
24+ stop ();
25+ }
26+ }
27+ }
28+
29+ bool GenericVibration::isVibrating () {
30+ return duration > 0 ;
31+ }
32+
33+ void GenericVibration::stop () {
34+ duration = 0 ;
35+ digitalWrite (PIN_VIBRATION, LOW);
36+ }
37+
38+ #endif // ifdef PIN_VIBRATION
Original file line number Diff line number Diff line change 1+ #pragma once
2+
3+ #ifdef PIN_VIBRATION
4+
5+ #include < Arduino.h>
6+
7+ /*
8+ * Vibration motor control class
9+ *
10+ * Provides vibration feedback for events like new messages and new contacts
11+ * Features:
12+ * - 1-second vibration pulse
13+ * - 5-second nag timeout (cooldown between vibrations)
14+ * - Non-blocking operation
15+ */
16+
17+ #ifndef VIBRATION_TIMEOUT
18+ #define VIBRATION_TIMEOUT 5000 // 5 seconds default
19+ #endif
20+
21+ class GenericVibration {
22+ public:
23+ void begin (); // set up vibration pin
24+ void trigger (); // trigger vibration if cooldown has passed
25+ void loop (); // non-blocking timer handling
26+ bool isVibrating (); // returns true if currently vibrating
27+ void stop (); // stop vibration immediately
28+
29+ private:
30+ unsigned long duration;
31+ };
32+
33+ #endif // ifdef PIN_VIBRATION
Load Diff This file was deleted.
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments