Subversion Repositories HomeAutomation

Rev

Rev 1482 | Rev 1515 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1482 Rev 1514
Line 5... Line 5...
5
#define LOW 2
5
#define LOW 2
6
#define NOCHANGE 0  
6
#define NOCHANGE 0  
7
void sns_input_pcint_callback(uint8_t id, uint8_t status)
7
void sns_input_pcint_callback(uint8_t id, uint8_t status)
8
{
8
{
9
#ifdef  sns_input_CH0
9
#ifdef  sns_input_CH0
-
 
10
#if sns_input_CH0PCA95xxIO==0
10
    if (id == sns_input_PCINT_CH0) {
11
    if (id == sns_input_PCINT_CH0) {
11
      if (0 != status) {
12
      if (0 != status) {
12
        pinStatus[0] = HIGH;
13
        pinStatus[0] = HIGH;
13
      } else {
14
      } else {
14
        pinStatus[0] = LOW;
15
        pinStatus[0] = LOW;
15
      }
16
      }
16
    }
17
    }
-
 
18
#endif
17
#endif
19
#endif
18
#ifdef  sns_input_CH1
20
#ifdef  sns_input_CH1
-
 
21
#if sns_input_CH1PCA95xxIO==0
19
    if (id == sns_input_PCINT_CH1) {
22
    if (id == sns_input_PCINT_CH1) {
20
      if (0 != status) {
23
      if (0 != status) {
21
        pinStatus[1] = HIGH;
24
        pinStatus[1] = HIGH;
22
      } else {
25
      } else {
23
        pinStatus[1] = LOW;
26
        pinStatus[1] = LOW;
24
      }
27
      }
25
    }
28
    }
-
 
29
#endif
26
#endif
30
#endif
27
#ifdef  sns_input_CH2
31
#ifdef  sns_input_CH2
-
 
32
#if sns_input_CH2PCA95xxIO==0
28
    if (id == sns_input_PCINT_CH2) {
33
    if (id == sns_input_PCINT_CH2) {
29
      if (0 != status) {
34
      if (0 != status) {
30
        pinStatus[2] = HIGH;
35
        pinStatus[2] = HIGH;
31
      } else {
36
      } else {
32
        pinStatus[2] = LOW;
37
        pinStatus[2] = LOW;
33
      }
38
      }
34
    }
39
    }
-
 
40
#endif
35
#endif
41
#endif
36
#ifdef  sns_input_CH3
42
#ifdef  sns_input_CH3
-
 
43
#if sns_input_CH3PCA95xxIO==0
37
    if (id == sns_input_PCINT_CH3) {
44
    if (id == sns_input_PCINT_CH3) {
38
      if (0 != status) {
45
      if (0 != status) {
39
        pinStatus[3] = HIGH;
46
        pinStatus[3] = HIGH;
40
      } else {
47
      } else {
41
        pinStatus[3] = LOW;
48
        pinStatus[3] = LOW;
42
      }
49
      }
43
    }
50
    }
-
 
51
#endif
44
#endif
52
#endif
45
#ifdef  sns_input_CH4
53
#ifdef  sns_input_CH4
-
 
54
#if sns_input_CH4PCA95xxIO==0
46
    if (id == sns_input_PCINT_CH4) {
55
    if (id == sns_input_PCINT_CH4) {
47
      if (0 != status) {
56
      if (0 != status) {
48
        pinStatus[4] = HIGH;
57
        pinStatus[4] = HIGH;
49
      } else {
58
      } else {
50
        pinStatus[4] = LOW;
59
        pinStatus[4] = LOW;
51
      }
60
      }
52
    }
61
    }
-
 
62
#endif
53
#endif
63
#endif
54
#ifdef  sns_input_CH5
64
#ifdef  sns_input_CH5
-
 
65
#if sns_input_CH5PCA95xxIO==0
55
    if (id == sns_input_PCINT_CH5) {
66
    if (id == sns_input_PCINT_CH5) {
56
      if (0 != status) {
67
      if (0 != status) {
57
        pinStatus[5] = HIGH;
68
        pinStatus[5] = HIGH;
58
      } else {
69
      } else {
59
        pinStatus[5] = LOW;
70
        pinStatus[5] = LOW;
60
      }
71
      }
61
    }
72
    }
-
 
73
#endif
62
#endif
74
#endif
63
#ifdef  sns_input_CH6
75
#ifdef  sns_input_CH6
-
 
76
#if sns_input_CH6PCA95xxIO==0
64
    if (id == sns_input_PCINT_CH6) {
77
    if (id == sns_input_PCINT_CH6) {
65
      if (0 != status) {
78
      if (0 != status) {
66
        pinStatus[6] = HIGH;
79
        pinStatus[6] = HIGH;
67
      } else {
80
      } else {
68
        pinStatus[6] = LOW;
81
        pinStatus[6] = LOW;
69
      }
82
      }
70
    }
83
    }
-
 
84
#endif
71
#endif
85
#endif
72
#ifdef  sns_input_CH7
86
#ifdef  sns_input_CH7
-
 
87
#if sns_input_CH7PCA95xxIO==0
73
    if (id == sns_input_PCINT_CH7) {
88
    if (id == sns_input_PCINT_CH7) {
74
      if (0 != status) {
89
      if (0 != status) {
75
        pinStatus[7] = HIGH;
90
        pinStatus[7] = HIGH;
76
      } else {
91
      } else {
77
        pinStatus[7] = LOW;
92
        pinStatus[7] = LOW;
78
      }
93
      }
79
    }
94
    }
-
 
95
#endif
80
#endif
96
#endif
81
}
97
}
82
 
