Little refactoring: Move vibration motor functionality into features
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				Compile / Compile (push) Successful in 1m22s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	Compile / Compile (push) Successful in 1m22s
				
			This commit is contained in:
		
							parent
							
								
									2d11d69067
								
							
						
					
					
						commit
						d318322ae5
					
				
					 5 changed files with 28 additions and 13 deletions
				
			
		
							
								
								
									
										14
									
								
								src/WatchFeatures/VibrationMotor.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								src/WatchFeatures/VibrationMotor.cpp
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,14 @@
 | 
				
			||||||
 | 
					#include "VibrationMotor.h"
 | 
				
			||||||
 | 
					#include "config.h"
 | 
				
			||||||
 | 
					#include <Wire.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										12
									
								
								src/WatchFeatures/VibrationMotor.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								src/WatchFeatures/VibrationMotor.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,12 @@
 | 
				
			||||||
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <stdint.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace WatchFeatures
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  class VibrationMotor
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					  public:
 | 
				
			||||||
 | 
					    void Vibrate(uint8_t intervalMs = 100, uint8_t length = 20);
 | 
				
			||||||
 | 
					  };
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -5,6 +5,7 @@
 | 
				
			||||||
#include "RTC.h"
 | 
					#include "RTC.h"
 | 
				
			||||||
#include "Storage.h"
 | 
					#include "Storage.h"
 | 
				
			||||||
#include "Wifi.h"
 | 
					#include "Wifi.h"
 | 
				
			||||||
 | 
					#include "VibrationMotor.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace WatchFeatures
 | 
					namespace WatchFeatures
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -23,4 +24,5 @@ struct WatchFeatures::WatchFeatures
 | 
				
			||||||
  RTC rtc;
 | 
					  RTC rtc;
 | 
				
			||||||
  Storage storage;
 | 
					  Storage storage;
 | 
				
			||||||
  Wifi wifi;
 | 
					  Wifi wifi;
 | 
				
			||||||
 | 
					  VibrationMotor vibrationMotor;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					@ -101,17 +101,6 @@ void Watchy::DisplayBusyCallback(const void *)
 | 
				
			||||||
  esp_light_sleep_start();
 | 
					  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()
 | 
					void Watchy::SyncNTPTime()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  WiFiUDP ntpUDP;
 | 
					  WiFiUDP ntpUDP;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -14,8 +14,6 @@ public:
 | 
				
			||||||
  Watchy();
 | 
					  Watchy();
 | 
				
			||||||
  void Wake();
 | 
					  void Wake();
 | 
				
			||||||
  void DeepSleep();
 | 
					  void DeepSleep();
 | 
				
			||||||
  void VibeMotor(uint8_t intervalMs = 100, uint8_t length = 20);
 | 
					 | 
				
			||||||
  float GetBatteryVoltage();
 | 
					 | 
				
			||||||
  void ConnectWiFi();
 | 
					  void ConnectWiFi();
 | 
				
			||||||
  void SyncNTPTime();
 | 
					  void SyncNTPTime();
 | 
				
			||||||
  void DisconnectWiFi();
 | 
					  void DisconnectWiFi();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue