Subversion Repositories DashDisplay

Rev

Rev 2 | Rev 5 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 4
Line 37... Line 37...
37
        sw_count[i] = 0;
37
        sw_count[i] = 0;
38
}
38
}
39
 
39
 
40
// reset the dial positions
40
// reset the dial positions
41
dial_pos[0] = 0;
41
dial_pos[0] = 0;
42
dial_pos[1] = 1;
42
dial_pos[1] = 0;
43
}
43
}
44
 
44
 
45
// this gray encodes the dial .
45
// this gray encodes the dial , but you cannot turn the switch back below 0
46
void EncodeDial(int i) {
46
void EncodeDial(int i) {
47
if (i < MAX_DIALS && i >= 0) {
47
if (i < MAX_DIALS && i >= 0) {
48
        int sw_index = i << 1;
48
        int sw_index = i << 1;
49
        // dial 0 uses switches 0 and 1
49
        // dial 0 uses switches 0 and 1
50
        // dial 1 uses switches 2 and 3
50
        // dial 1 uses switches 2 and 3
51
        int current = sw_newstate[sw_index] | (sw_newstate[sw_index + 1] << 1);
51
        int current = sw_newstate[sw_index] | (sw_newstate[sw_index + 1] << 1);
52
        switch (dial_last[i]) {
52
        switch (dial_last[i]) {
53
        case PH_00:
53
        case PH_00:
54
                if (current == PH_10)
54
                if (current == PH_10)
55
                        dial_pos[i]++;
55
                        dial_pos[i]++;
56
                if (current == PH_01)
56
                if (current == PH_01 && dial_pos[i]>0)
57
                        dial_pos[i]--;
57
                        dial_pos[i]--;
58
                break;
58
                break;
59
        case PH_10:
59
        case PH_10:
60
                if (current == PH_11)
60
                if (current == PH_11)
61
                        dial_pos[i]++;
61
                        dial_pos[i]++;
62
                if (current == PH_00)
62
                if (current == PH_00 && dial_pos[i]>0)
63
                        dial_pos[i]--;
63
                        dial_pos[i]--;
64
                break;
64
                break;
65
        case PH_11:
65
        case PH_11:
66
                if (current == PH_01)
66
                if (current == PH_01)
67
                        dial_pos[i]++;
67
                        dial_pos[i]++;
68
                if (current == PH_10)
68
                if (current == PH_10 && dial_pos[i]>0)
69
                        dial_pos[i]--;
69
                        dial_pos[i]--;
70
                break;
70
                break;
71
        case PH_01:
71
        case PH_01:
72
                if (current == PH_00)
72
                if (current == PH_00)
73
                        dial_pos[i]++;
73
                        dial_pos[i]++;
74
                if (current == PH_11)
74
                if (current == PH_11 && dial_pos[i]>0)
75
                        dial_pos[i]--;
75
                        dial_pos[i]--;
76
                break;
76
                break;
77
        default:
77
        default:
78
                break;
78
                break;
79
        }
79
        }
Line 92... Line 92...
92
  {
92
  {
93
 
93
 
94
    int sw = HAL_GPIO_ReadPin(sw_arr[i].GPIO, sw_arr[i].Pin) == GPIO_PIN_RESET;
94
    int sw = HAL_GPIO_ReadPin(sw_arr[i].GPIO, sw_arr[i].Pin) == GPIO_PIN_RESET;
95
 
95
 
96
    // bouncing, reset counter
96
    // bouncing, reset counter
97
    if (sw != sw_newstate[i])
97
    if (sw == sw_newstate[i])
98
    {
98
    {
99
          sw_count[i] = 0;
99
          sw_count[i] = 0;
100
    }
100
    }
101
    else
101
    else
102
    {
102
    {