<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[M5Core2 library fork that supports multi-touch and provides Arduino-style virtual buttons [update: and gestures and events] [update2: MERGED !]]]></title><description><![CDATA[<p dir="auto">If you use <a href="https://github.com/ropg/M5Core2" target="_blank" rel="noopener noreferrer nofollow ugc">this</a> fork of the M5Core2 library, you get a Touch object that not only supports the existing API but also a newer API that reads up to two simultaneous touches from the touch sensor. (Limitations apply, see below.)</p>
<p dir="auto">The three touch circles are available as BtnA - BtnC and you get a TouchButton object class that lets you create additional Arduino-style buttons for any rectangle on the screen, and then you can use the regular Arduino functions like <code>isPressed()</code> etc. You can also define handler functions for the pressed and released events for any given TouchButton. You can see everything demonstrated if you run the example sketch from the library examples (also copied below).</p>
<p dir="auto">It's a drop-in replacement: the old touch API still works and the M5Stack factory test compiles fine. I have filed a Pull request on GitHub, so hopefully this all goes into the next version of the stock library.</p>
<pre><code class="language-text">

</code></pre>
<p dir="auto"><strong>Touch object documentation</strong> (from <code>src/touch.h</code>)</p>
<pre><code class="language-text">M5Stack Core2 touch library

	Touch is provided by a FocalTech FT6336 chip, which supports two
	simultaneous touches (see below for limitation).

	This library is initialised in M5Core2.h. An instance "M5.Touch" exists
	and can be used after you call "M5.begin()".


Two-touch API

	TouchPoint_t
		Variable type to hold a touchpoint. Has members x and y that hold
		the coordinates of a touch.

	M5.update()
		In the loop() part of your sketch, call "M5.update()". This is the
		only part that talks to the touch interface. It updates the data
		used by the rest of the two-touch API.

	uint8_t M5.Touch.points
		Contains the number of touches detected: 0, 1 or 2.

	TouchPoint_t M5.Touch.point[0], M5.Touch.point[1]
		M5.Touch.point[0] and M5.Touch.point[1] hold the detected touches.
		
	bool M5.Touch.inBox(x0, y0, x1, y1)
		true if any valid touch is found in the supplied rectangle. Can be
		used directly, but you'll be happier with the TouchButton library.

	bool M5.Touch.hasChanged()
		true if anything has moved on the touch screen since the last time
		this function was called.


Note about multi-touch

	The M5Stack Core2 touch display is only multi-touch in one dimension.
	What that means is that it can detect two separate touches only if they
	occur on different vertical positions. This has to do with the way the
	touch screen is wired, it's not something that can be changed in
	software. So you will only ever see two points if they do not occur
	side-by-side. Touches that do happen side-by-side blend into one touch
	that is detected somewhere between the actual touches.

	While this limits multi-touch somewhat, you can still create multiple
	buttons and see two that are not on the same row simultaneously. You
	could also use one of the buttons below the screen as a modifier for
	something touched on the screen.


Legacy single touch API

	TouchPoint_t
		Variable type to hold a touchpoint. Has members x and y that hold
		the coordinates of a touch.

	bool M5.Touch.ispressed()
		true when the touch screen is pressed.

	TouchPoint_t M5.Touch.getPressedPoint()
		Returns the point that is being pressed, or (-1,-1) is nothing is
		pressed. In case two points are pressed, this will return one of
		them.

	HotZone_t
		Defines a zone on the screen, comes with built-in functions to test
		if a given point is within that zone. Similar but more enhanced
		functionality is provided by the TouchButton library, see below.


</code></pre>
<p dir="auto"><strong>TouchButton documentation</strong> (from <code>src/utility/M5TouchButton.h</code>)</p>
<pre><code class="language-text">M5Stack Core2 M5TouchButton library version 1.0

	Implements Arduino button library compatible buttons for any chosen
	rectangle on the M5Stack Core2 touch screen. Up to two buttons can be
	pressed simultaneously.


Basic usage

	For this to work, M5.update() has to be ran to scan for button presses,
	so make sure to put that in the loop() part of your sketch.

	To create a button, just create a button variable that defines the area
	on the touch screen for the button. E.g.:

		TouchButton testButton(0, 0, 50, 50);

	The format is x0, y0, x1, y1 where x0, y0 is the left top of the button
	and x1, y1 is the right bottom. From here on you can use all the
	standard Arduino button functions such that testButtton.isPressed()
	will now tell you if the top left of the screen is touched.

	Buttons will be deleted from the list if their variables go out of
	focus, so if you define buttons in a subroutine, they will not be in
	your way anywhere else.

	If button areas overlap, both buttons will become pressed if the
	overlap is touched. Note that you cannot ever press two non-overlapping
	buttons simultaneously because the M5Core2 touch screen is not
	multi-touch.

	The three buttons BtnA, BtnB and BtnC from the older M5Stack units come
	already implemented as buttons that lie just below the screen where the
	three circles are. If you want them to be a little bigger and also
	cover the area of the screen where you may be showing labels for the
	buttons, simply raise the top of the buttons like this:

		 M5.BtnA.y0 = M5.BtnB.y0 = M5.BtnC.y0 = 220;

	The screen is 320 x 240 pixels, the touch sensor is 320 x 280, 40
	pixels are below the screen.
	

Note about multi-touch

	The M5Stack Core2 touch display is only multi-touch in one dimension.
	What that means is that it can detect two separate touches only if they
	occur on different vertical positions. This has to do with the way the
	touch screen is wired, it's not something that can be changed in
	software. So you will only ever see two points if they do not occur
	side-by-side. Touches that do happen side-by-side blend into one touch
	that is detected somewhere between the actual touches.

	While this limits multi-touch somewhat, you can still create multiple
	buttons and see two that are not on the same row simultaneously.
	

Calling functions automatically

	In addition to the coordinates, you can optionally specify a
	function to be called when a button is pressed, a function for when
	it's released, as well as an id number to figure out what button was
	pressed if multiple buttons are handled by the same function.
	
	Naturally you can also have a separate function for each key in which
	case you doon't need to supply an id number (it defaults to 0).
	Function pointers and id can also be retrieved or set later, with
	btn.fnPress, btn.fnRelease and fn.id. So to attach a function to the
	leftmost button under the screen, simply say:
	
		M5.BtnA.fnPress = myFunction;



</code></pre>
<p dir="auto"><strong>Touch example</strong> (<code>examples/Basics/Touch/touch.ino</code>)</p>
<pre><code class="language-c++">#include &lt;M5Core2.h&gt;

void setup() {
  M5.begin();
}

void loop() {
  M5.update();
  if (M5.Touch.hasChanged()) {
    if (!M5.Touch.points) Serial.print("--");
    if (M5.Touch.points) Serial.printf("x: %d, y: %d        ",  M5.Touch.point[0].x, M5.Touch.point[0].y);
    if (M5.Touch.points == 2) Serial.printf("x: %d, y: %d",  M5.Touch.point[1].x, M5.Touch.point[1].y);
    Serial.println();
  }
}

void btnHandler(TouchButton &amp;btn) {
  M5.Lcd.fillRect(btn.x0, btn.y0, btn.x1 - btn.x0, btn.y1 - btn.y0, btn.isPressed() ? WHITE : BLACK);
}

TouchButton lt = TouchButton(0, 0, 159, 119, btnHandler, btnHandler);
TouchButton lb = TouchButton(0, 120, 159, 240, btnHandler, btnHandler);
TouchButton rt = TouchButton(160, 0, 320, 119, btnHandler, btnHandler);
TouchButton rb = TouchButton(160, 120, 320, 240, btnHandler, btnHandler);
</code></pre>
]]></description><link>https://community.m5stack.com/topic/2306/m5core2-library-fork-that-supports-multi-touch-and-provides-arduino-style-virtual-buttons-update-and-gestures-and-events-update2-merged</link><generator>RSS for Node</generator><lastBuildDate>Wed, 29 Apr 2026 03:37:48 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/2306.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 15 Sep 2020 10:44:02 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to M5Core2 library fork that supports multi-touch and provides Arduino-style virtual buttons [update: and gestures and events] [update2: MERGED !] on Fri, 22 Jan 2021 17:30:16 GMT]]></title><description><![CDATA[<p dir="auto">For anybody else looking at fixing the issue with multiple simultaneous button presses it seems it can't be done.</p>
<p dir="auto">Having dived into the M5Core2 source the events generated for two button presses, e.g. A &amp; C, are press for A <strong>and move for A.</strong><br />
This looked like a deeper bug (since the second should have been identified as C), so going further in I found that an else branch wasn't refreshing the currently identified touched button on second press (C)  in the method "doEvents" in touch.cpp (it doesn't help the code isn't documented, isn't single responsibility and has an arrow antipattern too).</p>
<p dir="auto">Fixing that bug, so the correct button is refreshed, showed that two events together did not produce presses for A &amp; C but instead (I assume - I'm fed up at this point) the hardware averages the presses' coordinates and declares it's button B(!) that is pressed.</p>
<p dir="auto">If you have old Core 1 code you're porting that uses two simultaneous button presses I'd suggest changing the code to double taps of a single button instead which is the workaround I'm about to use - to remain consistent this behaviour is both on Core 1 and Core 2</p>
<p dir="auto">More formally, I should have read the file header in touch.h earlier:</p>
<p dir="auto">the M5Stack Core2 touch display is only<br />
multi-touch in one dimension. What that means is that it can detect two<br />
separate touches only if they occur on different vertical positions.<br />
This has to do with the way the touch screen is wired, it's not<br />
something that can be changed in software. So you will only ever see<br />
two points if they do not occur side-by-side. Touches that do happen<br />
side-by-side blend into one touch that is detected somewhere between<br />
the actual touches.</p>
]]></description><link>https://community.m5stack.com/post/11930</link><guid isPermaLink="true">https://community.m5stack.com/post/11930</guid><dc:creator><![CDATA[brownb2]]></dc:creator><pubDate>Fri, 22 Jan 2021 17:30:16 GMT</pubDate></item><item><title><![CDATA[Reply to M5Core2 library fork that supports multi-touch and provides Arduino-style virtual buttons [update: and gestures and events] [update2: MERGED !] on Sun, 17 Jan 2021 19:18:53 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rop" aria-label="Profile: Rop">@<bdi>Rop</bdi></a> I've just started some work porting some old Core 1 M5Stack code to the Core 2 API and found that the 3 bottom buttons don't work quite in the same way.</p>
<p dir="auto">For instance this:</p>
<p dir="auto">if (M5.BtnA.isPressed() &amp;&amp; M5.BtnC.isPressed()) {<br />
// do something<br />
}</p>
<p dir="auto">doesn't work on the Core 2 despite the multi touch. It only registers the first button to be pressed rather than both.</p>
<p dir="auto">Is this something you could fix or provide a hint as to what I need to look at to hack it myself?</p>
]]></description><link>https://community.m5stack.com/post/11848</link><guid isPermaLink="true">https://community.m5stack.com/post/11848</guid><dc:creator><![CDATA[brownb2]]></dc:creator><pubDate>Sun, 17 Jan 2021 19:18:53 GMT</pubDate></item><item><title><![CDATA[Reply to M5Core2 library fork that supports multi-touch and provides Arduino-style virtual buttons [update: and gestures and events] [update2: MERGED !] on Mon, 12 Oct 2020 23:41:11 GMT]]></title><description><![CDATA[<p dir="auto">I've updated TouchGoal with long touches and better syntax. It's ready to go. BTW, I consistently get 100% scores now, so Touch is doing exactly what I want it to do.</p>
<p dir="auto">I've added another testing program you may be interested in as well: <a href="https://github.com/vkichline/TouchView" target="_blank" rel="noopener noreferrer nofollow ugc">TouchView</a>.<br />
It displays events to the screen as well as to the serial port. I like to test in an easy chair.<br />
The A button turns E_MOVE an and off, B enables/disable long touches, and C toggles key repeat.<br />
A good way to look for unexpected events. Looks clean to me.</p>
<p dir="auto">I did report one bug I'd call a show stopper; #22. (I added a lot of issues, so it could get lost in the soup):</p>
<ul>
<li>Run events_buttons_gestures_rotation</li>
<li>Double-tap top-left button. Turns blue. Good.</li>
<li>Swipe up. Display inverts. Good.</li>
<li>Double-tap button named "top-left" (now at bottom-right.) Button named "bottom-left" (in top-right position) becomes blue. Error.</li>
</ul>
<p dir="auto">Also, the file M5Touch.h didn't get updated; it has at least one example program (the first example in the top level file) which does not compile. I opened detailed issues at <a href="https://github.com/ropg/M5Core2/issues" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/ropg/M5Core2/issues</a>. It looks like a lot but most are typos.</p>
<p dir="auto">I know I'm a noisy gong, always with the nits and quibbles, but on the whole this is excellent! I'm surprised at how reliably the gestures work; I took a stab at that myself and it was far from trivial. The two-finger support and rotation really go above and beyond as well! A huge leap forward for the Core2 platform.</p>
]]></description><link>https://community.m5stack.com/post/10259</link><guid isPermaLink="true">https://community.m5stack.com/post/10259</guid><dc:creator><![CDATA[vkichline]]></dc:creator><pubDate>Mon, 12 Oct 2020 23:41:11 GMT</pubDate></item><item><title><![CDATA[Reply to M5Core2 library fork that supports multi-touch and provides Arduino-style virtual buttons [update: and gestures and events] [update2: MERGED !] on Mon, 12 Oct 2020 20:22:03 GMT]]></title><description><![CDATA[<p dir="auto">I think it's a wrap...</p>
<p dir="auto">That is: on something this size there will always be more work to do and corners that could be even cleaner. But i think it works, does the job, is well-documented and at the very least doesn't break anything else.</p>
<p dir="auto">So please give it a good test and tell me what y'all think, and then I'll make the PRs for M5Core2 (with M5Touch) and M5Stack (just m5Button).</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/vkichline" aria-label="Profile: vkichline">@<bdi>vkichline</bdi></a> By all means wrap up TouchGoal so it can be included.</p>
<p dir="auto">Everyone: please give the documentation a read and maybe write a tiny thing yourself to see if it works like you would expect... I'd love some more really basic simple examples if you can find the time...</p>
]]></description><link>https://community.m5stack.com/post/10258</link><guid isPermaLink="true">https://community.m5stack.com/post/10258</guid><dc:creator><![CDATA[Rop]]></dc:creator><pubDate>Mon, 12 Oct 2020 20:22:03 GMT</pubDate></item><item><title><![CDATA[Reply to M5Core2 library fork that supports multi-touch and provides Arduino-style virtual buttons [update: and gestures and events] [update2: MERGED !] on Sun, 11 Oct 2020 23:25:05 GMT]]></title><description><![CDATA[<p dir="auto">Tried your changes and I can successfully double-tap every time now. Excellent!<br />
I will add long presses to TouchGoal as soon as I figure them out. But today's my anniversary, so until later!</p>
]]></description><link>https://community.m5stack.com/post/10257</link><guid isPermaLink="true">https://community.m5stack.com/post/10257</guid><dc:creator><![CDATA[vkichline]]></dc:creator><pubDate>Sun, 11 Oct 2020 23:25:05 GMT</pubDate></item><item><title><![CDATA[Reply to M5Core2 library fork that supports multi-touch and provides Arduino-style virtual buttons [update: and gestures and events] [update2: MERGED !] on Sun, 11 Oct 2020 17:24:52 GMT]]></title><description><![CDATA[<p dir="auto">You're welcome to include it! Some additional tests for what shouldn't happen and a few comments about the best way to detect things would make it more valuable.<br />
It's always nice to have a comprehensive suite to walk through after making 'improvements'. I could see TouchGoal being useful for testing subclasses of buttons, zones, etc.<br />
When you think about it being used for testing subclasses, are there any additions you can think of? It's mostly positive testing now, few negative checks. (For example, you should not get this event before that event in this case...)</p>
]]></description><link>https://community.m5stack.com/post/10254</link><guid isPermaLink="true">https://community.m5stack.com/post/10254</guid><dc:creator><![CDATA[vkichline]]></dc:creator><pubDate>Sun, 11 Oct 2020 17:24:52 GMT</pubDate></item><item><title><![CDATA[Reply to M5Core2 library fork that supports multi-touch and provides Arduino-style virtual buttons [update: and gestures and events] [update2: MERGED !] on Sun, 11 Oct 2020 10:51:28 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/vkichline" aria-label="Profile: vkichline">@<bdi>vkichline</bdi></a> In fact, shall we include TouchGoal as an example with the M5Core2 library?</p>
]]></description><link>https://community.m5stack.com/post/10253</link><guid isPermaLink="true">https://community.m5stack.com/post/10253</guid><dc:creator><![CDATA[Rop]]></dc:creator><pubDate>Sun, 11 Oct 2020 10:51:28 GMT</pubDate></item><item><title><![CDATA[Reply to M5Core2 library fork that supports multi-touch and provides Arduino-style virtual buttons [update: and gestures and events] [update2: MERGED !] on Sun, 11 Oct 2020 10:10:17 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/vkichline" aria-label="Profile: vkichline">@<bdi>vkichline</bdi></a> Thanks!! Shouldn't have used NONE, neither here nor in ezTime. Its now NODRAW (again) in this library. i like TouchGoal. Fixed all the issues, I think. The documentation has been completely overhauled.</p>
]]></description><link>https://community.m5stack.com/post/10252</link><guid isPermaLink="true">https://community.m5stack.com/post/10252</guid><dc:creator><![CDATA[Rop]]></dc:creator><pubDate>Sun, 11 Oct 2020 10:10:17 GMT</pubDate></item><item><title><![CDATA[Reply to M5Core2 library fork that supports multi-touch and provides Arduino-style virtual buttons [update: and gestures and events] [update2: MERGED !] on Sun, 11 Oct 2020 00:03:26 GMT]]></title><description><![CDATA[<p dir="auto">Rop, I've opened issues on your fork, and will continue to do so as I work through the library.<br />
I wrote a goal-based UI evaluation tool for Touch and posted it here: <a href="https://github.com/vkichline/TouchGoal" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/vkichline/TouchGoal</a> . Please give it a try!<br />
It asks you to accomplish 16 Touch tasks in random order and keeps score, telling you what you missed at the end. You have up to 8 seconds for each task, but they end as soon as you successfully complete them, so it's pretty fast.<br />
I had written some tools to spew event names, but didn't get a feel for how Touch <em>worked</em> in real life; this test tool provides that feedback.</p>
<p dir="auto">I expected to have issues with gestures based on my serial spewing tests, but they seem quite solid. However, I usually fail to get all the double taps. Does double-tapping work better for you?<br />
Age and fast-twitch motor neurons have a lot of sway over double-click success, it may be a bit too hot for me. Can the delay be adjusted?<br />
If you can breeze through this test w/o failures, that would tell you the UI is doing what you expect it to do.</p>
]]></description><link>https://community.m5stack.com/post/10251</link><guid isPermaLink="true">https://community.m5stack.com/post/10251</guid><dc:creator><![CDATA[vkichline]]></dc:creator><pubDate>Sun, 11 Oct 2020 00:03:26 GMT</pubDate></item><item><title><![CDATA[Reply to M5Core2 library fork that supports multi-touch and provides Arduino-style virtual buttons [update: and gestures and events] [update2: MERGED !] on Fri, 09 Oct 2020 21:06:57 GMT]]></title><description><![CDATA[<p dir="auto">This won't compile for me, it conflicts with another library I need and admire: <code>ezTime</code>.<br />
I get this over and over again:</p>
<pre><code>C:/users/van/.platformio/lib/M5Core2/src/utility/M5Button.h:379:14: error: expected identifier before numeric constant
 #define NONE 0x0120  // Special color value: transparent
              ^
