Subversion Repositories Code-Repo

Rev

Rev 263 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 263 Rev 264
Line 180... Line 180...
180
    TIMER5_DATA timer_5_data;
180
    TIMER5_DATA timer_5_data;
181
    TIMER5_Init(&timer_5_data, &Cube_Timer_Interrupt, 500);
181
    TIMER5_Init(&timer_5_data, &Cube_Timer_Interrupt, 500);
182
 
182
 
183
    // Start the controller polling and overlay rotation interrupt
183
    // Start the controller polling and overlay rotation interrupt
184
    TIMER4_DATA timer_4_data;
184
    TIMER4_DATA timer_4_data;
185
    TIMER4_Init(&timer_4_data, &Controller_Update, NULL, 0);
185
    TIMER4_Init(&timer_4_data, NULL, NULL, 0);
186
 
186
 
187
    // Process button inputs
187
    // Process button inputs
188
    BTN_DATA btn_data;
188
    BTN_DATA btn_data;
189
    BTN_Init(&btn_data, &BTN1_Interrupt, &BTN2_Interrupt, NULL);
189
    BTN_Init(&btn_data, &BTN1_Interrupt, &BTN2_Interrupt, NULL);
190
 
190
 
191
    // Initialize controllers
191
    // Initialize controllers
192
    CONTROLLER_DATA ctrl_data;
192
    CONTROLLER_DATA ctrl_data;
193
    Controller_Init(&ctrl_data, NULL);
193
    Controller_Init(&ctrl_data, NULL);
194
 
194
 
195
    // Initialize the Ethernet module
195
    // Initialize the Ethernet module
-
 
196
    if (op_state == BOARD_MODE_ETHERNET) {
196
    ETH_DATA eth_data;
197
        ETH_DATA eth_data;
197
    ETH_Init(&eth_data, NULL, &Cube_Ethernet_Frame_In);
198
        ETH_Init(&eth_data, NULL, &Cube_Ethernet_Frame_In);
-
 
199
    }
198
    
200
    
199
    SNAKE_DATA snake_data;
201
    SNAKE_DATA snake_data;
200
    TRON_DATA tron_data;
202
    TRON_DATA tron_data;
201
 
203
 
202
    PWM2_Start();
204
    PWM2_Start();
203
    TIMER5_Start();
205
    TIMER5_Start();
204
    TIMER4_Start();
-
 
205
    
206
    
206
    /* -------------------- END OF INITIALIZATION -------------------- */
207
    /* -------------------- END OF INITIALIZATION -------------------- */
207
    /* ------------------------ BEGIN DISPLAY ------------------------ */
208
    /* ------------------------ BEGIN DISPLAY ------------------------ */
208
 
209
 
209
    // Figure out what state to go into here
210
    // Figure out what to do at this point (depending on current state)
210
    switch (op_state) {
211
    switch (op_state) {
211
        case BOARD_MODE_IDLE:
212
        case BOARD_MODE_IDLE:
212
            Idle_Animation_Sequence();
213
            Idle_Animation_Sequence();
213
            break;
214
            break;
214
        case BOARD_MODE_SNAKE:;
215
        case BOARD_MODE_SNAKE:;
215
            Controller_Init(&ctrl_data, &Snake_Update_Direction);
216
            Controller_Init(&ctrl_data, &Snake_Update_Direction);
-
 
217
            TIMER4_Init(NULL, &Controller_Update, NULL, 0);
-
 
218
            TIMER4_Start();
216
            Snake_Init(&snake_data);
219
            Snake_Init(&snake_data);
217
            Snake_Main();
220
            Snake_Main();
218
            break;
221
            break;
219
        case BOARD_MODE_TRON:
222
        case BOARD_MODE_TRON:
220
            Controller_Init(&ctrl_data, &Tron_Update_Direction);
223
            Controller_Init(&ctrl_data, &Tron_Update_Direction);
-
 
224
            TIMER4_Init(NULL, &Controller_Update, NULL, 0);
-
 
225
            TIMER4_Start();
221
            Tron_Init(&tron_data);
226
            Tron_Init(&tron_data);
222
            Tron_Main();
227
            Tron_Main();
223
            break;
228
            break;
224
        case BOARD_MODE_ETHERNET:
229
        case BOARD_MODE_ETHERNET:
225
            TIMER4_Stop();
230
            TIMER4_Stop();
Line 228... Line 233...
228
    }
233
    }
