00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "config.h"
00038 #include "platform_leds.h"
00039 #include "platform.h"
00040 #include "pic_tick.h"
00041
00042 #ifndef PLATFORM_LEDS_FLASH_TICKS
00043 #define PLATFORM_LEDS_FLASH_TICKS 250
00044 #endif
00045
00046 #ifdef led1_port
00047 uns16 led1_start_tick;
00048 bit led1_on = 0;
00049 bit led1_flashing = 0;
00050 #endif
00051
00052 #ifdef led2_port
00053 uns16 led2_start_tick;
00054 bit led2_on = 0;
00055 bit led2_flashing = 0;
00056 #endif
00057
00058 #ifdef led3_port
00059 uns16 led3_start_tick;
00060 bit led3_on = 0;
00061 bit led3_flashing = 0;
00062 #endif
00063
00064 void platform_leds_setup_io() {
00065
00066 #ifdef led1_port
00067 clear_pin(led1_port, led1_pin);
00068 make_output(led1_port, led1_pin);
00069 #endif
00070 #ifdef led2_port
00071 clear_pin(led2_port, led2_pin);
00072 make_output(led2_port, led2_pin);
00073 #endif
00074 #ifdef led3_port
00075 clear_pin(led3_port, led3_pin);
00076 make_output(led3_port, led3_pin);
00077 #endif
00078 }
00079
00080
00081 void platform_leds_flash(uns8 led) {
00082
00083 switch (led) {
00084 case 1:
00085 platform_led1_on();
00086 led1_start_tick = tick_get_count();
00087 led1_on = 1;
00088 break;
00089 #ifdef led2_port
00090 case 2:
00091 platform_led2_on();
00092 led2_start_tick = tick_get_count();
00093 led2_on = 1;
00094 break;
00095 #endif
00096 #ifdef led3_port
00097 case 3:
00098 platform_led3_on();
00099 led3_start_tick = tick_get_count();
00100 led3_on = 1;
00101 break;
00102 #endif
00103 }
00104 }
00105
00106 void platform_leds_flashing(uns8 led, uns8 enable) {
00107 switch (led) {
00108 case 1:
00109 led1_flashing = enable.0;
00110 break;
00111 #ifdef led2_port
00112 case 2:
00113 led2_flashing = enable.0;
00114 break;
00115 #endif
00116 #ifdef led3_port
00117 case 3:
00118 led3_flashing = enable.0;
00119 break;
00120 #endif
00121 }
00122 }
00123
00124 void platform_leds_process() {
00125
00126 uns16 current_tick;
00127
00128 current_tick = tick_get_count();
00129
00130 #ifdef led1_port
00131 if (led1_on || led1_flashing) {
00132 if (tick_calc_diff(led1_start_tick, current_tick) > PLATFORM_LEDS_FLASH_TICKS) {
00133 if (led1_on) {
00134 led1_on = 0;
00135 platform_led1_off();
00136 } else {
00137 led1_on = 1;
00138 platform_led1_on();
00139 }
00140 if (led1_flashing) {
00141 led1_start_tick = tick_get_count();
00142 }
00143 }
00144 }
00145 #endif
00146 #ifdef led2_port
00147 if (led2_on || led2_flashing) {
00148 if (tick_calc_diff(led2_start_tick, current_tick) > PLATFORM_LEDS_FLASH_TICKS) {
00149 if (led2_on) {
00150 led2_on = 0;
00151 platform_led2_off();
00152 } else {
00153 led2_on = 1;
00154 platform_led2_on();
00155 }
00156 if (led2_flashing) {
00157 led2_start_tick = tick_get_count();
00158 }
00159 }
00160 }
00161 #endif
00162 #ifdef led3_port
00163 if (led3_on || led1_flashing) {
00164 if (tick_calc_diff(led3_start_tick, current_tick) > PLATFORM_LEDS_FLASH_TICKS) {
00165 if (led3_on) {
00166 led3_on = 0;
00167 platform_led3_off();
00168 } else {
00169 led3_on = 1;
00170 platform_led3_on();
00171 }
00172 if (led3_flashing) {
00173 led3_start_tick = tick_get_count();
00174 }
00175 }
00176 }
00177 #endif
00178 }