C:/users/van/.platformio/lib/ezTime/src/ezTime.h:69:2: note: in expansion of macro 'NONE'
  NONE, 
  ^
</code></pre>
<p dir="auto">If this specific case is fixed, it's likely to cause conflicts elsewhere. Maybe name spacing could be used to make a macro as general as <code>NONE</code> more compatible.</p>
]]></description><link>https://community.m5stack.com/post/10247</link><guid isPermaLink="true">https://community.m5stack.com/post/10247</guid><dc:creator><![CDATA[vkichline]]></dc:creator><pubDate>Fri, 09 Oct 2020 21:06:57 GMT</pubDate></item><item><title><![CDATA[Reply to M5Core2 library fork that supports multi-touch and provides Arduino-style virtual buttons [update: and gestures and events] [update2: MERGED !] on Fri, 09 Oct 2020 07:14:07 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/vkichline" aria-label="Profile: vkichline">@<bdi>vkichline</bdi></a> Ooops, further up I had said:</p>
<blockquote>
<p dir="auto">The version that's online now (I merged 'visual' into master on my repo) has fixes</p>
</blockquote>
<p dir="auto">but I did not delete the 'visual' branch. My bad. Use the master branch. Much nicer. Some changes, you'll see in the example. (gestures now have directions as well as start and end zones, all optional.)</p>
<p dir="auto">Will enable issues also...</p>
]]></description><link>https://community.m5stack.com/post/10246</link><guid isPermaLink="true">https://community.m5stack.com/post/10246</guid><dc:creator><![CDATA[Rop]]></dc:creator><pubDate>Fri, 09 Oct 2020 07:14:07 GMT</pubDate></item><item><title><![CDATA[Reply to M5Core2 library fork that supports multi-touch and provides Arduino-style virtual buttons [update: and gestures and events] [update2: MERGED !] on Thu, 08 Oct 2020 22:08:20 GMT]]></title><description><![CDATA[<p dir="auto">Rop, M5Button.cpp, line 176 is:</p>
<pre><code>    Serial.println(_time);
</code></pre>
<p dir="auto">...making it hard to catch any of my own debug output.<br />
It would be much easier to open issues if you enabled <code>Issues</code> on <a href="https://github.com/ropg/M5Core2/tree/visual" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/ropg/M5Core2/tree/visual</a>.</p>
]]></description><link>https://community.m5stack.com/post/10244</link><guid isPermaLink="true">https://community.m5stack.com/post/10244</guid><dc:creator><![CDATA[vkichline]]></dc:creator><pubDate>Thu, 08 Oct 2020 22:08:20 GMT</pubDate></item><item><title><![CDATA[Reply to M5Core2 library fork that supports multi-touch and provides Arduino-style virtual buttons [update: and gestures and events] [update2: MERGED !] on Wed, 07 Oct 2020 19:26:30 GMT]]></title><description><![CDATA[<p dir="auto"><strong>New version is up.</strong> You can now make gestures that have only directions. So that whole bit in the first part of the example is now:</p>
<pre><code class="language-c++">// Defines gestures
Gesture swipeRight("swipe right", 160, RIGHT, 30, true);
Gesture swipeDown("swipe down", 120, DOWN, 30, true);
Gesture swipeLeft("swipe left", 160, LEFT, 30, true);
Gesture swipeUp("swipe up", 120, UP, 30, true);
</code></pre>
<ul>
<li>
<p dir="auto">The first number is the minimum distance, the RIGHT, LEFT, etc are just <code>#define</code>s for compass directions, the <code>30</code> thereafter is 'plus or minus 30 degrees'. The Gesture definitions have the same <code>rot1</code> flag (the <code>true</code> at the end above) to denote that the direction is relative to the screen in rotation 1. You can still specify two zones for start and finish before the name of the gesture. If you want to specify just one, say <code>ANYWHERE</code> for the other. This direction stuff works because support for it is now in the underlying <code>Point</code> class. You can also say <code>pointA.directionTo(PointB)</code> or <code>if (PointA.isDirectionTo(PointB, 0, 15)) ...</code> to see if it's due north plus or minus 15 deg. <code>Event</code> has the same functions without the <code>To</code> because it has a start and end point in there already. So if you can want to see if a key was dragged upwards you just put something like that in the <code>E_DRAGGED</code> handler.</p>
</li>
<li>
<p dir="auto">Key repeat with <code>myButton.repeatDelay</code> and <code>repeatInterval</code>, gives repeated <code>E_PRESSING</code> events.</p>
</li>
<li>
<p dir="auto">The <code>Events</code> object is gone and its (few) functions are now functions of Buttons. Last time I move stuff around like that, I swear.</p>
</li>
<li>
<p dir="auto">All my code is now formatted (with <code>clang-format</code>) for easier reading and reworked to be maximally understandable. Will work in some more documentation on how I did things, esp. rotation and other tricky bits. (The <code>.clang-format</code> config file is in the root, see the comment in there for usage. I chose Google's style guide with a few minor tweaks, because that was closest to what the rest of the library was doing already anyway.)</p>
</li>
<li>
<p dir="auto">I expect to be submitting a Pull Request sometime in the next few days after I finish with the documentation.</p>
</li>
<li>
<p dir="auto">I'd be very happy with any test reports.</p>
</li>
</ul>
]]></description><link>https://community.m5stack.com/post/10242</link><guid isPermaLink="true">https://community.m5stack.com/post/10242</guid><dc:creator><![CDATA[Rop]]></dc:creator><pubDate>Wed, 07 Oct 2020 19:26:30 GMT</pubDate></item><item><title><![CDATA[Reply to M5Core2 library fork that supports multi-touch and provides Arduino-style virtual buttons [update: and gestures and events] [update2: MERGED !] on Mon, 05 Oct 2020 08:21:34 GMT]]></title><description><![CDATA[<p dir="auto">Or, even shorter (and with slightly thicker and better visible circles):</p>
<pre><code class="language-c++">#include &lt;M5Core2.h&gt;

