Skip to content

Commit

Permalink
Release v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
erfansn committed Oct 23, 2021
1 parent c8c9313 commit b2a768b
Show file tree
Hide file tree
Showing 18 changed files with 404 additions and 0 deletions.
166 changes: 166 additions & 0 deletions ESTimer.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
#define INCLUDE_OLED 0

#include <ESTimer.h>
#if INCLUDE_OLED
#include "Fonts.h"
#endif

#define seconds(n) (n)
#define minutes(n) (n * seconds(60))

#define AWAKE_TIME min(minutes(25), minutes(99))
#define SLEEP_TIME min(minutes(5), AWAKE_TIME / 4)
#define LED_PIN 1

int previousAwakeTime = 0;
int previousSleepTime = 0;
uint8_t countDonePomodoros = 0;

volatile bool isCompletedRest = false;

void setup() {
initTimer();
startTimer();
}

void loop() {
while (ESTimer.onSleepMode()) {
// This part of the code runs only when Windows is on sleep mode
if (!isCompletedRest) {
#if INCLUDE_OLED
updateStatusPomodoros();
#endif
startCountdownTimer(false);

EEPROM.put(8, ++countDonePomodoros);
isCompletedRest = true;
}
flashLight();
}

// This part of the code runs only when Windows is ready
if (isCompletedRest) {
startTimer();
}
}

void initTimer() {
DDRB |= 0b10; // pinMode(LED_PIN, OUTPUT);

EEPROM.get(8, countDonePomodoros);

#if INCLUDE_OLED
splash();

initNumbers();
initStatusPomodoros();
#endif
}

void startTimer() {
PORTB &= 0b01; // digitalWrite(LED_PIN, LOW);

EEPROM.get(0, previousAwakeTime);
EEPROM.get(4, previousSleepTime);

if (previousSleepTime == 0) {
#if INCLUDE_OLED
updateStatusPomodoros();
#endif

if (!ESTimer.onSleepMode()) {
startCountdownTimer(true);
} else {
while (ESTimer.onSleepMode()) {
flashLight();
}
startTimer();
}
}

while (!ESTimer.onSleepMode()) {
ESTimer.goToSleepMode();
ESTimer.delay(100);
}
isCompletedRest = false;
}

void flashLight() {
PORTB |= 0b10; // digitalWrite(LED_PIN, HIGH);
delay(500);
PORTB &= 0b01; // digitalWrite(LED_PIN, LOW);
}

void startCountdownTimer(bool isAwake) {
int totalTime;
if (isAwake) {
totalTime = previousAwakeTime > 0 ? previousAwakeTime : AWAKE_TIME;
} else {
totalTime = previousSleepTime > 0 ? previousSleepTime : SLEEP_TIME * ((countDonePomodoros + 1) % 4 == 0 ? 4 : 1);
}

do {
#if INCLUDE_OLED
uint8_t m0 = (totalTime / 60) / 10;
uint8_t m1 = (totalTime / 60) % 10;
uint8_t s0 = (totalTime % 60) / 10;
uint8_t s1 = (totalTime % 60) % 10;

drawNumbers(m0, m1, s0, s1);
#endif

if (isAwake) {
EEPROM.put(0, totalTime);
} else {
EEPROM.put(4, totalTime);
ESTimer.goToSleepMode();
}

#if INCLUDE_OLED
ESTimer.delay(845);
#else
ESTimer.delay(1000);
#endif

} while (totalTime-- > 0);
}

#if INCLUDE_OLED
void drawNumbers(uint8_t m0, uint8_t m1, uint8_t s0, uint8_t s1) {
ESTimer.drawBitmap(65, 1, 100, 4, numbers[m0]);
ESTimer.drawBitmap(65, 4, 100, 7, numbers[m1]);
ESTimer.drawBitmap(28, 1, 63, 4, numbers[s0]);
ESTimer.drawBitmap(28, 4, 63, 7, numbers[s1]);
}

void initNumbers() {
uint8_t t = 0;
drawNumbers(t, t, t, t);
}

