You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
2.4 KiB
C
86 lines
2.4 KiB
C
#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;
|
|
}
|
|
} |