const int r = 50;

void setup() {
  M5.begin();
  M5.Lcd.fillScreen(WHITE);
}

void loop() {
  M5.update();
  Event&amp; e = M5.background.event;
  if (e &amp; (E_MOVE | E_RELEASE)) circle(e &amp; E_MOVE ? e.from : e.to, WHITE);
  if (e &amp; (E_TOUCH | E_MOVE)) circle(e.to, e.finger ? BLUE : RED);
}

void circle(Point p, uint16_t c) {
  M5.Lcd.drawCircle(p.x, p.y, r, c);
  M5.Lcd.drawCircle(p.x, p.y, r + 2, c);
}
</code></pre>
]]></description><link>https://community.m5stack.com/post/10235</link><guid isPermaLink="true">https://community.m5stack.com/post/10235</guid><dc:creator><![CDATA[Rop]]></dc:creator><pubDate>Mon, 05 Oct 2020 08:21:34 GMT</pubDate></item><item><title><![CDATA[Reply to M5Core2 library fork that supports multi-touch and provides Arduino-style virtual buttons [update: and gestures and events] [update2: MERGED !] on Sun, 04 Oct 2020 22:25:26 GMT]]></title><description><![CDATA[<p dir="auto">I just pushed a new version that handles two fingers on same button (background is a button) properly.</p>
<p dir="auto">With that version, try this (it will be an example later) to nicely visualise what the sensor sees.</p>
<pre><code class="language-c++"> #include &lt;M5Core2.h&gt;

