Compare commits

...

48 Commits
main ... Test

Author SHA1 Message Date
Leon Wilzer e8facb4f4d spectrum 2022-11-23 18:40:54 +01:00
Leon Wilzer 5d11173711 spectrum 2022-11-23 18:40:10 +01:00
Leon Wilzer f0ca3f02b6 spectrum 2022-11-23 18:39:27 +01:00
Leon Wilzer 7464eb67e8 spectrum 2022-11-23 18:37:49 +01:00
Leon Wilzer 04ab351a79 spectrum 2022-11-23 18:36:14 +01:00
Leon Wilzer d54970289c spectrum 2022-11-23 18:34:36 +01:00
Leon Wilzer e6c9b03ee9 spectrum 2022-11-23 18:32:32 +01:00
Leon Wilzer 8709e0c415 spectrum 2022-11-23 18:31:23 +01:00
Leon Wilzer 1439693cf5 spectrum 2022-11-23 18:28:37 +01:00
Leon Wilzer e1adace604 spectrum 2022-11-23 18:26:29 +01:00
Leon Wilzer 3612b4b5df spectrum 2022-11-23 18:21:38 +01:00
Leon Wilzer 7fd61af329 spectrum 2022-11-23 18:13:08 +01:00
Leon Wilzer 6f279e01d8 spectrum 2022-11-23 18:08:47 +01:00
Leon Wilzer 96f368b4f5 spectrum 2022-11-23 18:05:40 +01:00
Leon Wilzer 9d3e9ccb45 spectrum 2022-11-23 18:03:07 +01:00
Leon Wilzer f6a63d8c5a spectrum 2022-11-23 17:58:46 +01:00
Leon Wilzer dd224fc223 spectrum 2022-11-23 17:44:04 +01:00
Leon Wilzer c8e8b722be spectrum 2022-11-23 17:43:10 +01:00
Leon Wilzer 941fcb8205 spectrum 2022-11-23 17:41:47 +01:00
Leon Wilzer f34c6acec4 spectrum 2022-11-23 17:35:45 +01:00
Leon Wilzer a7d49dbd9c spectrum 2022-11-23 17:34:54 +01:00
Leon Wilzer f2f0b2dccb spectrum 2022-11-23 17:33:47 +01:00
Leon Wilzer 16d8cc01dc spectrum 2022-11-23 17:32:15 +01:00
Leon Wilzer 1b38c4d638 spectrum 2022-11-23 17:26:24 +01:00
Leon Wilzer ac505afafe spectrum 2022-11-23 17:25:50 +01:00
Leon Wilzer 6c89a5b0d3 spectrum 2022-11-23 17:03:42 +01:00
Leon Wilzer e786945b8a spectrum 2022-11-23 17:03:13 +01:00
Leon Wilzer 18f7beaf6d spectrum 2022-11-23 17:01:56 +01:00
Leon Wilzer 1ca43965b1 spectrum 2022-11-23 17:01:18 +01:00
Leon Wilzer 2db70bae65 spectrum 2022-11-23 17:00:48 +01:00
Leon Wilzer c9462ecb16 spectrum 2022-11-23 17:00:10 +01:00
Leon Wilzer 4ab315cb0e simple rgb test 2022-11-23 16:59:06 +01:00
Leon Wilzer 4c542dc5d7 simple rgb test 2022-11-23 16:02:30 +01:00
Leon Wilzer 244791623c simple rgb test 2022-11-23 16:01:53 +01:00
Leon Wilzer 87e796e265 idk 2022-11-23 16:00:40 +01:00
Leon Wilzer 5a01c153b7 idk 2022-11-23 15:54:08 +01:00
Leon Wilzer f2084052d6 idk 2022-11-23 15:40:32 +01:00
Leon Wilzer 9c5d6fa7d1 idk 2022-11-23 15:39:35 +01:00
Leon Wilzer f6c99df275 idk 2022-11-23 15:38:34 +01:00
Leon Wilzer d37cccced7 idk 2022-11-23 15:33:38 +01:00
Leon Wilzer 2ff6570588 idk 2022-11-23 15:23:10 +01:00
Leon Wilzer 715d1fb59d idk 2022-11-23 15:18:27 +01:00
Leon Wilzer 95f4b78eb2 idk 2022-11-23 15:16:34 +01:00
Leon Wilzer 118ce9b99c idk 2022-11-23 14:58:46 +01:00
Leon Wilzer 76308a81dc idk 2022-11-23 13:47:23 +01:00
Leon Wilzer e36debccbb idk 2022-11-23 13:41:41 +01:00
Leon Wilzer 812ec58d0d idk 2022-11-23 13:40:34 +01:00
Leon Wilzer 2f3214dbeb idk 2022-11-23 13:04:41 +01:00
2 changed files with 309 additions and 156 deletions

View File

@ -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
View 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;
}