internal ActionContainer(IEnumerable <JToken> actions) { _actions = actions.Select(actionJToken => { Action action; switch (Action.ParseEventType(actionJToken["eventType"]?.ToString())) { case EventType.Twirl: action = new Twirl(actionJToken); break; case EventType.SetSpeed: action = new SetSpeed(actionJToken); break; case EventType.NotAvailable: goto default; default: action = new Action(actionJToken); break; } action.ActionChanged += Action_OnActionChanged; return(action); }).ToList(); }
public static Dictionary <string, object> ToParameters(this SetSpeed setSpeed, Domain domain, IEnumerable <IDevice> devices) { switch (domain) { case Domain.Fan: return(new Dictionary <string, object> { { "speed", setSpeed.Speed.ToString().ToLowerInvariant() } } .Add(devices)); default: throw new NotSupportedException($"Domain '{domain}' does not support command SetSpeed, but one or more device tries to use it ({devices.Select(d => d.Id.ToString()).JoinBy(", ")})"); } }
public void Add(Data.Action action) { Action instance = null; switch (action.EventType) { case EventType.Twirl: if (Find(EventType.Twirl) != null) { break; } instance = new Twirl(JToken.FromObject(action)); OnActionChanged?.Invoke(CacheValue.IsClockWise); break; case EventType.SetSpeed: var setSpeedData = (Data.SetSpeed)action; if (Find(EventType.SetSpeed) is SetSpeed setSpeed) { setSpeed.SetValue(setSpeedData.SpeedType, (setSpeedData.SpeedType == SpeedType.Bpm) ? setSpeedData.BeatsPerMinute : setSpeedData.BpmMultiplier); } else { instance = new SetSpeed(JToken.FromObject(setSpeedData)); } OnActionChanged?.Invoke(CacheValue.Bpm); break; case EventType.NotAvailable: goto default; default: break; } if (instance == null) { return; } instance.ActionChanged += Action_OnActionChanged; _actions.Add(instance); }
public async Task Handle(SetSpeed command, CancellationToken cancellationToken) { await shipService.Locate(command.Ship); }
public void SetSpeedTest() { SetSpeed request = new SetSpeed(); var result = JsonConvert.DeserializeObject <KodiJSON.Player.Response.SetSpeedResponse>(ExecuteTest.GetResponse(request)); }
private static void Run() { var inputFileName = cmd.arguments.First(); if (!File.Exists(inputFileName)) { throw new Exception(String.Format("File {0} does not exists", inputFileName)); } //TODO?: read SVG and convert to HPGL //TODO?: vectorize SVG, so white fills are wiped out from vectors List <HpglItem> hpglData; if (cmd.GetParamOrDefault("gerber", false)) { var gerberParser = new GerberParser(); using (var f = File.OpenRead(inputFileName)) { var gerberData = gerberParser.Parse(f); foreach (var item in gerberData.OfType <Gerber.Language.UnknownCommand>()) { Console.WriteLine(item); } var comp = cmd.GetParamOrDefault("gerberpen", 0.0); var unitstext = cmd.GetParamOrDefault("gerberunits", "Inches"); var units = (Units)Enum.Parse(typeof(Units), unitstext); var g2h = new Gerber.Transformations.Gerber2Hpgl() { PenWidthCompensation = comp, Units = units }; hpglData = g2h.Translate(gerberData); } } else { var parser = new HpglParser(); using (var f = File.OpenRead(inputFileName)) { hpglData = parser.Parse(f); } Console.WriteLine("HPGL file {0} readed", inputFileName); Console.WriteLine("Stats:"); Console.WriteLine("Parser: {0} tokens, {1} commands", hpglData.Count, hpglData.Where(h => !(h is Terminator)).Count()); } //MEASURE { var measure = new Measure(); measure.Visit(hpglData); Console.WriteLine("Dimensions: min={0}, max={1}", measure.Min, measure.Max); Console.WriteLine("Length of lines: with pen down={0:.1}, with pen up={1:.1}", measure.PenDownLength, measure.PenUpLength); } //remove unknowns hpglData = hpglData.Where(h => !(h is Hpgl.Language.UnknownCommand)).ToList(); int width = cmd.GetParamOrDefault("width", 1520); int height = cmd.GetParamOrDefault("height", 2160); if (cmd.GetParamOrDefault("textify", false)) { Console.WriteLine("Textificating..."); var t = new Textificator(); hpglData = t.Process(hpglData); } if (cmd.GetParamOrDefault("absolutize", false)) { var a = new Absolutizer(); hpglData = a.Process(hpglData); } //transformation { var transformer = new Transformer(cmd.GetParamOrDefault("transform", string.Empty)); hpglData = transformer.Transform(hpglData); } //autoscale if (cmd.GetParamOrDefault("autoscale", false)) { Console.WriteLine("Autoscaling..."); var measure = new Measure(); measure.Visit(hpglData); if (measure.ContainsRelative) { Console.WriteLine("Warning: input contains PR, results can be strange"); } Console.WriteLine("Dimensions: min={0}, max={1}", measure.Min, measure.Max); var size = new HPoint(measure.Max.X - measure.Min.X, measure.Max.Y - measure.Min.Y); //size.X/size.Y=width/height //newptx/pt.x = width/size.X double sx = (double)(width * 0.9d) / size.X; double sy = (double)(height * 0.9d) / size.Y; var transformer = new Transformer(); transformer.Move(-measure.Min.X, -measure.Min.Y); transformer.Scale(sx < sy ? sx : sy); transformer.Move((int)(width * 0.05d), (int)(height * 0.05d)); hpglData = transformer.Transform(hpglData); } //optimalization if (cmd.GetParamOrDefault("optimize", true)) { Console.WriteLine("Optimizing..."); var optimizer = new SegmentationOptimizer(); hpglData = optimizer.Process(hpglData); var optmeasure = new Measure(); optmeasure.Visit(hpglData); Console.WriteLine("Optimized lines: with pen down={0:.1}, with pen up={1:.1}", optmeasure.PenDownLength, optmeasure.PenUpLength); } var maxstep = cmd.GetParamOrDefault("maxstep", 0); if (maxstep > 0) { int split = 0; int i = 0; while (i < hpglData.Count) { var pcmd = hpglData[i] as HpglPointsCommand; if (pcmd != null) { if (pcmd.Points.Count > maxstep) { split++; var newcmd = Activator.CreateInstance(pcmd.GetType()) as HpglPointsCommand; newcmd.Points = pcmd.Points.Take(maxstep).ToList(); hpglData.Insert(i, newcmd); pcmd.Points = pcmd.Points.Skip(maxstep).ToList(); } } i++; } Console.WriteLine("Splitted " + split + " commands for maximum " + maxstep + " steps."); } //outline var outline = cmd.GetParamOrDefault("outline", -1); if (outline >= 0) { var measure = new Measure(); measure.Visit(hpglData); var size = new HPoint(outline, outline); var rect = new[] { new HPoint(measure.Min.X - outline, measure.Max.Y + outline), new HPoint(measure.Max.X + outline, measure.Max.Y + outline), new HPoint(measure.Max.X + outline, measure.Min.Y - outline), new HPoint(measure.Min.X - outline, measure.Min.Y - outline), }; hpglData.Insert(0, new PenUp() { Points = { rect[3] } }); hpglData.Insert(1, new PenDown() { Points = { rect[0], rect[1], rect[2], rect[3] } }); //hpglData.Insert(2, new PenUp() { } ); } //speed, delay var s = cmd.GetParamOrDefault("speed", 0); var d = cmd.GetParamOrDefault("updelay", 0); if (s != 0 || d != 0) { var ss = new SetSpeed() { SpeedMove = s, DelayUp = d }; hpglData.Insert(0, ss); } if (cmd.GetParamOrDefault("noinit", false)) { hpglData.RemoveAll(x => x is Initialization); } var outputType = cmd.GetParamOrDefault("output", "image").ToLowerInvariant(); switch (outputType) { case "image": { //TODO3: // colorization - add colors (SP, better gray) by position in list var outFile = cmd.GetParamOrDefault("filename", "result.png"); Console.WriteLine("Writing to bitmap {0} ({1}x{2})", outFile, width, height); var bmp = new Bitmap(width, height); var hpgl2Bmp = new Hpgl2Bmp(); hpgl2Bmp.DebugPenUp = cmd.GetParamOrDefault("showPenUp", false); hpgl2Bmp.Numbering = cmd.GetParamOrDefault("showNumbers", false); hpgl2Bmp.Process(bmp, hpglData); bmp.Save(outFile); break; } case "serial": { var sp = cmd.GetParamOrDefault("serial", "COM1,9600"); var ser = new Hpgl2SerialConsole(sp); if (cmd.GetParamOrDefault("paused", false)) { ser.IsPaused = true; } Console.WriteLine("Writing to serial {0},{1},{2},{3},{4}", ser.Port.PortName, ser.Port.BaudRate, ser.Port.Parity, ser.Port.DataBits, ser.Port.StopBits); ser.Proces(hpglData); break; } case "file": { var outFile = cmd.GetParamOrDefault("filename", "result.plt"); Console.WriteLine("Writing to file {0}", outFile); var f = new Hpgl2File(); f.Process(outFile, hpglData); break; } default: { throw new ArgumentOutOfRangeException("output"); } } }
/// <summary> /// Receives input from the microcontroller (used for acks informing of turn/stop complete). /// /// This method is NOT CURRENTLY COMPLETE, due to changes in the specification. /// </summary> /// <param name="sender">The sending object</param> /// <param name="e">The event</param> private void serialPort_dataRecieved(object sender, SerialDataReceivedEventArgs e) { while (myMotors.BytesToRead > 0) { int b = myMotors.ReadByte(); switch (state) { case 0: if (b == (int)MotorCommands.COMMAND_START) state = 1; break; case 1: switch (b) { case (int)MotorCommands.ACK: receive_ack = "Acknowledged"; SendAck a = new SendAck(); motorAckRecieve.Post(a); state = 2; break; case (int)MotorCommands.STOP: receive_ack = "STOP Acknowledged"; Stop stop = new Stop(); motorAckRecieve.Post(stop); StopComplete c = new StopComplete(); motorAckRecieve.Post(c); state = 2; break; case (int)MotorCommands.TURN: receive_ack = "TURN Acknowledged"; Turn turn = new Turn(); motorAckRecieve.Post(turn); state = 2; break; case (int)MotorCommands.MOVE: receive_ack = "MOVE Acknowledged"; SetSpeed ss = new SetSpeed(); motorAckRecieve.Post(ss); state = 2; break; case (int)MotorCommands.HAS_STOPPED: receive_ack = "Has Stopped"; StopComplete sc = new StopComplete(); motorAckRecieve.Post(sc); state = 2; break; case (int)MotorCommands.TURN_COMPLETE: receive_ack = "Turn complete in serial handler"; TurnComplete tc = new TurnComplete(); motorAckRecieve.Post(tc); state = 2; break; case (int)MotorCommands.BUMPER_ACTIVE: bumper.sendBumperNotification(); state = 2; break; default: receive_ack = "Unexpected input from motors!"; state = 0; break; } Console.WriteLine(receive_ack); break; case 2: if (b == (int)MotorCommands.COMMAND_STOP) state = 0; // motorAckRecieve.Post(a); Console.WriteLine(receive_ack); break; default: state = 0; break; } } }
public IEnumerator<ITask> SetMotorSpeedHandler(SetSpeed s) { MotorSpeed sp = s.Body; _motor.sendMove(sp.Left, sp.Right); yield break; }