-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisplay.cpp
More file actions
72 lines (55 loc) · 1.54 KB
/
Display.cpp
File metadata and controls
72 lines (55 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* Display.cpp
*
* Created on: Jan 31, 2013
* Author: jpm8766
*/
#include "Display.h"
Display::Display(DataProvider* d, uintptr_t cat, uintptr_t an)
:data(d)
,cathode( cat )
,anode( an )
,killThread( false )
{}
Display::~Display() {}
void Display::setDataProvider(DataProvider* next) {
data = next;
}
void* Display::run() {
this->setPriority(DISPLAY_PRIORITY);
//carry on with display...
char cathWriteVal;
char decimal;
int ctr = 0;
DisplayInfo inf;
//clear all the anodes.
out8(anode, in8(anode) | (0b00001111));
while(!killThread) {
// if the data provider isn't null, update the display
if(data != NULL) {
//First get the DisplayInfo
if(ctr == 0)
inf = data->getData();
//Iterate over the anodes of the display.
for(int i = 0; i < NUM_ANODES; i++) {
//set the anode for the digit being worked on
out8(anode, (in8(anode) & ~(1 << i)));
//set the decimal point if specified
decimal = 0;
if( inf.dp[i] ) {
decimal = DP_CATHODE;
}
//bitwise OR the decimal bit with the bits which define the number to display on this LED
cathWriteVal = CATHODE_TABLE[inf.val[i]] | decimal;
//write the value to the cathodes; inverted because it is Active LOW
out8(cathode, ~cathWriteVal);
//sleep for 25% of the total time spent on updating the display.
usleep(SLEEP_PERIOD);
//clear the anode.
out8(anode, (in8(anode) | (1 << i)));
}
ctr = (ctr + 1) % COUNT_INTERVAL;
}
}
return NULL;
}