98
 
-
 
99
#if sns_input_CH0PCA95xxIO==1 | sns_input_CH1PCA95xxIO==1 | sns_input_CH2PCA95xxIO==1 | sns_input_CH3PCA95xxIO==1 | sns_input_CH4PCA95xxIO==1 | sns_input_CH5PCA95xxIO==1 | sns_input_CH6PCA95xxIO==1 | sns_input_CH7PCA95xxIO==1
-
 
100
/*void sns_input_PCA95xx_callback(uint16_t status)
-
 
101
{
-
 
102
    printf("0x%x\n",status);
-
 
103
}*/
-
 
104
#endif 
-
 
105
 
-
 
106
 
83
void sns_input_Init(void)
107
void sns_input_Init(void)
84
{
108
{
-
 
109
 
-
 
110
#if sns_input_CH0PCA95xxIO==1 |sns_input_CH1PCA95xxIO==1 | sns_input_CH2PCA95xxIO==1 | sns_input_CH3PCA95xxIO==1 | sns_input_CH4PCA95xxIO==1 | sns_input_CH5PCA95xxIO==1 | sns_input_CH6PCA95xxIO==1 | sns_input_CH7PCA95xxIO==1
-
 
111
    Pca95xx_Init(0);
-
 
112
    //Pca95xx_SetCallback(sns_input_PCA95XX_CALLBACK_INDEX, &sns_input_PCA95xx_callback);
-
 
113
    Timer_SetTimeout(sns_input_PCA95XX_POLL_TIMER, sns_input_PCA95XX_POLL_TIME, TimerTypeFreeRunning, 0);
-
 
114
#endif 
-
 
115
 
85
    pinStatus[0] = NOCHANGE;
116
    pinStatus[0] = NOCHANGE;
86
    pinStatus[1] = NOCHANGE;
117
    pinStatus[1] = NOCHANGE;
87
    pinStatus[2] = NOCHANGE;
118
    pinStatus[2] = NOCHANGE;
88
    pinStatus[3] = NOCHANGE;
119
    pinStatus[3] = NOCHANGE;
89
    pinStatus[4] = NOCHANGE;
120
    pinStatus[4] = NOCHANGE;
90
    pinStatus[5] = NOCHANGE;
121
    pinStatus[5] = NOCHANGE;
91
    pinStatus[6] = NOCHANGE;
122
    pinStatus[6] = NOCHANGE;
92
    pinStatus[7] = NOCHANGE;
123
    pinStatus[7] = NOCHANGE;
93
    uint8_t index = 0;
124
    uint8_t index = 0;
94
#ifdef  sns_input_CH0
125
#ifdef  sns_input_CH0
-
 
126
#if sns_input_CH0PCA95xxIO==0
95
    #if (sns_input_CH0_pullup == 1)
127
    #if (sns_input_CH0_pullup == 1)
96
        gpio_set_pullup(sns_input_CH0);
128
        gpio_set_pullup(sns_input_CH0);
97
    #else
129
    #else
98
        gpio_clr_pullup(sns_input_CH0);
130
        gpio_clr_pullup(sns_input_CH0);
99
    #endif
131
    #endif
100
        gpio_set_in(sns_input_CH0);
132
        gpio_set_in(sns_input_CH0);
101
        Pcint_SetCallbackPin(sns_input_PCINT_CH0, sns_input_CH0, &sns_input_pcint_callback);
133
        Pcint_SetCallbackPin(sns_input_PCINT_CH0, sns_input_CH0, &sns_input_pcint_callback);
-
 
134
#else
-
 
135
        Pca95xx_set_in(sns_input_CH0);
-
 
136
#endif
102
        index++;
137
        index++;
103
#endif
138
#endif
104
#ifdef  sns_input_CH1
139
#ifdef  sns_input_CH1
-
 
140
#if sns_input_CH1PCA95xxIO==0
105
    #if (sns_input_CH1_pullup == 1)
141
    #if (sns_input_CH1_pullup == 1)
106
        gpio_set_pullup(sns_input_CH1);
142
        gpio_set_pullup(sns_input_CH1);
107
    #else
143
    #else
108
        gpio_clr_pullup(sns_input_CH1);
144
        gpio_clr_pullup(sns_input_CH1);
109
    #endif      
145
    #endif      
110
        gpio_set_in(sns_input_CH1);
146
        gpio_set_in(sns_input_CH1);
111
        Pcint_SetCallbackPin(sns_input_PCINT_CH1, sns_input_CH1, &sns_input_pcint_callback);
147
        Pcint_SetCallbackPin(sns_input_PCINT_CH1, sns_input_CH1, &sns_input_pcint_callback);
-
 
148
#else
-
 
149
        Pca95xx_set_in(sns_input_CH1);
-
 
150
#endif
112
        index++;
151
        index++;
113
#endif
152
#endif
114
#ifdef  sns_input_CH2
153
#ifdef  sns_input_CH2
-
 
154
#if sns_input_CH2PCA95xxIO==0
115
    #if (sns_input_CH2_pullup == 1)
155
    #if (sns_input_CH2_pullup == 1)
116
        gpio_set_pullup(sns_input_CH2);
156
        gpio_set_pullup(sns_input_CH2);
117
    #else
157
    #else
118
        gpio_clr_pullup(sns_input_CH2);
158
        gpio_clr_pullup(sns_input_CH2);
119
    #endif      
159
    #endif      
120
        gpio_set_in(sns_input_CH2);
160
        gpio_set_in(sns_input_CH2);
121
        Pcint_SetCallbackPin(sns_input_PCINT_CH2, sns_input_CH2, &sns_input_pcint_callback);
161
        Pcint_SetCallbackPin(sns_input_PCINT_CH2, sns_input_CH2, &sns_input_pcint_callback);
-
 
162
#else
-
 
163
        Pca95xx_set_in(sns_input_CH2);
-
 
164
#endif
122
        index++;
165
        index++;
123
#endif
166
#endif
124
#ifdef  sns_input_CH3
167
#ifdef  sns_input_CH3
-
 
168
#if sns_input_CH3PCA95xxIO==0
125
    #if (sns_input_CH3_pullup == 1)
169
    #if (sns_input_CH3_pullup == 1)
126
        gpio_set_pullup(sns_input_CH3);
170
        gpio_set_pullup(sns_input_CH3);
127
    #else
171
    #else
128
        gpio_clr_pullup(sns_input_CH3);
172
        gpio_clr_pullup(sns_input_CH3);
129
    #endif      
173
    #endif      
130
        gpio_set_in(sns_input_CH3);
174
        gpio_set_in(sns_input_CH3);
131
        Pcint_SetCallbackPin(sns_input_PCINT_CH3, sns_input_CH3, &sns_input_pcint_callback);
175
        Pcint_SetCallbackPin(sns_input_PCINT_CH3, sns_input_CH3, &sns_input_pcint_callback);
-
 
176
#else
-
 
177
        Pca95xx_set_in(sns_input_CH3);
-
 
178
#endif
132
        index++;
179
        index++;
133
#endif
180
#endif
134
#ifdef  sns_input_CH4
181
#ifdef  sns_input_CH4
-
 
182
#if sns_input_CH4PCA95xxIO==0
135
    #if (sns_input_CH4_pullup == 1)
183
    #if (sns_input_CH4_pullup == 1)
136
        gpio_set_pullup(sns_input_CH4);
184
        gpio_set_pullup(sns_input_CH4);
137
    #else
185
    #else
138
        gpio_clr_pullup(sns_input_CH4);
186
        gpio_clr_pullup(sns_input_CH4);
139
    #endif      
187
    #endif      
140
        gpio_set_in(sns_input_CH4);
188
        gpio_set_in(sns_input_CH4);
141
        Pcint_SetCallbackPin(sns_input_PCINT_CH4, sns_input_CH4, &sns_input_pcint_callback);
189
        Pcint_SetCallbackPin(sns_input_PCINT_CH4, sns_input_CH4, &sns_input_pcint_callback);
-
 
190
#else
-
 
191
        Pca95xx_set_in(sns_input_CH4);
-
 
192
#endif
142
        index++;
193
        index++;
143
#endif
194
#endif
144
#ifdef  sns_input_CH5
195
#ifdef  sns_input_CH5
-
 
196
#if sns_input_CH5PCA95xxIO==0
145
    #if (sns_input_CH5_pullup == 1)
197
    #if (sns_input_CH5_pullup == 1)
146
        gpio_set_pullup(sns_input_CH5);
198
        gpio_set_pullup(sns_input_CH5);
147
    #else
199
    #else
148
        gpio_clr_pullup(sns_input_CH5);
200
        gpio_clr_pullup(sns_input_CH5);
149
    #endif      
201
    #endif      
150
        gpio_set_in(sns_input_CH5);
202
        gpio_set_in(sns_input_CH5);
151
        Pcint_SetCallbackPin(sns_input_PCINT_CH5, sns_input_CH5, &sns_input_pcint_callback);
203
        Pcint_SetCallbackPin(sns_input_PCINT_CH5, sns_input_CH5, &sns_input_pcint_callback);
-
 
204
#else
-
 
205
        Pca95xx_set_in(sns_input_CH5);
-
 
206
#endif
152
        index++;
207
        index++;
153
#endif
208
#endif
154
#ifdef  sns_input_CH6
209
#ifdef  sns_input_CH6
-
 
210
#if sns_input_CH6PCA95xxIO==0
155
    #if (sns_input_CH6_pullup == 1)
211
    #if (sns_input_CH6_pullup == 1)
156
        gpio_set_pullup(sns_input_CH6);
212
        gpio_set_pullup(sns_input_CH6);
157
    #else
213
    #else
158
        gpio_clr_pullup(sns_input_CH6);
214
        gpio_clr_pullup(sns_input_CH6);
159
    #endif          
215
    #endif          
160
        gpio_set_in(sns_input_CH6);
216
        gpio_set_in(sns_input_CH6);
161
        Pcint_SetCallbackPin(sns_input_PCINT_CH6, sns_input_CH6, &sns_input_pcint_callback);
217
        Pcint_SetCallbackPin(sns_input_PCINT_CH6, sns_input_CH6, &sns_input_pcint_callback);
-
 
218
#else
-
 
219
        Pca95xx_set_in(sns_input_CH6);
-
 
220
#endif
162
        index++;
221
        index++;
163
#endif
222
#endif
164
#ifdef  sns_input_CH7
223
#ifdef  sns_input_CH7
-
 
224
#if sns_input_CH7PCA95xxIO==0
165
    #if (sns_input_CH7_pullup == 1)
225
    #if (sns_input_CH7_pullup == 1)
166
        gpio_set_pullup(sns_input_CH7);
226
        gpio_set_pullup(sns_input_CH7);
167
    #else
227
    #else
168
        gpio_clr_pullup(sns_input_CH7);
228
        gpio_clr_pullup(sns_input_CH7);
169
    #endif      
229
    #endif      
170
        gpio_set_in(sns_input_CH7);
230
        gpio_set_in(sns_input_CH7);
171
        Pcint_SetCallbackPin(sns_input_PCINT_CH7, sns_input_CH7, &sns_input_pcint_callback);
231
        Pcint_SetCallbackPin(sns_input_PCINT_CH7, sns_input_CH7, &sns_input_pcint_callback);
-
 
232
#else
-
 
233
        Pca95xx_set_in(sns_input_CH7);
-
 
234
#endif
172
        index++;
235
        index++;
173
#endif
236
#endif
174
    // to use PCINt lib, call this function: (the callback function look as a timer callback function)
237
    // to use PCINt lib, call this function: (the callback function look as a timer callback function)
175
    // Pcint_SetCallbackPin(sns_input_PCINT, EXP_C , &sns_input_pcint_callback);
238
    // Pcint_SetCallbackPin(sns_input_PCINT, EXP_C , &sns_input_pcint_callback);
176
 
239
 
177
}
240
}
178
 
