Subversion Repositories HomeAutomation

Rev

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

Rev 1095 Rev 1096
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;
-
 
19
 
16
 
20
/*  netConnected stores the connection status, if connected to the net or not */
17
/*  netConnected stores the connection status, if connected to the net or not */
21
uint8_t netConnected = CAN_MODULE_ENUM_DIMMER230_NETINFO_CONNECTION_DISCONNECTED;
18
uint8_t netConnected = CAN_MODULE_ENUM_DIMMER230_NETINFO_CONNECTION_DISCONNECTED;
22
 
19
 
23
/*  frequency stores the evaluated frequency, 50 or 60 Hz
20
/*  frequency stores the evaluated frequency, 50 or 60 Hz
Line 30... Line 27...
30
 
27
 
31
/*  dimmerValue is the current output
28
/*  dimmerValue is the current output
32
    value of 0 is zero output, value of 255 is max output (ACT_DIMMMER230_MIN_DIM, ACT_DIMMMER230_MAX_DIM)
29
    value of 0 is zero output, value of 255 is max output (ACT_DIMMMER230_MIN_DIM, ACT_DIMMMER230_MAX_DIM)
33
    stored in eeprom, and restored at startup */
30
    stored in eeprom, and restored at startup */
34
uint8_t dimmerValue = ACT_DIMMMER230_MIN_DIM;
31
uint8_t dimmerValue = ACT_DIMMMER230_MIN_DIM;
35
           
32
           
36
uint8_t state = ACT_DIMMMER230_STATE_IDLE;
33
uint8_t state = ACT_DIMMMER230_STATE_IDLE;
37
 
34
 
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) */
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) */
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};
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};
40
 
37
 
41
#if act_dimmer230_SYNC>0
38
#if act_dimmer230_SYNC>0
42
uint8_t zeroCrossCnt = 0;
39
uint8_t zeroCrossCnt = 0;
43
#endif
40
#endif
44
 
41
 
45
/*  Store dimmer value in eeprom if user has not changed it for a while */
-
 
46
void Store_value_callback(uint8_t timer)
-
 
47
{
-
 
48
    saveEEdata = 1;
-
 
49
}
-
 
50
 
42
 
51
/*  Set the variable to "disconnected" if no zerocross have arrived for a while */
43
/*  Set the variable to "disconnected" if no zerocross have arrived for a while */
52
void Net_Connection_callback(uint8_t timer)
44
void Net_Connection_callback(uint8_t timer)
53
{
45
{
54
    netConnected = CAN_MODULE_ENUM_DIMMER230_NETINFO_CONNECTION_DISCONNECTED;
46
    netConnected = CAN_MODULE_ENUM_DIMMER230_NETINFO_CONNECTION_DISCONNECTED;
Line 189... Line 181...
189
            if (dimmerValue == fadeTarget)
181
            if (dimmerValue == fadeTarget)
190
            {
182
            {
191
                sendNetInfo = 1;
183
                sendNetInfo = 1;
192
            }
184
            }
193
            /* 5 seconds after we have stopped fading we should store the current dimmerValue to eeprom */
185
            /* 5 seconds after we have stopped fading we should store the current dimmerValue to eeprom */
194
            Timer_SetTimeout(act_dimmer230_STORE_VALUE_TIMEOUT, 5000, TimerTypeOneShot, &Store_value_callback);
186
            Timer_SetTimeout(act_dimmer230_STORE_VALUE_TIMEOUT, 5000, TimerTypeOneShot, 0);
195
        }
187
        }
196
       
188
       
197
#if act_dimmer230_SYNC>0
189
#if act_dimmer230_SYNC>0
198
        /* Currently disabled, must add this packet to data.xml */
190
        /* Currently disabled, must add this packet to data.xml */
199
        zeroCrossCnt++;
191
        zeroCrossCnt++;
Line 270... Line 262...
270
 
262
 
271
 
263
 
272
/*  Process funtion of dimmer-module, currently everything is done interrupted */
264
/*  Process funtion of dimmer-module, currently everything is done interrupted */
273
void act_dimmer230_Process(void)
265
void act_dimmer230_Process(void)
274
{
266
{
-
 
267
    /* Send netinfo packet (if dimmervalue has changed, and periodically) */
275
    if (sendNetInfo)
268
    if (sendNetInfo)
276
    {
269
    {
277
        sendNetInfo = 0;
270
        sendNetInfo = 0;
278
        StdCan_Msg_t txMsg;
271
        StdCan_Msg_t txMsg;
279
        StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_ACT);
272
        StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_ACT);
Line 285... Line 278...
285
        txMsg.Data[0] = ((netConnected&0x1)<<7 | (frequency&0x3)<<5);
278
        txMsg.Data[0] = ((netConnected&0x1)<<7 | (frequency&0x3)<<5);
286
        txMsg.Data[1] = dimmerValue;
279
        txMsg.Data[1] = dimmerValue;
287
        StdCan_Put(&txMsg);
280
        StdCan_Put(&txMsg);
288
    }
281
    }
289
   
282
   
-
 
283
    /* If dimmervalue was changed over 5 seconds ago then store the new dimmervalue */
290
    if (saveEEdata)
284
    if (Timer_Expired(act_dimmer230_STORE_VALUE_TIMEOUT))
291
    {
285
    {
292
        saveEEdata = 0;
-
 
293
        eeprom_write_byte_crc(EEDATA.eeDimmerValue, dimmerValue, WITH_CRC);
286
        eeprom_write_byte_crc(EEDATA.eeDimmerValue, dimmerValue, WITH_CRC);
294
    }
287
    }
295
}
288
}
296
 
289
 
297
 
290