Register Display of Azoteq IQS620 Magnetic/Touch/Inductive sensor

Dependents:   IQS620_HelloWorld

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers IQS620DisplayTerminal.cpp Source File

IQS620DisplayTerminal.cpp

00001 // A class library to display Azoteq IQS620 registers on a terminal
00002 
00003 // Copyright 2017 Azoteq. 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.
00004 
00005 // More info on IQS620 sensor IC: http://www.azoteq.com/products/proxfusion/iqs620?mbed
00006 
00007 // ProxFusion 5-minute YouTube video: https://youtu.be/l7tO2ra5y74
00008 
00009 #include "IQS620DisplayTerminal.h"
00010 
00011 // constructor
00012 #if defined(TARGET_TEENSY3_1) || defined (TARGET_TEENSY3_2) || IQS_USE_USBSERIAL
00013 IQS620Display::IQS620Display() : USBSerial() // use our own USB device stack
00014 #else
00015 IQS620Display::IQS620Display() : Serial(USBTX,USBRX) // use mbed default serial port
00016 #endif
00017 
00018 {
00019     frameCounter=0;
00020     baud(DISPLAY_BAUD_RATE);
00021 }
00022 
00023 #if defined(TARGET_TEENSY3_1) || defined (TARGET_TEENSY3_2) || IQS_USE_USBSERIAL
00024 void IQS620Display::baud(int baudRate) {}
00025 #endif
00026 
00027 // display a startup message to serial port
00028 void IQS620Display::helloMessage(bool waitForUser)
00029 {
00030     puts("\x1b[2J  \x1b[?25l  \x1b[H"); // ANSII/VT100 codes to clear screen, invisible cursor, home cursor
00031     printf("           IQS620 Register Display\r\n\r\n");
00032     printf("To get a smooth screen refresh effect, use a terminal program that supports ANSI/VT100 escape codes such as Tera Term.\r\n\r\n");
00033     printf("Handy hint - In many terminal programs, Alt-B (break) will reset your mbed Board.\r\n\r\n");
00034     printf("Press any key to continue...\r\n");
00035     if ( waitForUser ) while( ! readable() ); // wait for keypress to continue
00036     puts("\x1b[2J  \x1b[?25l  \x1b[H"); // ANSII/VT100 codes to clear screen, invisible cursor, home cursor
00037 }
00038 
00039 // show headings and I2C error count
00040 void IQS620Display::showStatus(int I2Cspeed, int I2CErrorCount)
00041 {
00042     frameCounter++;
00043     puts("\x1b[H"); // ANSI/VT100 command for cursor home
00044     printf("\t");
00045     printf("\t IQS620 Register Display\r\n\r\n"); // heading
00046     printf("\t Frame number %06d", frameCounter);
00047     printf("\t I2C Speed %dk", I2Cspeed/1000);
00048     printf("\t I2C Errors %d", I2CErrorCount);
00049 }
00050 
00051 // dump one line of text from the buffer with VT100 color formatting
00052 void IQS620Display::showLine(char * buffer, char * color, int startbyte, int endbyte)
00053 {
00054     for (int i=startbyte; i<=endbyte; i++) {
00055         if ( color == NULL || color[i] == 0 )
00056             printf("%02x ", buffer[i]);
00057         else
00058 #define USE_IQS_COLOR_DISPLAY
00059 #ifndef DONT_USE_IQS_COLOR_DISPLAY
00060             printf("\x1b[32m%02x\x1b[30m ", buffer[i]); // print out in green (ANSI VT100 code)
00061 #else
00062             printf("%02x ", buffer[i]); // print out in black & white
00063 #endif
00064     }
00065 }
00066 
00067 
00068 
00069 
00070 // formatted hex display of IQS620 registers
00071 // with color highlighting
00072 void IQS620Display::showRegisters(char * buffer,char * color, bool showAllRegisters)
00073 {
00074     bool d = showAllRegisters; // if true show all 16 registers per line - for debugging
00075     printf("\r\n\r\n           Device ID (41) [00] ");    showLine(buffer,color,0x00,d?0x0f:0x02);
00076     printf("\r\n\r\n         Events and Flags [10] ");    showLine(buffer,color,0x10,d?0x1f:0x1b);
00077     printf("\r\n\r\n  Channels 0-5 Raw Values [20] ");    showLine(buffer,color,0x20,d?0x2f:0x2b);
00078     printf("\r\n\r\n   Long Term Average Data [30] ");    showLine(buffer,color,0x30,d?0x3f:0x35);
00079     printf("\r\n\r\n   Proxfusion Settings #0 [40] ");    showLine(buffer,color,0x40,d?0x4f:0x4b);
00080     printf("\r\n\r\n   Proxfusion Settings #1 [50] ");    showLine(buffer,color,0x50,d?0x5f:0x57);
00081     printf("\r\n\r\n    Proxfusion Thresholds [60] ");    showLine(buffer,color,0x60,d?0x6f:0x66);
00082     printf("\r\n\r\n           SAR Thresholds [70] ");    showLine(buffer,color,0x70,d?0x7f:0x75);
00083     printf("\r\n\r\n   Metal Detect Threshold [80] ");    showLine(buffer,color,0x80,d?0x8f:0x83);
00084     printf("\r\n\r\n     Hall Sensor Settings [90] ");    showLine(buffer,color,0x90,d?0x9f:0x93);
00085     printf("\r\n\r\n   Hall Switch Thresholds [A0] ");    showLine(buffer,color,0xa0,d?0xaf:0xa2);
00086     printf("\r\n\r\n   Temperature Cal/Limits [C0] ");    showLine(buffer,color,0xc0,d?0xcf:0xc3);
00087     printf("\r\n\r\n  Device & Power Settings [D0] ");    showLine(buffer,color,0xd0,d?0xdf:0xd8);
00088     printf("\r\n\r\n");
00089 }