229
 
234
 
230
}
235
}
231
 
236
 
232
void Idle_Animation_Sequence(void) {
237
void Idle_Animation_Sequence(void) {
233
      Delay_MS(250);
-
 
234
 
238
 
235
//    Cube_Set_All(RED);
239
//    Cube_Set_All(RED);
236
//    Delay_MS(2000);
240
//    Delay_MS(2000);
237
//    Cube_Set_All(GREEN);
241
//    Cube_Set_All(GREEN);
238
//    Delay_MS(2000);
242
//    Delay_MS(2000);
Line 245... Line 249...
245
//    Animation_Pseudo_Random_Colors(200);
249
//    Animation_Pseudo_Random_Colors(200);
246
//    Animation_Pseudo_Random_Colors(200);
250
//    Animation_Pseudo_Random_Colors(200);
247
 
251
 
248
    // Start the scrolling text
252
    // Start the scrolling text
249
    TIMER4_Stop();
253
    TIMER4_Stop();
250
    TIMER4_Init(NULL, &Controller_Update, &Cube_Text_Interrupt, 100);
254
    TIMER4_Init(NULL, NULL, &Cube_Text_Interrupt, 100);
251
//    TIMER4_Start();
255
//    TIMER4_Start();
252
 
256
 
253
//    int8_t start_text[] = "Cube Initialized\r\n";
257
//    int8_t start_text[] = "Cube Initialized\r\n";
254
//    UART1_Write(start_text, 18);
258
//    UART1_Write(start_text, 18);
255
 
259
 
Line 257... Line 261...
257
    uint8_t text_string[] = "Welcome to the CCM Lab     ";
261
    uint8_t text_string[] = "Welcome to the CCM Lab     ";
258
    Cube_Text_Init(text_string, 27, 0xFF, 0xFF, 0xFF);
262
    Cube_Text_Init(text_string, 27, 0xFF, 0xFF, 0xFF);
259
 
263
 
260
    // Loop through some preset animations
264
    // Loop through some preset animations
261
    while(1) {
265
    while(1) {
-
 
266
 
-
 
267
        Animation_Sawtooth(100);
-
 
268
        Animation_Sawtooth(100);
-
 
269
        Animation_Sawtooth(100);
-
 
270
        Animation_Sphere(100);
-
 
271
        Animation_Sphere(100);
-
 
272
        Animation_Sphere(100);
-
 
273
        Animation_Sphere(100);
-
 
274
        Animation_Wave1(100);
-
 
275
        Animation_Wave1(100);
-
 
276
        Animation_Wave1(100);
-
 
277
        Animation_Wave1(100);
-
 
278
        Animation_Wave2(100);
-
 
279
        Animation_Wave2(100);
-
 
280
        Animation_Wave2(100);
-
 
281
        Animation_Wave2(100);
262
//        Animation_Solid_Colors(300);
282
//        Animation_Solid_Colors(300);
263
//        Animation_Layer_Alternate(300);
283
//        Animation_Layer_Alternate(300);
264
//        Animation_Pixel_Alternate(200);
284
//        Animation_Pixel_Alternate(200);
265
//        Animation_Full_Color_Sweep(1000);
285
//        Animation_Full_Color_Sweep(1000);
266
        Animation_Row_Column_Sweep(40);
286
        Animation_Row_Column_Sweep(40);
267
        Animation_Row_Column_Sweep(40);
287
        Animation_Row_Column_Sweep(40);
268
        Animation_Row_Column_Sweep(40);
-
 
269
        Animation_Cube_In_Cube(300);
288
        Animation_Cube_In_Cube(300);
270
        Animation_Cube_In_Cube(300);
289
        Animation_Cube_In_Cube(300);
271
        Animation_Cube_In_Cube(300);
290
        Animation_Cube_In_Cube(300);
272
        Animation_Double_Rotation(40);
291
        Animation_Double_Rotation(30);
273
        Animation_Double_Rotation(40);
292
        Animation_Double_Rotation(30);
-
 
293
        Animation_Pseudo_Random_Colors(300);
-
 
294
        Animation_Pseudo_Random_Colors(300);
-
 
295
        Animation_Pseudo_Random_Colors(300);
-
 
296
        Animation_Pseudo_Random_Colors(300);
-
 
297
        Animation_Pseudo_Random_Colors(300);
-
 
298
        Animation_Pseudo_Random_Colors(300);
-
 
299
        Animation_Pseudo_Random_Colors(300);
-
 
300
        Animation_Pseudo_Random_Colors(300);
274
        Animation_Double_Rotation(40);
301
        Animation_Pseudo_Random_Colors(300);
275
//        Animation_Pseudo_Random_Colors(300);
302
        Animation_Pseudo_Random_Colors(300);
276
//        Animation_Random_Colors(300);
303
//        Animation_Random_Colors(300);
277
 
304
 
278
//        ClearWDT(); // Clear the WDT if we dont want the board to reset
305
//        ClearWDT(); // Clear the WDT if we dont want the board to reset
279
    }
306
    }
280
}
307
}
281
 
