]> git.donarmstrong.com Git - qmk_firmware.git/blob - users/edvorakjp/edvorakjp_status.c
[Keymap] add new planck keymap (#6122)
[qmk_firmware.git] / users / edvorakjp / edvorakjp_status.c
1 #include "eeprom.h"
2 #include "edvorakjp.h"
3
4 typedef union {
5   uint8_t raw;
6   struct {
7     bool enable_kc_lang;  // for macOS
8   };
9 } edvorakjp_config_t;
10 static edvorakjp_config_t edvorakjp_config;
11
12 typedef struct {
13   bool japanese_mode;
14 } edvorakjp_state_t;
15 static edvorakjp_state_t edvorakjp_state;
16
17 /*
18  * private methods
19  */
20 uint8_t eeconfig_read_edvorakjp(void) {
21   return eeprom_read_byte(EECONFIG_EDVORAK);
22 }
23
24 void eeconfig_update_edvorakjp(uint8_t val) {
25   eeprom_update_byte(EECONFIG_EDVORAK, val);
26 }
27
28 /*
29  * public methods
30  */
31 void edvorakjp_status_init(void) {
32   edvorakjp_state.japanese_mode = false;
33   edvorakjp_config.raw = eeconfig_read_edvorakjp();
34 }
35
36 bool get_enable_kc_lang(void) {
37   return edvorakjp_config.enable_kc_lang;
38 }
39
40 void set_enable_kc_lang(bool new_state) {
41   edvorakjp_config.enable_kc_lang = new_state;
42   eeconfig_update_edvorakjp(edvorakjp_config.raw);
43 }
44
45 bool get_japanese_mode(void) {
46   return edvorakjp_state.japanese_mode;
47 }
48
49 void set_japanese_mode(bool new_state) {
50   edvorakjp_state.japanese_mode = new_state;
51   if (edvorakjp_state.japanese_mode) {
52     if (edvorakjp_config.enable_kc_lang) {
53       SEND_STRING(SS_TAP(X_LANG1));
54     } else {
55       SEND_STRING(SS_LALT("`"));
56     }
57   } else {
58     if (edvorakjp_config.enable_kc_lang) {
59       SEND_STRING(SS_TAP(X_LANG2));
60     } else {
61       SEND_STRING(SS_LALT("`"));
62     }
63   }
64 }