Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1702 | - | 1 | #include "screenitem.h" |
2 | |||
3 | void ScreenItem::SetAttribs(uint8_t left, uint8_t top, uint8_t len, bool highlighted, bool pgm) |
||
4 | { |
||
5 | itemAttribs.bmLeft = left; |
||
6 | itemAttribs.bmTop = top; |
||
7 | itemAttribs.bmLen = len; |
||
8 | itemAttribs.bmHighlighted = (highlighted) ? 1 : 0; |
||
9 | itemAttribs.bmHlChanged = 1; // item highlighting changed flag |
||
10 | itemAttribs.bmPgmString = (pgm) ? 1 : 0; |
||
11 | }; |
||
12 | |||
13 | ScreenItem::ScreenItem(uint8_t left, uint8_t top, uint8_t len, bool highlighted, DataItemBase *item) : |
||
14 | dataItem(item) |
||
15 | { |
||
16 | SetAttribs(left, top, len, highlighted, 0); |
||
17 | } |
||
18 | |||
19 | ScreenItem::ScreenItem(uint8_t left, uint8_t top, uint8_t len, bool highlighted, const char *item) : |
||
20 | dataItem((void*)item) |
||
21 | { |
||
22 | SetAttribs(left, top, len, highlighted, 1); |
||
23 | } |
||
24 | |||
25 | void ScreenItem::Print(Max_LCD *p) |
||
26 | { |
||
27 | char* str; |
||
28 | bool is_pgm = false; |
||
29 | |||
30 | if (itemAttribs.bmPgmString == 1) |
||
31 | { |
||
32 | is_pgm = true; |
||
33 | str = (char*)dataItem; |
||
34 | } |
||
35 | else |
||
36 | ((DataItemBase*)dataItem)->GetText(&str, is_pgm); |
||
37 | |||
38 | if(!str) |
||
39 | return; |
||
40 | |||
41 | uint8_t cnt = 0; |
||
42 | |||
43 | if (is_pgm) |
||
44 | { |
||
45 | char c; |
||
46 | while((c = pgm_read_byte(str++)) && cnt < itemAttribs.bmLen) |
||
47 | { |
||
48 | p->print(c,BYTE); |
||
49 | cnt ++; |
||
50 | } |
||
51 | } |
||
52 | else |
||
53 | { |
||
54 | char *pc = str; |
||
55 | while(*pc && cnt < itemAttribs.bmLen) |
||
56 | { |
||
57 | p->print(*pc++,BYTE); |
||
58 | cnt ++; |
||
59 | } |
||
60 | } |
||
61 | } |
||
62 | |||
63 | void ScreenItem::Update(Max_LCD *pLcd, bool initial) |
||
64 | { |
||
65 | if (initial || ( itemAttribs.bmPgmString == 0 && ((DataItemBase*)dataItem)->IsUpdated() ) || itemAttribs.bmHlChanged) |
||
66 | { |
||
67 | pLcd->home(); |
||
68 | |||
69 | if (itemAttribs.bmLeft > 0) |
||
70 | { |
||
71 | pLcd->setCursor(itemAttribs.bmLeft-1, itemAttribs.bmTop); |
||
72 | |||
73 | pLcd->print((itemAttribs.bmHighlighted) ? '>' : ' ', BYTE); |
||
74 | } |
||
75 | else |
||
76 | pLcd->setCursor(itemAttribs.bmLeft, itemAttribs.bmTop); |
||
77 | |||
78 | Print(pLcd); |
||
79 | |||
80 | if (itemAttribs.bmLeft + itemAttribs.bmLen < 16) |
||
81 | pLcd->print((itemAttribs.bmHighlighted) ? '<' : ' ', BYTE); |
||
82 | |||
83 | if (itemAttribs.bmPgmString == 0) |
||
84 | ((DataItemBase*)dataItem)->SetUpdated(false); |
||
85 | |||
86 | itemAttribs.bmHlChanged = 0; |
||
87 | } |
||
88 | } |
||
89 |