Subversion Repositories HomeAutomation

Rev

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

Rev 1093 Rev 1095
Line 11... Line 11...
11
uint8_t demoHighValue = 0;
11
uint8_t demoHighValue = 0;
12
uint8_t demoState = ACT_DIMMMER230_DEMO_STATE_NOT_RUNNING;
12
uint8_t demoState = ACT_DIMMMER230_DEMO_STATE_NOT_RUNNING;
13
 
13
 
14
/*  This bool is set to make process routine send the NetInfo packet */
14
/*  This bool is set to make process routine send the NetInfo packet */
15
uint8_t sendNetInfo = 0;
15
uint8_t sendNetInfo = 0;
-
 
16
 
-
 
17
/*  This bool is set to make process routine save dimmervalue to eeprom */
-
 
18
uint8_t saveEEdata = 0;
16
 
19
 
17
/*  netConnected stores the connection status, if connected to the net or not */
20
/*  netConnected stores the connection status, if connected to the net or not */
18
uint8_t netConnected = CAN_MODULE_ENUM_DIMMER230_NETINFO_CONNECTION_DISCONNECTED;
21
uint8_t netConnected = CAN_MODULE_ENUM_DIMMER230_NETINFO_CONNECTION_DISCONNECTED;
19
 
22
 
20
/*  frequency stores the evaluated frequency, 50 or 60 Hz
23
/*  frequency stores the evaluated frequency, 50 or 60 Hz
21
    don't calculate net frequency since the internal oscillator is not to be trusted, instead check if 50Hz or 60Hz system
24
    don't calculate net frequency since the internal oscillator is not to be trusted, instead check if 50Hz or 60Hz system
22
    should be used for switching powerStepTable depending on frequency */
25
    should be used for switching powerStepTable depending on frequency */
23
uint8_t frequency = CAN_MODULE_ENUM_DIMMER230_NETINFO_FREQUENCY_ERROR_UNKNOWN; 
26
uint8_t frequency = CAN_MODULE_ENUM_DIMMER230_NETINFO_FREQUENCY_ERROR_UNKNOWN; 
24
           
27
           
25
/*  zero cross sync (time between pos flank of xc-detection and real zero cross) */
28
/*  zero cross sync (time between pos flank of xc-detection and real zero cross) */
26
uint16_t xcTimeDiff=0;
29
uint16_t xcTimeDiff=0;
27
 
30
 
28
/*  dimmerValue is the current output
31
/*  dimmerValue is the current output
29
    value of 0 is zero output, value of 255 is max output (ACT_DIMMMER230_MIN_DIM, ACT_DIMMMER230_MAX_DIM)
32
    value of 0 is zero output, value of 255 is max output (ACT_DIMMMER230_MIN_DIM, ACT_DIMMMER230_MAX_DIM)
30
    stored in eeprom, and restored at startup */
33
    stored in eeprom, and restored at startup */
31
uint8_t dimmerValue = ACT_DIMMMER230_MIN_DIM;
34
uint8_t dimmerValue = ACT_DIMMMER230_MIN_DIM;
32
           
35
           
33
uint8_t state = ACT_DIMMMER230_STATE_IDLE;
36
uint8_t state = ACT_DIMMMER230_STATE_IDLE;
34
 
37
 
