feat : add driver file

This commit is contained in:
linux-downey
2018-12-10 14:35:06 +08:00
parent 39914619f5
commit f94d470522
4 changed files with 2140 additions and 0 deletions

1377
I2Cdev.cpp Normal file

File diff suppressed because it is too large Load Diff

267
I2Cdev.h Normal file
View File

@@ -0,0 +1,267 @@
// I2Cdev library collection - Main I2C device class header file
// Abstracts bit and byte I2C R/W functions into a convenient class
// 6/9/2012 by Jeff Rowberg <jeff@rowberg.net>
//
// Changelog:
// 2012-06-09 - fix major issue with reading > 32 bytes at a time with Arduino Wire
// - add compiler warnings when using outdated or IDE or limited I2Cdev implementation
// 2011-11-01 - fix write*Bits mask calculation (thanks sasquatch @ Arduino forums)
// 2011-10-03 - added automatic Arduino version detection for ease of use
// 2011-10-02 - added Gene Knight's NBWire TwoWire class implementation with small modifications
// 2011-08-31 - added support for Arduino 1.0 Wire library (methods are different from 0.x)
// 2011-08-03 - added optional timeout parameter to read* methods to easily change from default
// 2011-08-02 - added support for 16-bit registers
// - fixed incorrect Doxygen comments on some methods
// - added timeout value for read operations (thanks mem @ Arduino forums)
// 2011-07-30 - changed read/write function structures to return success or byte counts
// - made all methods static for multi-device memory savings
// 2011-07-28 - initial release
/* ============================================
I2Cdev device library code is placed under the MIT license
Copyright (c) 2012 Jeff Rowberg
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
===============================================
*/
#ifndef _I2CDEV_H_
#define _I2CDEV_H_
#ifndef BUFFER_LENGTH
#define BUFFER_LENGTH 32
#endif
// -----------------------------------------------------------------------------
// I2C interface implementation setting
// -----------------------------------------------------------------------------
#define I2CDEV_IMPLEMENTATION I2CDEV_ARDUINO_WIRE
// comment this out if you are using a non-optimal IDE/implementation setting
// but want the compiler to shut up about it
#define I2CDEV_IMPLEMENTATION_WARNINGS
// -----------------------------------------------------------------------------
// I2C interface implementation options
// -----------------------------------------------------------------------------
#define I2CDEV_ARDUINO_WIRE 1 // Wire object from Arduino
#define I2CDEV_BUILTIN_NBWIRE 2 // Tweaked Wire object from Gene Knight's NBWire project
// ^^^ NBWire implementation is still buggy w/some interrupts!
#define I2CDEV_BUILTIN_FASTWIRE 3 // FastWire object from Francesco Ferrara's project
// ^^^ FastWire implementation in I2Cdev is INCOMPLETE!
// -----------------------------------------------------------------------------
// Arduino-style "Serial.print" debug constant (uncomment to enable)
// -----------------------------------------------------------------------------
//#define I2CDEV_SERIAL_DEBUG
#ifdef ARDUINO
#if ARDUINO < 100
#include "WProgram.h"
#else
#include "Arduino.h"
#endif
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
#include <Wire.h>
#endif
#else
#include "ArduinoWrapper.h"
#endif
// 1000ms default read timeout (modify with "I2Cdev::readTimeout = [ms];")
#define I2CDEV_DEFAULT_READ_TIMEOUT 1000
class I2Cdev {
public:
I2Cdev();
static int8_t readBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout);
static int8_t readBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout);
static int8_t readBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout);
static int8_t readBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout);
static int8_t readByte(uint8_t devAddr, uint8_t regAddr, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout);
static int8_t readWord(uint8_t devAddr, uint8_t regAddr, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout);
static int8_t readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout);
static int8_t readWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout);
static bool writeBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t data);
static bool writeBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t data);
static bool writeBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t data);
static bool writeBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t data);
static bool writeByte(uint8_t devAddr, uint8_t regAddr, uint8_t data);
static bool writeWord(uint8_t devAddr, uint8_t regAddr, uint16_t data);
static bool writeBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data);
static bool writeWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data);
static uint16_t readTimeout;
};
#if I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
//////////////////////
// FastWire 0.2
// This is a library to help faster programs to read I2C devices.
// Copyright(C) 2011
// Francesco Ferrara
//////////////////////
/* Master */
#define TW_START 0x08
#define TW_REP_START 0x10
/* Master Transmitter */
#define TW_MT_SLA_ACK 0x18
#define TW_MT_SLA_NACK 0x20
#define TW_MT_DATA_ACK 0x28
#define TW_MT_DATA_NACK 0x30
#define TW_MT_ARB_LOST 0x38
/* Master Receiver */
#define TW_MR_ARB_LOST 0x38
#define TW_MR_SLA_ACK 0x40
#define TW_MR_SLA_NACK 0x48
#define TW_MR_DATA_ACK 0x50
#define TW_MR_DATA_NACK 0x58
#define TW_OK 0
#define TW_ERROR 1
class Fastwire {
private:
static boolean waitInt();
public:
static void setup(int khz, boolean pullup);
static byte write(byte device, byte address, byte value);
static byte readBuf(byte device, byte address, byte *data, byte num);
};
#endif
#if I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_NBWIRE
// NBWire implementation based heavily on code by Gene Knight <Gene@Telobot.com>
// Originally posted on the Arduino forum at http://arduino.cc/forum/index.php/topic,70705.0.html
// Originally offered to the i2cdevlib project at http://arduino.cc/forum/index.php/topic,68210.30.html
#define NBWIRE_BUFFER_LENGTH 32
class TwoWire {
private:
static uint8_t rxBuffer[];
static uint8_t rxBufferIndex;
static uint8_t rxBufferLength;
static uint8_t txAddress;
static uint8_t txBuffer[];
static uint8_t txBufferIndex;
static uint8_t txBufferLength;
// static uint8_t transmitting;
static void (*user_onRequest)(void);
static void (*user_onReceive)(int);
static void onRequestService(void);
static void onReceiveService(uint8_t*, int);
public:
TwoWire();
void begin();
void begin(uint8_t);
void begin(int);
void beginTransmission(uint8_t);
//void beginTransmission(int);
uint8_t endTransmission(uint16_t timeout=0);
void nbendTransmission(void (*function)(int)) ;
uint8_t requestFrom(uint8_t, int, uint16_t timeout=0);
//uint8_t requestFrom(int, int);
void nbrequestFrom(uint8_t, int, void (*function)(int));
void send(uint8_t);
void send(uint8_t*, uint8_t);
//void send(int);
void send(char*);
uint8_t available(void);
uint8_t receive(void);
void onReceive(void (*)(int));
void onRequest(void (*)(void));
};
#define TWI_READY 0
#define TWI_MRX 1
#define TWI_MTX 2
#define TWI_SRX 3
#define TWI_STX 4
#define TW_WRITE 0
#define TW_READ 1
#define TW_MT_SLA_NACK 0x20
#define TW_MT_DATA_NACK 0x30
#define CPU_FREQ 16000000L
#define TWI_FREQ 100000L
#define TWI_BUFFER_LENGTH 32
/* TWI Status is in TWSR, in the top 5 bits: TWS7 - TWS3 */
#define TW_STATUS_MASK (_BV(TWS7)|_BV(TWS6)|_BV(TWS5)|_BV(TWS4)|_BV(TWS3))
#define TW_STATUS (TWSR & TW_STATUS_MASK)
#define TW_START 0x08
#define TW_REP_START 0x10
#define TW_MT_SLA_ACK 0x18
#define TW_MT_SLA_NACK 0x20
#define TW_MT_DATA_ACK 0x28
#define TW_MT_DATA_NACK 0x30
#define TW_MT_ARB_LOST 0x38
#define TW_MR_ARB_LOST 0x38
#define TW_MR_SLA_ACK 0x40
#define TW_MR_SLA_NACK 0x48
#define TW_MR_DATA_ACK 0x50
#define TW_MR_DATA_NACK 0x58
#define TW_ST_SLA_ACK 0xA8
#define TW_ST_ARB_LOST_SLA_ACK 0xB0
#define TW_ST_DATA_ACK 0xB8
#define TW_ST_DATA_NACK 0xC0
#define TW_ST_LAST_DATA 0xC8
#define TW_SR_SLA_ACK 0x60
#define TW_SR_ARB_LOST_SLA_ACK 0x68
#define TW_SR_GCALL_ACK 0x70
#define TW_SR_ARB_LOST_GCALL_ACK 0x78
#define TW_SR_DATA_ACK 0x80
#define TW_SR_DATA_NACK 0x88
#define TW_SR_GCALL_DATA_ACK 0x90
#define TW_SR_GCALL_DATA_NACK 0x98
#define TW_SR_STOP 0xA0
#define TW_NO_INFO 0xF8
#define TW_BUS_ERROR 0x00
//#define _MMIO_BYTE(mem_addr) (*(volatile uint8_t *)(mem_addr))
//#define _SFR_BYTE(sfr) _MMIO_BYTE(_SFR_ADDR(sfr))
#ifndef sbi // set bit
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif // sbi
#ifndef cbi // clear bit
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif // cbi
extern TwoWire Wire;
#endif // I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_NBWIRE
#endif /* _I2CDEV_H_ */

