upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
tm1637.h
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 
73  class TM1637
74  {
75  public:
79  typedef enum {
80  NO = 0,
81  YES = 1
82  } M_FAST_GPIO;
91  TM1637(int clk_pin, int dio_pin, int bright = 3, M_FAST_GPIO mmio = YES);
95  ~TM1637();
102  mraa_result_t write(uint8_t *digits);
109  mraa_result_t write(int d, ...);
117  mraa_result_t writeAt(int index, char symbol);
124  mraa_result_t write(std::string digits);
130  void setColon(bool value);
136  void setBrightness(int value);
137 
138  private:
139  void i2c_start();
140  void i2c_stop();
141  void i2c_writeByte(uint8_t value);
142  void update();
143  uint8_t encode(char c);
144 
145  mraa_gpio_context m_clk, m_dio;
146  std::string m_name;
147  uint8_t m_digits[4];
148  uint8_t m_brightness;
149  };
150 }
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.h:73
~TM1637()
Definition: tm1637.cxx:81
M_FAST_GPIO
Definition: tm1637.h:79
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