upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
my9221.h
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2016 Intel Corporation.
4  *
5  * These modules were rewritten, based on original work by:
6  *
7  * (original my9221/groveledbar)
8  * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
9  * Copyright (c) 2014 Intel Corporation.
10  *
11  * (grovecircularled)
12  * Author: Jun Kato and Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
13  * Contributions: Jon Trulson <jtrulson@ics.com>
14  * Copyright (c) 2014 Intel Corporation.
15  *
16  * Permission is hereby granted, free of charge, to any person obtaining
17  * a copy of this software and associated documentation files (the
18  * "Software"), to deal in the Software without restriction, including
19  * without limitation the rights to use, copy, modify, merge, publish,
20  * distribute, sublicense, and/or sell copies of the Software, and to
21  * permit persons to whom the Software is furnished to do so, subject to
22  * the following conditions:
23  *
24  * The above copyright notice and this permission notice shall be
25  * included in all copies or substantial portions of the Software.
26  *
27  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
31  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
32  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
33  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34  */
35 #pragma once
36 
37 #include <string>
38 #include <mraa/common.hpp>
39 #include <mraa/gpio.hpp>
40 
41 namespace upm {
42 
48  class MY9221 {
49  public:
50 
51  // 12 LED channels per chip (instance)
52  static const int LEDS_PER_INSTANCE = 12;
53 
61  MY9221(uint8_t dataPin, uint8_t clockPin, int instances=1);
62 
66  ~MY9221();
67 
76  void setAutoRefresh(bool enable)
77  {
78  m_autoRefresh = enable;
79  }
80 
88  void setLED(int led, bool on);
89 
98  void setLowIntensityValue(int intensity);
99 
108  void setHighIntensityValue(int intensity);
109 
113  void setAll();
114 
118  void clearAll();
119 
125  void refresh();
126 
127  protected:
128  virtual void lockData();
129  virtual void send16bitBlock(uint16_t data);
130 
131  bool m_autoRefresh;
132  // we're only doing 8-bit greyscale, so the high order bits are
133  // always 0
134  uint16_t m_lowIntensity;
135  uint16_t m_highIntensity;
136 
137  unsigned int m_instances;
138 
139  // an array of uint16_t's representing our bit states (on/off)
140  // intensities. Only the low 8 bits are used, but in the future
141  // 16bit support can work here as well.
142  uint16_t *m_bitStates;
143 
144  uint16_t m_commandWord;
145 
146  mraa::Gpio m_gpioClk;
147  mraa::Gpio m_gpioData;
148 
149  private:
150  };
151 
152 }
Definition: my9221.h:48
~MY9221()
Definition: my9221.cxx:87
void setLowIntensityValue(int intensity)
Definition: my9221.cxx:112
void refresh()
Definition: my9221.cxx:140
void setHighIntensityValue(int intensity)
Definition: my9221.cxx:117
void setLED(int led, bool on)
Definition: my9221.cxx:97
void setAll()
Definition: my9221.cxx:122
void clearAll()
Definition: my9221.cxx:131
void setAutoRefresh(bool enable)
Definition: my9221.h:76
MY9221(uint8_t dataPin, uint8_t clockPin, int instances=1)
Definition: my9221.cxx:47