const int r = 50;

void setup() {
  M5.begin();
  M5.Events.addHandler(moveEvent, E_MOVE);
  M5.Events.addHandler(touchEvent, E_TOUCH);
  M5.Events.addHandler(releaseEvent, E_RELEASE);
}

void loop() {
  M5.update();
}

void moveEvent(Event &amp;e) {
  M5.Lcd.drawCircle(e.from.x, e.from.y, r, BLACK);
  M5.Lcd.drawCircle(e.to.x, e.to.y, r, e.finger ? BLUE : RED);
}

void touchEvent(Event &amp;e) {
  M5.Lcd.drawCircle(e.to.x, e.to.y, r, e.finger ? BLUE : RED);
}

void releaseEvent(Event &amp;e) {
  M5.Lcd.drawCircle(e.to.x, e.to.y, r, BLACK);
}
</code></pre>
]]></description><link>https://community.m5stack.com/post/10234</link><guid isPermaLink="true">https://community.m5stack.com/post/10234</guid><dc:creator><![CDATA[Rop]]></dc:creator><pubDate>Sun, 04 Oct 2020 22:25:26 GMT</pubDate></item><item><title><![CDATA[Reply to M5Core2 library fork that supports multi-touch and provides Arduino-style virtual buttons [update: and gestures and events] [update2: MERGED !] on Sun, 04 Oct 2020 16:50:37 GMT]]></title><description><![CDATA[<p dir="auto"><a href="https://github.com/ropg/M5Core2" target="_blank" rel="noopener noreferrer nofollow ugc">New version</a> is up.</p>
<p dir="auto">Changes:</p>
<ul>
<li>
<p dir="auto">Introduced <code>M5.background</code>, the button object that is underneath all others and gets the events if nobody else does. So all events now have a button attached. <code>E_BTNONLY</code> pseudo-event removed.</p>
</li>
<li>
<p dir="auto">Various state-machine tweaks.</p>
</li>
<li>
<p dir="auto">Added <code>keywords.txt</code> for Arduino syntax highlighting.</p>
</li>
<li>
<p dir="auto">Internally cleaner, some functionality moved from M5Touch to M5Buttons.</p>
</li>
<li>
<p dir="auto">Added <code>M5.Touch.dump()</code> to see FT6336 registers.</p>
</li>
<li>
<p dir="auto"><code>M5.begin()</code> now shows <code>touch: FT6336 ready (fw id 0x10 rel 1, lib 0x300E)</code> as one of the lines.</p>
</li>
<li>
<p dir="auto"><code>M5.Touch.stale</code> is the location of the last past touch that is kept in memory of the FT6336. Can be used in light sleeping: only wake the ESP32 up two times a second and still see if someone touched.</p>
</li>
</ul>
]]></description><link>https://community.m5stack.com/post/10232</link><guid isPermaLink="true">https://community.m5stack.com/post/10232</guid><dc:creator><![CDATA[Rop]]></dc:creator><pubDate>Sun, 04 Oct 2020 16:50:37 GMT</pubDate></item><item><title><![CDATA[Reply to M5Core2 library fork that supports multi-touch and provides Arduino-style virtual buttons [update: and gestures and events] [update2: MERGED !] on Fri, 02 Oct 2020 20:41:53 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/felmue" aria-label="Profile: felmue">@<bdi>felmue</bdi></a> Removed that line.</p>
<p dir="auto">I just updated my M5Stack classic version of the library. Buttons have a few new features, such as <code>myButton.cancel()</code> which stops any further high-level event processing for that button, only <code>E_RELEASE</code> will be sent after that. It's used internally for gestures, but you can also use it for something like this:</p>
<pre><code class="language-c++">#include &lt;M5Stack.h&gt;

