Subversion Repositories HomeAutomation

Rev

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

Rev 1156 Rev 1177
Line 1... Line 1...
1
 
1
 
2
#include "act_softPWM.h"
2
#include "act_softPWM.h"
-
 
3
uint16_t currentTimer = 0;
-
 
4
uint16_t maxTimer = 10;
-
 
5
uint8_t resolution = 1;
3
 
6
 
4
#ifdef act_softPWM_USEEEPROM
7
#ifdef act_softPWM_USEEEPROM
5
#include "act_softPWM_eeprom.h"
8
#include "act_softPWM_eeprom.h"
6
struct eeprom_act_softPWM EEMEM eeprom_act_softPWM =
9
struct eeprom_act_softPWM EEMEM eeprom_act_softPWM =
7
{
10
{
Line 10... Line 13...
10
        0xAB,   // x
13
        0xAB,   // x
11
        0x1234  // y
14
        0x1234  // y
12
    },
15
    },
13
    0   // crc, must be a correct value, but this will also be handled by the EEPROM module or make scripts
16
    0   // crc, must be a correct value, but this will also be handled by the EEPROM module or make scripts
14
};
17
};
-
 
18
#endif
-
 
19
#ifdef PIN_0
-
 
20
    uint16_t PIN_0_timer=0;
-
 
21
#endif
-
 
22
#ifdef PIN_1
-
 
23
    uint16_t PIN_1_timer=0;
-
 
24
#endif
-
 
25
#ifdef PIN_2
-
 
26
    uint16_t PIN_2_timer=0;
-
 
27
#endif
-
 
28
#ifdef PIN_3
-
 
29
    uint16_t PIN_3_timer=0;
-
 
30
#endif
-
 
31
#ifdef PIN_4
-
 
32
    uint16_t PIN_4_timer=0;
-
 
33
#endif
-
 
34
#ifdef PIN_5
-
 
35
    uint16_t PIN_5_timer=0;
-
 
36
#endif
-
 
37
#ifdef PIN_6
-
 
38
    uint16_t PIN_6_timer=0;
-
 
39
#endif
-
 
40
#ifdef PIN_7
-
 
41
    uint16_t PIN_7_timer=0;
15
#endif
42
#endif
16
 
43
 
17
void act_softPWM_Init(void)
44
void act_softPWM_Init(void)
18
{
45
{
19
#ifdef act_softPWM_USEEEPROM
46
#ifdef act_softPWM_USEEEPROM
20
    if (EEDATA_OK)
47
    if (EEDATA_OK)
21
    {
48
    {
22
      ///TODO: Use stored data to set initial values for the module
49
      ///TODO: Use stored data to set initial values for the module
23
      blablaX = eeprom_read_byte(EEDATA.x);
50
      blablaX = eeprom_read_byte(EEDATA.x);
24
      blablaY = eeprom_read_word(EEDATA.y);
51
      blablaY = eeprom_read_word(EEDATA.y);
25
    } else
52
    } else
26
    {   //The CRC of the EEPROM is not correct, store default values and update CRC
53
    {   //The CRC of the EEPROM is not correct, store default values and update CRC
Line 28... Line 55...
28
      eeprom_write_word_crc(EEDATA.y, 0x1234, WITHOUT_CRC);
55
      eeprom_write_word_crc(EEDATA.y, 0x1234, WITHOUT_CRC);
29
      EEDATA_UPDATE_CRC;
56
      EEDATA_UPDATE_CRC;
30
    }
57
    }
31
#endif  
58
#endif  
32
    ///TODO: Initialize hardware etc here
59
    ///TODO: Initialize hardware etc here
-
 
60
#ifdef PIN_0
33
    gpio_set_out(PIN_RED);
61
    gpio_set_out(PIN_0);
-
 
62
    gpio_clr_pin(PIN_0);
-
 
63
#endif
-
 
64
#ifdef PIN_1
-
 
65
    gpio_set_out(PIN_1);
-
 
66
    gpio_clr_pin(PIN_1);
-
 
67
#endif
-
 
68
#ifdef PIN_2
-
 
69
    gpio_set_out(PIN_2);
-
 
70
    gpio_clr_pin(PIN_2);
-
 
71
#endif
-
 
72
#ifdef PIN_3
-
 
73
    gpio_set_out(PIN_3);
-
 
74
    gpio_clr_pin(PIN_3);
-
 
75
#endif
-
 
76
#ifdef PIN_4
34
    gpio_set_out(PIN_GREEN);
77
    gpio_set_out(PIN_4);
-
 
78
    gpio_clr_pin(PIN_4);
-
 
79
#endif
-
 
80
#ifdef PIN_5
35
    gpio_set_out(PIN_BLUE);
81
    gpio_set_out(PIN_5);
36
    gpio_clr_pin(PIN_RED);
82
    gpio_clr_pin(PIN_5);
-
 
83
#endif
-
 
84
#ifdef PIN_6
-
 
85
    gpio_set_out(PIN_6);
37
    gpio_clr_pin(PIN_GREEN);
86
    gpio_clr_pin(PIN_6);
-
 
87
#endif
-
 
88
#ifdef PIN_7
-
 
89
    gpio_set_out(PIN_7);
38
    gpio_clr_pin(PIN_BLUE);
90
    gpio_clr_pin(PIN_7);
-
 
91
#endif
39
   
92
   
40
    Timer_SetTimeout(act_softPWM_TIMER, 1, TimerTypeFreeRunning, NULL);
93
    Timer_SetTimeout(act_softPWM_TIMER, resolution, TimerTypeFreeRunning, NULL);
41
    // to use PCINt lib, call this function: (the callback function look as a timer callback function)
94
    // to use PCINt lib, call this function: (the callback function look as a timer callback function)
42
    // Pcint_SetCallbackPin(act_softPWM_PCINT, EXP_C , &act_softPWM_pcint_callback);
95
    // Pcint_SetCallbackPin(act_softPWM_PCINT, EXP_C , &act_softPWM_pcint_callback);
43
 
96
 
44
}
97
}
45
uint8_t redTimer = 0;
-
 
