Lab4
Dependencies: SeeedStudioTFTv2 TFT_fonts mbed
Fork of Seeed_TFT_Touch_Shield by
Revision 6:ebffa73d4f95, committed 2014-09-26
- Comitter:
- uswickra
- Date:
- Fri Sep 26 15:33:34 2014 +0000
- Parent:
- 5:b33fc1aa8d33
- Commit message:
- fix report
Changed in this revision
--- a/ActionListener.cpp Fri Sep 26 12:42:10 2014 +0000 +++ b/ActionListener.cpp Fri Sep 26 15:33:34 2014 +0000 @@ -5,21 +5,18 @@ is_reg = false ; }; -void ActionListener::registerForEvents(ActionListener* widg) +void ActionListener::registerForEvents(ActionListener* tagt) { - target = widg ; + target = tagt ; is_reg = true ; - children.push_back(widg); +// if(tagt != NULL) +// children.push_back(tagt); }; void ActionListener::action(ActionType type, ActionEvent evnt) { + //trigger action for target if(is_reg) { -// target->trigger_action(type, evnt); - for(vector<ActionListener*>::iterator it = children.begin(); it != children.end(); it++) { - ActionListener* w = *it; - w->trigger_action(type, evnt); - } + trigger_action(type, evnt, (void*) target); } - }; \ No newline at end of file
--- a/ActionListener.h Fri Sep 26 12:42:10 2014 +0000 +++ b/ActionListener.h Fri Sep 26 15:33:34 2014 +0000 @@ -11,7 +11,7 @@ //pixel y that event took place int y; - char* string; + char* str; }; class ActionListener{ @@ -23,11 +23,10 @@ void action(ActionType type, ActionEvent evnt); protected: - virtual void trigger_action( ActionType type, ActionEvent evnt)=0; + virtual void trigger_action( ActionType type, ActionEvent evnt, void* target)=0; + bool is_reg; private: - bool is_reg; - ActionListener* target; - vector<ActionListener*> children; + ActionListener* target; }; \ No newline at end of file
--- a/Button.cpp Fri Sep 26 12:42:10 2014 +0000 +++ b/Button.cpp Fri Sep 26 15:33:34 2014 +0000 @@ -19,7 +19,17 @@ TFT.printf(lbl); } -void Button::trigger_action(ActionType type, ActionEvent evnt){ - //do something - +void Button::trigger_action(ActionType type, ActionEvent evnt, void* target){ + //do something + if(type == CORD){ + ActionEvent new_event; + new_event.x = evnt.x; + new_event.y = evnt.y; + new_event.str = lbl; + ActionType type; + type = CORD_STR; + + Panel* target_pnl = (Panel*) target; + target_pnl->trigger_action(type, new_event, NULL); + } } \ No newline at end of file
--- a/Button.h Fri Sep 26 12:42:10 2014 +0000 +++ b/Button.h Fri Sep 26 15:33:34 2014 +0000 @@ -9,7 +9,7 @@ Button(char* label, int p_color, int bd_color, int w, int h); virtual void paint(); - virtual void trigger_action(ActionType type, ActionEvent evnt); + virtual void trigger_action(ActionType type, ActionEvent evnt, void* target); private: char* lbl;
--- a/Panel.cpp Fri Sep 26 12:42:10 2014 +0000 +++ b/Panel.cpp Fri Sep 26 15:33:34 2014 +0000 @@ -1,4 +1,5 @@ #include "Panel.h" +#include "Arial12x12.h" Panel::Panel(int x_0, int y_0, int x_1, int y_1, int p_color, int bd_color, int r = 1, int c = 1) { @@ -7,7 +8,7 @@ x1 = x_1; y1 = y_1 ; init(p_color, bd_color, r, c); - //calculate pixels per row/col + //calculate pixels per row/col pp_row = TFT.height() / (rows+0.0) ; pp_col = TFT.width() / (cols+0.0) ; redraw(); @@ -41,6 +42,11 @@ //state info state_changed = true ; push_children = true ; + draw_text = false; + cursor_x0 = x0; + cursor_y0 = y0 ; + next_cursor_x0 = cursor_x0 ; + next_cursor_y0 = cursor_y0; } void Panel::paint() @@ -48,17 +54,23 @@ TFT.rect(x0,y0,x1,y1,border_color); //paint fill TFT.fillrect(x0+2,y0+2,x1-2,y1-2,back_color); + if(draw_text) { + TFT.set_font((unsigned char*) Arial12x12); + TFT.locate(cursor_x0 ,cursor_y0); + TFT.printf(input_string); + draw_text = false; + } } bool Panel::addWidget(AbstractWidget *p) { //include as a child - if(push_children){ + if(push_children) { children.push_back(p); } - + //adjust pixels per row/col values for panel 'p' - //this is [number of pixels taken by p] / [row or col divisions] + //this is [number of pixels taken by p] / [row or col divisions] p->pp_row = (pp_row*p->height)/p->rows; p->pp_col = (pp_col*p->width)/p->cols; //re-adjust absolute cordinates of Panel 'p' @@ -78,14 +90,14 @@ p->x0 = x0 + pp_col*curr_col ; p->y0 = y0 + pp_row*curr_row ; p->x1 = p->x0 + pp_col*p->width; - if(p->x1 + pp_col*1 > x1){ + if(p->x1 + pp_col*1 > x1) { //lookahead if the panel that is added now is in the last coloumn adjust it x corner to boundary - p->x1 = x1; + p->x1 = x1; } p->y1 = p->y0 + pp_row*p->height; - if(p->y1 + pp_row*1 > y1){ + if(p->y1 + pp_row*1 > y1) { //if the panel that is added is in the last row then adjust its x corner to boundary - p->y1 = y1; + p->y1 = y1; } //keep previous row,col for updates to this widget prev_col = curr_col; @@ -113,10 +125,36 @@ curr_col = 0 ; } } - + pc.printf("c_row: %d c_col: %d --- child x0,y0 : %d,%d x1,y1 : %d,%d --- pp_row, pp_col : %f,%f \r\n", curr_row, curr_col, - p->x0,p->y0,p->x1,p->y1,p->pp_row ,p->pp_col); + p->x0,p->y0,p->x1,p->y1,p->pp_row ,p->pp_col); return true; } + +void Panel::trigger_action(ActionType type, ActionEvent evnt, void* target) +{ + //do something + if(type == CORD_STR) { + char* input_str = evnt.str; + int len = strlen(input_str); + + int x_pixels = len*12; + cursor_x0 = next_cursor_x0 ; + cursor_y0 = next_cursor_y0 ; + + if(cursor_x0 < 240 && cursor_y0 < 320 ) { + if(cursor_x0 + x_pixels >= 240) { + next_cursor_y0 = cursor_y0 + 14; + next_cursor_x0 = x0 ; + } else { + next_cursor_x0 = (cursor_x0 + x_pixels); + } + input_string = input_str; + draw_text = true; + state_changed = true; + } + + } +}
--- a/Panel.h Fri Sep 26 12:42:10 2014 +0000 +++ b/Panel.h Fri Sep 26 15:33:34 2014 +0000 @@ -6,6 +6,12 @@ private: int used_cells ; + //for panel displays + int cursor_x0, cursor_y0; + int next_cursor_x0, next_cursor_y0; + bool draw_text; + char* input_string ; + void init(int p_color, int bd_color, int r, int c); public: @@ -17,5 +23,7 @@ Panel(int p_color, int bd_color, int w, int h, int r, int c); virtual bool addWidget(AbstractWidget *p); + + virtual void trigger_action(ActionType type, ActionEvent evnt, void* target); }; \ No newline at end of file
--- a/Widget.cpp Fri Sep 26 12:42:10 2014 +0000 +++ b/Widget.cpp Fri Sep 26 15:33:34 2014 +0000 @@ -36,17 +36,44 @@ } } -AbstractWidget* AbstractWidget::remove_child() { - AbstractWidget* w = children.back(); - children.pop_back(); - //refresh state of returned widget +AbstractWidget* AbstractWidget::remove_child() +{ + AbstractWidget* w = children.back(); + children.pop_back(); + //refresh state of returned widget // w->refresh(); - //revert to previous row/col position - curr_row = prev_row; - curr_col = prev_col; - return w; + //revert to previous row/col position + curr_row = prev_row; + curr_col = prev_col; + return w; +} + +void AbstractWidget::trigger_action(ActionType type, ActionEvent evnt, void* target) +{ + //do nothing +} + + +void AbstractWidget::inject_action(int x, int y) +{ + double di_per_pixel = 28.9583; + double dj_per_pixel = 21.25; + + int x_cord = x / di_per_pixel ; + int y_cord = y / dj_per_pixel ; + //do nothing + ActionEvent evnt; + ActionType type; + evnt.x = x_cord; + evnt.y = y_cord ; + type = CORD; + //do this action if registered for events and is inside the input window + if(x_cord > x0 && x_cord < x1 && y_cord > y0 && y_cord < y1 ) { + action(type, evnt); } - -void AbstractWidget::trigger_action(ActionType type, ActionEvent evnt){ - //do nothing + //also inject for children + for(vector<AbstractWidget*>::iterator it = children.begin(); it != children.end(); it++) { + AbstractWidget* w = *it; + w->inject_action(x, y); + } }
--- a/Widget.h Fri Sep 26 12:42:10 2014 +0000 +++ b/Widget.h Fri Sep 26 15:33:34 2014 +0000 @@ -22,7 +22,9 @@ AbstractWidget* remove_child(); - virtual void trigger_action(ActionType type, ActionEvent evnt); + virtual void trigger_action(ActionType type, ActionEvent evnt, void* target); + + void inject_action(int x, int y); protected:
--- a/main.cpp Fri Sep 26 12:42:10 2014 +0000 +++ b/main.cpp Fri Sep 26 15:33:34 2014 +0000 @@ -208,6 +208,7 @@ //DIAL Pad Panel dialPanel(Black, Black, 1, 2, 4, 3); Button Key_1("1",DarkGrey,White); + Key_1.registerForEvents(&textDisplay); Button Key_2("2",DarkGrey,White); Button Key_3("3",DarkGrey,White);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/report.txt Fri Sep 26 15:33:34 2014 +0000 @@ -0,0 +1,24 @@ +Lab 4 Report +Udayanga Wickramasinghe +uswickra@umail.iu.edu + +1. Results +============== + +I was able to program LCD touch display and create a user interface for Phone and Text messaging. Two screens were created that basically +involved creating a basic UI framework. However I had difficulty configuring touch input since somehow my display does not recognize touch +properly even after calibration. + + +2. Difficulties +=================== +It was extremely difficult to configure touch input for the LCD since somehow it is not calibrating properly even after using #calibrate +function and tweaking the threshold values. +I had to initially put some thought into designing a basic UI framework which involved panels and buttons ,etc, but after the inital design +phase was over, creating a functional UI was fairly easy. + + +3. Things I Learnt +================== + +Learnt how to interact with LCD output and input techniques and also working state machine involved with UI interactions. \ No newline at end of file