Organize pomodoro
parent
00010e432a
commit
2a6e36bf62
@ -0,0 +1,86 @@
|
||||
#include "keymap.h"
|
||||
#include "pomodoro.h"
|
||||
#include "lighting.h"
|
||||
|
||||
#define POM_CURRENT_INDEX 68
|
||||
#define POM_LIGHT_COUNT 9
|
||||
#define POM_COMPLETE_INDEX POM_CURRENT_INDEX + POM_LIGHT_COUNT + 1
|
||||
#define POM_DURATION 1500 /* 25 * 60 */
|
||||
|
||||
void draw_pom(void) {
|
||||
static bool blink_on;
|
||||
static short last_pos;
|
||||
|
||||
const uint8_t complete_hsv[3] = {HSV_TEAL};
|
||||
const uint8_t current_hsv[3] = {HSV_GOLDENROD};
|
||||
const uint8_t hidden_hsv[3] = C_MODI;
|
||||
|
||||
// Clear row
|
||||
if (pom_visible) {
|
||||
if (current_pom_state != STOPPED) {
|
||||
for(int i = POM_CURRENT_INDEX; i < POM_CURRENT_INDEX + POM_LIGHT_COUNT; i++)
|
||||
hsv_matrix_set_color(i, (uint8_t[3]){0, 0, 0});
|
||||
}
|
||||
|
||||
for(int i = POM_COMPLETE_INDEX; i < POM_COMPLETE_INDEX + 3; i++)
|
||||
hsv_matrix_set_color(i, (uint8_t[3]){0, 0, 0});
|
||||
}
|
||||
|
||||
// Draw completed
|
||||
if (pom_visible) {
|
||||
for(int i = POM_COMPLETE_INDEX; i < POM_COMPLETE_INDEX + poms_completed && i < POM_COMPLETE_INDEX + 3; i++ ) {
|
||||
hsv_matrix_set_color(i, complete_hsv);
|
||||
}
|
||||
} else if (poms_completed > 0 && poms_completed <= 3) {
|
||||
const short completed_position = POM_COMPLETE_INDEX + poms_completed - 1;
|
||||
hsv_matrix_set_color(completed_position, hidden_hsv);
|
||||
}
|
||||
|
||||
if (current_pom_state == STOPPED)
|
||||
return;
|
||||
|
||||
const short current_pos = POM_CURRENT_INDEX + (short)((float)pom_current_secs / POM_DURATION * POM_LIGHT_COUNT);
|
||||
|
||||
if(last_pos != current_pos) {
|
||||
last_pos = current_pos;
|
||||
blink_on = true;
|
||||
} else if (pom_second_start == 0) {
|
||||
blink_on = !blink_on;
|
||||
}
|
||||
|
||||
// Current solid
|
||||
if (pom_visible) {
|
||||
for(int i = POM_CURRENT_INDEX; i < current_pos; i++) {
|
||||
hsv_matrix_set_color(i, current_hsv);
|
||||
}
|
||||
}
|
||||
|
||||
// Current blinking
|
||||
if (blink_on) {
|
||||
if (pom_visible) {
|
||||
hsv_matrix_set_color(current_pos, current_hsv);
|
||||
} else {
|
||||
hsv_matrix_set_color(current_pos, hidden_hsv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void count_pom(void) {
|
||||
// Start ms counter
|
||||
if(pom_second_start == 0)
|
||||
pom_second_start = timer_read32();
|
||||
|
||||
// Check if second completed
|
||||
if (timer_elapsed32(pom_second_start) > 1000) {
|
||||
pom_second_start = 0;
|
||||
pom_current_secs++;
|
||||
}
|
||||
|
||||
// Check if pom completed
|
||||
if (pom_current_secs >= POM_DURATION) {
|
||||
poms_completed++;
|
||||
current_pom_state = STOPPED;
|
||||
pom_current_secs = 0;
|
||||
pom_second_start = 0;
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
enum pom_state {
|
||||
STOPPED,
|
||||
RUNNING,
|
||||
PAUSED
|
||||
};
|
||||
|
||||
enum pom_state current_pom_state;
|
||||
bool pom_visible;
|
||||
short poms_completed;
|
||||
short pom_current_secs;
|
||||
uint32_t pom_second_start;
|
||||
|
||||
void draw_pom(void);
|
||||
void count_pom(void);
|
Loading…
Reference in New Issue