Emiel Estiévenart
/
QT1070_copy
Schoolproject, Emulates a QT1070 from a touchberry
Diff: I2C_QT1070.cpp
- Revision:
- 0:b7b55b8a4d2b
- Child:
- 1:f4caacc4df1b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/I2C_QT1070.cpp Thu Nov 10 13:28:23 2016 +0000 @@ -0,0 +1,85 @@ +#include "I2C_QT1070.h" + +namespace QT1070touchemulator +{ + +I2cQT1070::I2cQT1070(PinName sda, PinName scl, int address, int frequentie):I2CSlave(sda, scl) +{ + this->address(address); + int registerAdress = 0; + frequency(frequentie); +} + +void I2cQT1070::check_for_instruction(void) +{ + int adressed = receive(); + int command = 0; + switch (adressed) { + case I2CSlave::ReadAddressed: + printf("Read addressed \r\n"); + + send_data_to_master(); + break; + + case I2CSlave::WriteAddressed: + printf("Write addressed \r\n"); + // process_instruction(); + save_register_adress(); + // command = read(); + + break; + } + +} + +void I2cQT1070::save_register_adress(){ + registerAdress = read(); + printf("This is what the read function goves \r\n"); + printf("" + registerAdress); + stop(); +} + +void I2cQT1070::send_data_to_master() +{ + + switch(registerAdress) { + + + case CHIP_ID: { + printf("received CHIP_ID command \r\n"); + char value[1]; + value[0] = Qt1070Chip.getChipID(); + write(value, 1); + + break; + } + + case FIRMWARE: { + printf("received FIRMWARE command \r\n"); + char value2[1]; + value2[0] = Qt1070Chip.getFirmware(); + write(value2, 1); + break; + } + case KEY_STATUS: { + printf("received KEY_STATUS command \r\n"); + char value3[1]; + value3[0] = Qt1070Chip.getKeystate(); + write(value3, 1); + break; + } + case RESET: { + printf("recieved WRITE_DATA command \r\n"); + break; + } + + default: { + printf("unknown command\n\r"); + } + } + +} + + + +}; \ No newline at end of file