#define OLED_SDA GPIO_NUM_4
#define OLED_SCL GPIO_NUM_15
#define OLED_ADDR 0x3C
#define OLED_RESET GPIO_UNUSED // ie Heltec has GPIO_NUM_16 for reset
#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);
}