Skip to content

Commit 44719cf

Browse files
committed
Fixing Issue with wifi connection and touch
1 parent 1f595ee commit 44719cf

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

Tests/M5Core2TestApp/M5Core2TestApp.nfproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@
7272
<Reference Include="nanoFramework.System.Collections">
7373
<HintPath>..\..\packages\nanoFramework.System.Collections.1.3.0\lib\nanoFramework.System.Collections.dll</HintPath>
7474
</Reference>
75+
<Reference Include="nanoFramework.System.Text">
76+
<HintPath>..\..\packages\nanoFramework.System.Text.1.1.3-preview.4\lib\nanoFramework.System.Text.dll</HintPath>
77+
</Reference>
7578
<Reference Include="System.Buffers.Binary.BinaryPrimitives">
7679
<HintPath>..\..\packages\nanoFramework.System.Buffers.Binary.BinaryPrimitives.1.0.259\lib\System.Buffers.Binary.BinaryPrimitives.dll</HintPath>
7780
</Reference>
@@ -96,6 +99,9 @@
9699
<Reference Include="System.Device.Spi">
97100
<HintPath>..\..\packages\nanoFramework.System.Device.Spi.1.0.3-preview.3\lib\System.Device.Spi.dll</HintPath>
98101
</Reference>
102+
<Reference Include="System.Device.WiFi">
103+
<HintPath>..\..\packages\nanoFramework.System.Device.WiFi.1.4.0-preview.11\lib\System.Device.WiFi.dll</HintPath>
104+
</Reference>
99105
<Reference Include="System.Diagnostics.Stopwatch">
100106
<HintPath>..\..\packages\nanoFramework.System.Diagnostics.Stopwatch.1.0.259\lib\System.Diagnostics.Stopwatch.dll</HintPath>
101107
</Reference>
@@ -107,9 +113,15 @@
107113
<Reference Include="System.Math">
108114
<HintPath>..\..\packages\nanoFramework.System.Math.1.4.3\lib\System.Math.dll</HintPath>
109115
</Reference>
116+
<Reference Include="System.Net">
117+
<HintPath>..\..\packages\nanoFramework.System.Net.1.8.0-preview.9\lib\System.Net.dll</HintPath>
118+
</Reference>
110119
<Reference Include="System.Numerics">
111120
<HintPath>..\..\packages\nanoFramework.System.Numerics.1.0.259\lib\System.Numerics.dll</HintPath>
112121
</Reference>
122+
<Reference Include="System.Threading">
123+
<HintPath>..\..\packages\nanoFramework.System.Threading.1.0.3\lib\System.Threading.dll</HintPath>
124+
</Reference>
113125
<Reference Include="UnitsNet.ElectricCurrent, Version=4.112.0.0, Culture=neutral, PublicKeyToken=null">
114126
<HintPath>..\..\packages\UnitsNet.nanoFramework.ElectricCurrent.4.112.0\lib\UnitsNet.ElectricCurrent.dll</HintPath>
115127
<Private>True</Private>

Tests/M5Core2TestApp/Program.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using nanoFramework.M5Core2;
55
using nanoFramework.M5Stack;
6+
using nanoFramework.Networking;
67
using nanoFramework.Runtime.Native;
78
using System;
89
using System.Diagnostics;
@@ -13,6 +14,21 @@
1314

1415
Debug.WriteLine("Hello from M5Core2!");
1516

17+
const string Ssid = "SSID";
18+
const string Password = "YourWifiPassword";
19+
// Give 60 seconds to the wifi join to happen
20+
CancellationTokenSource cs = new(60000);
21+
var success = WiFiNetworkHelper.ConnectDhcp(Ssid, Password, requiresDateTime: true, token: cs.Token);
22+
if (!success)
23+
{
24+
// Something went wrong, you can get details with the ConnectionError property:
25+
Debug.WriteLine($"Can't connect to the network, error: {WiFiNetworkHelper.Status}");
26+
if (WiFiNetworkHelper.HelperException != null)
27+
{
28+
Debug.WriteLine($"ex: {WiFiNetworkHelper.HelperException}");
29+
}
30+
}
31+
1632
M5Core2.TouchEvent += TouchEventCallback;
1733

1834
Thread.Sleep(Timeout.Infinite);

