upm  0.1.8
Sensor/Actuator repository for libmraa (v0.4.5)
 All Data Structures Files Functions Variables Macros Pages
tm1637.h
1 /*
2  * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
3  * Copyright (c) 2014 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 #pragma once
25 
26 #include <string>
27 #include <mraa/aio.h>
28 #include <mraa/gpio.h>
29 
30 #define SEG_A 0b00000001
31 #define SEG_B 0b00000010
32 #define SEG_C 0b00000100
33 #define SEG_D 0b00001000
34 #define SEG_E 0b00010000
35 #define SEG_F 0b00100000
36 #define SEG_G 0b01000000
37 
38 #define TM1637_I2C_COMM1 0x40
39 #define TM1637_I2C_COMM2 0xC0
40 #define TM1637_I2C_COMM3 0x80
41 
42 #define PULSE_LENGTH 50
43 
44 #define HIGH 1
45 #define LOW 0
46 
47 namespace upm {
48 
65 class TM1637 {
66  public:
73  TM1637 (uint8_t di, uint8_t dcki);
78  ~TM1637 ();
79 
85  mraa_result_t setBrightness (uint8_t level);
86 
95  mraa_result_t setSegments (const uint8_t segments[], uint8_t length = 4, uint8_t pos = 0);
96 
102  mraa_result_t write (std::string msg);
103 
107  std::string name()
108  {
109  return m_name;
110  }
111 
112  private:
113  mraa_result_t start();
114  mraa_result_t stop();
115  mraa_result_t writeByte (uint8_t value);
116  mraa_result_t pinMode (mraa_gpio_context ctx, gpio_dir_t mode);
117 
118  mraa_gpio_context m_clkPinCtx;
119  mraa_gpio_context m_dataPinCtx;
120 
121  std::string m_name;
122  uint8_t m_brightness;
123 };
124 
125 }
mraa_result_t setBrightness(uint8_t level)
Definition: tm1637.cxx:99
std::string name()
Definition: tm1637.h:107
C++ API for Seven segments screen.
Definition: tm1637.h:65
~TM1637()
Definition: tm1637.cxx:86
mraa_result_t setSegments(const uint8_t segments[], uint8_t length=4, uint8_t pos=0)
Definition: tm1637.cxx:104
mraa_result_t write(std::string msg)
Definition: tm1637.cxx:122
TM1637(uint8_t di, uint8_t dcki)
Definition: tm1637.cxx:53