Subversion Repositories HomeAutomation

Rev

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

Rev 302 Rev 304
Line 37... Line 37...
37
 
37
 
38
/*-----------------------------------------------------------------------------
38
/*-----------------------------------------------------------------------------
39
 * Programs! This will most likely be improooved, but I have to start somewhere.
39
 * Programs! This will most likely be improooved, but I have to start somewhere.
40
 *---------------------------------------------------------------------------*/
40
 *---------------------------------------------------------------------------*/
41
 
41
 
-
 
42
//0x00, 0x00, 0x00, 0x00 means end of program. This combination is useless for lighting anyway.
42
/*
43
 
43
struct Color pgm1[] = {
44
Color pgm1[] PROGMEM = {
-
 
45
{0xff,0x00,0x00,0x00},
-
 
46
{0xff,0xff,0x00,0x00},
44
{0x10,0x20,0x30,0x40},
47
{0x00,0xff,0x00,0x00},
-
 
48
{0x00,0xff,0xff,0x00},
45
{0x10,0x20,0x30,0x40},
49
{0x00,0x00,0xff,0x00},
-
 
50
{0xff,0x00,0xff,0x00},
46
{0x10,0x20,0x30,0x40}
51
{0x00,0x00,0x00,0x00}
47
};
52
};
48
 
53
 
49
struct Color pgm2[] = {
54
Color pgm2[] PROGMEM = {
50
{0x20,0x20,0x30,0x50},
55
{0x20,0x20,0x30,0x50},
51
{0x20,0x20,0x30,0x50},
56
{0x20,0x20,0x30,0x50},
52
{0x20,0x20,0x30,0x50}
57
{0x20,0x20,0x30,0x50}
53
};
58
};
54
 
59
 
55
struct Color* programs[] PROGMEM = {
60
Color* programs[] PROGMEM = {
56
(struct Color*)pgm1,
61
(Color*)pgm1,
57
(struct Color*)pgm2
62
(Color*)pgm2
58
};
63
};
59
 
64
 
60
 
65
 
61
uint16_t temp_address = pgm_read_word(&programs[1]);
-
 
62
*/
-
 
63
 
66
 
64
/*-----------------------------------------------------------------------------
67
/*-----------------------------------------------------------------------------
65
 * Variables
68
 * Variables
66
 *---------------------------------------------------------------------------*/
69
 *---------------------------------------------------------------------------*/
67
uint32_t timeStamp; //TimeStamp to keep track of time
70
uint32_t timeStamp; //TimeStamp to keep track of time
Line 89... Line 92...
89
 
92
 
90
/*-----------------------------------------------------------------------------
93
/*-----------------------------------------------------------------------------
91
 * Main Program
94
 * Main Program
92
 *---------------------------------------------------------------------------*/
95
 *---------------------------------------------------------------------------*/
93
int main(void) {
96
int main(void) {
-
 
97
 
94
    Timebase_Init();
98
    Timebase_Init();
95
    Serial_Init();
99
    Serial_Init();
96
    Can_Init();
100
    Can_Init();
97
 
101
 
98
//Setting up OC1A, 16 bit counter used as 8 bit.
102
//Setting up OC1A, 16 bit counter used as 8 bit.
Line 126... Line 130...
126
    currColor = destColor;
130
    currColor = destColor;
127
 
131
 
128
//Just temporary for now, they keep track of some kind of demo-program.
132
//Just temporary for now, they keep track of some kind of demo-program.
129
    program = 1;
133
    program = 1;
130
    temp = 1;
134
    temp = 1;
-
 
135
    uint16_t temp_adress = pgm_read_word(&programs[0]); //Get adress for program 0
131
 
136
 
132
 
137
 
133
    sei();
138
    sei();
134
 
139
 
135
    /* main loop */
140
    /* main loop */
136
    while (1) {
141
    while (1) {
137
        /* service the CAN routines */
142
        /* service the CAN routines */
138
        Can_Service();
143
        Can_Service();
139
 
144
 
Line 164... Line 169...
164
        }
169
        }
165
 
170
 
166
        /* Just a nice fade-demo */
171
        /* Just a nice fade-demo */
167
        if ((Timebase_PassedTimeMillis(tempStamp) >= 2500)&(program == 1)) {
172
        if ((Timebase_PassedTimeMillis(tempStamp) >= 2500)&(program == 1)) {
168
            tempStamp = Timebase_CurrentTime();
173
            tempStamp = Timebase_CurrentTime();
169
           
-
 
170
            switch(temp){
-
 
171
            case 1:
-
 
172
                reformatRGB(0xff,0x00,0x00,0);
-
 
173
                break;
-
 
174
            case 2:
-
 
175
                reformatRGB(0xff,0xff,0x00,0);
174
            reformatRGB(pgm_read_byte(temp_adress),pgm_read_byte(temp_adress + 1),pgm_read_byte(temp_adress + 2),0);
176
                break;
-
 
177
            case 3:
-
 
178
                reformatRGB(0x00,0xff,0x00,0);
-
 
179
                break;
-
 
180
            case 4:
-
 
181
                reformatRGB(0x00,0xff,0xff,0);
-
 
182
                break;
-
 
183
            case 5:
-
 
184
                reformatRGB(0x00,0x00,0xff,0);
-
 
185
                break;
-
 
186
            case 6:
-
 
187
                reformatRGB(0xff,0x00,0xff,0);
175
            temp_adress = temp_adress + 4;
188
                temp = 255;
-
 
189
                break;
-
 
190
            }
-
 
191
            temp++;
-
 
192
               
-
 
193
        }
176
        }
194
 
177
 
195
 
178
 
196
        /* check if any messages have been received */
179
        /* check if any messages have been received */
197
        /* A lot of remote control crap going on here now for testing */
180
        /* A lot of remote control crap going on here now for testing */
198
        while (Can_Receive(&rxMsg) == CAN_OK) {
181
        while (Can_Receive(&rxMsg) == CAN_OK) {
199
            if ((rxMsg.Data.bytes[0] == 0x0)&(rxMsg.Data.bytes[3] == 0x20)){
182
            if ((rxMsg.Data.bytes[0] == 0x0)&(rxMsg.Data.bytes[3] == 0x20)){
200
                program = 1;
183
                program = 1;
201
                fadeSpeed = 0;
184
                fadeSpeed = 0;
202
            }
185
            }
203
 
186
 
204
            if ((rxMsg.Data.bytes[0] == 0x0)&(rxMsg.Data.bytes[3] == 0x21)){
187
            if ((rxMsg.Data.bytes[0] == 0x0)&(rxMsg.Data.bytes[3] == 0x21)){
205
                program = 2;
188
                program = 2;
206
                fadeSpeed = 0;
189
                fadeSpeed = 0;
207
            }
190
            }
208
        }
191
        }
209
 
-
 
210
 
192
 
211
    }
193
    }
212
   
194
   
213
    return 0;
195
    return 0;
214
}
196
}