46
uint8_t greenTimer = 0;
-
 
47
uint8_t blueTimer = 0;
-
 
48
uint8_t currentTimer = 0;
-
 
49
 
98
 
50
void act_softPWM_Process(void)
99
void act_softPWM_Process(void)
51
{
100
{
52
    if (Timer_Expired(act_softPWM_TIMER)) {
101
    if (Timer_Expired(act_softPWM_TIMER)) {
53
        currentTimer++;
102
        currentTimer++;
54
        if (currentTimer == 10) {
103
        if (currentTimer == 10) {
55
            currentTimer=0;
104
            currentTimer=0;
-
 
105
            #ifdef PIN_0 
56
            gpio_set_pin(PIN_RED);
106
                gpio_set_pin(PIN_0);
-
 
107
            #endif
-
 
108
            #ifdef PIN_1 
-
 
109
                gpio_set_pin(PIN_1);
-
 
110
            #endif
-
 
111
            #ifdef PIN_2 
-
 
112
                gpio_set_pin(PIN_2);
-
 
113
            #endif
-
 
114
            #ifdef PIN_3 
-
 
115
                gpio_set_pin(PIN_3);
-
 
116
            #endif
-
 
117
            #ifdef PIN_4 
-
 
118
                gpio_set_pin(PIN_4);
-
 
119
            #endif
-
 
120
            #ifdef PIN_5 
57
            gpio_set_pin(PIN_GREEN);
121
                gpio_set_pin(PIN_5);
-
 
122
            #endif
-
 
123
            #ifdef PIN_6 
-
 
124
                gpio_set_pin(PIN_6);
-
 
125
            #endif
-
 
126
            #ifdef PIN_7 
58
            gpio_set_pin(PIN_BLUE);
127
                gpio_set_pin(PIN_7);
-
 
128
            #endif
59
        }
129
        }
-
 
130
        #ifdef PIN_0
-
 
131
        if (currentTimer >= PIN_0_timer) {
-
 
132
            gpio_clr_pin(PIN_0);
60
       
133
        }
-
 
134
        #endif
-
 
135
        #ifdef PIN_1
61
        if (currentTimer == redTimer) {
136
        if (currentTimer >= PIN_1_timer) {
62
            gpio_clr_pin(PIN_RED);
137
            gpio_clr_pin(PIN_1);
63
        }
138
        }
-
 
139
        #endif
-
 
140
        #ifdef PIN_2
64
        if (currentTimer == greenTimer) {
141
        if (currentTimer >= PIN_2_timer) {
65
            gpio_clr_pin(PIN_GREEN);
142
            gpio_clr_pin(PIN_2);
66
        }
143
        }
-
 
144
        #endif
-
 
145
        #ifdef PIN_3
67
        if (currentTimer == blueTimer) {
146
        if (currentTimer >= PIN_3_timer) {
68
            gpio_clr_pin(PIN_BLUE);
147
            gpio_clr_pin(PIN_3);
69
        }
148
        }
-
 
149
        #endif
-
 
150
        #ifdef PIN_4
-
 
151
        if (currentTimer >= PIN_4_timer) {
-
 
152
            gpio_clr_pin(PIN_4);
-
 
153
        }
-
 
154
        #endif
-
 
155
        #ifdef PIN_5
-
 
156
        if (currentTimer >= PIN_5_timer) {
-
 
157
            gpio_clr_pin(PIN_5);
-
 
158
        }
-
 
159
        #endif
-
 
160
        #ifdef PIN_6
-
 
161
        if (currentTimer >= PIN_6_timer) {
-
 
162
            gpio_clr_pin(PIN_6);
-
 
163
        }
-
 
164
        #endif
-
 
165
        #ifdef PIN_7
-
 
166
        if (currentTimer >= PIN_7_timer) {
-
 
167
            gpio_clr_pin(PIN_7);
-
 
168
        }
-
 
169
        #endif
70
    }
170
    }
71
}
171
}
72
 
