aboutsummaryrefslogtreecommitdiffstats
path: root/users/edvorakjp/edvorakjp_status.c
blob: a60c8d853b0a632d696cbed0e9b601ece33787b7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "eeprom.h"
#include "edvorakjp.h"

typedef union {
  uint8_t raw;
  struct {
    bool enable_jp_extra_layer : 1;
    bool enable_kc_lang        : 1;  // for macOS
  };
} edvorakjp_config_t;
static edvorakjp_config_t edvorakjp_config;

typedef struct {
  bool japanese_mode;
} edvorakjp_state_t;
static edvorakjp_state_t edvorakjp_state;

/*
 * private methods
 */
uint8_t eeconfig_read_edvorakjp(void) {
  return eeprom_read_byte(EECONFIG_EDVORAK);
}

void eeconfig_update_edvorakjp(uint8_t val) {
  eeprom_update_byte(EECONFIG_EDVORAK, val);
}

/*
 * public methods
 */
void edvorakjp_status_init(void) {
  edvorakjp_state.japanese_mode = false;
  edvorakjp_config.raw = eeconfig_read_edvorakjp();
}

bool get_enable_jp_extra_layer(void) {
  return edvorakjp_config.enable_jp_extra_layer;
}

void set_enable_jp_extra_layer(bool new_state) {
  edvorakjp_config.enable_jp_extra_layer = new_state;
  eeconfig_update_edvorakjp(edvorakjp_config.raw);
}

bool get_enable_kc_lang(void) {
  return edvorakjp_config.enable_kc_lang;
}

void set_enable_kc_lang(bool new_state) {
  edvorakjp_config.enable_kc_lang = new_state;
  eeconfig_update_edvorakjp(edvorakjp_config.raw);
}

bool get_japanese_mode(void) {
  return edvorakjp_state.japanese_mode;
}

void set_japanese_mode(bool new_state) {
  edvorakjp_state.japanese_mode = new_state;
  if (edvorakjp_state.japanese_mode) {
    if (edvorakjp_config.enable_kc_lang) {
      SEND_STRING(SS_TAP(X_LANG1));
    } else {
      SEND_STRING(SS_LALT("`"));
    }
  } else {
    dvorakj_layer_off();
    if (edvorakjp_config.enable_kc_lang) {
      SEND_STRING(SS_TAP(X_LANG2));
    } else {
      SEND_STRING(SS_LALT("`"));
    }
  }
}