Announcement

Collapse
No announcement yet.

Orientation of theTouch panel

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Orientation of theTouch panel

    Hi everybody, each time i ask something here i get more than i hope, so here is one more question :

    I need to set some touch buttons in my new project with this sweet Picadillo 35t.
    I start with the "Buttons" given example and keep the essential code only for two buttons. It gives this ;

    #include <TFT.h>
    #include <Widgets.h>

    PICadillo35t tft;
    AnalogTouch ts(LCD_XL, LCD_XR, LCD_YU, LCD_YD, 320, 480);

    twButton on(tft, ts, 0, 100, 160, 100, "ON");
    twButton off(tft, ts, 160, 100, 160, 100, "OFF");

    void setup() {
    analogWrite(PIN_BACKLIGHT, 255);
    tft.initializeDevice();
    ts.initializeDevice();
    ts.scaleX(4.3);
    ts.scaleY(3.3);
    ts.offsetY(5);

    tft.fillScreen(Color::Black);
    tft.setFont(Fonts::Default);
    tft.setTextColor(Color::White);
    on.setBevel(4);
    on.setTextColor(Color::DarkGreen);
    on.setFont(Fonts::Ubuntu30);

    off.setBevel(4);
    off.setTextColor(Color::Red);
    off.setFont(Fonts::Ubuntu30);
    }

    void loop() {
    ts.sample();

    if (on.render()) analogWrite(PIN_BACKLIGHT, 100);
    if (off.render()) analogWrite(PIN_BACKLIGHT, 255);

    }

    It works.

    then i set the orientation by adding "tft.setRotation(1);" to get landscape view and the problem begins.
    the two buttons are visually landscape oriented but the touch areas are still in the portrait orientation.

    I tried to change the line "AnalogTouch ts(LCD_XL, LCD_XR, LCD_YU, LCD_YD, 320, 480);" for "AnalogTouch ts(LCD_XL, LCD_XR, LCD_YU, LCD_YD, 480, 320);" but nothing changes.
    I also tried to chage the order of the other arguments in the parenthesis like LCD_XL but it's even worse, the touch is disabled.
    I tried to add "ts.setRotation(1);", no results.

    An idea ?

    Regards, Dagui.
    Last edited by Dagui; 2nd December 2014, 04:31 AM.

  • #2
    You should, from what I recall, keep the touch screen setup as 320x480 in portrait. Then the touch screen should rotate properly with setRotation. This is the touchscreen setup code from James's reflow oven (the demo in the video):

    Code:
    AnalogTouch ts(LCD_XL, LCD_XR, LCD_YU, LCD_YD, 320, 480);
    ...
        ts.initializeDevice();
        ts.setRotation(1);
        ts.scaleX(4.3);
        ts.scaleY(3.3);
        ts.offsetY(5);
    However, that program uses the GCI widgets, not the software drawn widgets. It should work fine for the software drawn widgets, since all the rotation does is swap around the coordinates that are returned by the x() and y() functions:

    Code:
    uint16_t AnalogTouch::x() {
        int x = _pos.x + _offset_x;
        int y = _pos.y + _offset_y;
    
        switch (_rotation) {
            case 0:
                return x;
            case 3:
                return _height - y;
            case 2:
                return _width - x;
            case 1:
                return y;
        }
        return 0;
    }
    
    uint16_t AnalogTouch::y() {
        int x = _pos.x + _offset_x;
        int y = _pos.y + _offset_y;
    
        switch (_rotation) {
            case 0:
                return y;
            case 3:
                return x;
            case 2:
                return _height - y;
            case 1:
                return _width - x;
        }
        return 0;
    }
    That is, of course, if your TFT library is up to date...

    Comment

    Working...
    X