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.

64 lines
1.3 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) {
  18. return eeprom_read_byte(EECONFIG_EDVORAK);
  19. }
  20. void eeconfig_update_edvorakjp(uint8_t val) {
  21. eeprom_update_byte(EECONFIG_EDVORAK, val);
  22. }
  23. /*
  24. * public methods
  25. */
  26. void edvorakjp_status_init(void) {
  27. edvorakjp_state.japanese_mode = false;
  28. edvorakjp_config.raw = eeconfig_read_edvorakjp();
  29. }
  30. bool get_enable_kc_lang(void) {
  31. return edvorakjp_config.enable_kc_lang;
  32. }
  33. void set_enable_kc_lang(bool new_state) {
  34. edvorakjp_config.enable_kc_lang = new_state;
  35. eeconfig_update_edvorakjp(edvorakjp_config.raw);
  36. }
  37. bool get_japanese_mode(void) {
  38. return edvorakjp_state.japanese_mode;
  39. }
  40. void set_japanese_mode(bool new_state) {
  41. edvorakjp_state.japanese_mode = new_state;
  42. if (edvorakjp_state.japanese_mode) {
  43. if (edvorakjp_config.enable_kc_lang) {
  44. SEND_STRING(SS_TAP(X_LANG1));
  45. } else {
  46. SEND_STRING(SS_LALT("`"));
  47. }
  48. } else {
  49. if (edvorakjp_config.enable_kc_lang) {
  50. SEND_STRING(SS_TAP(X_LANG2));
  51. } else {
  52. SEND_STRING(SS_LALT("`"));
  53. }
  54. }
  55. }