172
 
73
void act_softPWM_HandleMessage(StdCan_Msg_t *rxMsg)
173
void act_softPWM_HandleMessage(StdCan_Msg_t *rxMsg)
74
{
174
{
75
    if (    StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_ACT &&
175
    if (    StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_ACT &&
76
        StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_TO_OWNER &&
176
        StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_TO_OWNER &&
77
        rxMsg->Header.ModuleType == CAN_MODULE_TYPE_ACT_SOFTPWM &&
177
        rxMsg->Header.ModuleType == CAN_MODULE_TYPE_ACT_SOFTPWM &&
78
        rxMsg->Header.ModuleId == act_softPWM_ID)
178
        rxMsg->Header.ModuleId == act_softPWM_ID)
79
    {
179
    {
80
        switch (rxMsg->Header.Command)
180
        switch (rxMsg->Header.Command)
81
        {
181
        {
82
        case CAN_MODULE_CMD_SOFTPWM_RGB_VALUE:
182
        case CAN_MODULE_CMD_PHYSICAL_PWM:
-
 
183
            if ((((uint16_t)rxMsg->Data[1])<8) + rxMsg->Data[2] > maxTimer)
-
 
184
            {
-
 
185
                rxMsg->Data[2] = maxTimer & 0x00ff;
-
 
186
                rxMsg->Data[1] = (maxTimer>>8) & 0x00ff;
-
 
187
            }
83
            redTimer = rxMsg->Data[0];
188
            switch (rxMsg->Data[0])
-
 
189
            {
-
 
190
            #ifdef PIN_0
-
 
191
            case 0:
-
 
192
                PIN_0_timer = (((uint16_t)rxMsg->Data[1])<<8) + rxMsg->Data[2];
-
 
193
                break;
-
 
194
            #endif
-
 
195
            #ifdef PIN_1
-
 
196
            case 1:
-
 
197
                PIN_1_timer = (((uint16_t)rxMsg->Data[1])<<8) + rxMsg->Data[2];
-
 
198
                break;
-
 
199
            #endif
-
 
200
            #ifdef PIN_2
-
 
201
            case 2:
-
 
202
                PIN_2_timer = (((uint16_t)rxMsg->Data[1])<<8) + rxMsg->Data[2];
-
 
203
                break;
-
 
204
            #endif
-
 
205
            #ifdef PIN_3
-
 
206
            case 3:
-
 
207
                PIN_3_timer = (((uint16_t)rxMsg->Data[1])<<8) + rxMsg->Data[2];
-
 
208
                break;
-
 
209
            #endif
-
 
210
            #ifdef PIN_4
-
 
211
            case 4:
-
 
212
                PIN_4_timer = (((uint16_t)rxMsg->Data[1])<<8) + rxMsg->Data[2];
-
 
213
                break;
-
 
214
            #endif
-
 
215
            #ifdef PIN_5
-
 
216
            case 5:
-
 
217
                PIN_5_timer = (((uint16_t)rxMsg->Data[1])<<8) + rxMsg->Data[2];
-
 
218
                break;
-
 
219
            #endif
-
 
220
            #ifdef PIN_6
-
 
221
            case 6:
-
 
222
                PIN_6_timer = (((uint16_t)rxMsg->Data[1])<<8) + rxMsg->Data[2];
-
 
223
                break;
-
 
224
            #endif
-
 
225
            #ifdef PIN_7
-
 
226
            case 7:
-
 
227
                PIN_7_timer = (((uint16_t)rxMsg->Data[1])<<8) + rxMsg->Data[2];
-
 
228
                break;
-
 
229
            #endif
-
 
230
            }
-
 
231
            break;
-
 
232
        case CAN_MODULE_CMD_SOFTPWM_CONFIG:
84
            greenTimer = rxMsg->Data[1];
233
            maxTimer = (((uint16_t)rxMsg->Data[0])<<8) + rxMsg->Data[1];
85
            blueTimer = rxMsg->Data[2];
234
            resolution = rxMsg->Data[2];
-
 
235
            Timer_SetTimeout(act_softPWM_TIMER, resolution, TimerTypeFreeRunning, NULL);
86
        break;
236
            break;
-
 
237
 
87
        }
238
        }
88
    }
239
    }
89
}
240
}
90
 
241
 
91
void act_softPWM_List(uint8_t ModuleSequenceNumber)
242
void act_softPWM_List(uint8_t ModuleSequenceNumber)