upm  1.5.0
Sensor/Actuator repository for libmraa (v1.8.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:
80  typedef enum {
81  NO = 0,
82  YES = 1
83  } M_FAST_GPIO;
92  TM1637(int clk_pin, int dio_pin, int bright = 3, M_FAST_GPIO mmio = YES);
96  ~TM1637();
103  mraa_result_t write(uint8_t *digits);
110  mraa_result_t write(int d, ...);
118  mraa_result_t writeAt(int index, char symbol);
125  mraa_result_t write(std::string digits);
131  void setColon(bool value);
137  void setBrightness(int value);
138 
139  private:
140  void i2c_start();
141  void i2c_stop();
142  void i2c_writeByte(uint8_t value);
143  void update();
144  uint8_t encode(char c);
145 
146  mraa_gpio_context m_clk, m_dio;
147  std::string m_name;
148  uint8_t m_digits[4];
149  uint8_t m_brightness;
150  };
151 }
mraa_result_t writeAt(int index, char symbol)
Definition: tm1637.cxx:110
TM1637(int clk_pin, int dio_pin, int bright=3, M_FAST_GPIO mmio=YES)
Definition: tm1637.cxx:43
API for the TM1637 7-Segment Display.
Definition: tm1637.hpp:74
~TM1637()
Definition: tm1637.cxx:81
Definition: a110x.hpp:29
M_FAST_GPIO
Definition: tm1637.hpp:80
void setColon(bool value)
Definition: tm1637.cxx:130
mraa_result_t write(uint8_t *digits)
Definition: tm1637.cxx:90
void setBrightness(int value)
Definition: tm1637.cxx:139