-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom_bargraph_display.cpp
More file actions
150 lines (133 loc) · 3.12 KB
/
custom_bargraph_display.cpp
File metadata and controls
150 lines (133 loc) · 3.12 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include <Arduino.h>
#include "SoftataDevice_display.h"
// Custom_Bargraph
// Default Setup
bool Custom_Bargraph::Setup()
{
ic595 = new IC_74HC595_ShiftRegister();
this->DisplayType = GBARGRAPH;
return true;
}
bool Custom_Bargraph::Setup(byte * settings, byte numSettings)
{
ic595 = new IC_74HC595_ShiftRegister(settings,numSettings);
this->DisplayType = GBARGRAPH;
return true;
}
Tristate Custom_Bargraph::Clear()
{
ic595->Write(0);
return (Tristate)true;
}
Tristate Custom_Bargraph::Dummy()
{
return notImplemented;;
}
Tristate Custom_Bargraph::Backlight()
{
return notImplemented;
}
Tristate Custom_Bargraph::Home()
{
return notImplemented;
}
Tristate Custom_Bargraph::SetCursor(byte x, byte y)
{
return notImplemented;
}
Tristate Custom_Bargraph::WriteString(String msg)
{
int len = msg.length();
if (len>10) len = 10;
int numVal=0;
String prefix = msg.substring(0,2);
numStringType typ = _NONE;
if(prefix == "0b" ){
typ = _BIN;
} else if( prefix == "0x"){
typ = _HEX;
}
switch (typ){
case _BIN:
for (int i=0; i<len-2; i++){
// shift over what's there
numVal = numVal << 1;
if(msg[len - i] == 1){
numVal |= 1;
}
};
break;
case _HEX:
numVal = (int) strtoull(msg.c_str(), 0, 16);
numVal &= 0b00001111111111;
break;
default:
Serial.println(msg);
numVal = msg.toInt();
numVal &= 0b00001111111111;
break;
}
ic595->Write(numVal);
return (Tristate)true;
}
// No setcursor and/or no writestring
Tristate Custom_Bargraph::CursorWriteStringAvailable()
{
return notImplemented;
}
Tristate Custom_Bargraph::WriteString(byte x, byte y, String msg)
{
return notImplemented;
}
Tristate Custom_Bargraph::Misc(byte cmd, byte * data, byte length)
{
Serial.println("Custom_Bargraph::Misc");
Serial.println(cmd);
Serial.println(length);
if(length >0)
Serial.println(data[0]);
BARGRAPHMiscCmds Cmd = (BARGRAPHMiscCmds)cmd;
switch(Cmd)
{
case flowodd:
//Just set every odd segment for now.
ic595->Write((byte)85);
Serial.println("flow()");
break;
case floweven:
//Just set even segment for now.
ic595->Write((byte)170);
Serial.println("flow2()");
break;
case set_Led:
case clr_Led:
case toggle_Led:
// Set or toggle a specific LED
if (length < 1)
return (Tristate)false;
if (Cmd == set_Led)
ic595->SetBit(data[0]);
else if (Cmd == clr_Led)
ic595->ClearBit(data[0]);
else
ic595->ToggleBit(data[0]);
break;
case setLevel:
// Set the level of the bar
if (length < 1)
return (Tristate)false;
ic595->SetLevel(data[0]);
break;
case exercise:
// Turn on all LEDs
ic595->Write(0x3ff);
delay(1000);
// Turn off all LEDs
ic595->Write(0x0);
break;
default:
return (Tristate)false;
break;
}
return (Tristate)true;
}