-
Notifications
You must be signed in to change notification settings - Fork 0
/
mizraith_HDSP2111.h
143 lines (105 loc) · 4.24 KB
/
mizraith_HDSP2111.h
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
/***************************************************
This is a library for controlling an HDSP2111 through
an MCP23017 port expander using 2 wire i2C.
Author: Red Byer www.redstoyland.com
Date: 9/3/2013
https://github.com/mizraith/mizraith_HDSP2111
****************************************************/
#ifndef _mizraith_HDSP2111_H_
#define _mizraith_HDSP2111_H_
//#include <Wire.h>
#include <avr/pgmspace.h>
#include "Adafruit_MCP23017.h"
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
class mizraith_HDSP2111 {
Adafruit_MCP23017 mcp_display;
uint8_t mcp_display_addr;
char * BLANK_STRING;
const static uint8_t NUMBER_OF_DISPLAYS = 2;
/* Structure containing state function and data */
struct display_data {
unsigned long LAST_UPDATE;
char *TEXT;
uint8_t TEXT_LENGTH; //auto-calculated
uint8_t SCROLL_POSITION; //[0:stringlength-1]
uint16_t SCROLL_DELAY;
bool SCROLL_COMPLETE; // (sets to 1 at end of string and stops operation)
bool TEXT_CHANGED;
} DISPLAY_DATA[NUMBER_OF_DISPLAYS];
public:
mizraith_HDSP2111(void);
void setup(uint8_t mcpaddr);
void resetDisplays();
void resetDisplay(uint8_t displaynum);
//where brightness value is 0:6 inclusive. We don't allow an 'off' setting of 7
void setBrightnessForAllDisplays(uint8_t value);
void setBrightnessForDisplay(uint8_t value, uint8_t displaynum);
//where percentage is 0-100%
void setBrightnessPercentageForAllDisplays(uint8_t percent);
void setBrightnessPercentageForDisplay(uint8_t percent, uint8_t displaynum);
//set scroll speed from 0:7 [without having to think about ms]
void setScrollSpeedForAllDisplays(uint8_t value);
//lower level set the delay between scroll steps. Default is 150ms
void setScrollDelay(uint16_t delayms, uint8_t displaynum);
//is the scroll flag complete on this
bool isScrollComplete(uint8_t displaynum);
void setScrollCompleteFlag(bool flag, uint8_t displaynum);
void setScrollPosition(uint8_t pos, uint8_t displaynum);
void automaticallyResetScrollFlagAndPosition(uint8_t displaynum);
void automaticallyResetScrollFlagAndPositions(void);
//useful for tweaking the same display string if scrolling
void setDisplayString(char *words, uint8_t displaynum);
//RECOMMENDED #1
//set display string and start over as if new
void setDisplayStringAsNew(char *words, uint8_t displaynum);
char * getDisplayString(uint8_t displaynum);
//PRIMARY CONVENIENCE ALL-IN-ONE METHOD TO BE CALLED EVERY LOOP
// wraps up the automatic scroll flag reset with the
//update displays method.
void GoDogGo(void);
//RECOMMENDED METHOD #2
//convenience method for updating both displays, whether
//they be scrolling or static. This method should be
//called more frequently than the desired scroll rate...
// This method will not update if:
// (a) short enough (therefore static) and unchanged
// (b) not yet reached scroll delay since last update
// (calls updateDisplayScroll)
void updateDisplays();
//these could be private
void writeDisplay(char *input, uint8_t displaynum);
void updateDisplayScroll(uint8_t displaynum);
void DEBUG_PrintDisplayData( void );
private:
bool stringLengthChanged( uint8_t displaynum );
uint8_t getDisplayControlRegister(uint8_t displaynum);
uint8_t getDisplayCEFromDisplayNum(uint8_t displaynum);
uint8_t getBitsFromPercent(uint8_t percent);
void clearControlWord(uint8_t displaynum);
};
//--------- MCP23017 --> HDSP2111 HOOK UPS ---------------
//On the MCP23017 there is PORT A and PORT B
//The library numbers these pins (for convenience) 0:15
//the following are for the display MCP23017
#define HDSP_A0 0
#define HDSP_A1 1
#define HDSP_A2 2
#define HDSP_A3 3
// NOTE: A4 is always held HIGH for this implementation
#define HDSP_RD 4
#define HDSP_WR 5
#define HDSP_CE1 6
#define HDSP_CE2 7
#define HDSP_D0 8
#define HDSP_D1 9
#define HDSP_D2 10
#define HDSP_D3 11
#define HDSP_D4 12
#define HDSP_D5 13
#define HDSP_D6 14
#define HDSP_D7 15
#endif