forked from airgradienthq/arduino
Complete rewrite of the library with modular structure.
This commit is contained in:
1 parent
d0e9d729a5
commit
990f2482bb
278 files changed
+54881
-5058
No files matched your search
@@ -0,0 +1,178 @@
|
||||
#include "oled.h"
|
||||
#include "../library/Adafruit_SH110x/Adafruit_SH110X.h"
|
||||
#include "../library/Adafruit_SSD1306_Wemos_OLED/Adafruit_SSD1306.h"
|
||||
|
||||
#define disp(func) \
|
||||
if (this->_boardType == BOARD_DIY_BASIC_KIT) { \
|
||||
((Adafruit_SSD1306 *)(this->oled))->func; \
|
||||
} else { \
|
||||
((Adafruit_SH110X *)(this->oled))->func; \
|
||||
}
|
||||
|
||||
#if defined(ESP8266)
|
||||
void Display::begin(TwoWire &wire, Stream &debugStream) {
|
||||
this->_debugStream = &debugStream;
|
||||
this->begin(wire);
|
||||
}
|
||||
#else
|
||||
#endif
|
||||
|
||||
Display::Display(BoardType type) : _boardType(type) {}
|
||||
|
||||
void Display::begin(TwoWire &wire) {
|
||||
this->_bsp = getBoardDef(this->_boardType);
|
||||
if ((this->_bsp == nullptr) || (this->_bsp->I2C.supported == false) ||
|
||||
(this->_bsp->OLED.supported == false)) {
|
||||
AgLog("Init failed: board not supported");
|
||||
return;
|
||||
}
|
||||
|
||||
/** Init OLED */
|
||||
if (this->_boardType == BOARD_DIY_BASIC_KIT) {
|
||||
AgLog("Init Adafruit_SSD1306");
|
||||
Adafruit_SSD1306 *_oled = new Adafruit_SSD1306();
|
||||
_oled->begin(wire, SSD1306_SWITCHCAPVCC, this->_bsp->OLED.addr);
|
||||
this->oled = _oled;
|
||||
} else {
|
||||
AgLog("Init Adafruit_SH1106G");
|
||||
Adafruit_SH1106G *_oled = new Adafruit_SH1106G(this->_bsp->OLED.width, this->_bsp->OLED.height, &wire);
|
||||
_oled->begin(this->_bsp->OLED.addr, false);
|
||||
this->oled = _oled;
|
||||
}
|
||||
|
||||
this->_isInit = true;
|
||||
disp(clearDisplay());
|
||||
AgLog("Init");
|
||||
}
|
||||
|
||||
void Display::clear(void) {
|
||||
if (this->checkInit() == false) {
|
||||
return;
|
||||
}
|
||||
disp(clearDisplay());
|
||||
}
|
||||
|
||||
void Display::invertDisplay(uint8_t i) {
|
||||
if (this->checkInit() == false) {
|
||||
return;
|
||||
}
|
||||
disp(invertDisplay(i));
|
||||
}
|
||||
|
||||
void Display::show() {
|
||||
if (this->checkInit() == false) {
|
||||
return;
|
||||
}
|
||||
disp(display());
|
||||
}
|
||||
|
||||
void Display::setContrast(uint8_t value) {
|
||||
if (this->checkInit() == false) {
|
||||
return;
|
||||
}
|
||||
disp(setContrast(value));
|
||||
}
|
||||
|
||||
void Display::drawPixel(int16_t x, int16_t y, uint16_t color) {
|
||||
if (this->checkInit() == false) {
|
||||
return;
|
||||
}
|
||||
disp(drawPixel(x, y, color));
|
||||
}
|
||||
|
||||
void Display::setTextSize(int size) {
|
||||
if (this->checkInit() == false) {
|
||||
return;
|
||||
}
|
||||
disp(setTextSize(size));
|
||||
}
|
||||
|
||||
void Display::setCursor(int16_t x, int16_t y) {
|
||||
if (this->checkInit() == false) {
|
||||
return;
|
||||
}
|
||||
disp(setCursor(x, y));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set Text Color
|
||||
*
|
||||
* @param color 0:black, 1: While
|
||||
*/
|
||||
void Display::setTextColor(uint16_t color) {
|
||||
if (this->checkInit() == false) {
|
||||
return;
|
||||
}
|
||||
disp(setTextColor(color));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set text foreground color and background color
|
||||
*
|
||||
* @param foreGroundColor Text Color (foreground color)
|
||||
* @param backGroundColor Text background color
|
||||
*/
|
||||
void Display::setTextColor(uint16_t foreGroundColor, uint16_t backGroundColor) {
|
||||
if (this->checkInit() == false) {
|
||||
return;
|
||||
}
|
||||
disp(setTextColor(foreGroundColor, backGroundColor));
|
||||
}
|
||||
|
||||
void Display::setText(String text) {
|
||||
if (this->checkInit() == false) {
|
||||
return;
|
||||
}
|
||||
disp(print(text));
|
||||
}
|
||||
|
||||
void Display::drawBitmap(int16_t x, int16_t y, const uint8_t bitmap[],
|
||||
int16_t w, int16_t h, uint16_t color) {
|
||||
if (this->checkInit() == false) {
|
||||
return;
|
||||
}
|
||||
disp(drawBitmap(x, y, bitmap, w, h, color));
|
||||
}
|
||||
|
||||
void Display::setText(const char text[]) {
|
||||
if (this->checkInit() == false) {
|
||||
return;
|
||||
}
|
||||
disp(print(text));
|
||||
}
|
||||
|
||||
void Display::drawLine(int x0, int y0, int x1, int y1, uint16_t color) {
|
||||
if (this->checkInit() == false) {
|
||||
return;
|
||||
}
|
||||
disp(drawLine(x0, y0, x1, y1, color));
|
||||
}
|
||||
|
||||
void Display::drawCircle(int x, int y, int r, uint16_t color) {
|
||||
if (this->checkInit() == false) {
|
||||
return;
|
||||
}
|
||||
disp(drawCircle(x, y, r, color));
|
||||
}
|
||||
|
||||
void Display::drawRect(int x0, int y0, int x1, int y1, uint16_t color) {
|
||||
if (this->checkInit() == false) {
|
||||
return;
|
||||
}
|
||||
disp(drawRect(x0, y0, x1, y1, color));
|
||||
}
|
||||
|
||||
bool Display::checkInit(void) {
|
||||
if (this->_isInit) {
|
||||
return true;
|
||||
}
|
||||
AgLog("OLED is not init");
|
||||
return false;
|
||||
}
|
||||
|
||||
void Display::setRotation(uint8_t r) {
|
||||
if (checkInit() == false) {
|
||||
return;
|
||||
}
|
||||
disp(setRotation(r));
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
#ifndef _AIR_GRADIENT_OLED_H_
|
||||
#define _AIR_GRADIENT_OLED_H_
|
||||
|
||||
#include "../bsp/BoardDef.h"
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
|
||||
class Display {
|
||||
public:
|
||||
const uint16_t COLOR_WHILTE = 1;
|
||||
const uint16_t COLOR_BLACK = 0;
|
||||
#if defined(ESP8266)
|
||||
void begin(TwoWire &wire, Stream &debugStream);
|
||||
#else
|
||||
#endif
|
||||
Display(BoardType type);
|
||||
void begin(TwoWire &wire);
|
||||
|
||||
void clear(void); // .clear
|
||||
void invertDisplay(uint8_t i);
|
||||
void show(); // .show()
|
||||
|
||||
void setContrast(uint8_t value);
|
||||
void drawPixel(int16_t x, int16_t y, uint16_t color);
|
||||
void setTextSize(int size);
|
||||
void setCursor(int16_t x, int16_t y);
|
||||
void setTextColor(uint16_t color);
|
||||
void setTextColor(uint16_t foreGroundColor, uint16_t backGroundColor);
|
||||
void setText(String text);
|
||||
void setText(const char text[]);
|
||||
void drawBitmap(int16_t x, int16_t y, const uint8_t bitmap[], int16_t w,
|
||||
int16_t h, uint16_t color);
|
||||
void drawLine(int x0, int y0, int x1, int y1, uint16_t color);
|
||||
void drawCircle(int x, int y, int r, uint16_t color);
|
||||
void drawRect(int x0, int y0, int x1, int y1, uint16_t color);
|
||||
void setRotation(uint8_t r);
|
||||
|
||||
private:
|
||||
BoardType _boardType;
|
||||
const BoardDef *_bsp = nullptr;
|
||||
void *oled;
|
||||
bool _isInit = false;
|
||||
#if defined(ESP8266)
|
||||
const char *TAG = "oled";
|
||||
Stream *_debugStream = nullptr;
|
||||
#else
|
||||
|
||||
#endif
|
||||
bool checkInit(void);
|
||||
};
|
||||
|
||||
#endif /** _AIR_GRADIENT_OLED_H_ */
|
||||
Reference in new issue
Block a user