You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.4 KiB

  1. #include "eeprom.h"
  2. #include "edvorakjp.h"
  3. typedef union {
  4. uint8_t raw;
  5. struct {
  6. bool enable_kc_lang; // for macOS
  7. };
  8. } edvorakjp_config_t;
  9. static edvorakjp_config_t edvorakjp_config;
  10. typedef struct {
  11. bool japanese_mode;
  12. } edvorakjp_state_t;
  13. static edvorakjp_state_t edvorakjp_state;
  14. /*
  15. * private methods
  16. */
  17. uint8_t eeconfig_read_edvorakjp(void) { return eeprom_read_byte(EECONFIG_EDVORAK); }
  18. void eeconfig_update_edvorakjp(uint8_t val) { eeprom_update_byte(EECONFIG_EDVORAK, val); }
  19. /*
  20. * public methods
  21. */
  22. void edvorakjp_status_init(void) {
  23. edvorakjp_state.japanese_mode = false;
  24. edvorakjp_config.raw = eeconfig_read_edvorakjp();
  25. }
  26. bool get_enable_kc_lang(void) { return edvorakjp_config.enable_kc_lang; }
  27. void set_enable_kc_lang(bool new_state) {
  28. edvorakjp_config.enable_kc_lang = new_state;
  29. eeconfig_update_edvorakjp(edvorakjp_config.raw);
  30. }
  31. bool get_japanese_mode(void) { return edvorakjp_state.japanese_mode; }
  32. void set_japanese_mode(bool new_state) {
  33. edvorakjp_state.japanese_mode = new_state;
  34. if (edvorakjp_state.japanese_mode) {
  35. if (edvorakjp_config.enable_kc_lang) {
  36. SEND_STRING(SS_TAP(X_LANG1));
  37. } else {
  38. SEND_STRING(SS_LALT("`"));
  39. }
  40. } else {
  41. if (edvorakjp_config.enable_kc_lang) {
  42. SEND_STRING(SS_TAP(X_LANG2));
  43. } else {
  44. SEND_STRING(SS_LALT("`"));
  45. }
  46. }
  47. }