Compare commits
48 Commits
Author | SHA1 | Date | |
---|---|---|---|
e8facb4f4d | |||
5d11173711 | |||
f0ca3f02b6 | |||
7464eb67e8 | |||
04ab351a79 | |||
d54970289c | |||
e6c9b03ee9 | |||
8709e0c415 | |||
1439693cf5 | |||
e1adace604 | |||
3612b4b5df | |||
7fd61af329 | |||
6f279e01d8 | |||
96f368b4f5 | |||
9d3e9ccb45 | |||
f6a63d8c5a | |||
dd224fc223 | |||
c8e8b722be | |||
941fcb8205 | |||
f34c6acec4 | |||
a7d49dbd9c | |||
f2f0b2dccb | |||
16d8cc01dc | |||
1b38c4d638 | |||
ac505afafe | |||
6c89a5b0d3 | |||
e786945b8a | |||
18f7beaf6d | |||
1ca43965b1 | |||
2db70bae65 | |||
c9462ecb16 | |||
4ab315cb0e | |||
4c542dc5d7 | |||
244791623c | |||
87e796e265 | |||
5a01c153b7 | |||
f2084052d6 | |||
9c5d6fa7d1 | |||
f6c99df275 | |||
d37cccced7 | |||
2ff6570588 | |||
715d1fb59d | |||
95f4b78eb2 | |||
118ce9b99c | |||
76308a81dc | |||
e36debccbb | |||
812ec58d0d | |||
2f3214dbeb |
@ -1,180 +1,153 @@
|
||||
//=============================================================================
|
||||
// Demo program "Light run".
|
||||
//
|
||||
// Can be run under control of the ROBO TX Controller
|
||||
// firmware in download (local) mode.
|
||||
// Switches one after another six lamps connected to the outputs O1...O6.
|
||||
//
|
||||
// Disclaimer - Exclusion of Liability
|
||||
//
|
||||
// This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE. It can be used and modified by anyone
|
||||
// free of any license obligations or authoring rights.
|
||||
//=============================================================================
|
||||
|
||||
// #include <stddef.h>
|
||||
#include "ROBO_TX_PRG.h"
|
||||
#include "ROBO_TX_FW.h"
|
||||
#include <stddef.h>
|
||||
|
||||
#define LIGHT_ON DUTY_MAX
|
||||
#define LIGHT_OFF 0
|
||||
#define LIGHT_MAX DUTY_MAX
|
||||
#define LIGHT_MIN DUTY_MIN
|
||||
#define LIGHT_OFF 0
|
||||
#define wait 10
|
||||
|
||||
#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 0
|
||||
#define END_LAMP_IDX 2
|
||||
#define COLOR_AMOUNT 3
|
||||
enum color_pin {RED, GREEN, BLUE};
|
||||
enum color_spectrum {pr, mb, pg, mr, pb, mg};
|
||||
|
||||
static unsigned long cur_time;
|
||||
static unsigned long prev_time;
|
||||
static enum {ON_1, PAUSE_1, ON_2, PAUSE_2} stage;
|
||||
static short* states[COLOR_AMOUNT];
|
||||
short green_state;
|
||||
short red_state;
|
||||
short blue_state;
|
||||
enum color_pin pin;
|
||||
enum color_spectrum spectrum_state;
|
||||
static int lamp_idx;
|
||||
static int n_loops;
|
||||
static int wait;
|
||||
|
||||
void simple_rgb_test(TA * p_ta_array);
|
||||
void spectrum();
|
||||
void update_lights(TA * p_ta_array);
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
* Function Name : PrgInit
|
||||
*
|
||||
* This it the program initialization.
|
||||
* It is called once.
|
||||
*-----------------------------------------------------------------------------*/
|
||||
void PrgInit
|
||||
(
|
||||
TA * p_ta_array, // pointer to the array of transfer areas
|
||||
int ta_count // number of transfer areas in array (equal to TA_COUNT)
|
||||
TA * p_ta_array, // pointer to the array of transfer areas
|
||||
int ta_count // number of transfer areas in array (equal to TA_COUNT)
|
||||
)
|
||||
{
|
||||
prev_time = 0;
|
||||
stage = ON_2;
|
||||
lamp_idx = BEG_LAMP_IDX;
|
||||
n_loops = 10;
|
||||
wait = 1000;
|
||||
prev_time = 0;
|
||||
red_state = LIGHT_MIN;
|
||||
green_state = LIGHT_MIN;
|
||||
blue_state = LIGHT_MIN;
|
||||
states[0] = &red_state;
|
||||
states[1] = &green_state;
|
||||
states[2] = &blue_state;
|
||||
spectrum_state = 0;
|
||||
pin = 0;
|
||||
lamp_idx = BEG_LAMP_IDX;
|
||||
}
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
* Function Name : PrgTic
|
||||
*
|
||||
* This is the main function of this program.
|
||||
* It is called every tic (1 ms) realtime.
|
||||
*-----------------------------------------------------------------------------*/
|
||||
int PrgTic
|
||||
(
|
||||
TA * p_ta_array, // pointer to the array of transfer areas
|
||||
int ta_count // number of transfer areas in array (equal to TA_COUNT)
|
||||
TA * p_ta_array, // pointer to the array of transfer areas
|
||||
int ta_count // number of transfer areas in array (equal to TA_COUNT)
|
||||
)
|
||||
{
|
||||
int rc = 0x7FFF; // return code: 0x7FFF - program should be further called by the firmware;
|
||||
// 0 - program should be normally stopped by the firmware;
|
||||
// any other value is considered by the firmware as an error code
|
||||
// and the program is stopped.
|
||||
TA * p_ta = &p_ta_array[TA_LOCAL];
|
||||
|
||||
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);
|
||||
|
||||
while (1)
|
||||
{
|
||||
switch (stage)
|
||||
{
|
||||
case ON_1:
|
||||
if (prev_time == 0)
|
||||
{
|
||||
// Switch the current lamp on
|
||||
p_ta->output.duty[lamp_idx] = LIGHT_ON;
|
||||
|
||||
// Store the current value of the system time
|
||||
prev_time = cur_time;
|
||||
}
|
||||
else
|
||||
{
|
||||
// The lamp should be on for the number of milliseconds from the variable "wait"
|
||||
if (cur_time - prev_time >= wait)
|
||||
{
|
||||
// Switch the current lamp off
|
||||
p_ta->output.duty[lamp_idx] = LIGHT_OFF;
|
||||
|
||||
if (lamp_idx + 1 <= END_LAMP_IDX)
|
||||
{
|
||||
prev_time = 0;
|
||||
lamp_idx++; // switch to the next lamp
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Store the current value of the system time
|
||||
prev_time = cur_time;
|
||||
|
||||
stage = PAUSE_1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
|
||||
case PAUSE_1:
|
||||
// All lamps should be off for the number of milliseconds from the variable "wait"
|
||||
if (cur_time - prev_time >= wait)
|
||||
{
|
||||
prev_time = 0;
|
||||
stage = ON_2;
|
||||
}
|
||||
else
|
||||
{
|
||||
return rc;
|
||||
}
|
||||
|
||||
case ON_2:
|
||||
if (prev_time == 0)
|
||||
{
|
||||
// Switch the current lamp on
|
||||
p_ta->output.duty[lamp_idx] = LIGHT_ON;
|
||||
|
||||
// Store the current value of the system time
|
||||
prev_time = cur_time;
|
||||
}
|
||||
else
|
||||
{
|
||||
// The lamp should be on for the number of milliseconds from the variable "wait"
|
||||
if (cur_time - prev_time >= wait)
|
||||
{
|
||||
// Switch the current lamp off
|
||||
p_ta->output.duty[lamp_idx] = LIGHT_OFF;
|
||||
|
||||
if (lamp_idx - 1 >= BEG_LAMP_IDX)
|
||||
{
|
||||
prev_time = 0;
|
||||
lamp_idx--; // switch to the previous lamp
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Store the current value of the system time
|
||||
prev_time = cur_time;
|
||||
|
||||
stage = PAUSE_2;
|
||||
}
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
|
||||
case PAUSE_2:
|
||||
// All lamps should be off for 1 second
|
||||
if (cur_time - prev_time >= 1000)
|
||||
{
|
||||
if (--n_loops <= 0)
|
||||
{
|
||||
rc = 0; // stop program
|
||||
}
|
||||
else
|
||||
{
|
||||
wait /= 2;
|
||||
prev_time = 0;
|
||||
stage = ON_1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
|
||||
default:
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
// if(cur_time-prev_time>=wait)
|
||||
// {
|
||||
// prev_time = cur_time;
|
||||
// simple_rgb_test(p_ta_array);
|
||||
// update_lights(p_ta_array);
|
||||
// }
|
||||
if(cur_time-prev_time>=wait)
|
||||
{
|
||||
prev_time = cur_time;
|
||||
spectrum();
|
||||
update_lights(p_ta_array);
|
||||
}
|
||||
return RC;
|
||||
}
|
||||
|
||||
void spectrum()
|
||||
{
|
||||
switch(spectrum_state)
|
||||
{
|
||||
case pr:
|
||||
if(++red_state>LIGHT_MAX) {++spectrum_state;}
|
||||
break;
|
||||
case mb:
|
||||
if(--blue_state<LIGHT_MIN) {++spectrum_state;}
|
||||
break;
|
||||
case pg:
|
||||
if(++green_state>LIGHT_MAX) {++spectrum_state;}
|
||||
break;
|
||||
case mr:
|
||||
if(--red_state<LIGHT_MIN) {++spectrum_state;}
|
||||
break;
|
||||
case pb:
|
||||
if(++blue_state>LIGHT_MAX) {++spectrum_state;}
|
||||
break;
|
||||
case mg:
|
||||
if(--green_state<LIGHT_MIN) {spectrum_state = 0;}
|
||||
break;
|
||||
default:
|
||||
spectrum_state = pr;
|
||||
}
|
||||
}
|
||||
|
||||
void simple_rgb_test
|
||||
(
|
||||
TA * p_ta_array // pointer to the array of transfer areas
|
||||
)
|
||||
{
|
||||
TA * p_ta = &p_ta_array[TA_LOCAL];
|
||||
p_ta->hook_table.DisplayMsg(p_ta, NULL);
|
||||
|
||||
switch(pin)
|
||||
{
|
||||
|
||||
case RED:
|
||||
p_ta->hook_table.DisplayMsg(p_ta, "RED");
|
||||
blue_state = LIGHT_MIN;
|
||||
red_state = LIGHT_MAX;
|
||||
pin = GREEN;
|
||||
break;
|
||||
case GREEN:
|
||||
p_ta->hook_table.DisplayMsg(p_ta, "GREEN");
|
||||
red_state = LIGHT_MIN;
|
||||
green_state = LIGHT_MAX;
|
||||
pin = BLUE;
|
||||
break;
|
||||
case BLUE:
|
||||
p_ta->hook_table.DisplayMsg(p_ta, "BLUE");
|
||||
green_state = LIGHT_MIN;
|
||||
blue_state = LIGHT_MAX;
|
||||
pin = RED;
|
||||
break;
|
||||
default:
|
||||
p_ta->hook_table.DisplayMsg(p_ta, NULL);
|
||||
pin = RED;
|
||||
}
|
||||
}
|
||||
|
||||
void update_lights(TA * p_ta_array)
|
||||
{
|
||||
TA * p_ta = &p_ta_array[TA_LOCAL];
|
||||
if(red_state>LIGHT_MAX) { red_state = LIGHT_MAX; }
|
||||
if(green_state>LIGHT_MAX) { green_state=LIGHT_MAX; }
|
||||
if(blue_state>LIGHT_MAX) { blue_state = LIGHT_MAX; }
|
||||
|
||||
if(red_state<LIGHT_MIN) { red_state = LIGHT_MIN; }
|
||||
if(green_state<LIGHT_MIN) { green_state=LIGHT_MIN; }
|
||||
if(blue_state<LIGHT_MIN) { blue_state = LIGHT_MIN; }
|
||||
|
||||
p_ta->output.duty[RED] = red_state;
|
||||
p_ta->output.duty[GREEN] = green_state;
|
||||
p_ta->output.duty[BLUE] = blue_state;
|
||||
}
|
180
Demo_C/Demo/LED/LightRun.c
Normal file
180
Demo_C/Demo/LED/LightRun.c
Normal file
@ -0,0 +1,180 @@
|
||||
//=============================================================================
|
||||
// Demo program "Light run".
|
||||
//
|
||||
// Can be run under control of the ROBO TX Controller
|
||||
// firmware in download (local) mode.
|
||||
// Switches one after another six lamps connected to the outputs O1...O6.
|
||||
//
|
||||
// Disclaimer - Exclusion of Liability
|
||||
//
|
||||
// This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE. It can be used and modified by anyone
|
||||
// free of any license obligations or authoring rights.
|
||||
//=============================================================================
|
||||
|
||||
#include "ROBO_TX_PRG.h"
|
||||
|
||||
#define LIGHT_ON DUTY_MAX
|
||||
#define LIGHT_OFF 0
|
||||
|
||||
#define BEG_LAMP_IDX 0
|
||||
#define END_LAMP_IDX 0
|
||||
|
||||
static unsigned long cur_time;
|
||||
static unsigned long prev_time;
|
||||
static enum {ON_1, PAUSE_1, ON_2, PAUSE_2} stage;
|
||||
static int lamp_idx;
|
||||
static int n_loops;
|
||||
static int wait;
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
* Function Name : PrgInit
|
||||
*
|
||||
* This it the program initialization.
|
||||
* It is called once.
|
||||
*-----------------------------------------------------------------------------*/
|
||||
void PrgInit
|
||||
(
|
||||
TA * p_ta_array, // pointer to the array of transfer areas
|
||||
int ta_count // number of transfer areas in array (equal to TA_COUNT)
|
||||
)
|
||||
{
|
||||
prev_time = 0;
|
||||
stage = ON_2;
|
||||
lamp_idx = BEG_LAMP_IDX;
|
||||
n_loops = 10;
|
||||
wait = 1000;
|
||||
}
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
* Function Name : PrgTic
|
||||
*
|
||||
* This is the main function of this program.
|
||||
* It is called every tic (1 ms) realtime.
|
||||
*-----------------------------------------------------------------------------*/
|
||||
int PrgTic
|
||||
(
|
||||
TA * p_ta_array, // pointer to the array of transfer areas
|
||||
int ta_count // number of transfer areas in array (equal to TA_COUNT)
|
||||
)
|
||||
{
|
||||
int rc = 0x7FFF; // return code: 0x7FFF - program should be further called by the firmware;
|
||||
// 0 - program should be normally stopped by the firmware;
|
||||
// any other value is considered by the firmware as an error code
|
||||
// and the program is stopped.
|
||||
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);
|
||||
|
||||
while (1)
|
||||
{
|
||||
switch (stage)
|
||||
{
|
||||
case ON_1:
|
||||
if (prev_time == 0)
|
||||
{
|
||||
// Switch the current lamp on
|
||||
p_ta->output.duty[lamp_idx] = LIGHT_ON;
|
||||
|
||||
// Store the current value of the system time
|
||||
prev_time = cur_time;
|
||||
}
|
||||
else
|
||||
{
|
||||
// The lamp should be on for the number of milliseconds from the variable "wait"
|
||||
if (cur_time - prev_time >= wait)
|
||||
{
|
||||
// Switch the current lamp off
|
||||
p_ta->output.duty[lamp_idx] = LIGHT_OFF;
|
||||
|
||||
if (lamp_idx + 1 <= END_LAMP_IDX)
|
||||
{
|
||||
prev_time = 0;
|
||||
lamp_idx++; // switch to the next lamp
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Store the current value of the system time
|
||||
prev_time = cur_time;
|
||||
|
||||
stage = PAUSE_1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
|
||||
case PAUSE_1:
|
||||
// All lamps should be off for the number of milliseconds from the variable "wait"
|
||||
if (cur_time - prev_time >= wait)
|
||||
{
|
||||
prev_time = 0;
|
||||
stage = ON_2;
|
||||
}
|
||||
else
|
||||
{
|
||||
return rc;
|
||||
}
|
||||
|
||||
case ON_2:
|
||||
if (prev_time == 0)
|
||||
{
|
||||
// Switch the current lamp on
|
||||
p_ta->output.duty[lamp_idx] = LIGHT_ON;
|
||||
|
||||
// Store the current value of the system time
|
||||
prev_time = cur_time;
|
||||
}
|
||||
else
|
||||
{
|
||||
// The lamp should be on for the number of milliseconds from the variable "wait"
|
||||
if (cur_time - prev_time >= wait)
|
||||
{
|
||||
// Switch the current lamp off
|
||||
p_ta->output.duty[lamp_idx] = LIGHT_OFF;
|
||||
|
||||
if (lamp_idx - 1 >= BEG_LAMP_IDX)
|
||||
{
|
||||
prev_time = 0;
|
||||
lamp_idx--; // switch to the previous lamp
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Store the current value of the system time
|
||||
prev_time = cur_time;
|
||||
|
||||
stage = PAUSE_2;
|
||||
}
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
|
||||
case PAUSE_2:
|
||||
// All lamps should be off for 1 second
|
||||
if (cur_time - prev_time >= 1000)
|
||||
{
|
||||
if (--n_loops <= 0)
|
||||
{
|
||||
rc = 0; // stop program
|
||||
}
|
||||
else
|
||||
{
|
||||
wait /= 2;
|
||||
prev_time = 0;
|
||||
stage = ON_1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
|
||||
default:
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
Loading…
Reference in New Issue
Block a user