241
 
179
void sns_input_Process(void)
242
void sns_input_Process(void)
180
{
243
{
181
    ///TODO: IMPLEMENT DEBOUNCE
244
    ///TODO: IMPLEMENT DEBOUNCE
182
    uint8_t index = 0;
245
    uint8_t index = 0;
183
    for (index = 0; index < 8; index++) {
246
    for (index = 0; index < 8; index++) {
Line 197... Line 260...
197
            }
260
            }
198
            pinStatus[index] = NOCHANGE;
261
            pinStatus[index] = NOCHANGE;
199
            while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
262
            while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
200
        }
263
        }
201
    }
264
    }
-
 
265
 
-
 
266
#if sns_input_CH0PCA95xxIO==1 | sns_input_CH1PCA95xxIO==1 | sns_input_CH2PCA95xxIO==1 | sns_input_CH3PCA95xxIO==1 | sns_input_CH4PCA95xxIO==1 | sns_input_CH5PCA95xxIO==1 | sns_input_CH6PCA95xxIO==1 | sns_input_CH7PCA95xxIO==1
-
 
267
    if (Timer_Expired(sns_input_PCA95XX_POLL_TIMER))
-
 
268
    {
-
 
269
    uint16_t status = Pca95xx_GetInputs();
-
 
270
#ifdef  sns_input_CH0
-
 
271
#if sns_input_CH0PCA95xxIO==1
-
 
272
        /* TODO: går inte så bra med tanke på att modulen inte minns föregående pinstatus!!
-
 
273
        if ((status>>sns_input_CH0)&0x1 != pinStatus[0]) {
-
 
274
            pinStatus[0] = status>>sns_input_CH0)&0x1;
-
 
275
        } else {
-
 
276
            pinStatus[0] = LOW;
-
 
277
        }
-
 
278
        */
-
 
279
#endif
-
 
280
#endif
-
 
281
       
-
 
282
    }
-
 
283
#endif 
202
}
284
}
203
 
285
 
204
void sns_input_HandleMessage(StdCan_Msg_t *rxMsg)
286
void sns_input_HandleMessage(StdCan_Msg_t *rxMsg)
205
{
287
{
206
   
288