Tests/M5Core2TestApp/packages.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@
2121
<package id="nanoFramework.System.Device.Model" version="1.0.259" targetFramework="netnanoframework10" />
2222
<package id="nanoFramework.System.Device.Pwm" version="1.0.0" targetFramework="netnanoframework10" />
2323
<package id="nanoFramework.System.Device.Spi" version="1.0.3-preview.3" targetFramework="netnanoframework10" />
24+
<package id="nanoFramework.System.Device.WiFi" version="1.4.0-preview.11" targetFramework="netnanoframework10" />
2425
<package id="nanoFramework.System.Diagnostics.Stopwatch" version="1.0.259" targetFramework="netnanoframework10" />
2526
<package id="nanoFramework.System.IO.Ports" version="1.0.3-preview.6" targetFramework="netnanoframework10" />
2627
<package id="nanoFramework.System.Math" version="1.4.3" targetFramework="netnanoframework10" />
28+
<package id="nanoFramework.System.Net" version="1.8.0-preview.9" targetFramework="netnanoframework10" />
2729
<package id="nanoFramework.System.Numerics" version="1.0.259" targetFramework="netnanoframework10" />
30+
<package id="nanoFramework.System.Text" version="1.1.3-preview.4" targetFramework="netnanoframework10" />
31+
<package id="nanoFramework.System.Threading" version="1.0.3" targetFramework="netnanoframework10" />
2832
<package id="UnitsNet.nanoFramework.ElectricCurrent" version="4.112.0" targetFramework="netnanoframework10" />
2933
<package id="UnitsNet.nanoFramework.ElectricPotential" version="4.112.0" targetFramework="netnanoframework10" />
3034
<package id="UnitsNet.nanoFramework.Power" version="4.112.0" targetFramework="netnanoframework10" />

nanoFramework.M5Core2/M5Core2.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public static partial class M5Core2
2828
private static Thread _callbackThread;
2929
private static CancellationTokenSource _cancelThread;
3030
private static CancellationTokenSource _startThread;
31+
private static Point _lastPoint;
3132

3233
/// <summary>
3334
/// Touch event handler for the touch event.
@@ -111,6 +112,8 @@ public static void InitializeScreen()
111112
Console.Font = Resource.GetFont(Resource.FontResources.consolas_regular_16);
112113
_touchController = new(I2cDevice.Create(new I2cConnectionSettings(1, Ft6xx6x.DefaultI2cAddress)));
113114
_touchController.SetInterruptMode(false);
115+
_lastPoint = new();
116+
_cancelThread = new();
114117
_startThread = new();
115118
_callbackThread = new(ThreadTouchCallback);
116119
_callbackThread.Start();
@@ -130,9 +133,13 @@ private static void TouchCallback(object sender, PinValueChangedEventArgs pinVal
130133
{
131134
_startThread = new();
132135
_cancelThread.Cancel();
133-
var point = _touchController.GetPoint(true);
134-
var touchCategory = CheckIfInButtons(point.X, point.Y, TouchEventCategory.Unknown) | TouchEventCategory.LiftUp;
135-
TouchEvent?.Invoke(_touchController, new TouchEventArgs() { TimeStamp = DateTime.UtcNow, EventCategory = EventCategory.Touch, TouchEventCategory = touchCategory, X = point.X, Y = point.Y, Id = point.TouchId });
136+
var point = _touchController.GetPoint(true);
137+
if ((_lastPoint.X != point.X) && (_lastPoint.Y != point.Y))
138+
{
139+
_lastPoint = point;
140+
var touchCategory = CheckIfInButtons(point.X, point.Y, TouchEventCategory.Unknown) | TouchEventCategory.LiftUp;
141+
TouchEvent?.Invoke(_touchController, new TouchEventArgs() { TimeStamp = DateTime.UtcNow, EventCategory = EventCategory.Touch, TouchEventCategory = touchCategory, X = point.X, Y = point.Y, Id = point.TouchId });
142+
}
136143
}
137144
}
138145

@@ -152,6 +159,7 @@ private static void ThreadTouchCallback()
152159
if (touchNumber == 1)
153160
{
154161
var point = _touchController.GetPoint(true);
162+
_lastPoint = point;
155163
touchCategory = CheckIfInButtons(point.X, point.Y, TouchEventCategory.Unknown);
156164
touchCategory = point.Event == Event.Contact ? touchCategory | TouchEventCategory.Moving : touchCategory;
157165
TouchEvent?.Invoke(_touchController, new TouchEventArgs() { TimeStamp = DateTime.UtcNow, EventCategory = EventCategory.Touch, TouchEventCategory = touchCategory, X = point.X, Y = point.Y, Id = point.TouchId });

0 commit comments

Comments
 (0)