|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | + |
| 4 | +using nanoFramework.Tough; |
| 5 | +using nanoFramework.M5Stack; |
| 6 | +using nanoFramework.Networking; |
| 7 | +using nanoFramework.Runtime.Native; |
| 8 | +using System; |
| 9 | +using System.Diagnostics; |
| 10 | +using System.Threading; |
| 11 | +using Console = nanoFramework.M5Stack.Console; |
| 12 | + |
| 13 | +Tough.InitializeScreen(); |
| 14 | + |
| 15 | +Debug.WriteLine("Hello from Tough!"); |
| 16 | + |
| 17 | +Console.WriteLine("Hello from Tough!"); |
| 18 | + |
| 19 | +const string Ssid = "SSID"; |
| 20 | +const string Password = "YourWifiPasswordHere"; |
| 21 | +// Give 60 seconds to the wifi join to happen |
| 22 | +CancellationTokenSource cs = new(60000); |
| 23 | +var success = WifiNetworkHelper.ConnectDhcp(Ssid, Password, requiresDateTime: true, token: cs.Token); |
| 24 | +if (!success) |
| 25 | +{ |
| 26 | + // Something went wrong, you can get details with the ConnectionError property: |
| 27 | + Debug.WriteLine($"Can't connect to the network, error: {WifiNetworkHelper.Status}"); |
| 28 | + if (WifiNetworkHelper.HelperException != null) |
| 29 | + { |
| 30 | + Debug.WriteLine($"ex: {WifiNetworkHelper.HelperException}"); |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +Tough.TouchEvent += TouchEventCallback; |
| 35 | + |
| 36 | +Thread.Sleep(Timeout.Infinite); |
| 37 | + |
| 38 | +void TouchEventCallback(object sender, TouchEventArgs e) |
| 39 | +{ |
| 40 | + const string StrLB = "LEFT BUTTON PRESSED "; |
| 41 | + const string StrMB = "MIDDLE BUTTON PRESSED "; |
| 42 | + const string StrRB = "RIGHT BUTTON PRESSED "; |
| 43 | + const string StrXY1 = "TOUCHED at X= "; |
| 44 | + const string StrXY2 = ",Y= "; |
| 45 | + const string StrID = ",Id= "; |
| 46 | + const string StrDoubleTouch = "Double touch. "; |
| 47 | + const string StrMove = "Moving... "; |
| 48 | + const string StrLiftUp = "Lift up. "; |
| 49 | + |
| 50 | + Debug.WriteLine($"Touch Panel Event Received Category= {e.EventCategory} Subcategory= {e.TouchEventCategory}"); |
| 51 | + Console.CursorLeft = 0; |
| 52 | + Console.CursorTop = 0; |
| 53 | + |
| 54 | + Debug.WriteLine(StrXY1 + e.X + StrXY2 + e.Y + StrID + e.Id); |
| 55 | + Console.WriteLine(StrXY1 + e.X + StrXY2 + e.Y + StrID + e.Id + " "); |
| 56 | + |
| 57 | + if ((e.TouchEventCategory & TouchEventCategory.LeftButton) == TouchEventCategory.LeftButton) |
| 58 | + { |
| 59 | + Debug.WriteLine(StrLB); |
| 60 | + Console.WriteLine(StrLB); |
| 61 | + } |
| 62 | + else if ((e.TouchEventCategory & TouchEventCategory.MiddleButton) == TouchEventCategory.MiddleButton) |
| 63 | + { |
| 64 | + Debug.WriteLine(StrMB); |
| 65 | + Console.WriteLine(StrMB); |
| 66 | + } |
| 67 | + else if ((e.TouchEventCategory & TouchEventCategory.RightButton) == TouchEventCategory.RightButton) |
| 68 | + { |
| 69 | + Debug.WriteLine(StrRB); |
| 70 | + Console.WriteLine(StrRB); |
| 71 | + } |
| 72 | + |
| 73 | + if ((e.TouchEventCategory & TouchEventCategory.Moving) == TouchEventCategory.Moving) |
| 74 | + { |
| 75 | + Debug.WriteLine(StrMove); |
| 76 | + Console.Write(StrMove); |
| 77 | + } |
| 78 | + |
| 79 | + if ((e.TouchEventCategory & TouchEventCategory.LiftUp) == TouchEventCategory.LiftUp) |
| 80 | + { |
| 81 | + Debug.WriteLine(StrLiftUp); |
| 82 | + Console.Write(StrLiftUp); |
| 83 | + } |
| 84 | + |
| 85 | + if ((e.TouchEventCategory & TouchEventCategory.DoubleTouch) == TouchEventCategory.DoubleTouch) |
| 86 | + { |
| 87 | + Debug.WriteLine(StrDoubleTouch); |
| 88 | + Console.Write(StrDoubleTouch); |
| 89 | + } |
| 90 | + |
| 91 | + Console.WriteLine(" "); |
| 92 | + Console.WriteLine(" "); |
| 93 | + Console.WriteLine(" "); |
| 94 | +} |
0 commit comments