Skip to content

Commit f7ef3bd

Browse files
committed
Add NeoPixel
1 parent 772a17e commit f7ef3bd

File tree

14 files changed

+295
-113
lines changed

14 files changed

+295
-113
lines changed

src/nf-telemetry-clients/Clients/RipTide.Nfirmware/Program.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
using Iot.Device.Button;
2+
using NeoPixel.Peripheral;
13
using System;
24
using System.Diagnostics;
5+
using System.Drawing;
36
using System.Threading;
47

58
namespace RipTide.Nfirmware
@@ -8,7 +11,23 @@ public class Program
811
{
912
public static void Main()
1013
{
11-
Debug.WriteLine("Hello from nanoFramework!");
14+
var buttonPressed = false;
15+
var button = new GpioButton(buttonPin: 8, debounceTime: TimeSpan.FromMilliseconds(50))
16+
{
17+
IsDoublePressEnabled = false,
18+
IsHoldingEnabled = false
19+
};
20+
button.ButtonDown += (sender, e) => { buttonPressed = true; };
21+
22+
Thread.Sleep(1000);
23+
if (buttonPressed)
24+
{
25+
Debug.WriteLine("Button pressed. Sleeping one minute");
26+
Thread.Sleep(TimeSpan.FromMinutes(1));
27+
}
28+
29+
var neo = new NeoPixelGauge(pixelsCount: 45, new[] { Color.Green, Color.Yellow, Color.Red }, pin: 11);
30+
neo.DemoRun();
1231

1332
Thread.Sleep(Timeout.Infinite);
1433
}

src/nf-telemetry-clients/Clients/RipTide.Nfirmware/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# RipTide.Nfirmware
22

3+
https://www.espressif.com/sites/default/files/documentation/esp32-s3_datasheet_en.pdf
4+
35
## Schematic
46

57
//TBD
555 KB
Loading

src/nf-telemetry-clients/Clients/RipTide.Nfirmware/RipTide.Nfirmware.nfproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,25 @@
3030
<Content Include="Resources\unexpected-maker-esp32-pros3-pinout.jpg" />
3131
</ItemGroup>
3232
<ItemGroup>
33+
<Reference Include="Iot.Device.Button">
34+
<HintPath>..\..\packages\nanoFramework.Iot.Device.Button.1.2.775\lib\Iot.Device.Button.dll</HintPath>
35+
</Reference>
3336
<Reference Include="mscorlib">
3437
<HintPath>..\..\packages\nanoFramework.CoreLibrary.1.16.11\lib\mscorlib.dll</HintPath>
3538
</Reference>
39+
<Reference Include="nanoFramework.Graphics.Core">
40+
<HintPath>..\..\packages\nanoFramework.Graphics.Core.1.2.35\lib\nanoFramework.Graphics.Core.dll</HintPath>
41+
</Reference>
42+
<Reference Include="nanoFramework.Runtime.Events">
43+
<HintPath>..\..\packages\nanoFramework.Runtime.Events.1.11.29\lib\nanoFramework.Runtime.Events.dll</HintPath>
44+
</Reference>
45+
<Reference Include="System.Device.Gpio">
46+
<HintPath>..\..\packages\nanoFramework.System.Device.Gpio.1.1.53\lib\System.Device.Gpio.dll</HintPath>
47+
</Reference>
48+
</ItemGroup>
49+
<ItemGroup>
50+
<ProjectReference Include="..\..\Peripherals\NeoPixel.Peripheral\NeoPixel.Peripheral.nfproj" />
51+
<ProjectReference Include="..\..\Shared\Client.Services\Client.Services.nfproj" />
3652
</ItemGroup>
3753
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets')" />
3854
<ProjectExtensions>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="nanoFramework.CoreLibrary" version="1.16.11" targetFramework="netnano1.0" />
4+
<package id="nanoFramework.Graphics.Core" version="1.2.35" targetFramework="netnano1.0" />
5+
<package id="nanoFramework.Iot.Device.Button" version="1.2.775" targetFramework="netnano1.0" />
6+
<package id="nanoFramework.Runtime.Events" version="1.11.29" targetFramework="netnano1.0" />
7+
<package id="nanoFramework.System.Device.Gpio" version="1.1.53" targetFramework="netnano1.0" />
48
</packages>

src/nf-telemetry-clients/Peripherals/Bluetooth.Sensor/BluetoothSensor.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,13 @@ private void Advertisement_Received(BluetoothLEAdvertisementWatcher sender, Blue
7272
return;
7373
}
7474

75-
var utcNow = DateTime.UtcNow;
76-
7775
lock(_eventHistory)
7876
{
77+
var utcNow = DateTime.UtcNow.Ticks;
7978
var expiry = _eventHistory[args.BluetoothAddress];
80-
if (expiry == null || (DateTime)expiry < utcNow)
79+
if (expiry == null || (long)expiry < utcNow)
8180
{
82-
_eventHistory[args.BluetoothAddress] = args.Timestamp.Add(_retentionInterval);
81+
_eventHistory[args.BluetoothAddress] = args.Timestamp.Add(_retentionInterval).Ticks;
8382
}
8483
else
8584
{
@@ -113,7 +112,7 @@ private void NotifyDataReceived(bool forceNotification = false)
113112
if (forceNotification || _telemetry.Count >= _preferredBatchSize)
114113
{
115114
// Postpone next notification
116-
if(_notificationTimer != null)
115+
if (_notificationTimer != null)
117116
{
118117
_notificationTimer.Change(_timerInerval, _timerInerval);
119118
}
@@ -134,11 +133,11 @@ private void TrimEventHistory()
134133
return;
135134
}
136135

137-
var now = DateTime.UtcNow;
136+
var now = DateTime.UtcNow.Ticks;
138137
var keys = new ArrayList();
139138
foreach (DictionaryEntry entry in _eventHistory)
140139
{
141-
if ((DateTime)entry.Value < now)
140+
if ((long)entry.Value < now)
142141
{
143142
keys.Add(entry.Key);
144143
}

src/nf-telemetry-clients/Peripherals/IO.Peripherals/IO.Peripherals.nfproj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,37 @@
2727
<Reference Include="mscorlib">
2828
<HintPath>..\..\packages\nanoFramework.CoreLibrary.1.16.11\lib\mscorlib.dll</HintPath>
2929
</Reference>
30+
<Reference Include="nanoFramework.Hardware.Esp32">
31+
<HintPath>..\..\packages\nanoFramework.Hardware.Esp32.1.6.29\lib\nanoFramework.Hardware.Esp32.dll</HintPath>
32+
</Reference>
3033
<Reference Include="nanoFramework.Runtime.Events">
3134
<HintPath>..\..\packages\nanoFramework.Runtime.Events.1.11.29\lib\nanoFramework.Runtime.Events.dll</HintPath>
3235
</Reference>
3336
<Reference Include="nanoFramework.System.Collections">
3437
<HintPath>..\..\packages\nanoFramework.System.Collections.1.5.59\lib\nanoFramework.System.Collections.dll</HintPath>
3538
</Reference>
39+
<Reference Include="nanoFramework.System.Runtime">
40+
<HintPath>..\..\packages\nanoFramework.System.Runtime.1.0.27\lib\nanoFramework.System.Runtime.dll</HintPath>
41+
</Reference>
42+
<Reference Include="nanoFramework.System.Text">
43+
<HintPath>..\..\packages\nanoFramework.System.Text.1.3.1\lib\nanoFramework.System.Text.dll</HintPath>
44+
</Reference>
3645
<Reference Include="System.Device.Gpio">
3746
<HintPath>..\..\packages\nanoFramework.System.Device.Gpio.1.1.53\lib\System.Device.Gpio.dll</HintPath>
3847
</Reference>
48+
<Reference Include="System.IO.FileSystem">
49+
<HintPath>..\..\packages\nanoFramework.System.IO.FileSystem.1.1.69\lib\System.IO.FileSystem.dll</HintPath>
50+
</Reference>
51+
<Reference Include="System.IO.Streams">
52+
<HintPath>..\..\packages\nanoFramework.System.IO.Streams.1.1.77\lib\System.IO.Streams.dll</HintPath>
53+
</Reference>
3954
</ItemGroup>
4055
<ItemGroup>
4156
<None Include="packages.config" />
4257
</ItemGroup>
58+
<ItemGroup>
59+
<ProjectReference Include="..\..\Shared\Shared\Shared.nfproj" />
60+
</ItemGroup>
4361
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets')" />
4462
<ProjectExtensions>
4563
<ProjectCapabilities>

src/nf-telemetry-clients/Peripherals/IO.Peripherals/packages.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="nanoFramework.CoreLibrary" version="1.16.11" targetFramework="netnano1.0" />
4+
<package id="nanoFramework.Hardware.Esp32" version="1.6.29" targetFramework="netnano1.0" />
45
<package id="nanoFramework.Runtime.Events" version="1.11.29" targetFramework="netnano1.0" />
56
<package id="nanoFramework.System.Collections" version="1.5.59" targetFramework="netnano1.0" />
67
<package id="nanoFramework.System.Device.Gpio" version="1.1.53" targetFramework="netnano1.0" />
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup Label="Globals">
4+
<NanoFrameworkProjectSystemPath>$(MSBuildExtensionsPath)\nanoFramework\v1.0\</NanoFrameworkProjectSystemPath>
5+
</PropertyGroup>
6+
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.Default.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.Default.props')" />
7+
<PropertyGroup>
8+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
9+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
10+
<ProjectTypeGuids>{11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
11+
<ProjectGuid>cc3f20b1-1b1e-45c1-ac32-ad400ae75cd3</ProjectGuid>
12+
<OutputType>Library</OutputType>
13+
<AppDesignerFolder>Properties</AppDesignerFolder>
14+
<FileAlignment>512</FileAlignment>
15+
<RootNamespace>NeoPixel.Peripheral</RootNamespace>
16+
<AssemblyName>NeoPixel.Peripheral</AssemblyName>
17+
<TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
18+
</PropertyGroup>
19+
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.props')" />
20+
<ItemGroup>
21+
<Compile Include="NeoPixelGauge.cs" />
22+
<Compile Include="Properties\AssemblyInfo.cs" />
23+
</ItemGroup>
24+
<ItemGroup>
25+
<Reference Include="CCSWE.nanoFramework.Math">
26+
<HintPath>..\..\packages\CCSWE.nanoFramework.Math.1.1.63\lib\CCSWE.nanoFramework.Math.dll</HintPath>
27+
</Reference>
28+
<Reference Include="CCSWE.nanoFramework.NeoPixel">
29+
<HintPath>..\..\packages\CCSWE.nanoFramework.NeoPixel.1.1.63\lib\CCSWE.nanoFramework.NeoPixel.dll</HintPath>
30+
</Reference>
31+
<Reference Include="mscorlib">
32+
<HintPath>..\..\packages\nanoFramework.CoreLibrary.1.16.11\lib\mscorlib.dll</HintPath>
33+
</Reference>
34+
<Reference Include="nanoFramework.Graphics.Core">
35+
<HintPath>..\..\packages\nanoFramework.Graphics.Core.1.2.35\lib\nanoFramework.Graphics.Core.dll</HintPath>
36+
</Reference>
37+
<Reference Include="nanoFramework.Hardware.Esp32.Rmt">
38+
<HintPath>..\..\packages\nanoFramework.Hardware.Esp32.Rmt.2.0.22\lib\nanoFramework.Hardware.Esp32.Rmt.dll</HintPath>
39+
</Reference>
40+
<Reference Include="nanoFramework.Runtime.Events">
41+
<HintPath>..\..\packages\nanoFramework.Runtime.Events.1.11.29\lib\nanoFramework.Runtime.Events.dll</HintPath>
42+
</Reference>
43+
<Reference Include="System.Math">
44+
<HintPath>..\..\packages\nanoFramework.System.Math.1.5.90\lib\System.Math.dll</HintPath>
45+
</Reference>
46+
</ItemGroup>
47+
<ItemGroup>
48+
<None Include="packages.config" />
49+
</ItemGroup>
50+
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets')" />
51+
<ProjectExtensions>
52+
<ProjectCapabilities>
53+
<ProjectConfigurationsDeclaredAsItems />
54+
</ProjectCapabilities>
55+
</ProjectExtensions>
56+
</Project>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using CCSWE.nanoFramework.NeoPixel;
2+
using CCSWE.nanoFramework.NeoPixel.Drivers;
3+
using System.Drawing;
4+
using System.Threading;
5+
6+
// https://docid81hrs3j1.cloudfront.net/medialibrary/2018/10/WS2812B_V1.4_EN_18090714224701.pdf
7+
// Enable LDO2 on UM FeatherS3
8+
//var gpioController = new GpioController();
9+
//gpioController.OpenPin(39, PinMode.Output).Write(PinValue.High);
10+
11+
namespace NeoPixel.Peripheral
12+
{
13+
public class NeoPixelGauge
14+
{
15+
private readonly Color[] _colors;
16+
private readonly NeoPixelStrip _pixels;
17+
18+
public NeoPixelGauge(ushort pixelsCount, Color[] gaugeColors, byte pin)
19+
{
20+
_pixels = new NeoPixelStrip(pin, pixelsCount, new Ws2812B());
21+
_colors = new Color[pixelsCount];
22+
23+
var partitionSize = pixelsCount / gaugeColors.Length;
24+
var remaining = pixelsCount % gaugeColors.Length;
25+
var brightnessScale = 1f / pixelsCount;
26+
27+
var index = 0;
28+
for (var i = 0; i < gaugeColors.Length; i++)
29+
{
30+
var partitionLength = partitionSize;
31+
if (i == 0)
32+
{
33+
partitionLength += remaining;
34+
}
35+
36+
for (var j = 0; j < partitionLength; j++)
37+
{
38+
var brightness = (index + 1) * brightnessScale;
39+
var color = ColorConverter.ScaleBrightness(gaugeColors[i], brightness);
40+
_colors[index++] = color;
41+
}
42+
}
43+
}
44+
45+
public void DemoRun()
46+
{
47+
var delay = 500;
48+
49+
while (true)
50+
{
51+
_pixels.Clear();
52+
_pixels.Update();
53+
54+
for (var i = 0; i < _pixels.Count; i++)
55+
{
56+
_pixels.SetLed(i, _colors[i]);
57+
_pixels.Update();
58+
Thread.Sleep(10);
59+
}
60+
61+
Thread.Sleep(delay * 5);
62+
}
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)