35
/*  powerStepTable is used for stepping the output for constant increase/decrease in power, this should be a quater of a sin^2-wave (since the second quater can be calculated) */
38
/*  powerStepTable is used for stepping the output for constant increase/decrease in power, this should be a quater of a sin^2-wave (since the second quater can be calculated) */
36
const uint16_t powerStepTable[] PROGMEM = {845, 1068, 1225, 1352, 1459, 1553, 1638, 1716, 1788, 1855, 1917, 1976, 2032, 2086, 2138, 2188, 2236, 2282, 2327, 2370, 2412, 2453, 2493, 2532, 2570, 2607, 2643, 2679, 2714, 2748, 2782, 2815, 2848, 2880, 2911, 2942, 2972, 3002, 3032, 3061, 3090, 3119, 3147, 3175, 3203, 3230, 3257, 3284, 3311, 3337, 3363, 3389, 3415, 3440, 3465, 3490, 3515, 3539, 3563, 3587, 3611, 3635, 3659, 3682, 3705, 3728, 3751, 3774, 3797, 3820, 3843, 3865, 3887, 3909, 3931, 3953, 3975, 3997, 4019, 4041, 4062, 4083, 4104, 4125, 4146, 4167, 4188, 4209, 4230, 4251, 4272, 4292, 4313, 4333, 4354, 4374, 4395, 4415, 4435, 4455, 4476, 4496, 4516, 4536, 4556, 4576, 4596, 4615, 4635, 4655, 4675, 4694, 4714, 4734, 4754, 4773, 4793, 4813, 4832, 4852, 4872, 4891, 4911, 4931, 4951, 4970, 4990};
39
const uint16_t powerStepTable[] PROGMEM = {845, 1068, 1225, 1352, 1459, 1553, 1638, 1716, 1788, 1855, 1917, 1976, 2032, 2086, 2138, 2188, 2236, 2282, 2327, 2370, 2412, 2453, 2493, 2532, 2570, 2607, 2643, 2679, 2714, 2748, 2782, 2815, 2848, 2880, 2911, 2942, 2972, 3002, 3032, 3061, 3090, 3119, 3147, 3175, 3203, 3230, 3257, 3284, 3311, 3337, 3363, 3389, 3415, 3440, 3465, 3490, 3515, 3539, 3563, 3587, 3611, 3635, 3659, 3682, 3705, 3728, 3751, 3774, 3797, 3820, 3843, 3865, 3887, 3909, 3931, 3953, 3975, 3997, 4019, 4041, 4062, 4083, 4104, 4125, 4146, 4167, 4188, 4209, 4230, 4251, 4272, 4292, 4313, 4333, 4354, 4374, 4395, 4415, 4435, 4455, 4476, 4496, 4516, 4536, 4556, 4576, 4596, 4615, 4635, 4655, 4675, 4694, 4714, 4734, 4754, 4773, 4793, 4813, 4832, 4852, 4872, 4891, 4911, 4931, 4951, 4970, 4990};
37
 
40
 
Line 39... Line 42...
39
uint8_t zeroCrossCnt = 0;
42
uint8_t zeroCrossCnt = 0;
40
#endif
43
#endif
41
 
44
 
42
/*  Store dimmer value in eeprom if user has not changed it for a while */
45
/*  Store dimmer value in eeprom if user has not changed it for a while */
43
void Store_value_callback(uint8_t timer)
46
void Store_value_callback(uint8_t timer)
44
{
47
{
45
    eeprom_write_byte_crc(EEDATA.eeDimmerValue, dimmerValue, WITH_CRC);
48
    saveEEdata = 1;
46
}
49
}
47
 
50
 
48
/*  Set the variable to "disconnected" if no zerocross have arrived for a while */
51
/*  Set the variable to "disconnected" if no zerocross have arrived for a while */
49
void Net_Connection_callback(uint8_t timer)
52
void Net_Connection_callback(uint8_t timer)
50
{
53
{
51
    netConnected = CAN_MODULE_ENUM_DIMMER230_NETINFO_CONNECTION_DISCONNECTED;
54
    netConnected = CAN_MODULE_ENUM_DIMMER230_NETINFO_CONNECTION_DISCONNECTED;
52
}
55
}
53
 
56
 
54
/*  This function will send the dimmer-status-packet containing connection status and frequency */
57
/*  This function will send the dimmer-status-packet containing connection status and frequency */
55
void Send_Status_callback(uint8_t timer)
58
void Send_Status_callback(uint8_t timer)
Line 178... Line 181...
178
            dimmerValue += fadeSpeed;
181
            dimmerValue += fadeSpeed;
179
            if ((fadeSpeed > 0 && (dimmerValue < tempDimVal || dimmerValue >= fadeTarget)) ||
182
            if ((fadeSpeed > 0 && (dimmerValue < tempDimVal || dimmerValue >= fadeTarget)) ||
180
                (fadeSpeed < 0 && (dimmerValue > tempDimVal || dimmerValue <= fadeTarget)))
183
                (fadeSpeed < 0 && (dimmerValue > tempDimVal || dimmerValue <= fadeTarget)))
181
            {
184
            {
182
                dimmerValue = fadeTarget;
185
                dimmerValue = fadeTarget;
183
            }
186
            }
