Subversion Repositories HomeAutomation

Rev

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

Rev 1091 Rev 1093
Line 8... Line 8...
8
uint8_t fadeSpeedCnt = 0;
8
uint8_t fadeSpeedCnt = 0;
9
 
9
 
10
uint8_t demoEndValue = 0;
10
uint8_t demoEndValue = 0;
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
 
-
 
14
/*  This bool is set to make process routine send the NetInfo packet */
-
 
15
uint8_t sendNetInfo = 0;
13
 
16
 
14
/*  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 */
15
uint8_t netConnected = CAN_MODULE_ENUM_DIMMER230_NETINFO_CONNECTION_DISCONNECTED;
18
uint8_t netConnected = CAN_MODULE_ENUM_DIMMER230_NETINFO_CONNECTION_DISCONNECTED;
16
 
19
 
17
/*  frequency stores the evaluated frequency, 50 or 60 Hz
20
/*  frequency stores the evaluated frequency, 50 or 60 Hz
Line 49... Line 52...
49
}
52
}
50
 
53
 
51
/*  This function will send the dimmer-status-packet containing connection status and frequency */
54
/*  This function will send the dimmer-status-packet containing connection status and frequency */
52
void Send_Status_callback(uint8_t timer)
55
void Send_Status_callback(uint8_t timer)
53
{
56
{
54
    StdCan_Msg_t txMsg;
-
 
55
    StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_ACT);
-
 
56
    StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
-
 
57
    txMsg.Header.ModuleType = CAN_MODULE_TYPE_ACT_DIMMER230;
-
 
58
    txMsg.Header.ModuleId = act_dimmer230_ID;
-
 
59
    txMsg.Header.Command = CAN_MODULE_CMD_DIMMER230_NETINFO;
-
 
60
    txMsg.Length = 1;
57
    sendNetInfo = 1;
61
    txMsg.Data[0] = ((netConnected&0x1)<<7 | (frequency&0x3)<<5);
-
 
62
    StdCan_Put(&txMsg);
-
 
63
}
58
}
64
 
59
 
65
/*  When the timer reaches its compare value the triac should be trigged */
60
/*  When the timer reaches its compare value the triac should be trigged */
66
ISR (TIMER1_COMPA_vect)
61
ISR (TIMER1_COMPA_vect)
67
{
62
{
Line 136... Line 131...
136
                fadeSpeed = -fadeSpeed;
131
                fadeSpeed = -fadeSpeed;
137
            break;
132
            break;
138
            case ACT_DIMMMER230_DEMO_STATE_GOBACK:
133
            case ACT_DIMMMER230_DEMO_STATE_GOBACK:
139
                demoState = ACT_DIMMMER230_DEMO_STATE_NOT_RUNNING;
134
                demoState = ACT_DIMMMER230_DEMO_STATE_NOT_RUNNING;
140
            break;
135
            break;
141
            }
136
            }
142
        }
137
        }
143
       
138
       
144
        /* Calculate new time to triac triggering */
139
        /* Calculate new time to triac triggering */
145
        uint16_t newTimerVal = xcTimeDiff;      /* add the zerocross timediff */
140
        uint16_t newTimerVal = xcTimeDiff;      /* add the zerocross timediff */
146
 
141
 
147
        if (dimmerValue > 0 && dimmerValue <= 127)
142
        if (dimmerValue > 0 && dimmerValue <= 127)
148
        {
143
        {
Line 153... Line 148...
153
            newTimerVal += pgm_read_word(&powerStepTable[254-dimmerValue]);
148
            newTimerVal += pgm_read_word(&powerStepTable[254-dimmerValue]);
154
        }
149
        }
155
        else if (dimmerValue == 255)
150
        else if (dimmerValue == 255)
156
        {
151
        {
157
            newTimerVal += 100; /* almost max, to make sure we don't fire before zerocross */
152
            newTimerVal += 100; /* almost max, to make sure we don't fire before zerocross */
158
        }
153
        }
159
       
154
       
160
        if (newTimerVal > ACT_DIMMMER230_50HZ_PERIOD_TIME)
155
        if (newTimerVal > ACT_DIMMMER230_50HZ_PERIOD_TIME)
161
        {
156
        {
162
            newTimerVal -= ACT_DIMMMER230_50HZ_PERIOD_TIME;
157
            newTimerVal -= ACT_DIMMMER230_50HZ_PERIOD_TIME;
163
        }
158
        }
164
 
159
 
Line 170... Line 165...
170
            /* enable timer and timer interrupt */
165
            /* enable timer and timer interrupt */
171
            TIFR1=(1<<OCF1A);       /* clear interrupt flag before enabling interrupt */
