Compare commits
3 Commits
58b8891d41
...
e66fd11e68
Author | SHA1 | Date | |
---|---|---|---|
|
e66fd11e68 | ||
|
281e07c30a | ||
|
e0bea5fae4 |
@ -104,7 +104,7 @@ boolean ConnectivityManager::isAPEnabled()
|
||||
unsigned char ConnectivityManager::RSSIPercent()
|
||||
{
|
||||
int RSSIdBm = RSSI();
|
||||
return COEF_RSSI * ((double)RSSIdBm - (double)MIN_RSSI);
|
||||
return (RSSIdBm < MIN_RSSI) ? 0 : COEF_RSSI * ((double)RSSIdBm - (double)MIN_RSSI);
|
||||
}
|
||||
|
||||
unsigned char ConnectivityManager::getError() const
|
||||
|
@ -7,9 +7,9 @@
|
||||
#include "CFGDictionary.h"
|
||||
#include "definition.h"
|
||||
|
||||
#define MIN_RSSI -81
|
||||
#define MIN_RSSI -90
|
||||
#define MAX_RSSI -50
|
||||
#define COEF_RSSI 3.225806452
|
||||
#define COEF_RSSI 2.5
|
||||
|
||||
#define STA_ENABLED_DISABLE_ERR B00001000
|
||||
#define AP_ENABLED_DISABLE_ERR B00000001
|
||||
|
58
src/app/EventHandler.cpp
Normal file
58
src/app/EventHandler.cpp
Normal file
@ -0,0 +1,58 @@
|
||||
#include "EventHandler.h"
|
||||
|
||||
EventHandler::EventHandler(uint8_t queueSize) : _maxQueueSize(queueSize)
|
||||
{
|
||||
//We set the various inputs needed
|
||||
pinMode(GPIO_0, INPUT);
|
||||
}
|
||||
|
||||
void EventHandler::run()
|
||||
{
|
||||
//FLASH_BUTTON PART
|
||||
if(!digitalRead(GPIO_0) && !_flashBtnPushed && millis() - _flashBtnDebounceTs > 200)
|
||||
{
|
||||
_flashBtnPushed = true;
|
||||
_flashBtnTs = millis();
|
||||
}
|
||||
|
||||
if(!digitalRead(GPIO_0) && _flashBtnPushed && millis() - _flashBtnTs > 500 && !_flashBtnLongPressFired)
|
||||
{
|
||||
_flashBtnLongPressFired = true;
|
||||
addEventCheckSizeLimit(FLASH_BUTTON_LONG_PRESS);
|
||||
}
|
||||
|
||||
if(digitalRead(GPIO_0) && _flashBtnPushed && millis() - _flashBtnTs < 500)
|
||||
{
|
||||
_flashBtnPushed = false;
|
||||
addEventCheckSizeLimit(FLASH_BUTTON_PRESS);
|
||||
_flashBtnDebounceTs = millis();
|
||||
}
|
||||
else if(digitalRead(GPIO_0) && _flashBtnPushed && _flashBtnLongPressFired)
|
||||
{
|
||||
_flashBtnPushed = false;
|
||||
_flashBtnLongPressFired = false;
|
||||
_flashBtnDebounceTs = millis();
|
||||
}
|
||||
//FLASH_BUTTON END PART
|
||||
}
|
||||
|
||||
EventHandler::Event EventHandler::getEvent()
|
||||
{
|
||||
if(_eventQueue.count() > 0)
|
||||
return _eventQueue.remove();
|
||||
|
||||
return NO_EVENT;
|
||||
}
|
||||
|
||||
void EventHandler::addEventCheckSizeLimit(Event e)
|
||||
{
|
||||
if(_eventQueue.count() < _maxQueueSize)
|
||||
{
|
||||
_eventQueue.add(e);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete _eventQueue.removeRef();
|
||||
_eventQueue.add(e);
|
||||
}
|
||||
}
|
28
src/app/EventHandler.h
Normal file
28
src/app/EventHandler.h
Normal file
@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Anatole SCHRAMM-HENRY
|
||||
* 27/04/2020 à 19:45
|
||||
* Tested, working
|
||||
*/
|
||||
#ifndef EVENTHANDLER_H
|
||||
#define EVENTHANDLER_H
|
||||
#include "definition.h"
|
||||
#include "Queue.h"
|
||||
|
||||
class EventHandler
|
||||
{
|
||||
public:
|
||||
enum Event {NO_EVENT = -1,FLASH_BUTTON_PRESS, FLASH_BUTTON_LONG_PRESS};
|
||||
EventHandler(uint8_t queueSize = 10);
|
||||
void run();
|
||||
Event getEvent();
|
||||
protected:
|
||||
private:
|
||||
void addEventCheckSizeLimit(Event e);
|
||||
|
||||
Queue<Event> _eventQueue;
|
||||
uint8_t _maxQueueSize;
|
||||
unsigned long _flashBtnTs = 0, _flashBtnDebounceTs = 0;
|
||||
boolean _flashBtnPushed = false, _flashBtnLongPressFired = false;
|
||||
};
|
||||
|
||||
#endif //EVENTHANDLER_H
|
@ -5,13 +5,15 @@
|
||||
#include "tasks.h"
|
||||
#include "CFGDictionary.h"
|
||||
#include "CFGParameterValue.h"
|
||||
#include "EventHandler.h"
|
||||
#define DEBUG
|
||||
|
||||
SAB sab;
|
||||
EventHandler evHan;
|
||||
EventHandler::Event evt;
|
||||
|
||||
unsigned long currentMs = 0, buttonDownMs(0), buttonUpMs(0);
|
||||
unsigned long currentMs = 0;
|
||||
volatile boolean ioStateChange(false);
|
||||
boolean buttonPushSampled(false);
|
||||
View1Packet v1p = {sab.getRtcManager().getDateTime(), sab.getSdCardManager().getSize(GBYTE), sab.getPowerManager().getPowerInfo(),0, sab.getSoftVersion(), &sab};
|
||||
ViewAPPacket vap = {sab.getConnectivityManager().softAPmacAddress(), sab.getConnectivityManager().softAPSSID(), sab.getConnectivityManager().softAPIP(), sab.getConnectivityManager().softAPgetStationNum(), sab.getConnectivityManager().isAPEnabled()};
|
||||
ViewSTAPacket vstap = {sab.getConnectivityManager().macAddress(), sab.getConnectivityManager().localIP(), sab.getConnectivityManager().RSSI(), sab.getConnectivityManager().isSTAEnabled()};
|
||||
@ -115,48 +117,26 @@ void loop()
|
||||
}
|
||||
}
|
||||
|
||||
/*if(digitalRead(GPIO_0) == 0 && millis() - buttonMs > 500)
|
||||
evt = evHan.getEvent();
|
||||
switch(evt)
|
||||
{
|
||||
buttonMs = millis();
|
||||
sab.getScreenManager().displayNextView();
|
||||
#ifdef DEBUG
|
||||
Serial.println("Changing view");
|
||||
Serial.print("Selected view is : ");Serial.println(sab.getScreenManager().getCurrentViewUID());
|
||||
#endif
|
||||
}*/
|
||||
|
||||
if(digitalRead(GPIO_0) == 0 && !buttonPushSampled)
|
||||
{
|
||||
buttonPushSampled = true;
|
||||
buttonDownMs = millis();
|
||||
}
|
||||
|
||||
if(digitalRead(GPIO_0) == 1 && buttonPushSampled)
|
||||
{
|
||||
buttonPushSampled = false;
|
||||
buttonUpMs = millis();
|
||||
|
||||
if(buttonUpMs - buttonDownMs < 700 && buttonUpMs - buttonDownMs > 200)//Short press
|
||||
{
|
||||
case EventHandler::Event::FLASH_BUTTON_PRESS:
|
||||
sab.getScreenManager().displayNextView();
|
||||
#ifdef DEBUG
|
||||
Serial.printf("Changing view\nSelected view is : %d\n",sab.getScreenManager().getCurrentViewUID());
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
case EventHandler::Event::FLASH_BUTTON_LONG_PRESS:
|
||||
sab.getScreenManager().displayPreviousView();
|
||||
#ifdef DEBUG
|
||||
Serial.printf("Changing view\nSelected view is : %d\n",sab.getScreenManager().getCurrentViewUID());
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
if(digitalRead(GPIO_0) == 0 && buttonPushSampled && millis() - buttonDownMs > 700)
|
||||
{
|
||||
buttonPushSampled = false;
|
||||
|
||||
sab.getScreenManager().displayPreviousView();
|
||||
#ifdef DEBUG
|
||||
Serial.printf("Changing view\nSelected view is : %d\n",sab.getScreenManager().getCurrentViewUID());
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//Run the different services
|
||||
sab.run();
|
||||
evHan.run();
|
||||
}
|
||||
|
||||
ICACHE_RAM_ATTR void ioISR()
|
||||
|
Loading…
Reference in New Issue
Block a user