fork of seeed studio 4-digit display for st nucleo board

Dependencies:   Data_Clock_Pair Seeed_Chainable_LED Seeed_Four_Digit_Disp Seeed_IR_Temp_Sensor Seeed_Led_Bar

Fork of Seeed_Grove_4_Digit_Display_Clock by Seeed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SeeedQTouch.h Source File

SeeedQTouch.h

00001 #ifndef MBED_SEEED_Q_TOUCH_H
00002 #define MBED_SEEED_Q_TOUCH_H
00003 #include "mbed.h"
00004 #include "DataClockPair.h"
00005 
00006 #define QTOUCH_REG_RESET        0X39            // reset
00007 class SeeedQTouch {
00008 
00009     static const int devAddr_ = 0x1b;
00010     int readOpCode_;
00011     int writeOpCode_;
00012     static const int stateReg_ = 0x03;
00013     static const int calibrateReg_ = 0x38;
00014     I2C i2c_;
00015     int read_register_(int address, Serial* pc);
00016     int read_state_(Serial* pc);
00017   public:
00018     SeeedQTouch(DataClockPair pins);
00019     int key_touch(Serial* pc);
00020 };
00021 
00022 SeeedQTouch::SeeedQTouch(DataClockPair pins) : i2c_(pins.dataPin, pins.clockPin) {
00023     /* readOpCode_ = devAddr_ | 0x01; */
00024     /* writeOpCode_ = devAddr_ & 0xFE; */
00025     /* writeOpCode_ = devAddr_ | 0x00; */
00026     readOpCode_ = devAddr_;
00027     writeOpCode_ = devAddr_;
00028 }
00029 
00030 int SeeedQTouch::read_register_(int address, Serial* pc) {
00031     int success;
00032     char dataWrite[2];
00033     char resetWrite[2];
00034     char dataRead[2];
00035 dataWrite[0] = 0x00;
00036 dataWrite[1] = 0x55;
00037 resetWrite[0] = QTOUCH_REG_RESET;
00038 resetWrite[1] = 0x55;
00039     /* int success = i2c_.write(devAddr_, dataWrite, 1, 0); */
00040     /* if( pc ) pc->printf("requesting register %i success is %i", dataWrite[0], success); */
00041 /* dataWrite[0] = 0x55; */
00042     success = i2c_.write(writeOpCode_, resetWrite, 2);
00043     success = i2c_.write(writeOpCode_, dataWrite, 2);
00044     if( pc ) pc->printf("requesting register %i success is %i", dataWrite[0], success);
00045     /* dataWrite[0] = stateReg_; */
00046     /* wait_ms(1); */
00047     /* i2c_.start(); */
00048     /* wait_ms(1); */
00049     /* success = i2c_.write(devAddr_, dataWrite, 1, 1); */
00050     /* wait_ms(1); */
00051     success = i2c_.read(readOpCode_, dataRead, 2);
00052     if( pc ) pc->printf("return value is %i or %i success is %i", dataRead[0] , dataRead[1], success);
00053     /* i2c_.stop(); */
00054     wait_ms(1);
00055     /* int result; */
00056     /* i2c_.start(); */
00057     wait_ms(1);
00058     /* result = i2c_.read(1); */
00059     wait_ms(1);
00060     /* i2c_.stop(); */
00061     return dataRead[0];
00062 }
00063 
00064 int SeeedQTouch::read_state_(Serial* pc) {
00065     return read_register_(0x03, pc);
00066 }
00067 
00068 int SeeedQTouch::key_touch(Serial* pc = 0) {
00069     int keys = read_state_(pc);
00070     return(keys);
00071 }
00072 #endif