diff --git a/keymap/keymap.c b/keymap/keymap.c index 94d9f34..814d10d 100644 --- a/keymap/keymap.c +++ b/keymap/keymap.c @@ -1,5 +1,6 @@ #include "keymap.h" #include "lighting.h" +#include "pomodoro.h" #define _TL _TALI_LAYER #define _T2 _TALI_LAYER2 @@ -338,89 +339,6 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { return true; } -#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; - } -} - void rgb_matrix_indicators_user(void) { if (g_suspend_state || disable_layer_color || rgb_matrix_get_flags() == LED_FLAG_NONE || diff --git a/keymap/keymap.h b/keymap/keymap.h index 153e338..b8dbc86 100644 --- a/keymap/keymap.h +++ b/keymap/keymap.h @@ -32,16 +32,4 @@ enum layout_names { extern bool g_suspend_state; bool disable_layer_color; -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 send_alt_code(int); \ No newline at end of file diff --git a/keymap/pomodoro.c b/keymap/pomodoro.c new file mode 100644 index 0000000..35e34e1 --- /dev/null +++ b/keymap/pomodoro.c @@ -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; + } +} \ No newline at end of file diff --git a/keymap/pomodoro.h b/keymap/pomodoro.h new file mode 100644 index 0000000..6c8fd9c --- /dev/null +++ b/keymap/pomodoro.h @@ -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); \ No newline at end of file diff --git a/keymap/rules.mk b/keymap/rules.mk index ad660ae..133c8de 100644 --- a/keymap/rules.mk +++ b/keymap/rules.mk @@ -14,4 +14,4 @@ EXTRAKEY_ENABLE = yes # Audio control and System control # COMBO_ENABLE # Key combo feature # LEADER_ENABLE # Enable leader key chording -SRC += lighting_funcs.c \ No newline at end of file +SRC += lighting_funcs.c pomodoro.c \ No newline at end of file