166
            TIFR1=(1<<OCF1A);       /* clear interrupt flag before enabling interrupt */
172
            TIMSK1|=(1<<OCIE1A);
167
            TIMSK1|=(1<<OCIE1A);
173
 
168
 
174
            state = ACT_DIMMMER230_STATE_TIMER_ON;
169
            state = ACT_DIMMMER230_STATE_TIMER_ON;
175
        }
170
        }
176
       
171
       
177
        /* Change the dimmerValue according to the current fading */
172
        /* Change the dimmerValue according to the current fading */
178
        fadeSpeedCnt++;
173
        fadeSpeedCnt++;
179
        if (fadeSpeedCnt == fadeSpeedFrac && dimmerValue != fadeTarget)
174
        if (fadeSpeedCnt == fadeSpeedFrac && dimmerValue != fadeTarget)
180
        {
175
        {
181
            fadeSpeedCnt = 0;
176
            fadeSpeedCnt = 0;
182
            uint8_t tempDimVal = dimmerValue;
177
            uint8_t tempDimVal = dimmerValue;
183
            dimmerValue += fadeSpeed;
178
            dimmerValue += fadeSpeed;
184
            if ((fadeSpeed > 0 && (dimmerValue < tempDimVal || dimmerValue >= fadeTarget)) ||
179
            if ((fadeSpeed > 0 && (dimmerValue < tempDimVal || dimmerValue >= fadeTarget)) ||
185
                (fadeSpeed < 0 && (dimmerValue > tempDimVal || dimmerValue <= fadeTarget)))
180
                (fadeSpeed < 0 && (dimmerValue > tempDimVal || dimmerValue <= fadeTarget)))
186
            {
181
            {
187
                dimmerValue = fadeTarget;
182
                dimmerValue = fadeTarget;
-
 
183
            }
-
 
184
           
-
 
185
            /* if targetvalue was reached then send the netinfo packet */
-
 
186
            if (dimmerValue == fadeTarget)
-
 
187
            {
-
 
188
                sendNetInfo = 1;
188
            }
189
            }
189
            /* 5 seconds after we have stopped fading we should store the current dimmerValue to eeprom */
190
            /* 5 seconds after we have stopped fading we should store the current dimmerValue to eeprom */
190
            Timer_SetTimeout(act_dimmer230_STORE_VALUE_TIMEOUT, 5000, TimerTypeOneShot, &Store_value_callback);
191
            Timer_SetTimeout(act_dimmer230_STORE_VALUE_TIMEOUT, 5000, TimerTypeOneShot, &Store_value_callback);
191
        }
192
        }
192
       
193
       
Line 261... Line 262...
261
    PCICR=(1<<act_dimmer230_ZC_PCIE);   /* enable interrupt for PCINT */
262
    PCICR=(1<<act_dimmer230_ZC_PCIE);   /* enable interrupt for PCINT */
262
 
263
 
263
    /* Setup timeout for sending the net status packet */
264
    /* Setup timeout for sending the net status packet */
264
    Timer_SetTimeout(act_dimmer230_SEND_STATUS_TIMEOUT, act_dimmer230_SEND_STATUS_INTERVAL*1000, TimerTypeFreeRunning, &Send_Status_callback);
265
    Timer_SetTimeout(act_dimmer230_SEND_STATUS_TIMEOUT, act_dimmer230_SEND_STATUS_INTERVAL*1000, TimerTypeFreeRunning, &Send_Status_callback);
265
}
266
}
-
 
267
 
266
 
268
 
267
/*  Process funtion of dimmer-module, currently everything is done interrupted */
269
/*  Process funtion of dimmer-module, currently everything is done interrupted */
268
void act_dimmer230_Process(void)
270
void act_dimmer230_Process(void)
269
{
271
{
-
 
272
    if (sendNetInfo)
270
 
273
    {
-
 
274
        sendNetInfo = 0;
-
 
275
        StdCan_Msg_t txMsg;
-
 
276
        StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_ACT);
-
 
277
        StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
-
 
278
        txMsg.Header.ModuleType = CAN_MODULE_TYPE_ACT_DIMMER230;
-
 
279
        txMsg.Header.ModuleId = act_dimmer230_ID;
-
 
280
        txMsg.Header.Command = CAN_MODULE_CMD_DIMMER230_NETINFO;
-
 
281
        txMsg.Length = 2;
-
 
282
        txMsg.Data[0] = ((netConnected&0x1)<<7 | (frequency&0x3)<<5);
-
 
283
        txMsg.Data[1] = dimmerValue;
-
 
284
        StdCan_Put(&txMsg);
-
 
285
    }
271
}
286
}
-
 
