bosko lekovic
/
IO_board
IO plocana FRDM K64
SPIledovi/LedLight.h@7:4aa3dac73b66, 2021-03-21 (annotated)
- Committer:
- bosko001
- Date:
- Sun Mar 21 18:20:15 2021 +0100
- Revision:
- 7:4aa3dac73b66
novi pocetak
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bosko001 | 7:4aa3dac73b66 | 1 | #ifndef LEDLIGHT_H |
bosko001 | 7:4aa3dac73b66 | 2 | #define LEDLIGHT_H |
bosko001 | 7:4aa3dac73b66 | 3 | |
bosko001 | 7:4aa3dac73b66 | 4 | #include "mbed.h" |
bosko001 | 7:4aa3dac73b66 | 5 | #include "ClassThreadAbstract.h" |
bosko001 | 7:4aa3dac73b66 | 6 | |
bosko001 | 7:4aa3dac73b66 | 7 | |
bosko001 | 7:4aa3dac73b66 | 8 | #define BYTE_TO_BINARY_PATTERN "%c%c%c%c%c%c%c%c" |
bosko001 | 7:4aa3dac73b66 | 9 | #define BYTE_TO_BINARY(byte) \ |
bosko001 | 7:4aa3dac73b66 | 10 | (byte & 0x80 ? '1' : '0'), \ |
bosko001 | 7:4aa3dac73b66 | 11 | (byte & 0x40 ? '1' : '0'), \ |
bosko001 | 7:4aa3dac73b66 | 12 | (byte & 0x20 ? '1' : '0'), \ |
bosko001 | 7:4aa3dac73b66 | 13 | (byte & 0x10 ? '1' : '0'), \ |
bosko001 | 7:4aa3dac73b66 | 14 | (byte & 0x08 ? '1' : '0'), \ |
bosko001 | 7:4aa3dac73b66 | 15 | (byte & 0x04 ? '1' : '0'), \ |
bosko001 | 7:4aa3dac73b66 | 16 | (byte & 0x02 ? '1' : '0'), \ |
bosko001 | 7:4aa3dac73b66 | 17 | (byte & 0x01 ? '1' : '0') |
bosko001 | 7:4aa3dac73b66 | 18 | // printf("Leading text "BYTE_TO_BINARY_PATTERN, BYTE_TO_BINARY(byte)); |
bosko001 | 7:4aa3dac73b66 | 19 | // printf(" leading text"BYTE_TO_BINARY_PATTERN" "BYTE_TO_BINARY_PATTERN"\n\r", j, BYTE_TO_BINARY(byte>>8),BYTE_TO_BINARY(byte) ); |
bosko001 | 7:4aa3dac73b66 | 20 | |
bosko001 | 7:4aa3dac73b66 | 21 | |
bosko001 | 7:4aa3dac73b66 | 22 | |
bosko001 | 7:4aa3dac73b66 | 23 | |
bosko001 | 7:4aa3dac73b66 | 24 | /****************************** class C_spi ***************************************** */ |
bosko001 | 7:4aa3dac73b66 | 25 | //extern DigitalOut led; |
bosko001 | 7:4aa3dac73b66 | 26 | class C_spi: public SPI |
bosko001 | 7:4aa3dac73b66 | 27 | { |
bosko001 | 7:4aa3dac73b66 | 28 | DigitalOut *p_csdata; |
bosko001 | 7:4aa3dac73b66 | 29 | public: |
bosko001 | 7:4aa3dac73b66 | 30 | |
bosko001 | 7:4aa3dac73b66 | 31 | C_spi( PinName mosi, PinName miso, PinName sclk, PinName pin_csdata ); |
bosko001 | 7:4aa3dac73b66 | 32 | unsigned short transfer( unsigned short tx ); |
bosko001 | 7:4aa3dac73b66 | 33 | |
bosko001 | 7:4aa3dac73b66 | 34 | }; |
bosko001 | 7:4aa3dac73b66 | 35 | |
bosko001 | 7:4aa3dac73b66 | 36 | /********************************* class C_spiled ********************************************* */ |
bosko001 | 7:4aa3dac73b66 | 37 | #define NO_LED 6 |
bosko001 | 7:4aa3dac73b66 | 38 | |
bosko001 | 7:4aa3dac73b66 | 39 | enum E_ledColor { ledOff, ledRed, ledGreen, ledYellow}; |
bosko001 | 7:4aa3dac73b66 | 40 | |
bosko001 | 7:4aa3dac73b66 | 41 | union U_ledovi |
bosko001 | 7:4aa3dac73b66 | 42 | { |
bosko001 | 7:4aa3dac73b66 | 43 | unsigned short ledovi =0; |
bosko001 | 7:4aa3dac73b66 | 44 | struct |
bosko001 | 7:4aa3dac73b66 | 45 | { |
bosko001 | 7:4aa3dac73b66 | 46 | char ledpar1 : 2; |
bosko001 | 7:4aa3dac73b66 | 47 | char ledpar2 : 2; |
bosko001 | 7:4aa3dac73b66 | 48 | char ledpar3 : 2; |
bosko001 | 7:4aa3dac73b66 | 49 | char ledpar4 : 2; |
bosko001 | 7:4aa3dac73b66 | 50 | char ledpar5 : 2; |
bosko001 | 7:4aa3dac73b66 | 51 | char ledpar6 : 2; |
bosko001 | 7:4aa3dac73b66 | 52 | }; |
bosko001 | 7:4aa3dac73b66 | 53 | }; |
bosko001 | 7:4aa3dac73b66 | 54 | |
bosko001 | 7:4aa3dac73b66 | 55 | |
bosko001 | 7:4aa3dac73b66 | 56 | |
bosko001 | 7:4aa3dac73b66 | 57 | class C_spiled: public C_spi |
bosko001 | 7:4aa3dac73b66 | 58 | { |
bosko001 | 7:4aa3dac73b66 | 59 | unsigned short sifter; |
bosko001 | 7:4aa3dac73b66 | 60 | U_ledovi u_ledovi; |
bosko001 | 7:4aa3dac73b66 | 61 | unsigned short received; |
bosko001 | 7:4aa3dac73b66 | 62 | public: |
bosko001 | 7:4aa3dac73b66 | 63 | |
bosko001 | 7:4aa3dac73b66 | 64 | C_spiled(); |
bosko001 | 7:4aa3dac73b66 | 65 | |
bosko001 | 7:4aa3dac73b66 | 66 | void do_Sifter( void ); |
bosko001 | 7:4aa3dac73b66 | 67 | unsigned short get_received( void ){ return received;}; |
bosko001 | 7:4aa3dac73b66 | 68 | |
bosko001 | 7:4aa3dac73b66 | 69 | void set_led( char no, E_ledColor ct ); |
bosko001 | 7:4aa3dac73b66 | 70 | |
bosko001 | 7:4aa3dac73b66 | 71 | E_ledColor get_led( char no ); |
bosko001 | 7:4aa3dac73b66 | 72 | |
bosko001 | 7:4aa3dac73b66 | 73 | }; |
bosko001 | 7:4aa3dac73b66 | 74 | |
bosko001 | 7:4aa3dac73b66 | 75 | /************************* C_ledLight ***************************** */ |
bosko001 | 7:4aa3dac73b66 | 76 | |
bosko001 | 7:4aa3dac73b66 | 77 | // stuktura svakog pojedinacnog led-a: boja i binarni tickPatern tj, ako je patern 10101010 znaci blinkanje 4 puta u ciklusu, ili 11001100 bva puta u ciklusu |
bosko001 | 7:4aa3dac73b66 | 78 | struct S_ledLight { E_ledColor ct; char tickPatern; }; |
bosko001 | 7:4aa3dac73b66 | 79 | |
bosko001 | 7:4aa3dac73b66 | 80 | |
bosko001 | 7:4aa3dac73b66 | 81 | // klasa osvezavanja prikaza funkcija. Aktivira sopstveni C_thread i periodicno salje novo stanje ledova |
bosko001 | 7:4aa3dac73b66 | 82 | |
bosko001 | 7:4aa3dac73b66 | 83 | class C_ledLight: public C_spiled, C_thread |
bosko001 | 7:4aa3dac73b66 | 84 | { |
bosko001 | 7:4aa3dac73b66 | 85 | char tickCounter =1; |
bosko001 | 7:4aa3dac73b66 | 86 | S_ledLight s_ledLight[NO_LED] = {{ledOff,0},{ledOff,0},{ledOff,0},{ledOff,0},{ledOff,0},{ledOff,0}}; |
bosko001 | 7:4aa3dac73b66 | 87 | |
bosko001 | 7:4aa3dac73b66 | 88 | public: |
bosko001 | 7:4aa3dac73b66 | 89 | |
bosko001 | 7:4aa3dac73b66 | 90 | virtual void _refresh( void); |
bosko001 | 7:4aa3dac73b66 | 91 | |
bosko001 | 7:4aa3dac73b66 | 92 | void thread_fun(void) override { _refresh(); } |
bosko001 | 7:4aa3dac73b66 | 93 | |
bosko001 | 7:4aa3dac73b66 | 94 | C_ledLight( );// { } |
bosko001 | 7:4aa3dac73b66 | 95 | C_ledLight( int stack );//:C_thread( stack) { } |
bosko001 | 7:4aa3dac73b66 | 96 | |
bosko001 | 7:4aa3dac73b66 | 97 | void set_ledLight( char no, E_ledColor c, char t); |
bosko001 | 7:4aa3dac73b66 | 98 | |
bosko001 | 7:4aa3dac73b66 | 99 | void set_ledLight( char no, E_ledColor c ); |
bosko001 | 7:4aa3dac73b66 | 100 | void set_ledLightTickPatern( char no, char t ); |
bosko001 | 7:4aa3dac73b66 | 101 | // void set_ledLight( char no, bool on ) { if( no && no<=NO_LED ) {s_ledLight[no-1].tickPatern = ((on==true) ? 0xff : 0);} } |
bosko001 | 7:4aa3dac73b66 | 102 | void set_ledLightByte( char Port ); |
bosko001 | 7:4aa3dac73b66 | 103 | |
bosko001 | 7:4aa3dac73b66 | 104 | |
bosko001 | 7:4aa3dac73b66 | 105 | S_ledLight get_ledLight( char no ); |
bosko001 | 7:4aa3dac73b66 | 106 | char get_ledLightTickPatern( char no ); |
bosko001 | 7:4aa3dac73b66 | 107 | E_ledColor get_ledLightColor( char no ); |
bosko001 | 7:4aa3dac73b66 | 108 | |
bosko001 | 7:4aa3dac73b66 | 109 | void apply_ledColorTemplate( const E_ledColor *e_ct ); |
bosko001 | 7:4aa3dac73b66 | 110 | |
bosko001 | 7:4aa3dac73b66 | 111 | |
bosko001 | 7:4aa3dac73b66 | 112 | |
bosko001 | 7:4aa3dac73b66 | 113 | |
bosko001 | 7:4aa3dac73b66 | 114 | }; |
bosko001 | 7:4aa3dac73b66 | 115 | |
bosko001 | 7:4aa3dac73b66 | 116 | |
bosko001 | 7:4aa3dac73b66 | 117 | |
bosko001 | 7:4aa3dac73b66 | 118 | |
bosko001 | 7:4aa3dac73b66 | 119 | |
bosko001 | 7:4aa3dac73b66 | 120 | |
bosko001 | 7:4aa3dac73b66 | 121 | #endif |