Skip to content

Commit

Permalink
Add functions so you can configure programatically
Browse files Browse the repository at this point in the history
  • Loading branch information
drashna authored and skullydazed committed Sep 25, 2018
1 parent e72e4b6 commit cfb1b35
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 19 deletions.
3 changes: 2 additions & 1 deletion quantum/audio/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ typedef union {
uint8_t raw;
struct {
bool enable :1;
uint8_t level :7;
bool clicky_enable :1;
uint8_t level :6;
};
} audio_config_t;

Expand Down
60 changes: 42 additions & 18 deletions quantum/process_keycode/process_clicky.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,53 @@ void clicky_play(void) {
PLAY_SONG(clicky_song);
}

void clicky_freq_up(void) {
float new_freq = clicky_freq * AUDIO_CLICKY_FREQ_FACTOR;
if (new_freq < AUDIO_CLICKY_FREQ_MAX) {
clicky_freq = new_freq;
}
}

void clicky_freq_down(void) {
float new_freq = clicky_freq / AUDIO_CLICKY_FREQ_FACTOR;
if (new_freq > AUDIO_CLICKY_FREQ_MIN) {
clicky_freq = new_freq;
}
}

void clicky_freq_reset(void) {
clicky_freq = AUDIO_CLICKY_FREQ_DEFAULT;
}

void clicky_freq_toggle(void) {
audio_config.clicky_enable ^= 1;
eeconfig_update_audio(audio_config.raw);
}

void clicky_freq_on(void) {
audio_config.clicky_enable = 1;
eeconfig_update_audio(audio_config.raw);
}

void clicky_freq_off(void) {
audio_config.clicky_enable = 0;
eeconfig_update_audio(audio_config.raw);
}

bool is_clicky_on(void) {
return (audio_config.clicky_enable != 0);
}

bool process_clicky(uint16_t keycode, keyrecord_t *record) {
if (keycode == CLICKY_TOGGLE && record->event.pressed) {
audio_config.clicky ^= 1;
eeconfig_update_audio(audio_config.raw);
}
if (keycode == CLICKY_TOGGLE && record->event.pressed) { clicky_freq_toggle(); }

if (keycode == CLICKY_RESET && record->event.pressed) { clicky_freq = AUDIO_CLICKY_FREQ_DEFAULT; }
if (keycode == CLICKY_RESET && record->event.pressed) { clicky_freq_reset(); }

if (keycode == CLICKY_UP && record->event.pressed) {
float new_freq = clicky_freq * AUDIO_CLICKY_FREQ_FACTOR;
if (new_freq < AUDIO_CLICKY_FREQ_MAX) {
clicky_freq = new_freq;
}
}
if (keycode == CLICKY_DOWN && record->event.pressed) {
float new_freq = clicky_freq / AUDIO_CLICKY_FREQ_FACTOR;
if (new_freq > AUDIO_CLICKY_FREQ_MIN) {
clicky_freq = new_freq;
}
}
if (keycode == CLICKY_UP && record->event.pressed) { clicky_freq_up(); }
if (keycode == CLICKY_DOWN && record->event.pressed) { clicky_freq_down(); }


if ( audio_config.clicky ) {
if ( audio_config.clicky_enable ) {
if (record->event.pressed) {
clicky_play();;
}
Expand Down
9 changes: 9 additions & 0 deletions quantum/process_keycode/process_clicky.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,13 @@
void clicky_play(void);
bool process_clicky(uint16_t keycode, keyrecord_t *record);

void clicky_freq_up(void);
void clicky_freq_down(void);
void clicky_freq_reset(void);
void clicky_freq_toggle(void);
void clicky_freq_on(void);
void clicky_freq_off(void);

bool is_clicky_on(void);

#endif

0 comments on commit cfb1b35

Please sign in to comment.