simple rgb test
This commit is contained in:
parent
4c542dc5d7
commit
4ab315cb0e
@ -1,24 +1,36 @@
|
||||
#include <stddef.h>
|
||||
#include<stdio.h>
|
||||
#include "ROBO_TX_PRG.h"
|
||||
#include "ROBO_TX_FW.h"
|
||||
|
||||
#define LIGHT_MAX DUTY_MAX
|
||||
#define LIGHT_MIN DUTY_MIN
|
||||
#define LIGHT_OFF 0
|
||||
|
||||
#define RC 0x7FFF // return code: 0x7FFF - program should be further called by the firmware;
|
||||
#define sRC 0
|
||||
|
||||
#define BEG_LAMP_IDX 0
|
||||
#define END_LAMP_IDX 3
|
||||
#define END_LAMP_IDX 2
|
||||
#define COLOR_AMOUNT 3
|
||||
enum color_pin {GREEN, RED, BLUE};
|
||||
enum spectrum_transisition {g, bg, r, gr, b, rb};
|
||||
|
||||
static unsigned long cur_time;
|
||||
static unsigned long prev_time;
|
||||
enum color_pin {GREEN, RED, BLUE};
|
||||
static short* states[COLOR_AMOUNT];
|
||||
short green_state;
|
||||
short red_state;
|
||||
short blue_state;
|
||||
enum color_pin pin;
|
||||
enum spectrum_transisition spectrum_state;
|
||||
static int lamp_idx;
|
||||
static int n_loops;
|
||||
static int wait;
|
||||
|
||||
int simple_rgb_test(TA * p_ta_array);
|
||||
void simple_rgb_test(TA * p_ta_array);
|
||||
void spectrum(TA * p_ta_array);
|
||||
void update_lights(TA * p_ta_array);
|
||||
|
||||
void PrgInit
|
||||
(
|
||||
@ -27,6 +39,13 @@ void PrgInit
|
||||
)
|
||||
{
|
||||
prev_time = 0;
|
||||
green_state = LIGHT_MIN;
|
||||
red_state = LIGHT_MIN;
|
||||
blue_state = LIGHT_MIN;
|
||||
states[0] = &green_state;
|
||||
states[1] = &red_state;
|
||||
states[2] = &blue_state;
|
||||
spectrum_state = g;
|
||||
pin = GREEN;
|
||||
lamp_idx = BEG_LAMP_IDX;
|
||||
n_loops = 10;
|
||||
@ -39,39 +58,72 @@ int PrgTic
|
||||
int ta_count // number of transfer areas in array (equal to TA_COUNT)
|
||||
)
|
||||
{
|
||||
return simple_rgb_test(p_ta_array);
|
||||
// Get the current value of the system time
|
||||
cur_time = p_ta->hook_table.GetSystemTime(TIMER_UNIT_MILLISECONDS);
|
||||
// if(cur_time-prev_time>=wait)
|
||||
// {
|
||||
// simple_rgb_test(p_ta_array);
|
||||
// }
|
||||
if(cur_time-prev_time>=wait*0.1)
|
||||
{
|
||||
spectrum(int *p_ta_array);
|
||||
}
|
||||
update_lights(int *p_ta_array);
|
||||
return RC;
|
||||
}
|
||||
|
||||
int simple_rgb_test
|
||||
void spectrum(TA * p_ta_array)
|
||||
{
|
||||
switch(spectrum_state)
|
||||
{
|
||||
case g:
|
||||
if(++green_state>=LIGHT_MAX) { spectrum_state = bg; }
|
||||
break;
|
||||
case bg:
|
||||
if(--blue_state<=LIGHT_MIN) { spectrum_state = r; }
|
||||
break;
|
||||
case r:
|
||||
if(++red_state>=LIGHT_MAX) { spectrum_state = gr; }
|
||||
break;
|
||||
case gr:
|
||||
if(--green_state<=LIGHT_MIN) { spectrum_state = b; }
|
||||
break;
|
||||
case b:
|
||||
if(++blue_state>=LIGHT_MAX) { spectrum_state = rb; }
|
||||
break;
|
||||
case rb:
|
||||
if(--red_state<=LIGHT_MIN) { spectrum_state = g; }
|
||||
}
|
||||
}
|
||||
|
||||
void simple_rgb_test
|
||||
(
|
||||
TA * p_ta_array // pointer to the array of transfer areas
|
||||
)
|
||||
{
|
||||
TA * p_ta = &p_ta_array[TA_LOCAL];
|
||||
|
||||
// Get the current value of the system time
|
||||
cur_time = p_ta->hook_table.GetSystemTime(TIMER_UNIT_MILLISECONDS);
|
||||
if(cur_time-prev_time>=wait)
|
||||
{
|
||||
prev_time = cur_time;
|
||||
p_ta->hook_table.DisplayMsg(p_ta, NULL);
|
||||
|
||||
p_ta->output.duty[pin] = LIGHT_MAX;
|
||||
*states[pin] = LIGHT_MAX;
|
||||
switch(pin)
|
||||
{
|
||||
case GREEN:
|
||||
p_ta->hook_table.DisplayMsg(p_ta, "GREEN");
|
||||
p_ta->output.duty[BLUE] = LIGHT_OFF;
|
||||
blue_state = LIGHT_MIN;
|
||||
pin = RED;
|
||||
break;
|
||||
case RED:
|
||||
p_ta->hook_table.DisplayMsg(p_ta, "RED");
|
||||
p_ta->output.duty[GREEN] = LIGHT_OFF;
|
||||
blue_state = LIGHT_MIN;
|
||||
pin = BLUE;
|
||||
break;
|
||||
case BLUE:
|
||||
p_ta->hook_table.DisplayMsg(p_ta, "BLUE");
|
||||
p_ta->output.duty[RED] = LIGHT_OFF;
|
||||
blue_state = LIGHT_MIN;
|
||||
pin = GREEN;
|
||||
break;
|
||||
default:
|
||||
@ -79,5 +131,18 @@ int simple_rgb_test
|
||||
pin = GREEN;
|
||||
}
|
||||
}
|
||||
return RC;
|
||||
|
||||
void update_lights(TA * p_ta_array)
|
||||
{
|
||||
if(green_state>LIGHT_MAX) { green_state=LIGHT_MAX; }
|
||||
if(red_state>LIGHT_MAX) { red_state = LIGHT_MAX; }
|
||||
if(blue_state>LIGHT_MAX) { blue_state = LIGHT_MAX; }
|
||||
|
||||
if(green_state<LIGHT_MIN) { green_state=LIGHT_MIN; }
|
||||
if(red_state<LIGHT_MIN) { red_state = LIGHT_MIN; }
|
||||
if(blue_state<LIGHT_MIN) { blue_state = LIGHT_MIN; }
|
||||
|
||||
p_ta->output.duty[GREEN] = green_state;
|
||||
p_ta->output.duty[RED] = red_state;
|
||||
p_ta->output.duty[BLUE] = blue_state;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user