Subversion Repositories HomeAutomation

Rev

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

Rev 1180 Rev 1183
Line 1... Line 1...
1
 
1
 
2
#include "act_softPWM.h"
2
#include "act_softPWM.h"
-
 
3
 
-
 
4
 
3
uint16_t currentTimer = 0;
5
uint16_t currentTimer = 0;
4
uint16_t maxTimer = 10;
6
uint16_t maxTimer = 10;
5
uint8_t resolution = 1;
7
uint8_t resolution = 1;
6
uint8_t pwmDefaultState,pwmDefaultStartState,act_softPWM_ReportInterval;
8
uint8_t pwmDefaultState,pwmDefaultStartState,act_softPWM_ReportInterval;
7
uint16_t pwmDefaultValue;
9
uint16_t pwmDefaultValue;
8
uint16_t pwmPeriod;
10
uint16_t pwmPeriod;
9
uint8_t pwmStatus;
11
uint8_t pwmStatus;
10
uint8_t currentSendChannelId = 0;
12
uint8_t currentSendChannelId = 0;
-
 
13
 
-
 
14
#ifdef PIN_2_ID
-
 
15
#warning Hej2
-
 
16
#endif
-
 
17
 
11
 
18
 
12
#ifdef act_softPWM_USEEEPROM
19
#ifdef act_softPWM_USEEEPROM
13
#include "act_softPWM_eeprom.h"
20
#include "act_softPWM_eeprom.h"
14
struct eeprom_act_softPWM EEMEM eeprom_act_softPWM =
21
struct eeprom_act_softPWM EEMEM eeprom_act_softPWM =
15
{
22
{
Line 21... Line 28...
21
        0x14    //Reportinteval 20 sec.
28
        0x14    //Reportinteval 20 sec.
22
    },
29
    },
23
    0   // crc, must be a correct value, but this will also be handled by the EEPROM module or make scripts
30
    0   // crc, must be a correct value, but this will also be handled by the EEPROM module or make scripts
24
};
31
};
25
#endif
32
#endif
26
#define NUMBEROFCHANNELS 0
-
 
27
#ifdef PIN_0
-
 
28
    #define PIN_0_ID NUMBEROFCHANNELS
-
 
29
    #undefine NUMBEROFCHANNELS
-
 
30
    #define NUMBEROFCHANNELS PIN_0_ID + 1
-
 
31
#endif
33
 
32
#ifdef PIN_1
-
 
33
    #define PIN_1_ID NUMBEROFCHANNELS
-
 
34
    #undefine NUMBEROFCHANNELS
-
 
35
    #define NUMBEROFCHANNELS PIN_1_ID + 1
-
 
36
#endif
-
 
37
#ifdef PIN_2
-
 
38
    #define PIN_2_ID NUMBEROFCHANNELS
-
 
39
    #undefine NUMBEROFCHANNELS
-
 
40
    #define NUMBEROFCHANNELS PIN_2_ID + 1
-
 
41
#endif
-
 
42
#ifdef PIN_3
-
 
43
    #define PIN_3_ID NUMBEROFCHANNELS
-
 
44
    #undefine NUMBEROFCHANNELS
-
 
45
    #define NUMBEROFCHANNELS PIN_3_ID + 1
-
 
46
#endif
-
 
47
#ifdef PIN_4
-
 
48
    #define PIN_4_ID NUMBEROFCHANNELS
-
 
49
    #undefine NUMBEROFCHANNELS
-
 
50
    #define NUMBEROFCHANNELS PIN_4_ID + 1
-
 
51
#endif
-
 
52
#ifdef PIN_5
-
 
53
    #define PIN_5_ID NUMBEROFCHANNELS
-
 
54
    #undefine NUMBEROFCHANNELS
-
 
55
    #define NUMBEROFCHANNELS PIN_5_ID + 1
-
 
56
#endif
-
 
57
#ifdef PIN_6
-
 
58
    #define PIN_6_ID NUMBEROFCHANNELS
-
 
59
    #undefine NUMBEROFCHANNELS
-
 
60
    #define NUMBEROFCHANNELS PIN_6_ID + 1
-
 
61
#endif
-
 
62
#ifdef PIN_7
-
 
63
    #define PIN_7_ID NUMBEROFCHANNELS
-
 
64
    #undefine NUMBEROFCHANNELS
-
 
65
    #define NUMBEROFCHANNELS PIN_7_ID + 1
-
 
66
#endif
-
 
