feat: 增加示波器探测参数显示,增加旋转编码器按下的功能
This commit is contained in:
@@ -268,10 +268,10 @@ public class OscilloscopeApiController : ControllerBase
|
||||
|
||||
var response = new OscilloscopeDataResponse
|
||||
{
|
||||
ADFrequency = freqResult.Value,
|
||||
ADVpp = vppResult.Value,
|
||||
ADMax = maxResult.Value,
|
||||
ADMin = minResult.Value,
|
||||
AdFrequency = freqResult.Value,
|
||||
AdVpp = vppResult.Value,
|
||||
AdMax = maxResult.Value,
|
||||
AdMin = minResult.Value,
|
||||
WaveformData = Convert.ToBase64String(waveformResult.Value)
|
||||
};
|
||||
|
||||
|
||||
@@ -34,10 +34,10 @@ public interface IOscilloscopeReceiver
|
||||
[TranspilationSource]
|
||||
public class OscilloscopeDataResponse
|
||||
{
|
||||
public uint ADFrequency { get; set; }
|
||||
public byte ADVpp { get; set; }
|
||||
public byte ADMax { get; set; }
|
||||
public byte ADMin { get; set; }
|
||||
public uint AdFrequency { get; set; }
|
||||
public byte AdVpp { get; set; }
|
||||
public byte AdMax { get; set; }
|
||||
public byte AdMin { get; set; }
|
||||
public string WaveformData { get; set; } = "";
|
||||
}
|
||||
|
||||
@@ -275,19 +275,19 @@ public class OscilloscopeHub : Hub<IOscilloscopeReceiver>, IOscilloscopeHub
|
||||
|
||||
var response = new OscilloscopeDataResponse
|
||||
{
|
||||
ADFrequency = freqResult.Value,
|
||||
ADVpp = vppResult.Value,
|
||||
ADMax = maxResult.Value,
|
||||
ADMin = minResult.Value,
|
||||
AdFrequency = freqResult.Value,
|
||||
AdVpp = vppResult.Value,
|
||||
AdMax = maxResult.Value,
|
||||
AdMin = minResult.Value,
|
||||
WaveformData = Convert.ToBase64String(waveformResult.Value)
|
||||
};
|
||||
|
||||
return new OscilloscopeDataResponse
|
||||
{
|
||||
ADFrequency = freqResult.Value,
|
||||
ADVpp = vppResult.Value,
|
||||
ADMax = maxResult.Value,
|
||||
ADMin = minResult.Value,
|
||||
AdFrequency = freqResult.Value,
|
||||
AdVpp = vppResult.Value,
|
||||
AdMax = maxResult.Value,
|
||||
AdMin = minResult.Value,
|
||||
WaveformData = Convert.ToBase64String(waveformResult.Value)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ public interface IRotaryEncoderHub
|
||||
{
|
||||
Task<bool> SetEnable(bool enable);
|
||||
Task<bool> RotateEncoderOnce(int num, RotaryEncoderDirection direction);
|
||||
Task<bool> PressEncoderOnce(int num, RotaryEncoderPressStatus press);
|
||||
Task<bool> EnableCycleRotateEncoder(int num, RotaryEncoderDirection direction, int freq);
|
||||
Task<bool> DisableCycleRotateEncoder();
|
||||
}
|
||||
@@ -133,6 +134,30 @@ public class RotaryEncoderHub : Hub<IRotaryEncoderReceiver>, IRotaryEncoderHub
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> PressEncoderOnce(int num, RotaryEncoderPressStatus press)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (num <= 0 || num > 4)
|
||||
throw new ArgumentException($"RotaryEncoder num should be 1~3, instead of {num}");
|
||||
|
||||
var board = TryGetBoard().OrThrow(() => new Exception("Board not found"));
|
||||
var encoderCtrl = new RotaryEncoderCtrl(board.IpAddr, board.Port, 0);
|
||||
var result = await encoderCtrl.PressEncoderOnce(num, press);
|
||||
if (!result.IsSuccessful)
|
||||
{
|
||||
logger.Error(result.Error, $"RotateEncoderOnce({num}, {press}) failed");
|
||||
return false;
|
||||
}
|
||||
return result.Value;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex, "Failed to rotate encoder once");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> EnableCycleRotateEncoder(int num, RotaryEncoderDirection direction, int freq)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -7,8 +7,10 @@ namespace Peripherals.RotaryEncoderClient;
|
||||
class RotaryEncoderCtrlAddr
|
||||
{
|
||||
public const UInt32 BASE = 0xB0_00_00_30;
|
||||
public const UInt32 PRESS_BASE = 0xB0_00_00_40;
|
||||
|
||||
public const UInt32 ENABLE = BASE;
|
||||
public const UInt32 PRESS_ENABLE = PRESS_BASE;
|
||||
}
|
||||
|
||||
[TranspilationSource]
|
||||
@@ -18,6 +20,13 @@ public enum RotaryEncoderDirection : uint
|
||||
Clockwise = 1,
|
||||
}
|
||||
|
||||
[TranspilationSource]
|
||||
public enum RotaryEncoderPressStatus : uint
|
||||
{
|
||||
Press = 0,
|
||||
Release = 1,
|
||||
}
|
||||
|
||||
public class RotaryEncoderCtrl
|
||||
{
|
||||
private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
@@ -45,10 +54,22 @@ public class RotaryEncoderCtrl
|
||||
MsgBus.UDPServer.ClearUDPData(this.address, this.taskID);
|
||||
else return new(new Exception("Message Bus not work!"));
|
||||
|
||||
var ret = await UDPClientPool.WriteAddr(
|
||||
this.ep, this.taskID, RotaryEncoderCtrlAddr.ENABLE, enable ? 0x1U : 0x0U, this.timeout);
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
return ret.Value;
|
||||
{
|
||||
var ret = await UDPClientPool.WriteAddr(
|
||||
this.ep, this.taskID, RotaryEncoderCtrlAddr.ENABLE, enable ? 0x1U : 0x0U, this.timeout);
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
if (!ret.Value)
|
||||
{
|
||||
logger.Error($"Set Rotary Encoder Enable failed: {ret.Error}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
{
|
||||
var ret = await UDPClientPool.WriteAddr(
|
||||
this.ep, this.taskID, RotaryEncoderCtrlAddr.PRESS_ENABLE, enable ? 0x1U : 0x0U, this.timeout);
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
return ret.Value;
|
||||
}
|
||||
}
|
||||
|
||||
public async ValueTask<Result<bool>> RotateEncoderOnce(int num, RotaryEncoderDirection direction)
|
||||
@@ -61,7 +82,23 @@ public class RotaryEncoderCtrl
|
||||
this.ep, this.taskID, RotaryEncoderCtrlAddr.BASE + (UInt32)num, (UInt32)direction, this.timeout);
|
||||
if (!ret.IsSuccessful)
|
||||
{
|
||||
logger.Error($"Set Rotary Encoder {num} {direction.ToString()} failed: {ret.Error}");
|
||||
logger.Error($"Set Rotary Encoder Rotate {num} {direction.ToString()} failed: {ret.Error}");
|
||||
return new(ret.Error);
|
||||
}
|
||||
return ret.Value;
|
||||
}
|
||||
|
||||
public async ValueTask<Result<bool>> PressEncoderOnce(int num, RotaryEncoderPressStatus press)
|
||||
{
|
||||
if (MsgBus.IsRunning)
|
||||
MsgBus.UDPServer.ClearUDPData(this.address, this.taskID);
|
||||
else return new(new Exception("Message Bus not work!"));
|
||||
|
||||
var ret = await UDPClientPool.WriteAddr(
|
||||
this.ep, this.taskID, RotaryEncoderCtrlAddr.PRESS_BASE + (UInt32)num, (UInt32)press, this.timeout);
|
||||
if (!ret.IsSuccessful)
|
||||
{
|
||||
logger.Error($"Set Rotary Encoder Set {num} {press.ToString()} failed: {ret.Error}");
|
||||
return new(ret.Error);
|
||||
}
|
||||
return ret.Value;
|
||||
|
||||
Reference in New Issue
Block a user