Adding a bunch of classes
This commit is contained in:
parent
518a53de6b
commit
cc15cf3366
File diff suppressed because it is too large
Load Diff
59
src/app/PinMapping.cpp
Normal file
59
src/app/PinMapping.cpp
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
#include "PinMapping.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper class to define the pin mapping
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Default pin mapping
|
||||||
|
PinMapping::PinMapping() :
|
||||||
|
_I2C_sda(GPIO_4_SDA),
|
||||||
|
_I2C_scl(GPIO_5_SCL),
|
||||||
|
_SPI_mosi(GPIO_13_MOSI),
|
||||||
|
_SPI_miso(GPIO_12_MISO),
|
||||||
|
_SPI_clk(GPIO_14_CLK),
|
||||||
|
_SPI_sdCard_cs(GPIO_2)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//Custom pin mapping
|
||||||
|
PinMapping::PinMapping(const Pin I2C_sda, const Pin I2C_scl, const Pin SPI_mosi, const Pin SPI_miso, const Pin SPI_clk, const Pin SPI_sdCard_cs) :
|
||||||
|
_I2C_sda(I2C_sda == DEFAULT_PIN ? GPIO_4_SDA : I2C_sda),
|
||||||
|
_I2C_scl(I2C_scl == DEFAULT_PIN ? GPIO_5_SCL : I2C_scl),
|
||||||
|
_SPI_mosi(SPI_mosi == DEFAULT_PIN ? GPIO_13_MOSI : SPI_mosi),
|
||||||
|
_SPI_miso(SPI_miso == DEFAULT_PIN ? GPIO_12_MISO : SPI_miso),
|
||||||
|
_SPI_clk(SPI_clk == DEFAULT_PIN ? GPIO_14_CLK : SPI_clk),
|
||||||
|
_SPI_sdCard_cs(SPI_sdCard_cs == DEFAULT_PIN ? GPIO_2 : SPI_sdCard_cs)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//Accessors
|
||||||
|
Pin PinMapping::getI2C_sda() const
|
||||||
|
{
|
||||||
|
return _I2C_sda;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pin PinMapping::getI2C_scl() const
|
||||||
|
{
|
||||||
|
return _I2C_scl;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pin PinMapping::getSPI_mosi() const
|
||||||
|
{
|
||||||
|
return _SPI_mosi;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pin PinMapping::getSPI_miso() const
|
||||||
|
{
|
||||||
|
return _SPI_miso;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pin PinMapping::getSPI_clk() const
|
||||||
|
{
|
||||||
|
return _SPI_clk;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pin PinMapping::getSPI_sdCard_cs() const
|
||||||
|
{
|
||||||
|
return _SPI_sdCard_cs;
|
||||||
|
}
|
||||||
|
|
27
src/app/PinMapping.h
Normal file
27
src/app/PinMapping.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#ifndef PINMAPPING_H
|
||||||
|
#define PINMAPPING_H
|
||||||
|
#include "definition.h"
|
||||||
|
|
||||||
|
class PinMapping
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PinMapping();
|
||||||
|
PinMapping(const Pin I2C_sda, const Pin I2C_scl, const Pin SPI_mosi, const Pin SPI_miso, const Pin SPI_clk, const Pin SPI_sdCard_cs);
|
||||||
|
|
||||||
|
Pin getI2C_sda() const;
|
||||||
|
Pin getI2C_scl() const;
|
||||||
|
|
||||||
|
Pin getSPI_mosi() const;
|
||||||
|
Pin getSPI_miso() const;
|
||||||
|
Pin getSPI_clk() const;
|
||||||
|
Pin getSPI_sdCard_cs() const;
|
||||||
|
private:
|
||||||
|
const Pin _I2C_sda;
|
||||||
|
const Pin _I2C_scl;
|
||||||
|
const Pin _SPI_mosi;
|
||||||
|
const Pin _SPI_miso;
|
||||||
|
const Pin _SPI_clk;
|
||||||
|
const Pin _SPI_sdCard_cs;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //PINMAPPING_H
|
33
src/app/RtcManager.cpp
Normal file
33
src/app/RtcManager.cpp
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#include "RtcManager.h"
|
||||||
|
|
||||||
|
RtcManager::RtcManager(const RTC_DS3231 &rtc) : _rtcRef(rtc)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
DateTime RtcManager::getDateTime() const
|
||||||
|
{
|
||||||
|
return _rtcRef.now();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RtcManager::setDate(const DateTime dateTime)
|
||||||
|
{
|
||||||
|
DateTime timePart = _rtcRef.now();
|
||||||
|
_rtcRef.adjust(DateTime(dateTime.year(), dateTime.month(), dateTime.day(), timePart.hour(), timePart.minute(), timePart.second()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void RtcManager::setTime(const DateTime dateTime)
|
||||||
|
{
|
||||||
|
DateTime datePart = _rtcRef.now();
|
||||||
|
_rtcRef.adjust(DateTime(datePart.year(), datePart.month(), datePart.day(), dateTime.hour(), dateTime.minute(), dateTime.second()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void RtcManager::setDateTime(const DateTime dateTime)
|
||||||
|
{
|
||||||
|
_rtcRef.adjust(dateTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean RtcManager::hasLostPower() const
|
||||||
|
{
|
||||||
|
return _rtcRef.lostPower();
|
||||||
|
}
|
||||||
|
|
20
src/app/RtcManager.h
Normal file
20
src/app/RtcManager.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#ifndef RTCMANAGER_H
|
||||||
|
#define RTCMANAGER_H
|
||||||
|
#include <RTClib.h>
|
||||||
|
|
||||||
|
class RtcManager
|
||||||
|
{
|
||||||
|
friend class SAB;
|
||||||
|
public:
|
||||||
|
DateTime getDateTime() const;
|
||||||
|
void setDate(const DateTime dateTime);
|
||||||
|
void setTime(const DateTime dateTime);
|
||||||
|
void setDateTime(const DateTime dateTime);
|
||||||
|
boolean hasLostPower() const;
|
||||||
|
protected:
|
||||||
|
RtcManager(const RTC_DS3231 &rtc);
|
||||||
|
private:
|
||||||
|
const RTC_DS3231 &_rtcRef;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //RTCMANAGER_H
|
49
src/app/SAB.cpp
Normal file
49
src/app/SAB.cpp
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#include "SAB.h"
|
||||||
|
|
||||||
|
SAB::SAB() : _screenConfig(128, 64, 0x3C), _display(_screenConfig.getWidth(), _screenConfig.getHeight(), &Wire), _screenManager(_display), _rtc(), _rtcManager(_rtc), _error(0)
|
||||||
|
{
|
||||||
|
Serial.begin(9600);
|
||||||
|
delay(200);
|
||||||
|
|
||||||
|
//We initialize the pins for the I2C communication
|
||||||
|
Wire.begin(_pinConfig.getI2C_sda(), _pinConfig.getI2C_scl());
|
||||||
|
if(!_rtc.begin()) _error |= RTC_BEGIN_ERR;
|
||||||
|
if(!_display.begin(SSD1306_SWITCHCAPVCC, _screenConfig.getAddress())) _error |= DISP_BEGIN_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
SAB::SAB(const PinMapping pinConfig, const ScreenConfig screenConfig) : _pinConfig(pinConfig), _screenConfig(screenConfig), _display(_screenConfig.getWidth(), _screenConfig.getHeight(), &Wire), _screenManager(_display), _rtc(), _rtcManager(_rtc), _error(0)
|
||||||
|
{
|
||||||
|
Serial.begin(9600);
|
||||||
|
delay(200);
|
||||||
|
|
||||||
|
//We initialize the pins for the I2C communication
|
||||||
|
Wire.begin(_pinConfig.getI2C_sda(), _pinConfig.getI2C_scl());
|
||||||
|
if(!_rtc.begin()) _error |= RTC_BEGIN_ERR;
|
||||||
|
if(!_display.begin(SSD1306_SWITCHCAPVCC, _screenConfig.getAddress())) _error |= DISP_BEGIN_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
ScreenManager& SAB::getScreenManager()
|
||||||
|
{
|
||||||
|
return _screenManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
const RtcManager& SAB::getRtcManager() const
|
||||||
|
{
|
||||||
|
return _rtcManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
ScreenConfig SAB::getScreenConfig() const
|
||||||
|
{
|
||||||
|
return _screenConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
PinMapping SAB::getPinConfig() const
|
||||||
|
{
|
||||||
|
return _pinConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char SAB::getError() const
|
||||||
|
{
|
||||||
|
return _error;
|
||||||
|
}
|
||||||
|
|
34
src/app/SAB.h
Normal file
34
src/app/SAB.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#ifndef SAB_H
|
||||||
|
#define SAB_H
|
||||||
|
#include "PinMapping.h"
|
||||||
|
#include "ScreenConfig.h"
|
||||||
|
#include "RtcManager.h"
|
||||||
|
#include "ScreenManager.h"
|
||||||
|
#include <Adafruit_SSD1306.h>
|
||||||
|
#include <RTClib.h>
|
||||||
|
|
||||||
|
class SAB
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SAB();
|
||||||
|
SAB(const PinMapping pinConfig, const ScreenConfig screenConfig);
|
||||||
|
|
||||||
|
ScreenManager& getScreenManager();
|
||||||
|
const RtcManager& getRtcManager() const;
|
||||||
|
ScreenConfig getScreenConfig() const;
|
||||||
|
PinMapping getPinConfig() const;
|
||||||
|
|
||||||
|
unsigned char getError() const;
|
||||||
|
private:
|
||||||
|
const PinMapping _pinConfig;
|
||||||
|
const ScreenConfig _screenConfig;
|
||||||
|
|
||||||
|
Adafruit_SSD1306 _display;
|
||||||
|
ScreenManager _screenManager;
|
||||||
|
const RTC_DS3231 _rtc;
|
||||||
|
const RtcManager _rtcManager;
|
||||||
|
|
||||||
|
unsigned char _error;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //SAB_H
|
24
src/app/ScreenConfig.cpp
Normal file
24
src/app/ScreenConfig.cpp
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#include "ScreenConfig.h"
|
||||||
|
|
||||||
|
ScreenConfig::ScreenConfig(const unsigned char width, const unsigned char height, const unsigned char address) :
|
||||||
|
_width(width),
|
||||||
|
_height(height),
|
||||||
|
_address(address)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char ScreenConfig::getWidth() const
|
||||||
|
{
|
||||||
|
return _width;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char ScreenConfig::getHeight() const
|
||||||
|
{
|
||||||
|
return _height;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char ScreenConfig::getAddress() const
|
||||||
|
{
|
||||||
|
return _address;
|
||||||
|
}
|
||||||
|
|
17
src/app/ScreenConfig.h
Normal file
17
src/app/ScreenConfig.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#ifndef SCREENCONFIG_H
|
||||||
|
#define SCREENCONFIG_H
|
||||||
|
|
||||||
|
class ScreenConfig
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ScreenConfig(const unsigned char width, const unsigned char height, const unsigned char address);
|
||||||
|
unsigned char getWidth() const;
|
||||||
|
unsigned char getHeight() const;
|
||||||
|
unsigned char getAddress() const;
|
||||||
|
private:
|
||||||
|
const unsigned char _width;
|
||||||
|
const unsigned char _height;
|
||||||
|
const unsigned char _address;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //SCREENCONFIG_H
|
56
src/app/ScreenManager.cpp
Normal file
56
src/app/ScreenManager.cpp
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#include "ScreenManager.h"
|
||||||
|
|
||||||
|
ScreenManager::ScreenManager(Adafruit_SSD1306 &display) : _displayRef(display)
|
||||||
|
{
|
||||||
|
_viewLinkedList = (ViewLinkedList) createEmptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean ScreenManager::addView(boolean (*viewLogicFunction)(Adafruit_SSD1306&, void*), void *pData, const unsigned char UID)
|
||||||
|
{
|
||||||
|
ViewLink viewLink ={viewLogicFunction, pData, UID, NULL};
|
||||||
|
addNewLinkAtTheEnd(&_viewLinkedList, viewLink);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *ScreenManager::createEmptyList()
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean ScreenManager::addNewLinkAtTheEnd(ViewLinkedList *viewLinkedList, ViewLink viewLink)
|
||||||
|
{
|
||||||
|
ViewLink *newViewLink = (ViewLink*) malloc(sizeof(ViewLink));
|
||||||
|
if(newViewLink == NULL)
|
||||||
|
{
|
||||||
|
_error |= MALLOC_ERR;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Because of the const member
|
||||||
|
memcpy(newViewLink, &viewLink, sizeof(*newViewLink));
|
||||||
|
|
||||||
|
/*TO DO*/
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean ScreenManager::isListEmpty(ViewLinkedList viewLinkedList)
|
||||||
|
{
|
||||||
|
return viewLinkedList == NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char ScreenManager::getError() const
|
||||||
|
{
|
||||||
|
return _error;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScreenManager::iterateThroughList()
|
||||||
|
{
|
||||||
|
Serial.println("Lets go through");
|
||||||
|
while(!isListEmpty(_viewLinkedList))
|
||||||
|
{
|
||||||
|
Serial.print("UID : ");Serial.println(_viewLinkedList->UID);
|
||||||
|
_viewLinkedList = _viewLinkedList->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
28
src/app/ScreenManager.h
Normal file
28
src/app/ScreenManager.h
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#ifndef SCREENMANAGER_H
|
||||||
|
#define SCREENMANAGER_H
|
||||||
|
#include "definition.h"
|
||||||
|
#include <Adafruit_SSD1306.h>
|
||||||
|
|
||||||
|
class ScreenManager
|
||||||
|
{
|
||||||
|
friend class SAB;
|
||||||
|
public:
|
||||||
|
boolean addView(boolean (*viewLogicFunction)(Adafruit_SSD1306&, void*), void *pData, const unsigned char UID);
|
||||||
|
unsigned char getError() const;
|
||||||
|
|
||||||
|
|
||||||
|
void iterateThroughList();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
ScreenManager(Adafruit_SSD1306 &display);
|
||||||
|
private:
|
||||||
|
void *createEmptyList();
|
||||||
|
boolean addNewLinkAtTheEnd(ViewLinkedList *viewLinkedList, ViewLink viewLink);
|
||||||
|
boolean isListEmpty(ViewLinkedList viewLinkedList);
|
||||||
|
|
||||||
|
Adafruit_SSD1306 &_displayRef;
|
||||||
|
ViewLinkedList _viewLinkedList;
|
||||||
|
unsigned char _error;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //SCREENMANAGER_H
|
@ -1,7 +1,21 @@
|
|||||||
|
#include "definition.h"
|
||||||
|
#include "PinMapping.h"
|
||||||
|
#include "SAB.h"
|
||||||
|
#include "views.h"
|
||||||
|
|
||||||
|
#define DEBUG
|
||||||
|
|
||||||
|
SAB sab;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// put your setup code here, to run once:
|
// put your setup code here, to run once:
|
||||||
|
Serial.println("Starting");
|
||||||
|
sab.getScreenManager().addView(&(view_1), NULL,9);
|
||||||
|
sab.getScreenManager().addView(&(view_1), NULL, 3);
|
||||||
|
sab.getScreenManager().addView(&(view_1), NULL, 6);
|
||||||
|
sab.getScreenManager().addView(&(view_1), NULL, 7);
|
||||||
|
sab.getScreenManager().iterateThroughList();
|
||||||
|
Serial.println("fin");
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
37
src/app/definition.h
Normal file
37
src/app/definition.h
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#ifndef DEFINITION_H
|
||||||
|
#define DEFINITION_H
|
||||||
|
|
||||||
|
#include <Adafruit_SSD1306.h>
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
enum Pin { GPIO_0 = 0,
|
||||||
|
GPIO_1_TX = 1,
|
||||||
|
GPIO_2 = 2,
|
||||||
|
GPIO_3_RX = 3,
|
||||||
|
GPIO_4_SDA = 4,
|
||||||
|
GPIO_5_SCL = 5,
|
||||||
|
GPIO_10 = 10,
|
||||||
|
GPIO_12_MISO = 12,
|
||||||
|
GPIO_13_MOSI = 13,
|
||||||
|
GPIO_14_CLK = 14,
|
||||||
|
GPIO_15 = 15,
|
||||||
|
GPIO_16 = 16,
|
||||||
|
ADC = A0,
|
||||||
|
DEFAULT_PIN = -1};
|
||||||
|
|
||||||
|
#define RTC_BEGIN_ERR B00000001
|
||||||
|
#define DISP_BEGIN_ERR B00000010
|
||||||
|
|
||||||
|
#define MALLOC_ERR B00000001
|
||||||
|
|
||||||
|
//Data structure for the view handling
|
||||||
|
typedef struct viewLink{
|
||||||
|
boolean (*viewLogicFunction)(Adafruit_SSD1306&, void*);
|
||||||
|
void *pData;
|
||||||
|
const unsigned char UID;
|
||||||
|
|
||||||
|
viewLink *next;
|
||||||
|
} ViewLink, *ViewLinkedList;
|
||||||
|
|
||||||
|
|
||||||
|
#endif //DEFINITION_H
|
7
src/app/views.cpp
Normal file
7
src/app/views.cpp
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#include "views.h"
|
||||||
|
|
||||||
|
boolean view_1(Adafruit_SSD1306 &display, void *pData)
|
||||||
|
{
|
||||||
|
display.clearDisplay();
|
||||||
|
}
|
||||||
|
|
7
src/app/views.h
Normal file
7
src/app/views.h
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#ifndef VIEWS_H
|
||||||
|
#define VIEWS_H
|
||||||
|
#include <Adafruit_SSD1306.h>
|
||||||
|
|
||||||
|
boolean view_1(Adafruit_SSD1306 &display, void *pData);
|
||||||
|
|
||||||
|
#endif //VIEWS_H
|
Loading…
Reference in New Issue
Block a user