308
 
282
// Function call on button 1 press to change refresh rate
309
// Function call on button 1 press to change cube operation
283
void BTN1_Interrupt(void) {
310
void BTN1_Interrupt(void) {
284
    static uint8_t state;
-
 
285
    state = (state == 4) ? 0 : state + 1;
-
 
286
    TIMER5_Stop();
-
 
287
    switch (state) {
311
    switch (op_state) {
288
        case 0:
312
        case BOARD_MODE_IDLE:
289
            TIMER5_Init(NULL, &Cube_Timer_Interrupt, 500); // 250Hz
-
 
290
            break;
313
            Reset_Board(BOARD_MODE_SNAKE);
291
        case 1:
-
 
292
            TIMER5_Init(NULL, &Cube_Timer_Interrupt, 2083); // 60Hz
-
 
293
            break;
314
            break;
294
        case 2:
315
        case BOARD_MODE_SNAKE:
295
            TIMER5_Init(NULL, &Cube_Timer_Interrupt, 4166); // 30Hz
316
            Reset_Board(BOARD_MODE_TRON);
296
            break;
317
            break;
297
        case 3:
318
        case BOARD_MODE_TRON:
298
            TIMER5_Init(NULL, &Cube_Timer_Interrupt, 12498); // 10Hz
319
            Reset_Board(BOARD_MODE_ETHERNET);
299
            break;
320
            break;
300
        case 4:
321
        case BOARD_MODE_ETHERNET:
301
            TIMER5_Init(NULL, &Cube_Timer_Interrupt, 24996); // 5Hz
322
            Reset_Board(BOARD_MODE_IDLE);
302
            break;
323
            break;
303
    }
324
    }
-
 
325
 
-
 
326
    // Code to change refresh rate on button press
-
 
327
//    static uint8_t state;
-
 
328
//    state = (state == 4) ? 0 : state + 1;
-
 
329
//    TIMER5_Stop();
-
 
330
//    switch (state) {
-
 
331
//        case 0:
-
 
332
//            TIMER5_Init(NULL, &Cube_Timer_Interrupt, 500); // 250Hz
-
 
333
//            break;
-
 
334
//        case 1:
-
 
335
//            TIMER5_Init(NULL, &Cube_Timer_Interrupt, 2083); // 60Hz
-
 
336
//            break;
-
 
337
//        case 2:
-
 
338
//            TIMER5_Init(NULL, &Cube_Timer_Interrupt, 4166); // 30Hz
-
 
339
//            break;
-
 
340
//        case 3:
-
 
341
//            TIMER5_Init(NULL, &Cube_Timer_Interrupt, 12498); // 10Hz
-
 
342
//            break;
-
 
343
//        case 4:
-
 
344
//            TIMER5_Init(NULL, &Cube_Timer_Interrupt, 24996); // 5Hz
-
 
345
//            break;
-
 
346
//    }
304
    TIMER5_Start();
347
//    TIMER5_Start();
305
}
348
}
306
 
349
 
307
// Function call on button 2 press to change brightness
350
// Function call on button 2 press to change brightness
308
void BTN2_Interrupt(void) {
351
void BTN2_Interrupt(void) {
309
    static uint8_t state;
352
    static uint8_t state = 6;
310
    state = (state == 6) ? 0 : state + 1;
353
    state = (state == 6) ? 0 : state + 1;
311
    TIMER5_Stop();
354
    TIMER5_Stop();
312
    Delay_MS(1); // Need to wait for all SPI writes to complete
355
    Delay_MS(1); // Need to wait for all SPI writes to complete
313
    uint8_t BC;
356
    uint8_t BC;
314
    switch (state) {
357
    switch (state) {