// Shortcuts: the &amp; means it's a reference to the same object
Button&amp; A = M5.BtnA;
Button&amp; B = M5.BtnB;
Button&amp; C = M5.BtnC;

// New buttons, not tied to hardware pins, so off until set with setState()
Button AB = Button(55, 193, 102, 21, true, "BtnAB");
Button BC = Button(161, 193, 102, 21, true, "BtnBC");

void setup() {
  M5.begin();
  A.off = B.off = C.off = AB.off = BC.off = {BLUE, WHITE, NODRAW};
  A.on  = B.on  = C.on  = AB.on  = BC.on  = {RED,  WHITE, NODRAW};
  C.tapTime = 0;
  B.longPressTime = 700;
  M5.Events.addHandler(eventDisplay, E_ALL - E_TOUCH - E_RELEASE);
  M5.Events.addHandler(buttonDown, E_TOUCH);
  M5.Events.addHandler(buttonUp, E_RELEASE);
  M5.Buttons.draw();
}

void loop() {
  M5.update();
}

void buttonDown(Event&amp; e) {
    if (A &amp;&amp; B) {
        A.cancel();
        B.cancel();
        AB.setState(true);
    }
    if (B &amp;&amp; C) {
        B.cancel();
        C.cancel();
        BC.setState(true);
    }
}

