add: 添加前端对焦交互逻辑
This commit is contained in:
@@ -213,8 +213,7 @@ class Camera
|
||||
/// <returns>包含图像数据的字节数组</returns>
|
||||
public async ValueTask<Result<byte[]>> ReadFrame()
|
||||
{
|
||||
// 只在第一次或出错时清除UDP缓冲区,避免每帧都清除造成延迟
|
||||
// await MsgBus.UDPServer.ClearUDPData(this.address, this.taskID);
|
||||
MsgBus.UDPServer.ClearUDPData(this.address, this.taskID);
|
||||
|
||||
logger.Trace($"Reading frame from camera {this.address}");
|
||||
|
||||
@@ -303,7 +302,13 @@ class Camera
|
||||
return true;
|
||||
}
|
||||
|
||||
public async ValueTask<Result<byte>> ReadRegisters(UInt16 register)
|
||||
|
||||
/// <summary>
|
||||
/// 读取I2C寄存器字节值
|
||||
/// </summary>
|
||||
/// <param name="register">要读取的寄存器地址 (16位)</param>
|
||||
/// <returns>ret</returns>
|
||||
public async ValueTask<Result<byte>> ReadRegister(UInt16 register)
|
||||
{
|
||||
var i2c = new Peripherals.I2cClient.I2c(this.address, this.port, this.taskID, this.timeout);
|
||||
|
||||
@@ -1218,18 +1223,22 @@ class Camera
|
||||
{
|
||||
logger.Info("开始写入OV5640自动对焦固件");
|
||||
|
||||
MsgBus.UDPServer.ClearUDPData(this.address, this.taskID);
|
||||
var setStartAddrResult = await ConfigureRegisters([[0x3000, 0x80]]);
|
||||
if (!setStartAddrResult.IsSuccessful) return setStartAddrResult;
|
||||
|
||||
// 组装固件写入命令:地址 + 所有固件数据
|
||||
UInt16 firmwareAddr = 0x8000;
|
||||
var firmwareCommands = new List<UInt16[]>();
|
||||
var firmwareCommand = new UInt16[1 + OV5640_AF_FIRMWARE.Length];
|
||||
firmwareCommand[0] = firmwareAddr;
|
||||
|
||||
// 将固件数据复制到命令数组中
|
||||
for (int i = 0; i < OV5640_AF_FIRMWARE.Length; i++)
|
||||
{
|
||||
UInt16 addr = (UInt16)(firmwareAddr + i);
|
||||
firmwareCommands.Add([addr, OV5640_AF_FIRMWARE[i]]);
|
||||
firmwareCommand[i + 1] = OV5640_AF_FIRMWARE[i];
|
||||
}
|
||||
|
||||
var result = await ConfigureRegisters(firmwareCommands.ToArray());
|
||||
var result = await ConfigureRegisters([firmwareCommand]);
|
||||
if (!result.IsSuccessful)
|
||||
{
|
||||
logger.Error($"固件写入失败: {result.Error}");
|
||||
@@ -1324,7 +1333,7 @@ class Camera
|
||||
// 步骤2: 读取寄存器 0x3029 的状态,如果返回值为 0x10,代表对焦已完成
|
||||
for (int iteration = 5000; iteration > 0; iteration--)
|
||||
{
|
||||
var readResult = await ReadRegisters(0x3029);
|
||||
var readResult = await ReadRegister(0x3029);
|
||||
if (!readResult.IsSuccessful)
|
||||
{
|
||||
logger.Error($"读取对焦状态寄存器(0x3029)失败: {readResult.Error}");
|
||||
|
||||
Reference in New Issue
Block a user