Skip to content

Instantly share code, notes, and snippets.

@kdorff
Last active November 10, 2022 17:12
Show Gist options
  • Save kdorff/78d45057ee7a1aaf92f839f576c99e0b to your computer and use it in GitHub Desktop.
Save kdorff/78d45057ee7a1aaf92f839f576c99e0b to your computer and use it in GitHub Desktop.

Revisions

  1. kdorff revised this gist Nov 10, 2022. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions display-touch-panel.h
    Original file line number Diff line number Diff line change
    @@ -3,12 +3,11 @@
    // tft-office.yaml https://gist.github.com/kdorff/363cc20a26fddf7a3dea6fabbcd04805
    // display-panel.h https://gist.github.com/kdorff/5c26fb21c573e4309da2587aa6e9b5d3
    // display-touch-panel.h https://gist.github.com/kdorff/78d45057ee7a1aaf92f839f576c99e0b
    // tft-door-monitor.h https://gist.github.com/kdorff/811f86b33bf8b63050dce7e91d70cac8
    // tft-room-time-temp.h https://gist.github.com/kdorff/811f86b33bf8b63050dce7e91d70cac8
    //

    #include "esphome.h"
    #include <vector>
    #include "display-panel.h"

    // Extends DisplayPanel to add touch supports.
    class DisplayTouchPanel: public DisplayPanel {
    @@ -25,8 +24,9 @@ class DisplayTouchPanel: public DisplayPanel {

    // See the point touched is in the range of the Panel.
    bool isTouchOnPanel(esphome::touchscreen::TouchPoint touchPoint) {
    return
    bool found =
    (touchPoint.x >= x && touchPoint.x <= max_x) &&
    (touchPoint.y >= y && touchPoint.y <= max_y);
    return found;
    }
    };
  2. kdorff revised this gist Nov 1, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion display-touch-panel.h
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    //
    // This is part of 4 files. Make sure you have the whole set
    // tft-test-1.yaml https://gist.github.com/kdorff/363cc20a26fddf7a3dea6fabbcd04805
    // tft-office.yaml https://gist.github.com/kdorff/363cc20a26fddf7a3dea6fabbcd04805
    // display-panel.h https://gist.github.com/kdorff/5c26fb21c573e4309da2587aa6e9b5d3
    // display-touch-panel.h https://gist.github.com/kdorff/78d45057ee7a1aaf92f839f576c99e0b
    // tft-door-monitor.h https://gist.github.com/kdorff/811f86b33bf8b63050dce7e91d70cac8
  3. kdorff revised this gist Nov 1, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion display-touch-panel.h
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    // This is part of 4 files. Make sure you have the whole set
    // tft-test-1.yaml https://gist.github.com/kdorff/363cc20a26fddf7a3dea6fabbcd04805
    // display-panel.h https://gist.github.com/kdorff/5c26fb21c573e4309da2587aa6e9b5d3
    // display-touch-panel.h
    // display-touch-panel.h https://gist.github.com/kdorff/78d45057ee7a1aaf92f839f576c99e0b
    // tft-door-monitor.h https://gist.github.com/kdorff/811f86b33bf8b63050dce7e91d70cac8
    //

  4. kdorff created this gist Nov 1, 2022.
    32 changes: 32 additions & 0 deletions display-touch-panel.h
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    //
    // This is part of 4 files. Make sure you have the whole set
    // tft-test-1.yaml https://gist.github.com/kdorff/363cc20a26fddf7a3dea6fabbcd04805
    // display-panel.h https://gist.github.com/kdorff/5c26fb21c573e4309da2587aa6e9b5d3
    // display-touch-panel.h
    // tft-door-monitor.h https://gist.github.com/kdorff/811f86b33bf8b63050dce7e91d70cac8
    //

    #include "esphome.h"
    #include <vector>
    #include "display-panel.h"

    // Extends DisplayPanel to add touch supports.
    class DisplayTouchPanel: public DisplayPanel {
    public:
    // Calculated maximum x and y values. Use for touch in isTouchOnPanel()
    unsigned int max_x;
    unsigned int max_y;

    // Constructor, uses DisplayPanel's constructor.
    DisplayTouchPanel(unsigned int _x, unsigned int _y, unsigned int _w, unsigned int _h): DisplayPanel(_x, _y, _w, _h) {
    max_x = _x + _w;
    max_y = _y + _h;
    }

    // See the point touched is in the range of the Panel.
    bool isTouchOnPanel(esphome::touchscreen::TouchPoint touchPoint) {
    return
    (touchPoint.x >= x && touchPoint.x <= max_x) &&
    (touchPoint.y >= y && touchPoint.y <= max_y);
    }
    };