void buttonUp(Event&amp; e) {
    if (!(A &amp;&amp; B)) AB.setState(false);
    if (!(B &amp;&amp; C)) BC.setState(false);
}


void eventDisplay(Event&amp; e) {
  Serial.printf("\n%-14s %-18s", e.typeName(), e.objName());
  if (e.type == E_RELEASE || e.type == E_PRESSED) Serial.printf("%5d ms", e.duration);
}
</code></pre>
<p dir="auto">These two M5ez-like combi-buttons now behave like real buttons, with doubleclick and all. The event viewer in this example does not present the - noisy - <code>E_TOUCH</code> and <code>E_RELEASE</code> events but all the others. As you can see one button has no taps, another fires a longpress event after 700 ms. Also <code>if (myButton.isPressed() ...</code> can now be shortened to <code>if (myButton) ...</code></p>
<p dir="auto">Things have become cleaner and simpler on the inside, and there is now only one state-machine for touch and regular buttons. Will update the Core2 version later or tomorrow.</p>
]]></description><link>https://community.m5stack.com/post/10228</link><guid isPermaLink="true">https://community.m5stack.com/post/10228</guid><dc:creator><![CDATA[Rop]]></dc:creator><pubDate>Fri, 02 Oct 2020 20:41:53 GMT</pubDate></item><item><title><![CDATA[Reply to M5Core2 library fork that supports multi-touch and provides Arduino-style virtual buttons [update: and gestures and events] [update2: MERGED !] on Thu, 01 Oct 2020 19:28:33 GMT]]></title><description><![CDATA[<p dir="auto">Hi <a class="plugin-mentions-user plugin-mentions-a" href="/user/rop" aria-label="Profile: Rop">@<bdi>Rop</bdi></a></p>
<p dir="auto">playing with your latest code. Cool stuff.</p>
<p dir="auto">You probably might want to remove or comment the <code>Serial.println()</code> in below function.</p>
<pre><code>bool Button::pressedFor(uint32_t ms) {
	Serial.println(_time);
	return (_state &amp;&amp; _time - _lastChange &gt;= ms);
}
</code></pre>
<p dir="auto">Cheers<br />
Felix</p>
]]></description><link>https://community.m5stack.com/post/10226</link><guid isPermaLink="true">https://community.m5stack.com/post/10226</guid><dc:creator><![CDATA[felmue]]></dc:creator><pubDate>Thu, 01 Oct 2020 19:28:33 GMT</pubDate></item><item><title><![CDATA[Reply to M5Core2 library fork that supports multi-touch and provides Arduino-style virtual buttons [update: and gestures and events] [update2: MERGED !] on Thu, 01 Oct 2020 15:26:14 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/felmue" aria-label="Profile: felmue">@<bdi>felmue</bdi></a> Thanks! I fixed it but in the cpp and not in the .h. I prefer to not have too much in the header files.</p>
<p dir="auto">The version that's online now (I merged 'visual' into master on my repo) has fixes. Also there's now a copy of the original M5Stack library on my Github as well, it has the identical M5Button library file with Buttons and Events. Allows you to compile</p>
<pre><code class="language-c++">#include &lt;M5Stack.h&gt;

