#define OLED_SDA GPIO_NUM_4
#define OLED_SCL GPIO_NUM_15
#define OLED_ADDR 0x3C
#define OLED_RESET GPIO_UNUSED
#define DS3231_ADDR 0x68
bool dateInvalid;
{
static char str[11];
return str;
}
{
int d, m, y;
if (sscanf(str, "%02d/%02d/%d", &d, &m, &y) == 3) {
return true;
}
return false;
}
{
static char str[9];
return str;
}
{
int h, m, s;
if (sscanf(str, "%02d:%02d:%02d", &h, &m, &s) == 3) {
return true;
}
return false;
}
void inputDateTime()
{
LineEditor.setInsertMode(false);
char const * dtstr;
do {
Terminal.
write(
"Enter Date:\r\n");
LineEditor.setText(encodeDate(dt), false);
dtstr = LineEditor.edit();
} while (!decodeDate(&dt, dtstr));
do {
Terminal.
write(
"\nEnter Time:\r\n");
LineEditor.setText(encodeTime(dt), false);
dtstr = LineEditor.edit();
} while (!decodeTime(&dt, dtstr));
}
{
double cx = 96;
double cy = 32;
double radius = 42;
double pointsRadius = radius * 0.76;
double secondsRadius = radius * 0.72;
double minutesRadius = radius * 0.60;
double hoursRadius = radius * 0.48;
double s = dt.
seconds / 60.0 * TWO_PI - HALF_PI;
double m = (dt.
minutes + dt.
seconds / 60.0) / 60.0 * TWO_PI - HALF_PI;
double h = (dt.
hours + dt.
minutes / 60.0) / 24.0 * TWO_PI * 2.0 - HALF_PI;
cv.setPenWidth(3);
cv.drawLine(cx, cy, cx + cos(h) * hoursRadius, cy + sin(h) * hoursRadius);
cv.setPenWidth(1);
cv.drawLine(cx, cy, cx + cos(s) * secondsRadius, cy + sin(s) * secondsRadius);
cv.drawLine(cx, cy, cx + cos(m) * minutesRadius, cy + sin(m) * minutesRadius);
for (int a = 0; a < 360; a += 6) {
double arad = radians(a);
double x = cx + cos(arad) * pointsRadius;
double y = cy + sin(arad) * pointsRadius;
cv.setPixel(x, y);
if ((a % 15) == 0) {
double x2 = cx + cos(arad) * (pointsRadius - 3);
double y2 = cy + sin(arad) * (pointsRadius - 3);
cv.drawLine(x, y, x2, y2);
}
}
}
void setup()
{
Serial.begin(115200); delay(500); Serial.write("\n\n\n");
PS2Controller.
begin(PS2Preset::KeyboardPort0);
I2C.begin(OLED_SDA, OLED_SCL);
DisplayController.
begin(&I2C, OLED_ADDR, OLED_RESET);
Serial.write("Error, SSD1306 not available!\n");
delay(5000);
}
Terminal.
begin(&DisplayController);
Canvas cv(&DisplayController);
cv.clear();
Serial.write("DS3231 not available!\n");
}
inputDateTime();
}
cv.clear();
}
void loop()
{
static const char * D2S[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
static const char * M2S[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
Canvas cv(&DisplayController);
cv.beginUpdate();
cv.clear();
cv.selectFont(&fabgl::FONT_std_15);
cv.drawTextFmt(13, 18,
"%d", dt.
year);
cv.selectFont(&fabgl::FONT_std_12);
cv.drawTextFmt(78, 44, "%s", encodeTime(dt));
cv.selectFont(&fabgl::FONT_std_17);
cv.setGlyphOptions(GlyphOptions().
Bold(
true));
cv.drawTextFmt(4, 44,
"%0.1f \xb0 C", DS3231.
temperature());
cv.resetGlyphOptions();
paintClock(cv, dt);
cv.endUpdate();
char c = Terminal.
read();
if (c == 0x0d) {
inputDateTime();
}
}
delay(1000);
}
double temperature()
Forces DS3231 to read current temperature.
bool available()
Determines if DS3231 is reachable.
bool setDateTime(DateTime const &value)
Sets current date and time.
DateTime const & datetime()
Queries DS3231 for current date and time.
bool dateTimeValid()
Determines the validity of datetime.
void begin(I2C *i2c)
Initializes DS3231 driver.
DS3231 Real Time Clock driver.
I2C class allows multiple tasks to communicate with I2C devices, serializing read/write jobs.
bool isKeyboardAvailable()
Checks if keyboard has been detected and correctly initialized.
LineEditor is a single-line / multiple-rows editor which uses the Terminal object as input and output...
static Keyboard * keyboard()
Returns the instance of Keyboard object automatically created by PS2Controller.
static void begin(gpio_num_t port0_clkGPIO, gpio_num_t port0_datGPIO, gpio_num_t port1_clkGPIO=GPIO_UNUSED, gpio_num_t port1_datGPIO=GPIO_UNUSED)
Initializes PS2 device controller.
The PS2 device controller class.
void setResolution(char const *modeline, int viewPortWidth=-1, int viewPortHeight=-1, bool doubleBuffered=false)
Sets SSD1306 resolution and viewport size.
bool available()
Checks the SSD1306 device availability.
void begin(I2C *i2c, int address=0x3C, gpio_num_t resetGPIO=GPIO_UNUSED)
Initializes SSD1306 assigning I2C bus, reset pin and address.
Display driver for SSD1306 based OLED display, with I2C connection.
void connectLocally()
Permits using of terminal locally.
void clear(bool moveCursor=true)
Clears the screen.
int available()
Gets the number of codes available in the keyboard queue.
void loadFont(FontInfo const *font)
Sets the font to use.
size_t write(const uint8_t *buffer, size_t size)
Sends specified number of codes to the display.
int read()
Reads codes from keyboard.
void enableCursor(bool value)
Enables or disables cursor.
bool begin(BaseDisplayController *displayController, int maxColumns=-1, int maxRows=-1, Keyboard *keyboard=nullptr)
Initializes the terminal.
An ANSI-VT100 compatible display terminal.
GlyphOptions & Bold(bool value)
Helper method to set or reset bold.
This file is the all in one include file. Application can just include this file to use FabGL library...
Represents date and time.