67
uint16_t pwmValue[NUMBEROFCHANNELS];
34
uint16_t pwmValue[NUMBEROFCHANNELS];
68
 
35
 
69
void act_softPWM_Init(void)
36
void act_softPWM_Init(void)
70
{
37
{
71
#ifdef act_softPWM_USEEEPROM
38
#ifdef act_softPWM_USEEEPROM
72
    if (EEDATA_OK)
39
    if (EEDATA_OK)
73
    {
40
    {
74
      ;
41
      ;
75
    } else
42
    } else
76
    {   //The CRC of the EEPROM is not correct, store default values and update CRC
43
    {   //The CRC of the EEPROM is not correct, store default values and update CRC
77
        eeprom_write_word_crc(EEDATA16.PwmPeriod, DEFAULT_PWM_PERIOD , WITHOUT_CRC);
44
        eeprom_write_word_crc(EEDATA16.PwmPeriod, 10 , WITHOUT_CRC);
78
        eeprom_write_word_crc(EEDATA16.defaultPwmValue, DEFAULT_PWM_VALUE , WITHOUT_CRC);
45
        eeprom_write_word_crc(EEDATA16.defaultPwmValue, 0 , WITHOUT_CRC);
79
        eeprom_write_byte_crc(EEDATA.defaultStates, 0xa0 , WITHOUT_CRC);
46
        eeprom_write_byte_crc(EEDATA.defaultStates, 0xa0 , WITHOUT_CRC);
80
        eeprom_write_byte_crc(EEDATA.ReportInterval, 0x14 , WITHOUT_CRC);
47
        eeprom_write_byte_crc(EEDATA.ReportInterval, 0x14 , WITHOUT_CRC);
81
        EEDATA_UPDATE_CRC;
48
        EEDATA_UPDATE_CRC;
82
    }
49
    }
83
    pwmDefaultValue = eeprom_read_word(EEDATA16.defaultPwmValue);
50
    pwmDefaultValue = eeprom_read_word(EEDATA16.defaultPwmValue);
84
    pwmPeriod = eeprom_read_word(EEDATA16.PwmPeriod);
51
    pwmPeriod = eeprom_read_word(EEDATA16.PwmPeriod);
85
    pwmDefaultState = (eeprom_read_byte(EEDATA.defaultStates)>>6) & 0x03;
52
    pwmDefaultState = (eeprom_read_byte(EEDATA.defaultStates)>>6) & 0x03;
86
    pwmDefaultStartState = ((eeprom_read_byte(EEDATA.defaultStates)>>5) & 0x01);
53
    pwmDefaultStartState = ((eeprom_read_byte(EEDATA.defaultStates)>>5) & 0x01);
87
    act_softPWM_ReportInterval = (eeprom_read_byte(EEDATA.ReportInterval));
54
    act_softPWM_ReportInterval = (eeprom_read_byte(EEDATA.ReportInterval));
88
    Timer_SetTimeout(act_softPWM_SEND_TIMER, act_softPWM_ReportInterval*1000 , TimerTypeFreeRunning, 0);
55
    Timer_SetTimeout(act_softPWM_SEND_TIMER, act_softPWM_ReportInterval*1000 , TimerTypeFreeRunning, 0);
89
#endif  
56
#endif  
90
    ///TODO: Initialize hardware etc here
57
    ///TODO: Initialize hardware etc here
91
#ifdef PIN_0
58
#ifdef PIN_0
92
    gpio_set_out(PIN_0);
59
    gpio_set_out(PIN_0);
93
    gpio_clr_pin(PIN_0);
60
    gpio_clr_pin(PIN_0);
94
#endif
61
#endif
Line 101... Line 68...
101
    gpio_clr_pin(PIN_2);
68
    gpio_clr_pin(PIN_2);
102
#endif
69
#endif
103
#ifdef PIN_3
70
#ifdef PIN_3
104
    gpio_set_out(PIN_3);
71
    gpio_set_out(PIN_3);
105
    gpio_clr_pin(PIN_3);
72
    gpio_clr_pin(PIN_3);
106
#endif
73
#endif
107
#ifdef PIN_4
74
#ifdef PIN_4
108
    gpio_set_out(PIN_4);
75
    gpio_set_out(PIN_4);
109
    gpio_clr_pin(PIN_4);
76
    gpio_clr_pin(PIN_4);
110
#endif
77
#endif
111
#ifdef PIN_5
78
#ifdef PIN_5
Line 117... Line 84...
117
    gpio_clr_pin(PIN_6);
84
    gpio_clr_pin(PIN_6);
118
#endif
85
#endif
119
#ifdef PIN_7
86
#ifdef PIN_7
120
    gpio_set_out(PIN_7);
87
    gpio_set_out(PIN_7);
121
    gpio_clr_pin(PIN_7);
88
    gpio_clr_pin(PIN_7);
122
#endif
89
#endif
123
   
90
   
124
    Timer_SetTimeout(act_softPWM_TIMER, resolution, TimerTypeFreeRunning, NULL);
91
    Timer_SetTimeout(act_softPWM_TIMER, resolution, TimerTypeFreeRunning, NULL);
125
    // to use PCINt lib, call this function: (the callback function look as a timer callback function)
92
    // to use PCINt lib, call this function: (the callback function look as a timer callback function)
126
    // Pcint_SetCallbackPin(act_softPWM_PCINT, EXP_C , &act_softPWM_pcint_callback);
93
    // Pcint_SetCallbackPin(act_softPWM_PCINT, EXP_C , &act_softPWM_pcint_callback);
127
 
94
 
128
}
95
}
129
 