void setup() {
  M5.begin();
  M5.BtnA.setLabel("Test");
  M5.BtnB.setLabel("Wow !");
  M5.BtnC.setLabel("Amazing !");
  M5.BtnA.off = M5.BtnB.off = M5.BtnC.off = {BLUE, WHITE, NODRAW};
  M5.BtnA.on = M5.BtnB.on = M5.BtnC.on = {RED, WHITE, NODRAW};
  M5.Events.addHandler(eventDisplay);
  M5.Buttons.draw();
}

void loop() {
  M5.update();
}

void eventDisplay(Event&amp; e) {
  Serial.printf("\n%-12s %-18s", e.typeName(), e.objName());
  if (e.type == E_RELEASE || e.type == E_PRESSED) Serial.printf("%5d ms", e.duration);
}
</code></pre>
<p dir="auto">(I'll post this wider after a bit more testing and documenting.)</p>
]]></description><link>https://community.m5stack.com/post/10225</link><guid isPermaLink="true">https://community.m5stack.com/post/10225</guid><dc:creator><![CDATA[Rop]]></dc:creator><pubDate>Thu, 01 Oct 2020 15:26:14 GMT</pubDate></item><item><title><![CDATA[Reply to M5Core2 library fork that supports multi-touch and provides Arduino-style virtual buttons [update: and gestures and events] [update2: MERGED !] on Thu, 01 Oct 2020 09:06:00 GMT]]></title><description><![CDATA[<p dir="auto">Hi <a class="plugin-mentions-user plugin-mentions-a" href="/user/rop" aria-label="Profile: Rop">@<bdi>Rop</bdi></a></p>
<p dir="auto">Update2: I've created a pull-request with below fixes for your convenience.</p>
<p dir="auto"><a href="https://github.com/ropg/M5Core2/pull/2" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/ropg/M5Core2/pull/2</a></p>
<p dir="auto">I have found the reason for the crash: <code>drawFn</code> is not NULL, yet not set correctly which causes the crash when calling <code>drawFn(this, bc)</code> on line 212.</p>
<pre><code>void Button::draw(ButtonColors bc) {
  // use locally set draw function if aplicable, global one otherwise
  if (drawFn) {
    drawFn(this, bc);
</code></pre>
<p dir="auto">I've fixed it by modifying two lines (137, 157) in <code>M5Button.h</code> and initialising <code>drawFn</code> with <code>nullptr</code>.</p>
<pre><code>void (*drawFn)(Button* b, ButtonColors bc) = nullptr;
</code></pre>
<p dir="auto">Update: Just found another crash when using <code>new</code> and <code>delete</code>. Fixed by setting <code>_freeFont</code> to <code>nullptr</code> (lines 108 and 125).</p>
<pre><code>const GFXfont* _freeFont = nullptr;
</code></pre>
<p dir="auto">Thanks<br />
Felix</p>
]]></description><link>https://community.m5stack.com/post/10221</link><guid isPermaLink="true">https://community.m5stack.com/post/10221</guid><dc:creator><![CDATA[felmue]]></dc:creator><pubDate>Thu, 01 Oct 2020 09:06:00 GMT</pubDate></item><item><title><![CDATA[Reply to M5Core2 library fork that supports multi-touch and provides Arduino-style virtual buttons [update: and gestures and events] [update2: MERGED !] on Thu, 01 Oct 2020 04:32:19 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="plugin-mentions-user plugin-mentions-a" href="/user/rop" aria-label="Profile: Rop">@<bdi>Rop</bdi></a></p>
<p dir="auto">Thank you for the update. Unfortunately no luck for me. When I run your code with the latest M5Core2 from your visual branch I get a crash as soon as the code tries to instantiate the button in screen1() function.</p>
<p dir="auto">When I declare the buttons globally the code works, but as you mentioned they don't go away.</p>
<p dir="auto">I wonder if the button object is too large to be declared in a function?</p>
<p dir="auto">Thanks<br />
Felix</p>
]]></description><link>https://community.m5stack.com/post/10219</link><guid isPermaLink="true">https://community.m5stack.com/post/10219</guid><dc:creator><![CDATA[felmue]]></dc:creator><pubDate>Thu, 01 Oct 2020 04:32:19 GMT</pubDate></item><item><title><![CDATA[Reply to M5Core2 library fork that supports multi-touch and provides Arduino-style virtual buttons [update: and gestures and events] [update2: MERGED !] on Wed, 30 Sep 2020 22:31:42 GMT]]></title><description><![CDATA[<p dir="auto">I've worked extensively on the events system, so that there is now only one event per call to M5.update(). That means you can now also check for events in loops, no need for handler functions if you don't want them. Get the new library and try this:</p>
<pre><code class="language-c++">#include &lt;M5Core2.h&gt;

