private bool Populate(ExploreProtocol result) { if (buttonState == EButtonSensorState.None) { result.code = 1; return(false); } result.code = 0; switch (buttonState) { case EButtonSensorState.Click: // 点击 result.SetDatas(1); break; case EButtonSensorState.DoubleClick: // 双击 result.SetDatas(2); break; case EButtonSensorState.LongPress: // 长按 result.SetDatas(3); break; default: result.SetDatas(1); break; } return(true); }
protected override IProtocol ExecuteUKitCommands(ICommand command) { ExploreProtocol result = ExploreProtocol.CreateResponse(ProtocolCode.Failure, command); do { if (command is UKitCommands.ColorRecognitionCommand) { debug = command.debug; var cmd = (UKitCommands.ColorRecognitionCommand)command; if (LineTrace(out var distance, out Color rgb)) { result.SetDatas(Misc.Nearly(cmd.color, rgb)); result.code = 0; DebugUtility.Log(LoggerTags.Project, "ColorRecognitionCommand Reacted : {0}m", distance); } break; } if (command is UKitCommands.ColorRecognitionRGBCommand) { debug = command.debug; //var cmd = (UKitCommands.UltrasonicCommand)command; if (LineTrace(out var distance, out Color rgb)) { result.SetDatas((int)(rgb.r * 255), (int)(rgb.g * 255), (int)(rgb.b * 255)); result.code = 0; DebugUtility.Log(LoggerTags.Project, "ColorRecognitionRGBCommand Reacted : {0}m", distance); } break; } } while (false); return(result); }
private IProtocol ExecuteMotorCommands(ICommand command) { ExploreProtocol result = ExploreProtocol.CreateResponse(ProtocolCode.Failure, command); do { if (command is MotorCommands.VelocitySettingCommand) { var cmd = (MotorCommands.VelocitySettingCommand)command; jobStatus = WorkStatus.RotationAlways; var job = (RotationAlwaysJob)currentJob; job.velocity = cmd.velocity; result.code = 0; break; } if (command is MotorCommands.PWMSettingCommand) { var cmd = (MotorCommands.PWMSettingCommand)command; jobStatus = WorkStatus.RotationAlways; var job = (RotationAlwaysJob)currentJob; job.velocity = cmd.pwm; result.code = 0; break; } if (command is MotorCommands.ReadVelocityCommand) { var cmd = (MotorCommands.ReadVelocityCommand)command; int v = 0; if (jobStatus == WorkStatus.RotationAlways) { var job = (RotationAlwaysJob)currentJob; v = (int)job.velocity; } result.SetDatas((int)v); result.code = 0; break; } if (command is MotorCommands.StopCommand) { var cmd = (MotorCommands.StopCommand)command; Stop(); result.code = 0; break; } } while (false); return(result); }
protected override IProtocol ExecuteUKitCommands(ICommand command) { ExploreProtocol result = ExploreProtocol.CreateResponse(ProtocolCode.Failure, command); do { if (command is UKitCommands.TemperatureCommand) { debug = command.debug; if (GetEnvironment(out var env)) { var cmd = (UKitCommands.TemperatureCommand)command; if (cmd.mode == 0) { var temp = Mathf.CeilToInt(env.temperature); result.SetDatas(temp); DebugUtility.Log(LoggerTags.Project, "TemperatureCommand Reacted : {0}C", temp.ToString()); } else if (cmd.mode == 1) { var f = Mathf.CeilToInt(C2F(env.temperature)); result.SetDatas(f); DebugUtility.Log(LoggerTags.Project, "TemperatureCommand Reacted : {0}F", f.ToString()); } else if (cmd.mode == 2) { var f = Mathf.CeilToInt(env.humidity); result.SetDatas(f); DebugUtility.Log(LoggerTags.Project, "TemperatureCommand Reacted : {0}%", f.ToString()); } result.code = 0; } break; } } while (false); return(result); }
protected override IProtocol ExecuteUKitCommands(ICommand command) { ExploreProtocol result = ExploreProtocol.CreateResponse(ProtocolCode.Failure, command); do { if (command is UKitCommands.SoundCommand) { debug = command.debug; if (GetEnvironment(out var env)) { //var cmd = (UKitCommands.SoundCommand)command; result.SetDatas(Mathf.CeilToInt(env.soundVolume)); result.code = 0; DebugUtility.Log(LoggerTags.Project, "SoundCommand Reacted : {0}", env.soundVolume); } break; } } while (false); return(result); }
protected override IProtocol ExecuteUKitCommands(ICommand command) { ExploreProtocol result = ExploreProtocol.CreateResponse(ProtocolCode.Failure, command); do { if (command is UKitCommands.InfraredCommand) { debug = command.debug; if (LineTrace(out var distance)) { result.SetDatas((int)(distance * 100.0f)); result.code = 0; DebugUtility.Log(LoggerTags.Project, "InfraredCommand Reacted : {0}m", distance); } break; } } while (false); return(result); }
protected virtual IProtocol ExecutePatrolCommands(ICommand command) { ExploreProtocol result = ExploreProtocol.CreateResponse(ProtocolCode.Failure, command); do { if (command is PatrolSensorCommands.PatrolSensorBasicCommand) { debug = command.debug; var cmd = (PatrolSensorCommands.PatrolSensorBasicCommand)command; if (LineTrace(out var distance, out Color rgb)) { float gray = Misc.ToGray(rgb); result.SetDatas(gray >= 0.5f && cmd.isGray); result.code = 0; DebugUtility.Log(LoggerTags.Project, "PatrolSensorBasicCommand Reacted : {0}m", distance); } break; } } while (false); return(result); }
private IProtocol ExecuteServoCommands(ICommand command) { ExploreProtocol result = ExploreProtocol.CreateResponse(ProtocolCode.Failure, command); do { // 舵机角模式 if (command is ServoCommands.RotateCommand) { var cmd = (ServoCommands.RotateCommand)command; jobStatus = WorkStatus.Rotation; var job = (RotationJob)currentJob; job.accumulationTime = 0.0f; job.duration = cmd.duration; var rawAngle = localEulerAnglesY; rawAngle = Misc.Convert(convertMode, rawAngle); job.startAngle = rawAngle; job.endAngle = cmd.angel; result.code = 0; break; } // 舵机轮模式 if (command is ServoCommands.RotationAlwaysCommand) { var cmd = (ServoCommands.RotationAlwaysCommand)command; jobStatus = WorkStatus.RotationAlways; var job = (RotationAlwaysJob)currentJob; if (cmd.forward) { job.velocity = cmd.velocity; } else { job.velocity = cmd.velocity * -1.0f; } result.code = 0; break; } // 停止舵机 if (command is ServoCommands.StopCommand) { var cmd = (ServoCommands.StopCommand)command; Stop(); result.code = 0; break; } // 读取舵机角度 if (command is ServoCommands.ReadRotationCommand) { var cmd = (ServoCommands.ReadRotationCommand)command; if (!cmd.enable) { jobStatus = WorkStatus.Idle; } Vector2 angleRange = new Vector2(-118.0f, 118.0f); float angle = localEulerAnglesY; angle = Misc.Convert(convertMode, angle); ProtocolCode code = ProtocolCode.Success; if (angle < angleRange.x || angle > angleRange.y) { code = ProtocolCode.Failure; } result.SetDatas((int)angle); result.code = code == ProtocolCode.Success ? 0 : 1; break; } } while (false); return(result); }
public IProtocol ExecuteMainControlCommands(ICommand command) { ExploreProtocol result = ExploreProtocol.CreateResponse(ProtocolCode.Failure, command); do { if (command is MiscCommands.SetIDCommand) { var cmd = (MiscCommands.SetIDCommand)command; result.code = ChangeID(cmd.targetDevice, cmd.oldID, cmd.newID); break; } if (command is MiscCommands.QueryDeviceCommand) { var cmd = (MiscCommands.QueryDeviceCommand)command; result.code = QueryDevice(result); break; } if (command is MiscCommands.QueryDeviceUpgradableCommand) { var cmd = (MiscCommands.QueryDeviceUpgradableCommand)command; break; } if (command is MiscCommands.StopAllDevicesCommand) { var cmd = (MiscCommands.StopAllDevicesCommand)command; Stop(); result.code = 0; break; } if (command is MiscCommands.GetVersionCommand) { var cmd = (MiscCommands.GetVersionCommand)command; result.SetDatas("v1.2.4", "v2"); result.code = 0; break; } if (command is MiscCommands.StartUpgradeCommand) { var cmd = (MiscCommands.StartUpgradeCommand)command; break; } if (command is MiscCommands.TickUpgradeCommand) { var cmd = (MiscCommands.TickUpgradeCommand)command; break; } if (command is MiscCommands.EndUpgradeCommand) { var cmd = (MiscCommands.EndUpgradeCommand)command; break; } }while (false); return(result); }