void splash() {
ESTimer.drawBitmap(46, 0, 82, 8, es_logo);
ESTimer.delay(3000);
ESTimer.clear();
}

void initStatusPomodoros() {
for (uint8_t i = 0; i < 16; i += 2) {
if (i < 8) {
ESTimer.drawBitmap(108, i, 124, i + 2, dots[(countDonePomodoros / 8) % 2]);
} else {
ESTimer.drawBitmap(4, i - 8, 20, (i - 8) + 2, dots[(countDonePomodoros / 8) % 2]);
}
}
}

void updateStatusPomodoros() {
for (uint8_t i = 0; i < ((countDonePomodoros % 8) + 1) * 2; i += 2) {
if (i < 8) {
ESTimer.drawBitmap(108, i, 124, i + 2, dots[((countDonePomodoros / 8) + 1) % 2]);
} else {
ESTimer.drawBitmap(4, i - 8, 20, (i - 8) + 2, dots[((countDonePomodoros / 8) + 1) % 2]);
}
}
}
#endif
140 changes: 140 additions & 0 deletions Fonts.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
#include <avr/pgmspace.h>

// bitmap to code -> https://javl.github.io/image2cpp/

const unsigned char es_logo[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0xc0, 0xe0, 0xe0, 0xf0, 0xf0, 0xf0, 0xf8,
0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf0, 0xf0, 0xf0, 0xe0, 0xe0, 0xc0, 0xc0, 0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xf8, 0xfe, 0xff, 0xff, 0xff, 0x3f, 0x0f, 0x0f,
0x07, 0x03, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x03, 0x07, 0x0f, 0x0f, 0x3f, 0xff,
0xff, 0xff, 0xfe, 0xf8, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
0xff, 0xff, 0x7f, 0x3f, 0x00, 0x80, 0xc0, 0x00, 0x00, 0x00, 0x00, 0xe7, 0xe7, 0xe7, 0xe7, 0xe7,
0xe7, 0xe0, 0xc0, 0xc0, 0x80, 0x80, 0x00, 0x00, 0x3f, 0x7f, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00,
0x00, 0x00, 0x0f, 0x87, 0xe1, 0xf0, 0xfc, 0xfe, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x1f, 0x1f, 0x3f, 0xff, 0xff, 0xfe, 0xfc, 0xf0, 0xe1,
0x87, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0x1f, 0x3f, 0x7f, 0xff,
0xff, 0xfc, 0xf0, 0xe0, 0xe0, 0xc0, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
0x00, 0xf0, 0xfc, 0xff, 0xff, 0xff, 0x7f, 0x1f, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x07, 0x0f, 0x0f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f,
0x1f, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

const uint8_t numbers[10][105] PROGMEM = {
{
// 0
0x00, 0x00, 0x00, 0xc0, 0xe0, 0xf0, 0xf0, 0xf8, 0xf8, 0xf8, 0xf8, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c,
0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0xf8, 0xf8, 0xf8, 0xf8, 0xf0, 0xf0, 0xe0, 0xc0,
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xc3, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0xc3,
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x0f, 0x0f, 0x1f, 0x1f, 0x1f,
0x1f, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x1f, 0x1f,
0x1f, 0x1f, 0x0f, 0x0f, 0x07, 0x03, 0x00, 0x00, 0x00,
},
{
// 1
0x00, 0x00, 0xe0, 0xe0, 0xe0, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xe0, 0xe0, 0xe0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c,
0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7f, 0x7f, 0x7f, 0x7f, 0x7e,
0x7c, 0x7c, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
},
{
// 2
0x00, 0x00, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x38, 0xf8, 0xf8, 0xf8, 0xf0,
0x80, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f,
0x7e, 0xfc, 0xfc, 0xf8, 0xf0, 0xe0, 0xe0, 0xc0, 0xc0, 0x80, 0x80, 0x80, 0x80, 0xc0, 0xc0, 0xe0,
0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x1f, 0x1f, 0x1f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x07, 0x07, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
0x0f, 0x0f, 0x07, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00,
},
{
// 3
0x00, 0x00, 0xc0, 0xf8, 0xfc, 0xfc, 0xfc, 0x3c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x38, 0xf8, 0xf8, 0xf8, 0xf0,
0x80, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xe0, 0xc0, 0x80, 0x80, 0x00, 0x00, 0x00,
0x00, 0x80, 0x80, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xc0, 0xc0, 0x80, 0x80, 0x80, 0xc0, 0xe0,
0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x0f, 0x0f, 0x1f, 0x1f,
0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x0f, 0x0f, 0x07, 0x01, 0x01, 0x03, 0x07, 0x0f, 0x0f, 0x0f, 0x0f,
0x0f, 0x0f, 0x0f, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00,
},
{
// 4
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xfc, 0xfc, 0xfc,
0x3c, 0x7c, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff,
0xff, 0xff, 0xff, 0x80, 0x80, 0x80, 0x81, 0x83, 0x87, 0x8f, 0x9f, 0xbf, 0xfe, 0xfc, 0xf8, 0xf0,
0xe0, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x7f, 0x7f, 0x7f, 0x7f, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x00, 0x00, 0x00,
},
{
// 5
0x00, 0x00, 0xc0, 0xf8, 0xf8, 0xf8, 0xf8, 0x38, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x70, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xe1, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x80, 0x80, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0xff,
0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x0f, 0x0f, 0x1f, 0x1f,
0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x0f, 0x0f, 0x07, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x1f, 0x1f, 0x1f, 0x1f, 0x00, 0x00, 0x00,
},
{
// 6
0x00, 0x00, 0x00, 0x80, 0xe0, 0xf0, 0xf0, 0xf8, 0xf8, 0xf8, 0xfc, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c,
0x7c, 0xfc, 0xfc, 0xfc, 0xfc, 0x7c, 0x78, 0xf8, 0xf8, 0xf0, 0xf0, 0xe0, 0xe0, 0xc0, 0x80, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xc7, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xc1, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x0f,
0xff, 0xff, 0xfe, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x0f, 0x1f, 0x1f, 0x1f, 0x3e,
0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3f, 0x3f, 0x1f, 0x1f, 0x0f, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x06, 0x07, 0x07, 0x07, 0x07, 0x00, 0x00,
},
{
// 7
0x00, 0x00, 0xf0, 0xf0, 0xe0, 0xe0, 0xc0, 0xc0, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xfc, 0xfc, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0x07, 0x07, 0x0f, 0x0f, 0x1f, 0x1f, 0x3f, 0x3f,
0x7e, 0x7e, 0xfc, 0xfc, 0xf8, 0xf8, 0xf0, 0xf0, 0xe0, 0xe0, 0xc0, 0xc0, 0xc0, 0x80, 0x80, 0xff,
0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0xc3,
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x07, 0x0f, 0x0f,
0x1f, 0x1f, 0x1e, 0x3e, 0x3f, 0x3f, 0x3f, 0x3f, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3f, 0x1f,
0x1f, 0x1f, 0x0f, 0x0f, 0x07, 0x03, 0x00, 0x00, 0x00
}
};

const uint8_t dots[2][32] PROGMEM = {
{
// stroke and not fill
0x00, 0xc0, 0x30, 0x08, 0x04, 0x04, 0x02, 0x02, 0x02, 0x02, 0x04, 0x04, 0x08, 0x30, 0xc0, 0x00,
0x00, 0x03, 0x0c, 0x10, 0x20, 0x20, 0x40, 0x40, 0x40, 0x40, 0x20, 0x20, 0x10, 0x0c, 0x03, 0x00,
},
{
// fill
0x00, 0xc0, 0xf0, 0xf8, 0xfc, 0xfc, 0xfe, 0xfe, 0xfe, 0xfe, 0xfc, 0xfc, 0xf8, 0xf0, 0xc0, 0x00,
0x00, 0x03, 0x0f, 0x1f, 0x3f, 0x3f, 0x7f, 0x7f, 0x7f, 0x7f, 0x3f, 0x3f, 0x1f, 0x0f, 0x03, 0x00
}
};
Loading

0 comments on commit b2a768b

Please sign in to comment.