-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from aleemont1/alessandro
Alessandro
- Loading branch information
Showing
16 changed files
with
169 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef __ABSTRACT_BUTTON__ | ||
#define __ABSTRACT_BUTTON__ | ||
|
||
class AbstractButton { | ||
|
||
public: | ||
AbstractButton(); | ||
virtual bool isPressed() = 0; | ||
|
||
virtual void sync(); | ||
long getLastSyncTime(); | ||
|
||
protected: | ||
void updateSyncTime(long time); | ||
|
||
private: | ||
long lastTimeSync; | ||
|
||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,18 @@ | ||
#ifndef __BUTTON__ | ||
#define __BUTTON__ | ||
|
||
constexpr bool BUTTON_PRESSED = true; | ||
constexpr bool BUTTON_RELEASED = false; | ||
#include "AbstractButton.h" | ||
|
||
/** | ||
* @class Button | ||
* @brief This class represents a button component. | ||
* | ||
* This class provides the basic functionalities of a button. | ||
* It should be inherited by specific button types. | ||
*/ | ||
class Button | ||
{ | ||
|
||
public: | ||
/** | ||
* @brief Default constructor for the Button class. | ||
* | ||
* @param pin The pin number where the button is connected. | ||
*/ | ||
Button(int pin); | ||
|
||
/** | ||
* @brief Check if the button is pressed. | ||
* | ||
* @return true if the button is pressed, false otherwise. | ||
*/ | ||
bool checkButtonPressStatus(); | ||
|
||
/** | ||
* @brief Check if the button is released. | ||
* | ||
* @return true if the button is released, false otherwise. | ||
*/ | ||
bool checkButtonReleaseStatus(); | ||
|
||
/** | ||
* @brief Synchronizes the button state with the actual physical button. | ||
*/ | ||
void updateButtonState(); | ||
|
||
/** | ||
* @brief Retrieves the last time the button state was synchronized. | ||
* | ||
* @return The last synchronization time. | ||
*/ | ||
long retrieveLastButtonSyncTime(); | ||
|
||
protected: | ||
/** | ||
* @brief Set the last synchronization time. | ||
* | ||
* @param time The new synchronization time. | ||
*/ | ||
void setLastButtonSyncTime(long time); | ||
class Button: public AbstractButton { | ||
|
||
public: | ||
Button(int pin); | ||
bool isPressed(); | ||
void sync(); | ||
|
||
private: | ||
/** | ||
* @brief The last time the button state was synchronized. | ||
*/ | ||
long lastTimeButtonWasInSync; | ||
|
||
/** | ||
* @brief The pin number where the button is connected. | ||
*/ | ||
int buttonPin; | ||
|
||
/** | ||
* @brief The current state of the button (true if pressed, false otherwise). | ||
*/ | ||
bool buttonState; | ||
int pin; | ||
bool pressed; | ||
}; | ||
|
||
#endif // __BUTTON__ | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef __SERVO_IMPL__ | ||
#define __SERVO_IMPL__ | ||
#include "Arduino.h" | ||
#include "ServoTimer2.h" | ||
|
||
class ServoImpl | ||
{ | ||
public: | ||
ServoImpl(int pin); | ||
|
||
void write(int angle); | ||
|
||
void detach(); | ||
|
||
private: | ||
ServoTimer2 servo; | ||
int pin; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include "../api/AbstractButton.h" | ||
|
||
AbstractButton::AbstractButton(){} | ||
|
||
void AbstractButton::updateSyncTime(long time) | ||
{ | ||
lastTimeSync = time; | ||
} | ||
|
||
long AbstractButton::getLastSyncTime() | ||
{ | ||
return lastTimeSync; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,20 @@ | ||
#include "../api/Button.h" | ||
#include "config/config.h" | ||
#include "Arduino.h" | ||
|
||
Button::Button(int pin) : buttonState(BUTTON_RELEASED) | ||
Button::Button(int pin) | ||
{ | ||
this->buttonPin = BUTTON_PIN; | ||
lastTimeButtonWasInSync = 0; | ||
this->pin = pin; | ||
pinMode(pin, INPUT); | ||
updateButtonState(); | ||
sync(); | ||
} | ||
|
||
bool Button::checkButtonPressStatus() | ||
bool Button::isPressed() | ||
{ | ||
return buttonState == BUTTON_PRESSED; | ||
return pressed; | ||
} | ||
|
||
bool Button::checkButtonReleaseStatus() | ||
void Button::sync() | ||
{ | ||
return buttonState == BUTTON_RELEASED; | ||
} | ||
|
||
void Button::updateButtonState() | ||
{ | ||
// If the button is pressed, the pin will be HIGH. | ||
buttonState = digitalRead(buttonPin) == HIGH ? BUTTON_PRESSED : BUTTON_RELEASED; | ||
// Update the last time the button state was synchronized. | ||
setLastButtonSyncTime(millis()); | ||
} | ||
|
||
void Button::setLastButtonSyncTime(long time) | ||
{ | ||
lastTimeButtonWasInSync = time; | ||
} | ||
|
||
long Button::retrieveLastButtonSyncTime() | ||
{ | ||
return lastTimeButtonWasInSync; | ||
pressed = digitalRead(pin) == HIGH; | ||
updateSyncTime(millis()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include "../api/ServoImpl.h" | ||
#include "Arduino.h" | ||
|
||
ServoImpl::ServoImpl(int pin) | ||
{ | ||
servo.attach(pin); | ||
} | ||
|
||
void ServoImpl::write(int angle) | ||
{ | ||
servo.write(map(angle, 0, 180, 750, 2250)); | ||
} | ||
|
||
void ServoImpl::detach() | ||
{ | ||
servo.detach(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// #include "ServoTestTask.h" | ||
|
||
// void ServoTestTask::tick() | ||
// { | ||
// Serial.println("ServoTestTask::tick()"); | ||
// switch (this->getState()) | ||
// { | ||
// case OPEN: | ||
// Serial.println("ServoTestTask::OPEN"); | ||
// this->servo.writeMicroseconds(1500); | ||
// this->setState(CLOSE); | ||
// break; | ||
// case CLOSE: | ||
// // if (this->elapsedTime() >= 1000) | ||
// { | ||
// Serial.println("ServoTestTask::CLOSE"); | ||
// this->servo.writeMicroseconds(0); | ||
// this->setState(OPEN); | ||
// } | ||
// break; | ||
// } | ||
// } |
Oops, something went wrong.