nanoFramework.Iot.Device.Chsc6540 1.1.308

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package nanoFramework.Iot.Device.Chsc6540 --version 1.1.308                
NuGet\Install-Package nanoFramework.Iot.Device.Chsc6540 -Version 1.1.308                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="nanoFramework.Iot.Device.Chsc6540" Version="1.1.308" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add nanoFramework.Iot.Device.Chsc6540 --version 1.1.308                
#r "nuget: nanoFramework.Iot.Device.Chsc6540, 1.1.308"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install nanoFramework.Iot.Device.Chsc6540 as a Cake Addin
#addin nuget:?package=nanoFramework.Iot.Device.Chsc6540&version=1.1.308

// Install nanoFramework.Iot.Device.Chsc6540 as a Cake Tool
#tool nuget:?package=nanoFramework.Iot.Device.Chsc6540&version=1.1.308                

CHSC6540 - Touch screen controller

The CHSC6540 is the touch screen controllers of the M5Stack Tough.

Documentation

  • More information on the touch controller, unfortunately, the datasheet isn't available from the manufacturer. Only an incomplete shadow copy from a content provider here.

Usage

Important: make sure you properly setup the I2C pins especially for ESP32 before creating the I2cDevice, make sure you install the nanoFramework.Hardware.ESP32 nuget:

//////////////////////////////////////////////////////////////////////
// when connecting to an ESP32 device, need to configure the I2C GPIOs
// used for the bus
Configuration.SetPinFunction(21, DeviceFunction.I2C1_DATA);
Configuration.SetPinFunction(22, DeviceFunction.I2C1_CLOCK);

For other devices like STM32, please make sure you're using the preset pins for the I2C bus you want to use.

Note: this sample requires a M5Stack Tough. If you want to use another device, just remove all the related NuGet packages.

using System.Device.Gpio;
using System.Device.I2c;
using System.Diagnostics;
using System.Threading;
using Iot.Device.Chsc6540;
using nanoFramework.Hardware.Esp32;

//////////////////////////////////////////////////////////////////////
// when connecting to an ESP32 device, need to configure the I2C GPIOs
// used for the bus
Configuration.SetPinFunction(21, DeviceFunction.I2C1_DATA);
Configuration.SetPinFunction(22, DeviceFunction.I2C1_CLOCK);

I2cConnectionSettings settings = new(1, Chsc6540.DefaultI2cAddress);
using I2cDevice device = I2cDevice.Create(settings);
using GpioController gpio = new();

using Chsc6540 sensor = new(device);
sensor.SetInterruptMode(true);

gpio.OpenPin(39, PinMode.Input);
// This will enable an event on GPIO39 on falling edge when the screen if touched
gpio.RegisterCallbackForPinValueChangedEvent(39, PinEventTypes.Falling, TouchInterrupCallback);

while (true)
{
    Thread.Sleep(20);
}

void TouchInterrupCallback(object sender, PinValueChangedEventArgs pinValueChangedEventArgs)
{
    Debug.WriteLine("Touch interrupt");
    var points = sensor.GetNumberPoints();
    if (points == 1)
    {
        var point = sensor.GetPoint(true);
        // Some controllers supports as well events, you can get access to them as well thru point.Event
        Debug.WriteLine($"ID: {point.TouchId}, X: {point.X}, Y: {point.Y}, Weight: {point.Weigth}, Misc: {point.Miscelaneous}");
    }
    else if (points == 2)
    {
        var dp = sensor.GetDoublePoints();
        Debug.WriteLine($"ID: {dp.Point1.TouchId}, X: {dp.Point1.X}, Y: {dp.Point1.Y}, Weight: {dp.Point1.Weigth}, Misc: {dp.Point1.Miscelaneous}");
        Debug.WriteLine($"ID: {dp.Point2.TouchId}, X: {dp.Point2.X}, Y: {dp.Point2.Y}, Weight: {dp.Point2.Weigth}, Misc: {dp.Point2.Miscelaneous}");
    }
}
Product Compatible and additional computed target framework versions.
.NET Framework net is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on nanoFramework.Iot.Device.Chsc6540:

Package Downloads
nanoFramework.Tough

This package includes the nanoFramework.Tough assembly for .NET nanoFramework C# projects.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on nanoFramework.Iot.Device.Chsc6540:

Repository Stars
nanoframework/nanoFramework.M5Stack
:package: Board support package for M5Stack, M5StickC and M5StickCPlus for .NET nanoFramework
Version Downloads Last updated
1.1.696 151 12/16/2024
1.1.673 262 10/23/2024
1.1.665 133 10/16/2024
1.1.651 270 9/27/2024
1.1.631 242 8/28/2024
1.1.580 391 6/28/2024
1.1.570 166 6/14/2024
1.1.548 220 5/15/2024
1.1.436 711 11/10/2023
1.1.329 700 5/26/2023
1.1.313 246 5/12/2023
1.1.308 249 5/11/2023
1.1.304 199 5/10/2023
1.1.297 246 5/3/2023
1.1.203 2,335 12/28/2022
1.1.141 2,004 10/25/2022
1.1.82 2,961 9/14/2022
1.0.1.61117 8,989 6/3/2022