184
           
187
           
185
            /* if targetvalue was reached then send the netinfo packet */
188
            /* if targetvalue was reached then send the netinfo packet */
186
            if (dimmerValue == fadeTarget)
189
            if (dimmerValue == fadeTarget)
187
            {
190
            {
188
                sendNetInfo = 1;
191
                sendNetInfo = 1;
189
            }
192
            }
190
            /* 5 seconds after we have stopped fading we should store the current dimmerValue to eeprom */
193
            /* 5 seconds after we have stopped fading we should store the current dimmerValue to eeprom */
191
            Timer_SetTimeout(act_dimmer230_STORE_VALUE_TIMEOUT, 5000, TimerTypeOneShot, &Store_value_callback);
194
            Timer_SetTimeout(act_dimmer230_STORE_VALUE_TIMEOUT, 5000, TimerTypeOneShot, &Store_value_callback);
192
        }
195
        }
193
       
196
       
194
#if act_dimmer230_SYNC>0
197
#if act_dimmer230_SYNC>0
195
        /* Currently disabled, must add this packet to data.xml */
198
        /* Currently disabled, must add this packet to data.xml */
196
        zeroCrossCnt++;
199
        zeroCrossCnt++;
197
        if (zeroCrossCnt >= act_dimmer230_SYNC)
200
        if (zeroCrossCnt >= act_dimmer230_SYNC)
198
        {
201
        {
Line 205... Line 208...
205
            txMsg.Data[1] = newTimerVal&0xff;
208
            txMsg.Data[1] = newTimerVal&0xff;
206
            txMsg.Data[2] = frequency;  //(periodTime>>8)&0xff;
209
            txMsg.Data[2] = frequency;  //(periodTime>>8)&0xff;
207
            //txMsg.Data[3] = periodTime&0xff;
210
            //txMsg.Data[3] = periodTime&0xff;
208
            txMsg.Data[4] = (xcTimeDiff>>8)&0xff;
211
            txMsg.Data[4] = (xcTimeDiff>>8)&0xff;
209
            txMsg.Data[5] = xcTimeDiff&0xff;
212
            txMsg.Data[5] = xcTimeDiff&0xff;
210
            StdCan_Put(&txMsg);
213
            StdCan_Put(&txMsg);
211
#endif
214
#endif
212
        }
215
        }
213
#endif      
216
#endif      
214
    }
217
    }
215
}
218
}
216
 
219
 
217
#ifdef act_dimmer230_USEEEPROM
220
#ifdef act_dimmer230_USEEEPROM
218
struct eeprom_act_dimmer230 EEMEM eeprom_act_dimmer230 =
221
struct eeprom_act_dimmer230 EEMEM eeprom_act_dimmer230 =
219
{
222
{
220
    {
223
    {
221
        /* Define initialization values on the EEPROM variables here,
224
        /* Define initialization values on the EEPROM variables here,
222
        this will generate a *.eep file that can be used to store this values to the node,
225
        this will generate a *.eep file that can be used to store this values to the node,
Line 280... Line 283...
280
        txMsg.Header.Command = CAN_MODULE_CMD_DIMMER230_NETINFO;
283
        txMsg.Header.Command = CAN_MODULE_CMD_DIMMER230_NETINFO;
281
        txMsg.Length = 2;
284
        txMsg.Length = 2;
282
        txMsg.Data[0] = ((netConnected&0x1)<<7 | (frequency&0x3)<<5);
285
        txMsg.Data[0] = ((netConnected&0x1)<<7 | (frequency&0x3)<<5);
283
        txMsg.Data[1] = dimmerValue;
286
        txMsg.Data[1] = dimmerValue;
284
        StdCan_Put(&txMsg);
287
        StdCan_Put(&txMsg);
-
 
288
    }
-
 
289
   
-
 
290
    if (saveEEdata)
-
 
291
    {
-
 
292
        saveEEdata = 0;
-
 
293
        eeprom_write_byte_crc(EEDATA.eeDimmerValue, dimmerValue, WITH_CRC);
285
    }
294
    }
286
}
295
}
287
 
296
 
288
 
297
 
289
/*  Handle incoming message function of dimmer-module */
298
/*  Handle incoming message function of dimmer-module */