diff --git a/examples/companion_radio/ui-new/UITask.h b/examples/companion_radio/ui-new/UITask.h index bc12c679..5a087eeb 100644 --- a/examples/companion_radio/ui-new/UITask.h +++ b/examples/companion_radio/ui-new/UITask.h @@ -12,7 +12,7 @@ #include #endif #ifdef PIN_VIBRATION - #include + #include #endif #include "../AbstractUITask.h" @@ -25,7 +25,7 @@ class UITask : public AbstractUITask { genericBuzzer buzzer; #endif #ifdef PIN_VIBRATION - genericVibration vibration; + GenericVibration vibration; #endif unsigned long _next_refresh, _auto_off; NodePrefs* _node_prefs; diff --git a/src/helpers/ui/GenericVibration.cpp b/src/helpers/ui/GenericVibration.cpp new file mode 100644 index 00000000..9226b812 --- /dev/null +++ b/src/helpers/ui/GenericVibration.cpp @@ -0,0 +1,38 @@ +#ifdef PIN_VIBRATION +#include "GenericVibration.h" + +void GenericVibration::begin() { + pinMode(PIN_VIBRATION, OUTPUT); + digitalWrite(PIN_VIBRATION, LOW); + duration = 0; +} + +void GenericVibration::trigger() { + duration = millis(); + digitalWrite(PIN_VIBRATION, HIGH); +} + +void GenericVibration::loop() { + if (isVibrating()) { + if ((millis() / 1000) % 2 == 0) { + digitalWrite(PIN_VIBRATION, LOW); + } else { + digitalWrite(PIN_VIBRATION, HIGH); + } + + if (millis() - duration > VIBRATION_TIMEOUT) { + stop(); + } + } +} + +bool GenericVibration::isVibrating() { + return duration > 0; +} + +void GenericVibration::stop() { + duration = 0; + digitalWrite(PIN_VIBRATION, LOW); +} + +#endif // ifdef PIN_VIBRATION diff --git a/src/helpers/ui/GenericVibration.h b/src/helpers/ui/GenericVibration.h new file mode 100644 index 00000000..38755bd8 --- /dev/null +++ b/src/helpers/ui/GenericVibration.h @@ -0,0 +1,33 @@ +#pragma once + +#ifdef PIN_VIBRATION + +#include + +/* + * Vibration motor control class + * + * Provides vibration feedback for events like new messages and new contacts + * Features: + * - 1-second vibration pulse + * - 5-second nag timeout (cooldown between vibrations) + * - Non-blocking operation + */ + +#ifndef VIBRATION_TIMEOUT +#define VIBRATION_TIMEOUT 5000 // 5 seconds default +#endif + +class GenericVibration { +public: + void begin(); // set up vibration pin + void trigger(); // trigger vibration if cooldown has passed + void loop(); // non-blocking timer handling + bool isVibrating(); // returns true if currently vibrating + void stop(); // stop vibration immediately + +private: + unsigned long duration; +}; + +#endif // ifdef PIN_VIBRATION diff --git a/src/helpers/ui/vibration.cpp b/src/helpers/ui/vibration.cpp deleted file mode 100644 index 37db54ed..00000000 --- a/src/helpers/ui/vibration.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#ifdef PIN_VIBRATION -#include "vibration.h" - -void genericVibration::begin() -{ - pinMode(PIN_VIBRATION, OUTPUT); - digitalWrite(PIN_VIBRATION, LOW); - duration = 0; -} - -void genericVibration::trigger() -{ - duration = millis(); - digitalWrite(PIN_VIBRATION, HIGH); -} - -void genericVibration::loop() -{ - if (isVibrating()) { - if ((millis() / 1000) % 2 == 0) { - digitalWrite(PIN_VIBRATION, LOW); - } else { - digitalWrite(PIN_VIBRATION, HIGH); - } - - if (millis() - duration > VIBRATION_TIMEOUT) { - stop(); - } - } -} - -bool genericVibration::isVibrating() -{ - return duration > 0; -} - -void genericVibration::stop() -{ - duration = 0; - digitalWrite(PIN_VIBRATION, LOW); -} - -#endif // ifdef PIN_VIBRATION diff --git a/src/helpers/ui/vibration.h b/src/helpers/ui/vibration.h deleted file mode 100644 index 42cd0f67..00000000 --- a/src/helpers/ui/vibration.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#ifdef PIN_VIBRATION - -#include - -/* - * Vibration motor control class - * - * Provides vibration feedback for events like new messages and new contacts - * Features: - * - 1-second vibration pulse - * - 5-second nag timeout (cooldown between vibrations) - * - Non-blocking operation - */ - -#ifndef VIBRATION_TIMEOUT -#define VIBRATION_TIMEOUT 5000 // 5 seconds default -#endif - -class genericVibration -{ - public: - void begin(); // set up vibration pin - void trigger(); // trigger vibration if cooldown has passed - void loop(); // non-blocking timer handling - bool isVibrating(); // returns true if currently vibrating - void stop(); // stop vibration immediately - - private: - unsigned long duration; -}; - -#endif // ifdef PIN_VIBRATION