ButtonColors on = {RED, WHITE, WHITE};
ButtonColors off = {BLACK, WHITE, WHITE};

void setup() {
  M5.begin();
  while (true) {
    screen1();
    screen2();
  }
}

// Never comes here
void loop() {
	M5.update();
}

void screen1() {
  M5.Lcd.clearDisplay(YELLOW);
  Button tl(5, 5, 150, 110, false ,"top-left", off, on, TL_DATUM);
  while (true) {
    M5.update();
    if (tl.isPressed()) return;
  }
}


void screen2() {
  M5.Lcd.clearDisplay(BLUE);
  Button tr(165, 5, 150, 110, false, "top-right", off, on, TR_DATUM);
  while (true) {
    M5.update();
    if (tr.event.type == E_DBLTAP) return;
  }
}
</code></pre>
<p dir="auto">As you can see you don't need to orry about manually deleting the buttons, they go away as the function ends. But you cannot call one function from the other, because that leaves the variables in existence. Then you'd have to 'new' and 'delete' them indeed.</p>
]]></description><link>https://community.m5stack.com/post/10218</link><guid isPermaLink="true">https://community.m5stack.com/post/10218</guid><dc:creator><![CDATA[Rop]]></dc:creator><pubDate>Wed, 30 Sep 2020 22:31:42 GMT</pubDate></item></channel></rss>