-
-
Notifications
You must be signed in to change notification settings - Fork 37
Add M5Stack Tough #157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add M5Stack Tough #157
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
054deab
Add tough
Ellerbach 92ba987
Add nuspec for Tough
antoniofagundes bd371bf
Fix comment
antoniofagundes 5bb5a32
Remove RTC from Tough
antoniofagundes 01317f2
Add back Rtc
antoniofagundes 69c5888
Add Tough to package tasks
josesimoes 3884259
Enable display backlight
josesimoes 3753a9b
More changes in Tough
josesimoes e8ee64a
Update nugets for Tough
josesimoes c544157
More work on init and screen for Tough
josesimoes 3f476d8
Wrap up backlight for Tough
josesimoes 0431274
Fix nuspec
josesimoes 21f083a
Fixes from code review
josesimoes 1cd92e0
Add lazy loading pattern to GpioController
josesimoes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| #if M5CORE2 || TOUGH | ||
| using Iot.Device.Axp192; | ||
| using nanoFramework.M5Stack; | ||
| using nanoFramework.UI; | ||
| using System.Device.Gpio; | ||
| using System.Threading; | ||
| using UnitsNet; | ||
|
|
||
| namespace nanoFramework.M5Stack | ||
| { | ||
| /// <summary> | ||
| #if M5CORE2 | ||
| /// M5Core2 screen class. | ||
| #elif TOUGH | ||
| /// M5Tough screen class. | ||
| #endif | ||
| /// </summary> | ||
| public class Screen : ScreenBase | ||
| { | ||
| /// <summary> | ||
| /// Default memory allocation | ||
| /// </summary> | ||
| public const int DefaultMemoryAllocationBitmap = 320 * 240 * 4; | ||
|
|
||
| private const byte DefaultScreenBrightness = 75; | ||
| private const int ChipSelect = 5; | ||
| private const int DataCommand = 15; | ||
| private const int Reset = -1; | ||
| private static Axp192 _power; | ||
| private static byte _brightness; | ||
| private static bool _isInitialized = false; | ||
|
|
||
| /// <summary> | ||
| /// Initializes the screen | ||
| /// </summary> | ||
| /// <param name="memoryBitMapAllocation">The memory allocation.</param> | ||
| public Screen(int memoryBitMapAllocation = DefaultMemoryAllocationBitmap) | ||
| { | ||
| if (_isInitialized) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| // We're allocating enough memory for the full screen because these targets have PSRAM | ||
| MemoryAllocationBitmap = memoryBitMapAllocation; | ||
| // backligth is not controlled by the screen driver | ||
| BackLightPin = -1; | ||
|
|
||
| #if M5CORE2 | ||
| _power = M5Stack.M5Core2.Power; | ||
| #elif TOUGH | ||
| _power = M5Stack.Tough.Power; | ||
| #endif | ||
|
|
||
| // Reset screen | ||
| _power.Gpio4Value = PinValue.Low; | ||
| Thread.Sleep(100); | ||
| _power.Gpio4Value = PinValue.High; | ||
| Thread.Sleep(100); | ||
|
|
||
| // Create the screen | ||
| DisplayControl.Initialize(new SpiConfiguration(2, ChipSelect, DataCommand, Reset, BackLightPin), new ScreenConfiguration(0, 0, 320, 240), (uint)MemoryAllocationBitmap); | ||
|
|
||
| // set initial value for brightness | ||
| BrightnessPercentage = DefaultScreenBrightness; | ||
|
|
||
| // enable back-light | ||
| Enabled = true; | ||
|
|
||
| _isInitialized = true; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Enables or disables the screen. | ||
| /// </summary> | ||
| /// <value><see langword="true"/> to enable the screen, <see langword="false"/> to disable it.</value> | ||
| public static new bool Enabled | ||
| { | ||
| get => IsEnabled; | ||
|
|
||
| set | ||
| { | ||
| IsEnabled = value; | ||
|
|
||
| #if M5CORE2 | ||
| _power.EnableDCDC3(IsEnabled); | ||
| #elif TOUGH | ||
| _power.EnableLDO3(IsEnabled); | ||
| #endif | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the screen brightness. | ||
| /// </summary> | ||
| /// <value>Brightness as percentage.</value> | ||
| public static new byte BrightnessPercentage | ||
| { | ||
| get => _brightness; | ||
|
|
||
| set | ||
| { | ||
| // For M5Core2 and M5Tough, values from 2.5 to 3V are working fine | ||
| // 2.5 V = dark, 3.0 V full luminosity | ||
| _brightness = (byte)(value > 100 ? 100 : value); | ||
| var backLightVoltage = ElectricPotential.FromVolts(_brightness * 0.5 / 100.0 + 2.5); | ||
| #if M5CORE2 | ||
| _power.LDO3OutputVoltage = backLightVoltage; | ||
| #elif TOUGH | ||
| _power.LDO3OutputVoltage = backLightVoltage; | ||
| #endif | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -172,4 +172,4 @@ | |
| <ProjectConfigurationsDeclaredAsItems /> | ||
| </ProjectCapabilities> | ||
| </ProjectExtensions> | ||
| </Project> | ||
| </Project> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -132,4 +132,4 @@ | |
| <ProjectConfigurationsDeclaredAsItems /> | ||
| </ProjectCapabilities> | ||
| </ProjectExtensions> | ||
| </Project> | ||
| </Project> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using nanoFramework.Tough; | ||
| using nanoFramework.M5Stack; | ||
| using nanoFramework.Networking; | ||
| using nanoFramework.Runtime.Native; | ||
| using System; | ||
| using System.Diagnostics; | ||
| using System.Threading; | ||
| using Console = nanoFramework.M5Stack.Console; | ||
|
|
||
| Tough.InitializeScreen(); | ||
|
|
||
| Debug.WriteLine("Hello from Tough!"); | ||
|
|
||
| Console.WriteLine("Hello from Tough!"); | ||
|
|
||
josesimoes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const string Ssid = "SSID"; | ||
| const string Password = "YourWifiPasswordHere"; | ||
| // Give 60 seconds to the wifi join to happen | ||
| CancellationTokenSource cs = new(60000); | ||
| var success = WifiNetworkHelper.ConnectDhcp(Ssid, Password, requiresDateTime: true, token: cs.Token); | ||
| if (!success) | ||
| { | ||
| // Something went wrong, you can get details with the ConnectionError property: | ||
| Debug.WriteLine($"Can't connect to the network, error: {WifiNetworkHelper.Status}"); | ||
| if (WifiNetworkHelper.HelperException != null) | ||
| { | ||
| Debug.WriteLine($"ex: {WifiNetworkHelper.HelperException}"); | ||
| } | ||
| } | ||
|
|
||
| Tough.TouchEvent += TouchEventCallback; | ||
|
|
||
| Thread.Sleep(Timeout.Infinite); | ||
|
|
||
| void TouchEventCallback(object sender, TouchEventArgs e) | ||
| { | ||
| const string StrLB = "LEFT BUTTON PRESSED "; | ||
| const string StrMB = "MIDDLE BUTTON PRESSED "; | ||
| const string StrRB = "RIGHT BUTTON PRESSED "; | ||
| const string StrXY1 = "TOUCHED at X= "; | ||
| const string StrXY2 = ",Y= "; | ||
| const string StrID = ",Id= "; | ||
| const string StrDoubleTouch = "Double touch. "; | ||
| const string StrMove = "Moving... "; | ||
| const string StrLiftUp = "Lift up. "; | ||
|
|
||
| Debug.WriteLine($"Touch Panel Event Received Category= {e.EventCategory} Subcategory= {e.TouchEventCategory}"); | ||
| Console.CursorLeft = 0; | ||
| Console.CursorTop = 0; | ||
|
|
||
| Debug.WriteLine(StrXY1 + e.X + StrXY2 + e.Y + StrID + e.Id); | ||
| Console.WriteLine(StrXY1 + e.X + StrXY2 + e.Y + StrID + e.Id + " "); | ||
|
|
||
| if ((e.TouchEventCategory & TouchEventCategory.LeftButton) == TouchEventCategory.LeftButton) | ||
| { | ||
| Debug.WriteLine(StrLB); | ||
| Console.WriteLine(StrLB); | ||
| } | ||
| else if ((e.TouchEventCategory & TouchEventCategory.MiddleButton) == TouchEventCategory.MiddleButton) | ||
| { | ||
| Debug.WriteLine(StrMB); | ||
| Console.WriteLine(StrMB); | ||
| } | ||
| else if ((e.TouchEventCategory & TouchEventCategory.RightButton) == TouchEventCategory.RightButton) | ||
| { | ||
| Debug.WriteLine(StrRB); | ||
| Console.WriteLine(StrRB); | ||
| } | ||
|
|
||
| if ((e.TouchEventCategory & TouchEventCategory.Moving) == TouchEventCategory.Moving) | ||
| { | ||
| Debug.WriteLine(StrMove); | ||
| Console.Write(StrMove); | ||
| } | ||
|
|
||
| if ((e.TouchEventCategory & TouchEventCategory.LiftUp) == TouchEventCategory.LiftUp) | ||
| { | ||
| Debug.WriteLine(StrLiftUp); | ||
| Console.Write(StrLiftUp); | ||
| } | ||
|
|
||
| if ((e.TouchEventCategory & TouchEventCategory.DoubleTouch) == TouchEventCategory.DoubleTouch) | ||
| { | ||
| Debug.WriteLine(StrDoubleTouch); | ||
| Console.Write(StrDoubleTouch); | ||
| } | ||
|
|
||
| Console.WriteLine(" "); | ||
| Console.WriteLine(" "); | ||
| Console.WriteLine(" "); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| using System.Reflection; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| // General Information about an assembly is controlled through the following | ||
| // set of attributes. Change these attribute values to modify the information | ||
| // associated with an assembly. | ||
| [assembly: AssemblyTitle("CSharp.BlankApplication")] | ||
| [assembly: AssemblyDescription("")] | ||
| [assembly: AssemblyConfiguration("")] | ||
| [assembly: AssemblyCompany("")] | ||
| [assembly: AssemblyProduct("CSharp.BlankApplication")] | ||
| [assembly: AssemblyCopyright("Copyright © 2022")] | ||
| [assembly: AssemblyTrademark("")] | ||
| [assembly: AssemblyCulture("")] | ||
|
|
||
| // Setting ComVisible to false makes the types in this assembly not visible | ||
| // to COM components. If you need to access a type in this assembly from | ||
| // COM, set the ComVisible attribute to true on that type. | ||
| [assembly: ComVisible(false)] | ||
|
|
||
| // Version information for an assembly consists of the following four values: | ||
| // | ||
| // Major Version | ||
| // Minor Version | ||
| // Build Number | ||
| // Revision | ||
| // | ||
| // You can specify all the values or you can default the Build and Revision Numbers | ||
| // by using the '*' as shown below: | ||
| // [assembly: AssemblyVersion("1.0.*")] | ||
| [assembly: AssemblyVersion("1.0.0.0")] | ||
| [assembly: AssemblyFileVersion("1.0.0.0")] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.