fix: 修复示波器修改后无法配置的问题;修复无法生成api的问题;feat: 新增全局控制七段数码管
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System.Net;
|
||||
using DotNext;
|
||||
using Tapper;
|
||||
|
||||
namespace Peripherals.WS2812Client;
|
||||
|
||||
@@ -12,7 +13,8 @@ class WS2812Addr
|
||||
/// <summary>
|
||||
/// RGB颜色结构体,包含红、绿、蓝三个颜色分量
|
||||
/// </summary>
|
||||
public struct RGBColor
|
||||
[TranspilationSource]
|
||||
public class RGBColor
|
||||
{
|
||||
public byte Red { get; set; }
|
||||
public byte Green { get; set; }
|
||||
@@ -84,13 +86,13 @@ public class WS2812Client
|
||||
{
|
||||
if (ledIndex < 0 || ledIndex >= WS2812Addr.LED_COUNT)
|
||||
{
|
||||
return new(new ArgumentOutOfRangeException(nameof(ledIndex),
|
||||
return new(new ArgumentOutOfRangeException(nameof(ledIndex),
|
||||
$"LED index must be between 0 and {WS2812Addr.LED_COUNT - 1}"));
|
||||
}
|
||||
|
||||
if (MsgBus.IsRunning)
|
||||
MsgBus.UDPServer.ClearUDPData(this.address, this.taskID);
|
||||
else
|
||||
else
|
||||
return new(new Exception("Message Bus not work!"));
|
||||
|
||||
var addr = WS2812Addr.BASE + (UInt32)(ledIndex * 4); // 每个地址32位,步长为4字节
|
||||
@@ -123,14 +125,14 @@ public class WS2812Client
|
||||
{
|
||||
if (MsgBus.IsRunning)
|
||||
MsgBus.UDPServer.ClearUDPData(this.address, this.taskID);
|
||||
else
|
||||
else
|
||||
return new(new Exception("Message Bus not work!"));
|
||||
|
||||
try
|
||||
{
|
||||
// 一次性读取所有LED数据,每个LED占用4字节,总共128*4=512字节
|
||||
var ret = await UDPClientPool.ReadAddr4Bytes(this.ep, this.taskID, WS2812Addr.BASE, WS2812Addr.LED_COUNT, this.timeout);
|
||||
|
||||
|
||||
if (!ret.IsSuccessful)
|
||||
{
|
||||
logger.Error($"Get all LED colors failed: {ret.Error}");
|
||||
@@ -139,7 +141,7 @@ public class WS2812Client
|
||||
|
||||
var data = ret.Value;
|
||||
var expectedLength = WS2812Addr.LED_COUNT * 4; // 128 * 4 = 512 bytes
|
||||
|
||||
|
||||
if (data.Length < expectedLength)
|
||||
{
|
||||
var error = new Exception($"Invalid data length: expected {expectedLength} bytes, got {data.Length}");
|
||||
@@ -148,7 +150,7 @@ public class WS2812Client
|
||||
}
|
||||
|
||||
var colors = new RGBColor[WS2812Addr.LED_COUNT];
|
||||
|
||||
|
||||
for (int i = 0; i < WS2812Addr.LED_COUNT; i++)
|
||||
{
|
||||
var offset = i * 4;
|
||||
@@ -156,7 +158,7 @@ public class WS2812Client
|
||||
var colorData = BitConverter.ToUInt32(data, offset);
|
||||
colors[i] = RGBColor.FromUInt32(colorData);
|
||||
}
|
||||
|
||||
|
||||
return new(colors);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
Reference in New Issue
Block a user