287
 
272
 
288
 
273
/*  Handle incoming message function of dimmer-module */
289
/*  Handle incoming message function of dimmer-module */
274
void act_dimmer230_HandleMessage(StdCan_Msg_t *rxMsg)
290
void act_dimmer230_HandleMessage(StdCan_Msg_t *rxMsg)
275
{
291
{
276
    if (    StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_ACT &&
292
    if (    StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_ACT &&
Line 345... Line 361...
345
                    endValue = ACT_DIMMMER230_MIN_DIM;
361
                    endValue = ACT_DIMMMER230_MIN_DIM;
346
                }
362
                }
347
                   
363
                   
348
                if (speed == 0) {
364
                if (speed == 0) {
349
                    dimmerValue = endValue; /* set dimmer value immediately */
365
                    dimmerValue = endValue; /* set dimmer value immediately */
-
 
366
                    sendNetInfo = 1;        /* send netinfo with the current dimmervalue*/
350
                } else {
367
                } else {
351
                    fadeTarget = endValue;
368
                    fadeTarget = endValue;
352
                    if (fadeTarget != dimmerValue) {
369
                    if (fadeTarget != dimmerValue) {
353
                        if ((speed&0x80) == 0x80) {
370
                        if ((speed&0x80) == 0x80) {
354
                            fadeSpeed = (speed&0x7f)+1;
371
                            fadeSpeed = (speed&0x7f)+1;
Line 367... Line 384...
367
 
384
 
368
        case CAN_MODULE_CMD_DIMMER230_STOP_FADE:    /* StopFade(channel) */
385
        case CAN_MODULE_CMD_DIMMER230_STOP_FADE:    /* StopFade(channel) */
369
            if (rxMsg->Length == 1) {
386
            if (rxMsg->Length == 1) {
370
                demoState = ACT_DIMMMER230_DEMO_STATE_NOT_RUNNING;
387
                demoState = ACT_DIMMMER230_DEMO_STATE_NOT_RUNNING;
371
                fadeSpeed = 0;
388
                fadeSpeed = 0;
-
 
389
                sendNetInfo = 1;        /* send netinfo with the current dimmervalue*/
372
            }
390
            }
373
        break;
391
        break;
374
 
392
 
375
        case CAN_MODULE_CMD_DIMMER230_ABS_FADE: /* AbsFade(channel, speed, endValue) */
393
        case CAN_MODULE_CMD_DIMMER230_ABS_FADE: /* AbsFade(channel, speed, endValue) */
376
            if (rxMsg->Length == 3) {
394
            if (rxMsg->Length == 3) {
Line 381... Line 399...
381
 
399
 
382
                fadeSpeedCnt = 0;
400
                fadeSpeedCnt = 0;
383
                fadeSpeed = 0;
401
                fadeSpeed = 0;
384
                if (speed == 0) {
402
                if (speed == 0) {
385
                    dimmerValue = endValue; /* set dimmer value immediately */
403
                    dimmerValue = endValue; /* set dimmer value immediately */
-
 
404
                    sendNetInfo = 1;        /* send netinfo with the current dimmervalue*/
386
                } else {
405
                } else {
387
                    fadeTarget = endValue;
406
                    fadeTarget = endValue;
388
                    if (fadeTarget != dimmerValue) {
407
                    if (fadeTarget != dimmerValue) {
389
                        if ((speed&0x80) == 0x80) {
408
                        if ((speed&0x80) == 0x80) {
390
                            fadeSpeed = (speed&0x7f)+1;
409
                            fadeSpeed = (speed&0x7f)+1;
Line 424... Line 443...
424
                        tempDimVal2 = ACT_DIMMMER230_MIN_DIM;
443
                        tempDimVal2 = ACT_DIMMMER230_MIN_DIM;
425
                    }
444
                    }
426
                }
445
                }
427
                if (speed == 0) {
446
                if (speed == 0) {
428
                    dimmerValue = tempDimVal2;      /* set dimmer value immediately */
447
                    dimmerValue = tempDimVal2;      /* set dimmer value immediately */
-
 
448
                    sendNetInfo = 1;                /* send netinfo with the current dimmervalue*/
429
                } else {
449
                } else {
430
                    fadeTarget = tempDimVal2;       /* set the fade target */
450
                    fadeTarget = tempDimVal2;       /* set the fade target */
431
                   
451
                   
432
                    if (fadeTarget != dimmerValue) {
452
                    if (fadeTarget != dimmerValue) {
433
                        if ((speed&0x80) == 0x80) {
453
                        if ((speed&0x80) == 0x80) {