/*
* Copyright (c) 2025 LG Electronics Inc.
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
*/
using Aurora.Api;
using Aurora.Api.Devices;
using Hermes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace VisionLight {
///
/// MagnetAttach strobe 조명으로 사용.
/// light 관련 time delay 필요했던 조명
/// 조명 Mode를 변경할 경우 늦게 반영되는 경우가 많아, 자주 변경할 경우 GrabSeq와 별개로 별도로 호출해서도 사용 하였음 ( eLightMode )
/// !주의! 다른 Light와는 상대적으로 Thread sleep이 자주 호출됨. ( 추후 재검증 시 확인 후 주석 처리 할 것 )
///
public class Light_iPulse_ModbusSerial : LightBase_ModbusSerial {
///
/// Light Mode
///
public enum eLIGHT_MODE {
///
/// Off
///
Off = 0x00,
///
/// Continous
///
Continous = 0x01,
///
/// Strobe
///
Strobe = 0x02,
}
private const int _SetLightMode = 0x0300;
private const int _SetDuration = 0x0310;
private const int _SetPeriod = 0x0312;
private const int _SetContinuousBrigtness = 0x0330;
private const int _SetPulseBrigtness = 0x0340;
///
/// Light IPlus Modbus Serial 생성자
///
/// 디바이스 Id
public Light_iPulse_ModbusSerial(string deviceId) : base(deviceId) {
DeviceId = deviceId;
}
///
/// Set Level Implement
///
/// 레벨
/// 채널
///
protected override eLightResult SetLevelImpl(int level, int channel) {
LOG.FuncI();
int ret = 0;
int opmode = 0;
(ret, opmode) = ReadWord(_SetLightMode);
Thread.Sleep(100);
//if (_config.LightType == eLightType.Continuous) {
if (opmode == (short)eLIGHT_MODE.Continous) {
ret = WriteWord(_SetContinuousBrigtness, (short)level);
if (ret != 0)
return eLightResult.NG;
}
else {
ret = WriteWord(_SetPulseBrigtness, (short)level);
if (ret != 0)
return eLightResult.NG;
}
Thread.Sleep(100);
return eLightResult.OK;
}
///
/// Set Off Implement
///
/// 채널
/// Light 결과 값
protected override eLightResult SetOffImpl(int channel) {
LOG.FuncI();
WriteWord(_SetLightMode, (short)eLIGHT_MODE.Off);
Thread.Sleep(100);
return eLightResult.OK;
}
///
/// Set On Implement
///
/// 채널
/// Light 결과값
protected override eLightResult SetOnImpl(int channel) {
LOG.FuncI();
WriteWord(_SetLightMode, (short)eLIGHT_MODE.Strobe);
Thread.Sleep(100);
return eLightResult.OK;
}
///
/// 모드 변경
///
/// Light Mode
/// Light 결과 값
public eLightResult ModeChange(eLIGHT_MODE mode) {
int opmode = 0;
int ret = 0;
(ret, opmode) = ReadWord(_SetLightMode);
Thread.Sleep(100);
// 임시 사용을 위해 Ch1 = strobe, ch2 = continous 사용
//if (_config.LightType == eLightType.Continuous) {
if (mode == eLIGHT_MODE.Continous) {
if (opmode != (short)eLIGHT_MODE.Continous) {
ret = WriteWord(_SetLightMode, (short)eLIGHT_MODE.Continous);
Thread.Sleep(100);
if (ret != 0)
return eLightResult.NG;
}
}
else if (mode == eLIGHT_MODE.Off) {
if (opmode != (short)eLIGHT_MODE.Off) {
ret = WriteWord(_SetLightMode, (short)eLIGHT_MODE.Off);
Thread.Sleep(100);
if (ret != 0)
return eLightResult.NG;
}
}
else {
if (mode == eLIGHT_MODE.Strobe) {
ret = WriteWord(_SetLightMode, (short)eLIGHT_MODE.Strobe);
Thread.Sleep(100);
if (ret != 0)
return eLightResult.NG;
}
}
return eLightResult.OK;
}
///
/// Duration Setting
///
/// continous duriation setting
///
public eLightResult SetDuration(double duration) {
int opmode = 0;
int ret = 0;
(ret, opmode) = ReadWord(_SetLightMode);
Thread.Sleep(100);
// 임시 사용을 위해 Ch1 = strobe, ch2 = continous 사용
//if (_config.LightType == eLightType.Continuous) {
ret = WriteReal(_SetDuration, (float)duration);
if (ret != 0)
return eLightResult.NG;
Thread.Sleep(100);
return eLightResult.OK;
}
}
}