bosko lekovic
/
IO_board
IO plocana FRDM K64
SPIledovi/ledControl.h@16:a3085300cac3, 2021-04-30 (annotated)
- Committer:
- bosko001
- Date:
- Fri Apr 30 00:08:07 2021 +0200
- Revision:
- 16:a3085300cac3
- Parent:
- 7:4aa3dac73b66
i zero crossing dodat
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bosko001 | 7:4aa3dac73b66 | 1 | #ifndef LEDCONTROL_H |
bosko001 | 7:4aa3dac73b66 | 2 | #define LEDCONTROL_H |
bosko001 | 7:4aa3dac73b66 | 3 | |
bosko001 | 7:4aa3dac73b66 | 4 | #include "LedLight.h" |
bosko001 | 7:4aa3dac73b66 | 5 | #include "IOdata.h" |
bosko001 | 7:4aa3dac73b66 | 6 | //#include <functional> |
bosko001 | 7:4aa3dac73b66 | 7 | |
bosko001 | 7:4aa3dac73b66 | 8 | |
bosko001 | 7:4aa3dac73b66 | 9 | #define NO_BULB 6 |
bosko001 | 7:4aa3dac73b66 | 10 | |
bosko001 | 7:4aa3dac73b66 | 11 | |
bosko001 | 7:4aa3dac73b66 | 12 | enum E_blinkPatern { offBlink, onBlink, faultBlink, mouseBlink}; |
bosko001 | 7:4aa3dac73b66 | 13 | |
bosko001 | 7:4aa3dac73b66 | 14 | enum E_ledView { jednokratni_prikaz, komanda, indikacija, ispravnost, mis, poruka, validnost, podatak, adresa, aktuelna_indikacija}; |
bosko001 | 7:4aa3dac73b66 | 15 | |
bosko001 | 7:4aa3dac73b66 | 16 | union U_ledBulb |
bosko001 | 7:4aa3dac73b66 | 17 | { |
bosko001 | 7:4aa3dac73b66 | 18 | struct |
bosko001 | 7:4aa3dac73b66 | 19 | { |
bosko001 | 7:4aa3dac73b66 | 20 | char color: 2; |
bosko001 | 7:4aa3dac73b66 | 21 | char led: 3; |
bosko001 | 7:4aa3dac73b66 | 22 | char bulb: 3; |
bosko001 | 7:4aa3dac73b66 | 23 | }; |
bosko001 | 7:4aa3dac73b66 | 24 | char command; |
bosko001 | 7:4aa3dac73b66 | 25 | }; |
bosko001 | 7:4aa3dac73b66 | 26 | |
bosko001 | 7:4aa3dac73b66 | 27 | class C_ledControl: public C_ledLight |
bosko001 | 7:4aa3dac73b66 | 28 | { |
bosko001 | 7:4aa3dac73b66 | 29 | char bulb[NO_BULB] = {1, 2, 3, 4, 5, 6}; |
bosko001 | 7:4aa3dac73b66 | 30 | // char fault, mouse; |
bosko001 | 7:4aa3dac73b66 | 31 | |
bosko001 | 7:4aa3dac73b66 | 32 | C_data *pc_data; |
bosko001 | 7:4aa3dac73b66 | 33 | |
bosko001 | 7:4aa3dac73b66 | 34 | volatile E_ledView e_ledView = jednokratni_prikaz; |
bosko001 | 7:4aa3dac73b66 | 35 | |
bosko001 | 7:4aa3dac73b66 | 36 | E_ledColor e_colorTemplate[NO_LED] = { ledOff, ledOff, ledOff, ledOff, ledOff, ledOff }; |
bosko001 | 7:4aa3dac73b66 | 37 | |
bosko001 | 7:4aa3dac73b66 | 38 | |
bosko001 | 7:4aa3dac73b66 | 39 | void apply_colorTemplate( const E_ledColor *p_lcniz); |
bosko001 | 7:4aa3dac73b66 | 40 | void set_ledBlinker( char no, const E_blinkPatern bp ); |
bosko001 | 7:4aa3dac73b66 | 41 | void insert_ledInColorTemplate( char noled, E_ledColor c); |
bosko001 | 7:4aa3dac73b66 | 42 | |
bosko001 | 7:4aa3dac73b66 | 43 | public: |
bosko001 | 7:4aa3dac73b66 | 44 | |
bosko001 | 7:4aa3dac73b66 | 45 | C_ledControl( C_data *pc_data ) { this->pc_data = pc_data; }; |
bosko001 | 7:4aa3dac73b66 | 46 | |
bosko001 | 7:4aa3dac73b66 | 47 | void set_byte( char b ){ set_ledLightByte( b); } |
bosko001 | 7:4aa3dac73b66 | 48 | |
bosko001 | 7:4aa3dac73b66 | 49 | |
bosko001 | 7:4aa3dac73b66 | 50 | void set_ledView( E_ledView e ) { e_ledView = e; } |
bosko001 | 7:4aa3dac73b66 | 51 | E_ledView get_ledView( void ) {return e_ledView;} |
bosko001 | 7:4aa3dac73b66 | 52 | |
bosko001 | 7:4aa3dac73b66 | 53 | void unpack_ledBulb( char b ); |
bosko001 | 7:4aa3dac73b66 | 54 | void clear_ledBulbTable( void ); |
bosko001 | 7:4aa3dac73b66 | 55 | void execute_indications( char indication ); |
bosko001 | 7:4aa3dac73b66 | 56 | |
bosko001 | 7:4aa3dac73b66 | 57 | |
bosko001 | 7:4aa3dac73b66 | 58 | void set_colorTemplate( void ) {apply_colorTemplate( e_colorTemplate);} |
bosko001 | 7:4aa3dac73b66 | 59 | void set_colorTemplate_Red( void ); |
bosko001 | 7:4aa3dac73b66 | 60 | void set_colorTemplate_Green( void ); |
bosko001 | 7:4aa3dac73b66 | 61 | void set_colorTemplate_Yellow( void ); |
bosko001 | 7:4aa3dac73b66 | 62 | void set_colorTemplate_Example( void ); |
bosko001 | 7:4aa3dac73b66 | 63 | |
bosko001 | 7:4aa3dac73b66 | 64 | void set_led( char no ) { set_ledBlinker( no, onBlink );} /* paljenje leda */ |
bosko001 | 7:4aa3dac73b66 | 65 | void res_led( char no ) { set_ledBlinker( no, offBlink );} /* gasenje leda */ |
bosko001 | 7:4aa3dac73b66 | 66 | void fault_led( char no ) { set_ledBlinker( no, faultBlink );} /* blinkanje neispravne sijalice */ |
bosko001 | 7:4aa3dac73b66 | 67 | void mouse_led( char no ) { set_ledBlinker( no, mouseBlink );} /* blinkanje misa */ |
bosko001 | 7:4aa3dac73b66 | 68 | void set_ledPort( char port ) { set_ledLightByte(port);} /* ukljucenje celog porta da stabilno svetli */ |
bosko001 | 7:4aa3dac73b66 | 69 | |
bosko001 | 7:4aa3dac73b66 | 70 | // void set_fault( char bit ) { fault |= bit;} |
bosko001 | 7:4aa3dac73b66 | 71 | // void res_fault( char bit ) { fault &= ~bit;} |
bosko001 | 7:4aa3dac73b66 | 72 | // void clear_faults( void ) { fault = 0;} |
bosko001 | 7:4aa3dac73b66 | 73 | |
bosko001 | 7:4aa3dac73b66 | 74 | // void set_mouse( char bit ) { mouse |= bit;} |
bosko001 | 7:4aa3dac73b66 | 75 | // void res_mouse( char bit ) { mouse &= ~bit;} |
bosko001 | 7:4aa3dac73b66 | 76 | // void clear_mouses( void ) { mouse = 0;} |
bosko001 | 7:4aa3dac73b66 | 77 | |
bosko001 | 7:4aa3dac73b66 | 78 | |
bosko001 | 7:4aa3dac73b66 | 79 | |
bosko001 | 7:4aa3dac73b66 | 80 | // pregazi refreash iz C_ledLight, izvrsava se u ugradjenom threadu u C_ledLight |
bosko001 | 7:4aa3dac73b66 | 81 | |
bosko001 | 7:4aa3dac73b66 | 82 | void _refresh( void ) override |
bosko001 | 7:4aa3dac73b66 | 83 | { |
bosko001 | 7:4aa3dac73b66 | 84 | // DigitalOut ledG(LED2,1); |
bosko001 | 7:4aa3dac73b66 | 85 | |
bosko001 | 7:4aa3dac73b66 | 86 | while( true ) |
bosko001 | 7:4aa3dac73b66 | 87 | { |
bosko001 | 7:4aa3dac73b66 | 88 | pc_data->set_address( (C_spiled::get_received()>>8) & 0x0f); |
bosko001 | 7:4aa3dac73b66 | 89 | // ledG = 0; |
bosko001 | 7:4aa3dac73b66 | 90 | // if(pf != nullptr) { pf(); ledG = ! ledG; } |
bosko001 | 7:4aa3dac73b66 | 91 | if( e_ledView == komanda ) { set_ledPort(pc_data->get_command_uncut()); } |
bosko001 | 7:4aa3dac73b66 | 92 | else if( e_ledView == indikacija ) { set_ledPort(pc_data->get_indication()); } |
bosko001 | 7:4aa3dac73b66 | 93 | else if( e_ledView == ispravnost ) { set_ledPort(pc_data->get_correctness()); } |
bosko001 | 7:4aa3dac73b66 | 94 | else if( e_ledView == mis ) { set_ledPort(pc_data->get_faultVoltage()); } |
bosko001 | 7:4aa3dac73b66 | 95 | else if( e_ledView == poruka ) { set_ledPort(pc_data->get_message()); } |
bosko001 | 7:4aa3dac73b66 | 96 | else if( e_ledView == validnost ) { set_ledPort(pc_data->get_validity()); } |
bosko001 | 7:4aa3dac73b66 | 97 | else if( e_ledView == podatak ) { set_ledPort(pc_data->get_data()); } |
bosko001 | 7:4aa3dac73b66 | 98 | else if( e_ledView == adresa ) { set_ledPort(pc_data->get_address()); } |
bosko001 | 7:4aa3dac73b66 | 99 | |
bosko001 | 7:4aa3dac73b66 | 100 | else if( e_ledView == aktuelna_indikacija ) execute_indications( pc_data->get_raelIndication() ); |
bosko001 | 7:4aa3dac73b66 | 101 | |
bosko001 | 7:4aa3dac73b66 | 102 | // else ledG = 1; |
bosko001 | 7:4aa3dac73b66 | 103 | C_ledLight::_refresh(); |
bosko001 | 7:4aa3dac73b66 | 104 | } |
bosko001 | 7:4aa3dac73b66 | 105 | } |
bosko001 | 7:4aa3dac73b66 | 106 | |
bosko001 | 7:4aa3dac73b66 | 107 | }; |
bosko001 | 7:4aa3dac73b66 | 108 | |
bosko001 | 7:4aa3dac73b66 | 109 | |
bosko001 | 7:4aa3dac73b66 | 110 | #endif |