Subversion Repositories HomeAutomation

Rev

Rev 343 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 343 Rev 411
Line 18... Line 18...
18
/* system files */
18
/* system files */
19
#include <avr/interrupt.h>
19
#include <avr/interrupt.h>
20
#include <inttypes.h>
20
#include <inttypes.h>
21
#include <stdio.h>
21
#include <stdio.h>
22
#include <avr/pgmspace.h> //To allow read/write from flash
22
#include <avr/pgmspace.h> //To allow read/write from flash
-
 
23
 
-
 
24
#include <drivers/timer/timebase.h>
-
 
25
 
-
 
26
#include <config.h> // All configuration parameters
-
 
27
#include <bios.h>   // BIOS interface declarations, including CAN structure and ID defines.
23
 
28
 
24
/* lib files */
29
/* lib files */
25
#include <bios.h>
30
#include <bios.h>
26
#include <noddan_funcdefs.h>
31
#include <funcdefs/funcdefs.h>
27
 
32
 
28
/*----------------------------------------------------------------------------
33
/*----------------------------------------------------------------------------
29
 * Defines
34
 * Defines
30
 * -------------------------------------------------------------------------*/
35
 * -------------------------------------------------------------------------*/
31
 
36
 
Line 44... Line 49...
44
 
49
 
45
#define GROUP_ID    0x01L // FIXME
50
#define GROUP_ID    0x01L // FIXME
46
#define TRUE 1
51
#define TRUE 1
47
#define FALSE !TRUE
52
#define FALSE !TRUE
48
 
53
 
49
 
54
 
50
/*----------------------------------------------------------------------------
55
/*----------------------------------------------------------------------------
51
 * Ehm, struct?
56
 * Ehm, struct?
52
 * -------------------------------------------------------------------------*/
57
 * -------------------------------------------------------------------------*/
53
typedef struct
58
typedef struct
54
{
59
{
55
    uint8_t R;
60
    uint8_t R;
56
    uint8_t G;
61
    uint8_t G;
57
    uint8_t B;
62
    uint8_t B;
58
    uint8_t Intens;
63
    uint8_t Intens;
59
} Color;
64
} Color;
60
 
65
 
61
/*-----------------------------------------------------------------------------
66
/*-----------------------------------------------------------------------------
62
 * Programs! There will be a better way to add programs here.. some day.
67
 * Programs! There will be a better way to add programs here.. some day.
63
 *---------------------------------------------------------------------------*/
68
 *---------------------------------------------------------------------------*/
64
 
69
 
65
//Special combinations that means something special
70
//Special combinations that means something special
66
//The combinations are useless for lighting anyway
71
//The combinations are useless for lighting anyway
Line 138... Line 143...
138
        act_type = (act & ACT_TYPE_MASK) >> ACT_TYPE_BITS;
143
        act_type = (act & ACT_TYPE_MASK) >> ACT_TYPE_BITS;
139
        group = (act & ACT_GROUP_MASK) >> ACT_GROUP_BITS;
144
        group = (act & ACT_GROUP_MASK) >> ACT_GROUP_BITS;
140
        node = (act & ACT_NODE_MASK) >> ACT_NODE_BITS;
145
        node = (act & ACT_NODE_MASK) >> ACT_NODE_BITS;
141
 
146
 
142
        /* Check if it is command to control this servo */
147
        /* Check if it is command to control this servo */
