From d318322ae5259561029eaf13c9084d8298c727d2 Mon Sep 17 00:00:00 2001 From: Lewis Jackson <> Date: Fri, 2 Jun 2023 23:06:53 +0300 Subject: [PATCH] Little refactoring: Move vibration motor functionality into features --- src/WatchFeatures/VibrationMotor.cpp | 14 ++++++++++++++ src/WatchFeatures/VibrationMotor.h | 12 ++++++++++++ src/WatchFeatures/WatchFeatures.h | 2 ++ src/Watchy.cpp | 11 ----------- src/Watchy.h | 2 -- 5 files changed, 28 insertions(+), 13 deletions(-) create mode 100644 src/WatchFeatures/VibrationMotor.cpp create mode 100644 src/WatchFeatures/VibrationMotor.h diff --git a/src/WatchFeatures/VibrationMotor.cpp b/src/WatchFeatures/VibrationMotor.cpp new file mode 100644 index 0000000..24bc887 --- /dev/null +++ b/src/WatchFeatures/VibrationMotor.cpp @@ -0,0 +1,14 @@ +#include "VibrationMotor.h" +#include "config.h" +#include + +void WatchFeatures::VibrationMotor::Vibrate(uint8_t intervalMs, uint8_t length) +{ + pinMode(VIB_MOTOR_PIN, OUTPUT); + bool motorOn = false; + for (int i = 0; i < length; i++) { + motorOn = !motorOn; + digitalWrite(VIB_MOTOR_PIN, motorOn); + delay(intervalMs); + } +} \ No newline at end of file diff --git a/src/WatchFeatures/VibrationMotor.h b/src/WatchFeatures/VibrationMotor.h new file mode 100644 index 0000000..d14caa2 --- /dev/null +++ b/src/WatchFeatures/VibrationMotor.h @@ -0,0 +1,12 @@ +#pragma once + +#include + +namespace WatchFeatures +{ + class VibrationMotor + { + public: + void Vibrate(uint8_t intervalMs = 100, uint8_t length = 20); + }; +} \ No newline at end of file diff --git a/src/WatchFeatures/WatchFeatures.h b/src/WatchFeatures/WatchFeatures.h index e14b5c6..fc17289 100644 --- a/src/WatchFeatures/WatchFeatures.h +++ b/src/WatchFeatures/WatchFeatures.h @@ -5,6 +5,7 @@ #include "RTC.h" #include "Storage.h" #include "Wifi.h" +#include "VibrationMotor.h" namespace WatchFeatures { @@ -23,4 +24,5 @@ struct WatchFeatures::WatchFeatures RTC rtc; Storage storage; Wifi wifi; + VibrationMotor vibrationMotor; }; \ No newline at end of file diff --git a/src/Watchy.cpp b/src/Watchy.cpp index 8c3796b..a79fd78 100644 --- a/src/Watchy.cpp +++ b/src/Watchy.cpp @@ -101,17 +101,6 @@ void Watchy::DisplayBusyCallback(const void *) esp_light_sleep_start(); } -void Watchy::VibeMotor(uint8_t intervalMs, uint8_t length) -{ - pinMode(VIB_MOTOR_PIN, OUTPUT); - bool motorOn = false; - for (int i = 0; i < length; i++) { - motorOn = !motorOn; - digitalWrite(VIB_MOTOR_PIN, motorOn); - delay(intervalMs); - } -} - void Watchy::SyncNTPTime() { WiFiUDP ntpUDP; diff --git a/src/Watchy.h b/src/Watchy.h index 59137d1..2a9b29d 100644 --- a/src/Watchy.h +++ b/src/Watchy.h @@ -14,8 +14,6 @@ public: Watchy(); void Wake(); void DeepSleep(); - void VibeMotor(uint8_t intervalMs = 100, uint8_t length = 20); - float GetBatteryVoltage(); void ConnectWiFi(); void SyncNTPTime(); void DisconnectWiFi();