upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
tm1637.hpp
1 /*
2  * Author: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
3  * Copyright (c) 2015 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 
25 #pragma once
26 
27 #include <unistd.h>
28 #include <stdint.h>
29 #include <string>
30 #include <iostream>
31 
32 #include <mraa/gpio.h>
33 
34 
35 // TM1637-specific register addresses for writing all digits at a time
36 #define TM1637_ADDR 0x40
37 #define TM1637_REG 0xC0
38 #define TM1637_CMD 0x88
39 
40 // Display-specific values
41 #define M_DISPLAY_DIGITS 4
42 
43 namespace upm
44 {
45 
74  class TM1637
75  {
76  public:
84  TM1637(int clk_pin, int dio_pin, int bright = 3);
88  ~TM1637();
95  mraa_result_t write(uint8_t *digits);
102  mraa_result_t write(int d, ...);
110  mraa_result_t writeAt(int index, char symbol);
117  mraa_result_t write(std::string digits);
123  void setColon(bool value);
129  void setBrightness(int value);
130 
131  private:
132  void i2c_start();
133  void i2c_stop();
134  void i2c_writeByte(uint8_t value);
135  void update();
136  uint8_t encode(char c);
137 
138  mraa_gpio_context m_clk, m_dio;
139  std::string m_name;
140  uint8_t m_digits[4];
141  uint8_t m_brightness;
142  };
143 }
mraa_result_t writeAt(int index, char symbol)
Definition: tm1637.cxx:101
TM1637(int clk_pin, int dio_pin, int bright=3)
Definition: tm1637.cxx:43
API for the TM1637 7-Segment Display.
Definition: tm1637.hpp:74
~TM1637()
Definition: tm1637.cxx:72
C++ API wrapper for the bh1749 driver.
Definition: a110x.hpp:29
void setColon(bool value)
Definition: tm1637.cxx:121
mraa_result_t write(uint8_t *digits)
Definition: tm1637.cxx:81
void setBrightness(int value)
Definition: tm1637.cxx:130