View File

@@ -0,0 +1,330 @@
/*
* Grove_LED_Matrix_Driver_HT16K33.h
* A library for Grove - LED Matrix Driver(HT16K33 with 8x8 LED Matrix)
*
* Copyright (c) 2018 seeed technology inc.
* Website : www.seeed.cc
* Author : Jerry Yip
* Create Time: 2018-06
* Version : 0.1
* Change Log :
* Copyright (c) 2018 seeed technology inc.
* Website : www.seeed.cc
* Author : downey
* Create Time: 2018-06
* Version : 1.1
* Change Log :for digital tube development.
*
* The MIT License (MIT)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "grove_dual_alphanumeric_display.h"
HT16K33::HT16K33()
{
}
void HT16K33::init(uint8_t addr)
{
_addr = addr;
// turn on oscillator
I2Cdev::writeBytes(_addr, 0x21, 0, (uint8_t *)NULL);
}
/*brightness:0-15*/
void HT16K33::setBrightness(uint8_t brightness)
{
I2Cdev::writeBytes(_addr, (0xE0 | brightness), 0, (uint8_t *)NULL);
}
void HT16K33::setBlinkRate(blink_type_t blink_type)
{
I2Cdev::writeBytes(_addr, (0x80 | 0x01 | (blink_type << 1)), 0, (uint8_t *)NULL);
}
Digital_Tube::Digital_Tube()
{
_orientation = DISPLAY_ROTATE_0;
_offset_x = 0;
_offset_y = 0;
_cursor_start = 0;
_cursor_end = 0;
_cursor_steps = 1;
_ms = 100;
}
bool Digital_Tube::isLegalToDisplay(char byte)
{
if( !((byte >= '.' && byte <= '9') || (byte >= 'A' && byte <= 'Z') || (byte >= 'a' && byte <= 'z') ) )
return false;
return true;
}
uint16_t g_display_font[]={
// 0x0000, // display nothing.
0x0080, // 'upper .'
0x2000, // 'lower .'
0x4478, // '0'
0x0060, // '1'
0x0758, // '2'
0x0770, // '3'
0x4360, // '4'
0x4730, // '5'
0x4738, // '6'
0x0070, // '7'
0x4778, // '8'
0x4770, // '9'
0x4378, // 'A'
0x2d70, // 'B'
0x4418, // 'C'
0x2c70, // 'D'
0x4718, // 'E'
0x4318, // 'F'
0x4538, // 'G'
0x4368, // 'H'
0x2c10, // 'I'
0x0478, // 'J'
0x2806, // 'K'
0x4408, // 'L'
0x40ea, // 'M'
0x40ec, // 'N'
0x4478, // 'O'
0x4358, // 'P'
0x447c, // 'Q'
0x435c, // 'R'
0x0494, // 'S'
0x2810, // 'T'
0x4468, // 'U'
0x500a, // 'V'
0x506c, // 'W'
0x1086, // 'X'
0x0882, // 'Y'
0x1412, // 'Z'
0x0000, // '/' ilegal num
};
/**@brief Display number,If the param-num's len less than 4(or equal to),The tubes display static number,otherwise,it displays scroll number.
* When it displays scroll number,the param interval is scrolling interval(ms) ..
* @param num the number to display.
* @param interval :the interval of scroll number.
* */
void Digital_Tube::displayNum(uint32_t num,uint32_t interval)
{
char num_str[15] = {0};
sprintf(num_str,"%ld",(uint32_t)num);
displayString(num_str,interval);
}
void Digital_Tube::shiftDisplay(char *origin_disp_buf,char new_item)
{
char temp[TUBE_COUNT] = {0};
memcpy(temp,&origin_disp_buf[1],TUBE_COUNT-1);
temp[TUBE_COUNT-1] = new_item;
memcpy(origin_disp_buf,temp,TUBE_COUNT);
for(int i =0;i< TUBE_COUNT;i++)
{
setTubeBuf(i+1,g_display_font[get_char_index(temp[i])]);
}
I2Cdev::writeBytes(_addr, 0x00, 16, _buffer);
delay(_ms);
}
/**@brief Display string,If the param-str's len less than 4(or equal to),The tubes display static string,otherwise,it displays scroll string.
* When it displays scroll string,the param interval is scrolling interval(ms) ..
* @param str the str to display.
* @param interval :the interval of scroll string.
* */
void Digital_Tube::displayString(char *str,uint32_t interval)
{
char first_tube_byte = 0,second_tube_byte = 0;
int len = 0;
clearBuf();
len = strlen(str);
if(TUBE_COUNT >= len)
{
for(int i=0;i<len;i++)
{
setTubeBuf(TUBE_COUNT-len+i+1,g_display_font[get_char_index(str[i])]); //Convert number to char;
}
I2Cdev::writeBytes(_addr, 0x00, 16, _buffer);
delay(_ms);
}
else
{
if(len > 255 ) len = 255;
char origin_disp_buf[TUBE_COUNT]={0};
for(int i=0;i<len;i++)
{
shiftDisplay(origin_disp_buf,str[i]);
delay(interval);
}
}
}
void Digital_Tube::clear()
{
memset(_buffer, 0, sizeof(_buffer));
I2Cdev::writeBytes(_addr, 0x00, 16, _buffer);
delay(_ms);
}
void Digital_Tube::fulDisplay()
{
uint8_t buf[16] = {0};
memcpy(_buffer,buf,sizeof(buf));
memset(_buffer, 0xff, sizeof(_buffer));
I2Cdev::writeBytes(_addr, 0x00, 16, _buffer);
delay(_ms);
}
void Digital_Tube::replace_bit12(TubeNum tube_num,bool bit1,bool bit2)
{
switch(tube_num)
{
case FIRST_TUBE:
_buffer[10] |= (bit1<<4);
_buffer[10] |= (bit2<<3);
break;
case SECOND_TUBE:
_buffer[10] |= (bit1<<6);
_buffer[11] |= (bit2<<6);
break;
case THIRD_TUBE:
_buffer[10] |= (bit1<<5);
_buffer[11] |= (bit2<<1);
break;
case FOURTH_TUBE:
_buffer[11] |= (bit1<<2);
_buffer[11] |= (bit2<<0);
break;
default:break;
}
}
void Digital_Tube::setPoint(bool upper_on,bool lower_on)
{
if(upper_on){
_buffer[10] |= g_display_font[0];
_buffer[11] |= g_display_font[0]>>8;
}
if(lower_on){
_buffer[10] |= g_display_font[1];
_buffer[11] |= g_display_font[1]>>8;
}
}
void Digital_Tube::setTubeBuf(TubeNum tube_num,uint16_t value)
{
_buffer[tube_num*2] = value;
_buffer[tube_num*2+1] = value >> 8;
replace_bit12(tube_num,value&0x02,value&0x04);
}
/**@brief Specify the display char of a digital tube.
* @param tube_num The number of tube ,total 4.
* @param c ,The char to display
* */
void Digital_Tube::setTubeSingleChar(TubeNum tube_num,char c)
{
if(!(((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z'))) )
{
return ;
}
uint16_t value = g_display_font[get_char_index(c)];
_buffer[tube_num*2] = value;
_buffer[tube_num*2+1] = value >> 8;
replace_bit12(tube_num,value&0x02,value&0x04);
}
/**@brief Specify the display number of a digital tube.
* @param tube_num The number of tube ,total 4.
* @param num ,The number to display
* */
void Digital_Tube::setTubeSingleNum(TubeNum tube_num,char num)
{
if( !((num >= 0) && (num <= 9)) )
return ;
uint16_t value = g_display_font[get_char_index(num+0x30)];
_buffer[tube_num*2] = value;
_buffer[tube_num*2+1] = value >> 8;
replace_bit12(tube_num,value&0x02,value&0x04);
}
void Digital_Tube::display_one_tube(TubeNum tube_num,uint16_t value)
{
_buffer[tube_num*2] = value;
_buffer[tube_num*2+1] = value >> 8;
replace_bit12(tube_num,value&0x02,value&0x04);
I2Cdev::writeBytes(_addr, 0x00, 16, _buffer);
delay(_ms);
}
void Digital_Tube::clearBuf()
{
memset(_buffer,0,sizeof(_buffer));
}
int Digital_Tube::get_char_index(char c)
{
if((c >= '0') && (c <= '9'))
{
return c-0x30+2;
}
else if((c >= 'A') && (c <= 'Z'))
{
return c-0x37+2;
}
else if((c >= 'a') && (c <= 'z'))
{
return c-0x57+2;
}
else
{
return '/'+2;
}
}
void Digital_Tube::display()
{
I2Cdev::writeBytes(_addr, 0x00, 16, _buffer);
delay(_ms);
}

View File

@@ -0,0 +1,166 @@
/*
* Grove_LED_Matrix_Driver_HT16K33.h
* A library for Grove - LED Matrix Driver(HT16K33 with 8x8 LED Matrix)
*
* Copyright (c) 2018 seeed technology inc.
* Website : www.seeed.cc
* Author : Jerry Yip
* Create Time: 2018-06
* Version : 0.1
* Change Log :
* Copyright (c) 2018 seeed technology inc.
* Website : www.seeed.cc
* Author : downey
* Create Time: 2018-06
* Version : 1.1
* Change Log :for digital tube development.
*
* The MIT License (MIT)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef __GROVE_LED_MATRIX_DRIVER_HT16K33__
#define __GROVE_LED_MATRIX_DRIVER_HT16K33__
#include "I2Cdev.h"
#define HT16K33_DEFAULT_I2C_ADDR 0x71
#define MAX_BIG_BUFFER_SIZE (8*20)
#define TUBE_COUNT 4
enum orientation_type_t
{
DISPLAY_ROTATE_0 = 0,
DISPLAY_ROTATE_90,
DISPLAY_ROTATE_180,
DISPLAY_ROTATE_270,
};
enum action_type_t
{
ACTION_SCROLLING = 0,
ACTION_SHIFT,
};
enum blink_type_t
{
BLINK_OFF = 0,
BLINK_2HZ,
BLINK_1HZ,
};
typedef enum
{
FIRST_TUBE = 1,
SECOND_TUBE,
THIRD_TUBE,
FOURTH_TUBE,
}TubeNum;
class HT16K33 {
public:
HT16K33();
void init(uint8_t addr=HT16K33_DEFAULT_I2C_ADDR);
void setBlinkRate(blink_type_t blink_type);
void setBrightness(uint8_t brightness);
virtual void clear();
protected:
uint8_t _addr;
};
class Digital_Tube : public HT16K33 {
public:
Digital_Tube();
void clear();
/**@brief Display number,If the param-num's len less than 4,The tubes display static number,otherwise,it displays scroll number.
* When it displays scroll number,the param interval is scrolling interval(ms) ..
* @param num the number to display.
* @param interval :the interval of scroll number.
* */
void displayNum(uint32_t num,uint32_t interval = 0);
/**@brief Display string,If the param-str's len less than 4,The tubes display static string,otherwise,it displays scroll string.
* When it displays scroll string,the param interval is scrolling interval(ms) ..
* @param str the str to display.
* @param interval :the interval of scroll string.
* */
void displayString(char *str,uint32_t interval = 0);
/**@brief Display all part of digital tube.
*
* */
void fulDisplay();
/**@brief Clear _buffer,just clear.
*
* */
void clearBuf();
/**@brief Display the contents of _buffer.
*
* */
void display();
/**@brief Specify the display char of a digital tube.
* @param tube_num The number of tube ,total 4.
* @param num ,The number to display
* */
void setTubeSingleChar(TubeNum tube_num,char c);
/**@brief Specify the display number of a digital tube.
* @param tube_num The number of tube ,total 4.
* @param num ,The number to display
* */
void setTubeSingleNum(TubeNum tube_num,char num);
/**@brief Set two points status.
* @prarm upper_on if true,the upper point light on ,otherwise turn off;
* @prarm lower_on if true,the upper point light on ,otherwise turn off;
* */
void setPoint(bool upper_on,bool lower_on);
private:
void display_one_tube(TubeNum tube_num,uint16_t value);
void replace_bit12(TubeNum tube_num,bool bit1,bool bit2);
void setTubeBuf(TubeNum tube_num,uint16_t value);
int get_char_index(char c);
void shiftDisplay(char *origin_disp_buf,char new_item);
// Low1 High1 Low2 High2 ... Low8 High8
uint8_t _buffer[16];
uint8_t _big_buffer[MAX_BIG_BUFFER_SIZE];
uint16_t _cursor_start, _cursor_end, _cursor_steps;
uint16_t _ms;
orientation_type_t _orientation;
int8_t _offset_x, _offset_y;
bool isLegalToDisplay(char byte);
};
#endif //__GROVE_LED_MATRIX_DRIVER_HT16K33__