143
        if(act_type == ACT_TYPE_RGB){
148
        if(act_type == ACT_TYPE_RGBLED){
144
            if(group == GROUP_ID || node == NODE_ID){
149
            if(group == GROUP_ID || node == NODE_ID){
145
                for(m=0;m<msg->DataLength;m++){
150
                for(m=0;m<msg->DataLength;m++){
146
                    rxMsg.Data.bytes[m] = msg->Data.bytes[m];
151
                    rxMsg.Data.bytes[m] = msg->Data.bytes[m];
147
                }
152
                }
148
                msg_received = TRUE;
153
                msg_received = TRUE;
Line 178... Line 183...
178
    dimSpeed = 10;
183
    dimSpeed = 10;
179
    timeStamp = 0;
184
    timeStamp = 0;
180
    dimStamp = 0;
185
    dimStamp = 0;
181
 
186
 
182
    reformatRGB(0x00,0x00,0x00,1);
187
    reformatRGB(0x00,0x00,0x00,1);
183
    destColor.Intens = 100;
188
    destColor.Intens = 50;
184
    currColor = destColor;
189
    currColor = destColor;
185
 
190
 
186
//Just temporary for now, they keep track of some kind of demo-program.
191
//Just temporary for now, they keep track of some kind of demo-program.
187
    currProgram = 1;
192
    currProgram = 1;
188
    programMode = 0;
193
    programMode = 0;
189
    uint16_t temp_adress = pgm_read_word(&programs[currProgram-1]); //Get adress for program 0
194
    uint16_t temp_adress = pgm_read_word(&programs[currProgram-1]); //Get adress for program 0
190
 
195
 
191
    sei();
196
    sei();
192
 
197
 
193
    bios->can_callback = &can_receive;
198
    BIOS_CanCallback = &can_receive;
194
 
199
 
195
//Send a message that we are alive!
200
//Send a message that we are alive!
196
    txMsg.Id = (CAN_NMT_APP_START << CAN_SHIFT_NMT_TYPE) | (NODE_ID << CAN_SHIFT_NMT_SID);
201
    txMsg.Id = (CAN_NMT_APP_START << CAN_SHIFT_NMT_TYPE) | (NODE_ID << CAN_SHIFT_NMT_SID);
197
    txMsg.DataLength = 4;
202
    txMsg.DataLength = 4;
198
    txMsg.RemoteFlag = 0;
203
    txMsg.RemoteFlag = 0;
199
    txMsg.ExtendedFlag = 1;
204
    txMsg.ExtendedFlag = 1;
200
    txMsg.Data.words[0] = APP_TYPE;
205
    txMsg.Data.words[0] = APP_TYPE;
201
    txMsg.Data.words[1] = APP_VERSION;
206
    txMsg.Data.words[1] = APP_VERSION;
202
    bios->can_send(&txMsg);
207
    BIOS_CanSend(&txMsg);
-
 
208
 
-
 
209
//Lets get timebase up and running
-
 
210
    Timebase_Init();
203
 
211
 
204
 
212
 
205
    /* main loop */
213
    /* main loop */
206
    while (1) {
214
    while (1) {
207
       
215
       
208
        /* Time to fade color? */
216
        /* Time to fade color? */
209
        if ((bios->timebase_get() - timeStamp) >= fadeSpeed) {
217
        if ((Timebase_CurrentTime() - timeStamp) >= fadeSpeed) {
210
            fade(&currColor.R, &destColor.R);          
218
            fade(&currColor.R, &destColor.R);          
211
            fade(&currColor.G, &destColor.G);
219
            fade(&currColor.G, &destColor.G);
212
            fade(&currColor.B, &destColor.B);
220
            fade(&currColor.B, &destColor.B);
213
 
221
 
214
            timeStamp = bios->timebase_get();
222
            timeStamp = Timebase_CurrentTime();
215
            updateLED();
223
            updateLED();
216
        }
224
        }
217
 
225
 
218
 
226
 
219
        /* Time to fade intensity? */
227
        /* Time to fade intensity? */
220
        if (bios->timebase_get() - dimStamp >= dimSpeed) {
228
        if (Timebase_CurrentTime() - dimStamp >= dimSpeed) {
221
            fade(&currColor.Intens, &destColor.Intens);
229
            fade(&currColor.Intens, &destColor.Intens);
222
            dimStamp = bios->timebase_get();
230
            dimStamp = Timebase_CurrentTime();
223
            updateLED();
231
            updateLED();
224
        }
232
        }
225
 
233
 
226
 
234
 
227
        /* Program management */
235
        /* Program management */
Line 249... Line 257...
249
                    temp_adress = temp_adress + 4;             
257
                    temp_adress = temp_adress + 4;             
250
                }
258
                }
251
 
259
 
252
            }
260
            }
253
 
261
 
254
        }
262
        }
255
 
263
 
256
        /* check if any messages have been received */
264
        /* check if any messages have been received */
257
        if(msg_received){
265
        if(msg_received){
258
            /* This node that controls a RGB LED is adressed */
266
            /* This node that controls a RGB LED is adressed */
259
            if( rxMsg.Data.bytes[0] == RGBLED_CMD_SETPROGRAM ){
267
            if( rxMsg.Data.bytes[0] == RGBLED_CMD_SETPROGRAM ){
260
                /* Set a program! */
268
                /* Set a program! */
Line 309... Line 317...
309
    tempcontainer = currColor.R * currColor.Intens / 255;   //I really want to skip this, don't know how yet though.
317
    tempcontainer = currColor.R * currColor.Intens / 255;   //I really want to skip this, don't know how yet though.
310
    OCR1A = tempcontainer; 
318
    OCR1A = tempcontainer; 
311
      OCR0A = currColor.G * currColor.Intens / 255;
319
      OCR0A = currColor.G * currColor.Intens / 255;
312
    OCR0B = currColor.B * currColor.Intens / 255;      
320
    OCR0B = currColor.B * currColor.Intens / 255;      
313
 
321
 
314
/*     
322
       
315
    //Bara för debugcrap
323
    //Bara för debugcrap
316
    Can_Message_t txMsg;
324
    Can_Message_t txMsg;
317
    txMsg.Id = 0x55;
325
    txMsg.Id = 0x55;
318
    txMsg.RemoteFlag = 0;
326
    txMsg.RemoteFlag = 0;
319
    txMsg.ExtendedFlag = 1;
327
    txMsg.ExtendedFlag = 1;
Line 321... Line 329...
321
    txMsg.Data.bytes[0] = currColor.R;
329
    txMsg.Data.bytes[0] = currColor.R;
322
    txMsg.Data.bytes[1] = currColor.G;
330
    txMsg.Data.bytes[1] = currColor.G;
323
    txMsg.Data.bytes[2] = currColor.B;
331
    txMsg.Data.bytes[2] = currColor.B;
324
    txMsg.Data.bytes[3] = currColor.Intens;
332
    txMsg.Data.bytes[3] = currColor.Intens;
325
 
333
 
326
    bios->can_send(&txMsg);
334
    BIOS_CanSend(&txMsg);
327
*/
335
 
328
}
336
}
329
 
337
 
330
 
338
 
331
 
339
 
332
/************************************************************************************************
340
/************************************************************************************************