96
 
130
void act_softPWM_Process(void)
97
void act_softPWM_Process(void)
131
{
98
{
132
    if (Timer_Expired(act_softPWM_TIMER)) {
99
    if (Timer_Expired(act_softPWM_TIMER)) {
133
        currentTimer++;
100
        currentTimer++;
134
        if (currentTimer == 10) {
101
        if (currentTimer == 10) {
135
            currentTimer=0;
102
            currentTimer=0;
136
            #ifdef PIN_0 
103
            #ifdef PIN_0 
137
                gpio_set_pin(PIN_0);
104
                gpio_set_pin(PIN_0);
138
            #endif
105
            #endif
139
            #ifdef PIN_1 
106
            #ifdef PIN_1 
140
                gpio_set_pin(PIN_1);
107
                gpio_set_pin(PIN_1);
141
            #endif
108
            #endif
142
            #ifdef PIN_2 
109
            #ifdef PIN_2 
143
                gpio_set_pin(PIN_2);
110
                gpio_set_pin(PIN_2);
144
            #endif
111
            #endif
145
            #ifdef PIN_3 
112
            #ifdef PIN_3 
146
                gpio_set_pin(PIN_3);
113
                gpio_set_pin(PIN_3);
147
            #endif
114
            #endif
148
            #ifdef PIN_4 
115
            #ifdef PIN_4 
149
                gpio_set_pin(PIN_4);
116
                gpio_set_pin(PIN_4);
150
            #endif
117
            #endif
151
            #ifdef PIN_5 
118
            #ifdef PIN_5 
152
                gpio_set_pin(PIN_5);
119
                gpio_set_pin(PIN_5);
153
            #endif
120
            #endif
154
            #ifdef PIN_6 
121
            #ifdef PIN_6 
155
                gpio_set_pin(PIN_6);
122
                gpio_set_pin(PIN_6);
156
            #endif
123
            #endif
157
            #ifdef PIN_7 
124
            #ifdef PIN_7 
158
                gpio_set_pin(PIN_7);
125
                gpio_set_pin(PIN_7);
159
            #endif
126
            #endif
160
        }
127
        }
161
        #ifdef PIN_0
128
        #ifdef PIN_0
162
        if (currentTimer >= pwmValue[PIN_0_ID]) {
129
        if (currentTimer >= pwmValue[PIN_0_ID]) {
163
            gpio_clr_pin(PIN_0);
130
            gpio_clr_pin(PIN_0);
164
        }
131
        }
165
        #endif
132
        #endif
166
        #ifdef PIN_1
133
        #ifdef PIN_1
167
        if (currentTimer >= pwmValue[PIN_1_ID]) {
134
        if (currentTimer >= pwmValue[PIN_1_ID]) {
168
            gpio_clr_pin(PIN_1);
135
            gpio_clr_pin(PIN_1);
169
        }
136
        }
170
        #endif
137
        #endif
-
 
138
#ifdef PIN_2_ID
-
 
139
#warning Hej3
-
 
140
#endif
-
 
141
 
171
        #ifdef PIN_2
142
        #ifdef PIN_2
172
        if (currentTimer >= pwmValue[PIN_2_ID]) {
143
        if (currentTimer >= pwmValue[ PIN_2_ID ]) {
173
            gpio_clr_pin(PIN_2);
144
            gpio_clr_pin(PIN_2);
174
        }
145
        }
175
        #endif
146
        #endif