![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Novo
Fork of LukaIElmir by
DotMatrix.h@5:654e3398c1ef, 2014-05-26 (annotated)
- Committer:
- tim003
- Date:
- Mon May 26 18:28:21 2014 +0000
- Revision:
- 5:654e3398c1ef
- Parent:
- 4:ba24ce878e87
- Child:
- 6:dd675b967b60
jo? nest;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tim003 | 3:43648fa57d55 | 1 | #include "mbed.h" |
tim003 | 3:43648fa57d55 | 2 | #include "MatrixSPI.h" |
tim003 | 3:43648fa57d55 | 3 | #include <string> |
tim003 | 3:43648fa57d55 | 4 | #include <vector> |
tim003 | 5:654e3398c1ef | 5 | #include "Znak.h" |
tim003 | 3:43648fa57d55 | 6 | #ifndef DOTMATRIX_H |
tim003 | 3:43648fa57d55 | 7 | #define DOTMATRIX_H |
tim003 | 3:43648fa57d55 | 8 | |
tim003 | 3:43648fa57d55 | 9 | enum ModPrikazivanja{scroll, char_by_char, live_input}; |
tim003 | 3:43648fa57d55 | 10 | |
tim003 | 3:43648fa57d55 | 11 | class DotMatrix{ |
tim003 | 3:43648fa57d55 | 12 | |
tim003 | 3:43648fa57d55 | 13 | public: |
tim003 | 3:43648fa57d55 | 14 | DotMatrix(PinName data_input = dp2, PinName clock = dp6, PinName loadcs = dp24) |
tim003 | 3:43648fa57d55 | 15 | :spi(data_input, clock, loadcs), turnedON(false), mod(scroll), char_trenutni(0), |
tim003 | 3:43648fa57d55 | 16 | char_offset(0), repeat(true), brzina_ms(1000) |
tim003 | 3:43648fa57d55 | 17 | { |
tim003 | 3:43648fa57d55 | 18 | for(int i = 0; i < 8; i++) buffer[i] = 0; |
tim003 | 3:43648fa57d55 | 19 | } |
tim003 | 3:43648fa57d55 | 20 | |
tim003 | 3:43648fa57d55 | 21 | void refresh(); |
tim003 | 3:43648fa57d55 | 22 | void setIntensity(float jacina); |
tim003 | 3:43648fa57d55 | 23 | void setSpeed_ms(int ms); |
tim003 | 3:43648fa57d55 | 24 | void turnON(); |
tim003 | 3:43648fa57d55 | 25 | void turnOFF(); |
tim003 | 3:43648fa57d55 | 26 | void PromijeniRecenicu(string recenica){ |
tim003 | 3:43648fa57d55 | 27 | this->recenica = recenica; |
tim003 | 3:43648fa57d55 | 28 | } |
tim003 | 3:43648fa57d55 | 29 | void NadodajNaRecenicu(char c){ |
tim003 | 3:43648fa57d55 | 30 | recenica += c; |
tim003 | 3:43648fa57d55 | 31 | } |
tim003 | 3:43648fa57d55 | 32 | void NadodajNaRecenicu(string str){ |
tim003 | 3:43648fa57d55 | 33 | recenica += str; |
tim003 | 3:43648fa57d55 | 34 | } |
tim003 | 3:43648fa57d55 | 35 | void PromijeniMod(ModPrikazivanja mod){ |
tim003 | 3:43648fa57d55 | 36 | if(this->mod != mod){ |
tim003 | 3:43648fa57d55 | 37 | this->mod = mod; |
tim003 | 3:43648fa57d55 | 38 | attach(); |
tim003 | 3:43648fa57d55 | 39 | } |
tim003 | 3:43648fa57d55 | 40 | } |
tim003 | 3:43648fa57d55 | 41 | ModPrikazivanja dajMod() const{ |
tim003 | 3:43648fa57d55 | 42 | return mod; |
tim003 | 3:43648fa57d55 | 43 | } |
tim003 | 4:ba24ce878e87 | 44 | void SetRepeat(bool r){ |
tim003 | 4:ba24ce878e87 | 45 | repeat = r; |
tim003 | 4:ba24ce878e87 | 46 | } |
tim003 | 3:43648fa57d55 | 47 | |
tim003 | 4:ba24ce878e87 | 48 | bool GetRepeat() const{ |
tim003 | 4:ba24ce878e87 | 49 | return repeat; |
tim003 | 4:ba24ce878e87 | 50 | } |
tim003 | 3:43648fa57d55 | 51 | |
tim003 | 5:654e3398c1ef | 52 | void inicijaliziraj(){ |
tim003 | 5:654e3398c1ef | 53 | znakovi[0] = Znak(0x7e, 0x11, 0x11, 0x7e); |
tim003 | 5:654e3398c1ef | 54 | znakovi[1] = Znak(0x7e, 0x49, 0x49, 0x36); |
tim003 | 5:654e3398c1ef | 55 | znakovi[2] = Znak(0x3e, 0x41, 0x41, 0x22); |
tim003 | 5:654e3398c1ef | 56 | znakovi[3] = Znak(0x7f, 0x41, 0x41, 0x3e); |
tim003 | 5:654e3398c1ef | 57 | |
tim003 | 5:654e3398c1ef | 58 | } |
tim003 | 5:654e3398c1ef | 59 | void setChar(char c, int offset) |
tim003 | 5:654e3398c1ef | 60 | { |
tim003 | 5:654e3398c1ef | 61 | int index = c - 'A'; |
tim003 | 5:654e3398c1ef | 62 | if(offset < 0) |
tim003 | 5:654e3398c1ef | 63 | { |
tim003 | 5:654e3398c1ef | 64 | for(int i = 0; i < znakovi[index].vel + offset; i++) |
tim003 | 5:654e3398c1ef | 65 | { |
tim003 | 5:654e3398c1ef | 66 | buffer[i] = znakovi[index].niz[i - offset]; |
tim003 | 5:654e3398c1ef | 67 | } |
tim003 | 5:654e3398c1ef | 68 | } |
tim003 | 5:654e3398c1ef | 69 | else |
tim003 | 5:654e3398c1ef | 70 | { |
tim003 | 5:654e3398c1ef | 71 | for(int i = offset; i < 8 && i < znakovi[index].vel + offset; i++) |
tim003 | 5:654e3398c1ef | 72 | { |
tim003 | 5:654e3398c1ef | 73 | buffer[i] = znakovi[index].niz[i - offset]; |
tim003 | 5:654e3398c1ef | 74 | } |
tim003 | 5:654e3398c1ef | 75 | } |
tim003 | 5:654e3398c1ef | 76 | |
tim003 | 5:654e3398c1ef | 77 | } |
tim003 | 5:654e3398c1ef | 78 | |
tim003 | 5:654e3398c1ef | 79 | void displaySingleChar(char c){ |
tim003 | 5:654e3398c1ef | 80 | setChar(c, 2); |
tim003 | 5:654e3398c1ef | 81 | refresh(); |
tim003 | 5:654e3398c1ef | 82 | } |
tim003 | 5:654e3398c1ef | 83 | |
tim003 | 4:ba24ce878e87 | 84 | int buffer[8]; |
tim003 | 5:654e3398c1ef | 85 | Znak znakovi[4]; |
tim003 | 3:43648fa57d55 | 86 | private: |
tim003 | 3:43648fa57d55 | 87 | void attach(); |
tim003 | 4:ba24ce878e87 | 88 | void prikaziScroll(){} |
tim003 | 5:654e3398c1ef | 89 | void prikaziCBC(){ |
tim003 | 5:654e3398c1ef | 90 | if(char_trenutni == recenica.size()) refresh(); |
tim003 | 5:654e3398c1ef | 91 | else { |
tim003 | 5:654e3398c1ef | 92 | displaySingleChar(recenica[char_trenutni]); |
tim003 | 5:654e3398c1ef | 93 | char_trenutni++; |
tim003 | 5:654e3398c1ef | 94 | if(char_trenutni == recenica.size() && repeat) |
tim003 | 5:654e3398c1ef | 95 | char_trenutni = 0; |
tim003 | 5:654e3398c1ef | 96 | |
tim003 | 5:654e3398c1ef | 97 | } |
tim003 | 5:654e3398c1ef | 98 | } |
tim003 | 3:43648fa57d55 | 99 | |
tim003 | 3:43648fa57d55 | 100 | MatrixSPI spi; |
tim003 | 4:ba24ce878e87 | 101 | |
tim003 | 3:43648fa57d55 | 102 | bool turnedON; |
tim003 | 3:43648fa57d55 | 103 | string recenica; |
tim003 | 3:43648fa57d55 | 104 | ModPrikazivanja mod; |
tim003 | 3:43648fa57d55 | 105 | int char_trenutni, char_offset; |
tim003 | 3:43648fa57d55 | 106 | Ticker ticker; |
tim003 | 3:43648fa57d55 | 107 | //bool isAttached potrebno ako se ticker ne može 2. detachirati... |
tim003 | 3:43648fa57d55 | 108 | bool repeat; |
tim003 | 3:43648fa57d55 | 109 | int brzina_ms; |
tim003 | 3:43648fa57d55 | 110 | }; |
tim003 | 3:43648fa57d55 | 111 | |
tim003 | 5:654e3398c1ef | 112 | |
tim003 | 3:43648fa57d55 | 113 | #endif //DotMatrix_h |