Motoo Tanaka / Mbed 2 deprecated oscilloscope Featured

Dependencies:   SPI_STMPE610 UniGraphic mbed vt100

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TFTMenu.cpp Source File

TFTMenu.cpp

00001 /** mbed oscilloscope my implementation of a oscillo scope
00002  * Copyright (c) 2014, 2015 Motoo Tanaka @ Design Methodology Lab
00003  *
00004  * TFTMenu.cpp
00005  *
00006  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00007  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00008  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00009  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00010  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00011  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00012  * THE SOFTWARE.
00013  */
00014 #include "mbed.h"
00015 #include <ILI9341.h>
00016 #include "SPI_STMPE610.h"
00017 #include "Arial12x12.h"
00018 #include "Arial24x23.h"
00019 #include "Arial28x28.h"
00020 #include "Arial43x48_numb.h"
00021 #include "vt100.h"
00022 #include <string.h>
00023 
00024 #include "TFTMenu.h"
00025 
00026 extern ILI9341 TFT ;
00027 extern SPI_STMPE610 TSC ;
00028 extern vt100 *tty ;
00029 
00030 
00031 TFTMenuItem::TFTMenuItem(int x1, int y1, int x2, int y2, FuncPtr fnc, 
00032     char *name, uint16_t mcolor, uint16_t fcolor ) 
00033 {
00034     left = x1 ;
00035     right = x2 ;
00036     top = y1 ;
00037     bottom = y2 ;
00038     if (name) {
00039         label = new char[strlen(name)+1] ;
00040         strcpy(label, name) ;
00041         font_color = fcolor ;
00042     }
00043     menu_color = mcolor ;
00044     
00045     left_margin = 7 ;
00046     top_margin = 10 ;
00047     func = fnc ;
00048 }
00049 
00050 TFTMenuItem::~TFTMenuItem() 
00051 {
00052     left = 0 ;
00053     right = 0 ;
00054     top = 0 ;
00055     bottom = 0 ;
00056     if (label) {
00057         free(label) ;
00058     }
00059 }
00060 
00061 TFTRadioButton::TFTRadioButton(int x1, int y1, int x2, int y2, FuncPtr fnc, 
00062     char *name, uint16_t mcolor, uint16_t fcolor,
00063     char *altname, uint16_t altmcolor, uint16_t altfcolor, 
00064     bool sel) : TFTMenuItem(x1,y1,x2,y2,fnc,name,mcolor,fcolor)
00065 {
00066     if (altname) {
00067         alt_label = new char[strlen(altname) + 1] ;
00068         strcpy(alt_label, altname) ;
00069     } else {
00070         alt_label = 0 ;
00071     }
00072     alt_font_color = altfcolor ;
00073     alt_menu_color = altmcolor ;
00074     selected = sel ;
00075 }
00076 
00077 TFTRadioButton::~TFTRadioButton() 
00078 {
00079     left = 0 ;
00080     right = 0 ;
00081     top = 0 ;
00082     bottom = 0 ;
00083     if (label) {
00084         delete label ;
00085     }
00086     if (alt_label) {
00087         delete alt_label ;
00088     }
00089 }
00090 
00091 bool TFTRadioButton::hit(int x, int y)
00092 {
00093     bool result = false ;
00094     if ((left <= x)&&(x <= right)&&(top <= y)&&(y <= bottom)) {
00095         result = true ;
00096         if (selected) {
00097             selected = false ;
00098         } else {
00099             selected = true ;
00100         }
00101         draw() ;
00102     }
00103     return( result ) ;
00104 }
00105 
00106 void TFTRadioButton::select(bool value)
00107 {
00108     selected = value ;
00109 }
00110 
00111 uint16_t TFTMenuItem::getColor(void) 
00112 {
00113     return(menu_color) ;
00114 }
00115 
00116 bool TFTMenuItem::hit(int x, int y) 
00117 {
00118     bool result = false ;
00119     if ((left <= x)&&(x <= right)&&(top <= y)&&(y <= bottom)) {
00120         result = true ;
00121         draw() ;
00122     }
00123 //    draw() ;
00124     return( result ) ;
00125 }
00126 
00127 void TFTMenuItem::doIt(void)
00128 {
00129     if (func) {
00130         func() ;
00131     }
00132 }
00133 
00134 void TFTMenuItem::draw(int offset_x, int offset_y)
00135 {
00136     TFT.BusEnable(true) ;
00137     TFT.fillrect(left+offset_x, top+offset_y, right+offset_x, bottom+offset_y, Black) ;
00138     TFT.fillrect(left+offset_x, top+offset_y, right+offset_x, bottom+offset_y, menu_color) ;
00139     wait(0.1) ;
00140     TFT.locate(left+offset_x+left_margin, top+offset_y+top_margin) ;
00141     TFT.foreground(font_color) ;
00142     TFT.background(menu_color) ;
00143     TFT.set_font((unsigned char *)Arial12x12) ;
00144     wait(0.1) ;
00145     TFT.printf(label) ;
00146     TFT.BusEnable(false) ;
00147 }
00148 
00149 void TFTRadioButton::draw(int offset_x, int offset_y)
00150 {
00151     TFT.BusEnable(true) ;
00152     if (selected) {
00153         TFT.fillrect(left+offset_x, top+offset_y, right+offset_x, bottom+offset_y, Black) ;
00154         TFT.fillrect(left+offset_x, top+offset_y, right+offset_x, bottom+offset_y, alt_menu_color) ;
00155         wait(0.1) ;
00156         TFT.locate(left+offset_x+left_margin, top+offset_y+top_margin) ;
00157         TFT.foreground(alt_font_color) ;
00158         TFT.background(alt_menu_color) ;
00159         TFT.set_font((unsigned char *)Arial12x12) ;
00160         wait(0.1) ;
00161         TFT.printf(alt_label) ;
00162     } else {
00163         TFTMenuItem::draw(offset_x, offset_y) ;
00164     }
00165     TFT.BusEnable(false) ;
00166 }
00167         
00168 
00169 void TFTMenuItem::highlight(int offset_x, int offset_y)
00170 {
00171     TFT.BusEnable(true) ;
00172     TFT.rect(left+offset_x, top+offset_y, right+offset_x, bottom+offset_y, font_color) ;
00173     TFT.BusEnable(false) ;
00174 /*
00175     TFT.fillrect(left+offset_x, top+offset_y, right+offset_x, bottom+offset_y, font_color) ;
00176     wait(0.1) ;
00177     TFT.locate(left+offset_x+left_margin, top+offset_y+top_margin) ;
00178     TFT.foreground(menu_color) ;
00179     TFT.background(font_color) ;
00180     TFT.set_font((unsigned char *)Arial12x12) ;
00181     wait(0.1) ;
00182     TFT.printf(label) ;
00183 */
00184 }