add switchableencodeur
This commit is contained in:
parent
2c4e09a564
commit
700994a65c
80
lib/SwitchableEncodeur/include/SwitchableEncodeur.h
Normal file
80
lib/SwitchableEncodeur/include/SwitchableEncodeur.h
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
#ifndef SWITCHABLEENCODEUR_H
|
||||||
|
#define SWITCHABLEENCODEUR_H
|
||||||
|
|
||||||
|
#include "Encoder.h"
|
||||||
|
|
||||||
|
class SwitchableEncodeur : public Encoder {
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Construct a new Switchable Encodeur object
|
||||||
|
*
|
||||||
|
* @param pin1 ENCODER_DT
|
||||||
|
* @param pin2 ENCODER_CLK
|
||||||
|
* @param pinSW ENCODER_SW
|
||||||
|
* @param nbMenu nombre D'état du system
|
||||||
|
*/
|
||||||
|
SwitchableEncodeur(uint8_t pin1, uint8_t pin2, uint8_t pinSW, int nbMenu = 0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief reset the menu
|
||||||
|
*/
|
||||||
|
void resetMenu();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief add one to the menu
|
||||||
|
*/
|
||||||
|
void addMenu();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the Menu number
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
int getMenu();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get return the encodeur value
|
||||||
|
*
|
||||||
|
* @return int dernière valeur de l'encodeur
|
||||||
|
*/
|
||||||
|
int getValue();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief update the encodeur value
|
||||||
|
*
|
||||||
|
* @return true the value has changed
|
||||||
|
* @return false the value has not changed
|
||||||
|
*/
|
||||||
|
bool update();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief reset the encodeur value
|
||||||
|
*/
|
||||||
|
void resetValue();
|
||||||
|
|
||||||
|
static SwitchableEncodeur* getInstance();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
static SwitchableEncodeur* instance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief menu actuel
|
||||||
|
*/
|
||||||
|
int menu;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief old position of the encoder
|
||||||
|
*/
|
||||||
|
int oldPosition = -999;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief nombre de menu
|
||||||
|
*/
|
||||||
|
int nbMenu;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
54
lib/SwitchableEncodeur/src/SwitchableEncodeur.cpp
Normal file
54
lib/SwitchableEncodeur/src/SwitchableEncodeur.cpp
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
#include "../include/SwitchableEncodeur.h"
|
||||||
|
|
||||||
|
IRAM_ATTR void switchEncoder() {
|
||||||
|
SwitchableEncodeur::getInstance()->addMenu();
|
||||||
|
}
|
||||||
|
|
||||||
|
SwitchableEncodeur* SwitchableEncodeur::instance = nullptr;
|
||||||
|
|
||||||
|
SwitchableEncodeur::SwitchableEncodeur(uint8_t pin1, uint8_t pin2, uint8_t pinSW, int nbMenu): Encoder(pin1, pin2){
|
||||||
|
SwitchableEncodeur::instance = this;
|
||||||
|
this->menu = 0;
|
||||||
|
this->nbMenu = nbMenu;
|
||||||
|
pinMode(pinSW, INPUT_PULLUP);
|
||||||
|
attachInterrupt(digitalPinToInterrupt(pinSW), switchEncoder, RISING);//FIXME: maybe change to FALLING
|
||||||
|
this->oldPosition = -999;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SwitchableEncodeur::resetMenu() {
|
||||||
|
this->menu = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwitchableEncodeur::addMenu() {
|
||||||
|
this->menu++;
|
||||||
|
if (this->menu > this->nbMenu) {
|
||||||
|
this->menu = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int SwitchableEncodeur::getMenu() {
|
||||||
|
return this->menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
SwitchableEncodeur* SwitchableEncodeur::getInstance() {
|
||||||
|
return SwitchableEncodeur::instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SwitchableEncodeur::update() {
|
||||||
|
bool sortie = false;
|
||||||
|
long newPosition = this->read()/4;
|
||||||
|
if (newPosition != this->oldPosition) {
|
||||||
|
this->oldPosition = newPosition;
|
||||||
|
sortie = true;
|
||||||
|
}
|
||||||
|
return sortie;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SwitchableEncodeur::getValue() {
|
||||||
|
return this->oldPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwitchableEncodeur::resetValue() {
|
||||||
|
this->oldPosition = 0;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user