AceSegment  0.3.0
An adjustable, configurable, and extensible framework for rendering seven segment LED displays.
LedMatrixDirect.cpp
1 /*
2 MIT License
3 
4 Copyright (c) 2018 Brian T. Park
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12 
13 The above copyright notice and this permission notice shall be included in all
14 copies or substantial portions of the Software.
15 
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 SOFTWARE.
23 */
24 
25 #include "Hardware.h"
26 #include "LedMatrixDirect.h"
27 
28 namespace ace_segment {
29 
30 // TODO: Consider moving this into the constructor, now that there's a
31 // DriverBuilder.
32 void LedMatrixDirect::setGroupPins(const uint8_t* groupPins) {
33  mGroupPins = groupPins;
34 }
35 
36 // TODO: Consider moving this into the constructor, now that there's a
37 // DriverBuilder.
38 void LedMatrixDirect::setElementPins(const uint8_t* elementPins) {
39  mElementPins = elementPins;
40 }
41 
44 
45  for (uint8_t group = 0; group < mNumGroups; group++) {
46  uint8_t digitalPin = mGroupPins[group];
47  mHardware->pinMode(digitalPin, OUTPUT);
48  mHardware->digitalWrite(digitalPin, mGroupOff);
49  }
50  for (uint8_t element = 0; element < mNumElements; element++) {
51  uint8_t elementPin = mElementPins[element];
52  mHardware->pinMode(elementPin, OUTPUT);
53  mHardware->digitalWrite(elementPin, mElementOff);
54  }
55 }
56 
58  for (uint8_t group = 0; group < mNumGroups; group++) {
59  uint8_t digitalPin = mGroupPins[group];
60  mHardware->pinMode(digitalPin, INPUT);
61  }
62  for (uint8_t element = 0; element < mNumElements; element++) {
63  uint8_t elementPin = mElementPins[element];
64  mHardware->pinMode(elementPin, INPUT);
65  }
66 }
67 
68 void LedMatrixDirect::enableGroup(uint8_t group) {
69  writeGroupPin(group, mGroupOn);
70 }
71 
72 void LedMatrixDirect::disableGroup(uint8_t group) {
73  writeGroupPin(group, mGroupOff);
74 }
75 
76 void LedMatrixDirect::drawElements(uint8_t pattern) {
77  uint8_t elementMask = 0x1;
78  for (uint8_t element = 0; element < mNumElements; element++) {
79  uint8_t output =
80  (pattern & elementMask) ? mElementOn : mElementOff;
81  writeElementPin(element, output);
82  elementMask <<= 1;
83  }
84 }
85 
86 }
virtual void pinMode(uint8_t pin, uint8_t mode)
Set pin mode.
Definition: Hardware.h:48
virtual void configure()
Configure the pins for the given LED wiring.
Definition: LedMatrix.h:82
virtual void digitalWrite(uint8_t pin, uint8_t value)
Write value to pin.
Definition: Hardware.h:43
virtual void configure() override
Configure the pins for the given LED wiring.
virtual void finish() override
Turn off the pins by doing the opposite of configure().