Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

Commit

Permalink
#90, #89, #88, and #87 (#91)
Browse files Browse the repository at this point in the history
* closes #89
closes #88

* closes #87

* closes #90 : Provide Kick Start for the Locomotives in AutoMode

* fix build

Co-authored-by: Christian Benjamin Ries <c.ries@beckhoff.com>
  • Loading branch information
cbries and Christian Benjamin Ries committed Apr 7, 2021
1 parent b06a6fa commit e166666
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 11 deletions.
4 changes: 2 additions & 2 deletions EcosApp/railessentials.min.js

Large diffs are not rendered by default.

32 changes: 29 additions & 3 deletions EcosApp/src/occ.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,28 @@ class Occ {
oid: locData.objectId
});
});
locomotiveInfoFinal.on("contextmenu", function (event) {
event.preventDefault();

new Contextual({
isSticky: false,
items: [
{
cssIcon: 'fas fa-broom',
enabled: true,
label: 'Remove Assignment', onClick: () => {
console.log("OID: " + locData.objectId);
self.__trigger("resetAssignment",
{
mode: 'resetAssignment',
submode: 'final',
oid: locData.objectId
});
}
}
]
});
});

//
// add wait countdown to fromInfo
Expand Down Expand Up @@ -692,9 +714,13 @@ class Occ {

const offsetY = parseInt(h - locInfoHeight) / 2;

let ypos = (top - offsetY);
if (ypos < 0) ypos = 5;

locController.css({
top: (top - offsetY) + "px",
left: (left - w - 4) + "px"
"z-index": 150,
top: ypos + "px",
left: (left - w - 2) + "px"
});

locController.mousemove(function () {
Expand All @@ -705,7 +731,7 @@ class Occ {
locController.mouseleave(function () {
setTimeout(function () {
locController.hide();
}, 100);
}, 125);
});
}

Expand Down
25 changes: 24 additions & 1 deletion railessentials/AutoMode/AutoModeTaskBase.Accelerate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ private async Task AccelerateLocomotiveCurve(
if (ecosLoc == null) return;
if (speedCurve == null) return;

KickStart(currentSpeed, ecosLoc);

if (maxSeconds <= -1)
maxSeconds = speedCurve.MaxTime;

Expand Down Expand Up @@ -96,11 +98,13 @@ private async Task AccelerateLocomotive(

await Task.Run(() =>
{
KickStart(currentSpeed, ecosLoc);
var hasCanceled = false;
var newCurrentSpeed = currentSpeed;
var sw = Stopwatch.StartNew();
for (var i = currentSpeed; i <= targetSpeed; ++i)
{
Ctx.GetClientHandler()?.LocomotiveChangeSpeedstep(ecosLoc, i);
Expand Down Expand Up @@ -156,5 +160,24 @@ private bool __delayAccelerate(

return false;
}

private void KickStart(int currentSpeed, Locomotive ecosLoc)
{
var maxSpeedSteps = ecosLoc.GetNumberOfSpeedsteps();
if (currentSpeed > 2) return;
var previousSpeed = currentSpeed;
var kickStartSpeed = previousSpeed;

if (maxSpeedSteps <= 14)
kickStartSpeed = Globals.DccKickStartM14;
else if (maxSpeedSteps <= 28)
kickStartSpeed = Globals.DccKickStartM28;
else if (maxSpeedSteps <= 128)
kickStartSpeed = Globals.DccKickStartM128;

Ctx.GetClientHandler()?.LocomotiveChangeSpeedstep(ecosLoc, kickStartSpeed);
System.Threading.Thread.Sleep(Globals.DccKickStartDelayMsecs);
Ctx.GetClientHandler()?.LocomotiveChangeSpeedstep(ecosLoc, previousSpeed);
}
}
}
7 changes: 6 additions & 1 deletion railessentials/AutoMode/AutoModeTaskBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,14 @@ public async override Task Run()
var maxSpeed = Route.Locomotive.GetNumberOfSpeedsteps();
var speedCurve = Route.LocomotivesData?.SpeedCurve;

var targetSpeed = (int)(maxSpeed / 3.0);
var targetSpeed = (int)(maxSpeed / 2.0);
if (speedCurve != null)
targetSpeed = speedCurve.MaxSpeed;
else
{
if(Route.LocomotivesData != null)
targetSpeed = Route.LocomotivesData.GetLevel("level").Value;
}

#endregion

Expand Down
4 changes: 1 addition & 3 deletions railessentials/ClientHandler/ClientHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -546,9 +546,7 @@ private void HandleRouteCommand_ResetAssignment(JObject cmddata)

_metadata.Save(Metadata.SaveModelType.OccData);
}

ResetBlockEnterSideOf(oid);


SendModelToClients(ModelType.UpdateLocomotivesData);
SendModelToClients(ModelType.UpdateOcc);
}
Expand Down
5 changes: 5 additions & 0 deletions railessentials/Globals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public static class Globals
public const string ApplicationName = "RailEssentials";
public const string ApplicationDescription = "RailEssentials is a software for controlling your Model Trains especially when ESU's ECoS 50210/50200 is used.";

public const int DccKickStartM14 = 3;
public const int DccKickStartM28 = 3;
public const int DccKickStartM128 = 5;
public const int DccKickStartDelayMsecs = 100;

public static Dictionary<string, string> GetCfgDataPath()
{
var dict = new Dictionary<string, string>
Expand Down
19 changes: 19 additions & 0 deletions railessentials/Locomotives/Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License
// File: Data.cs

using System;
using System.Collections.Generic;

namespace railessentials.Locomotives
Expand All @@ -14,5 +15,23 @@ public class Data
public string EnterBlockSide { get; set; }
public SpeedCurve SpeedCurve { get; set; }
public Dictionary<string, SpeedLevel> SpeedLevels { get; set; } = new();

public SpeedLevel GetLevel(string level)
{
var def = new SpeedLevel { Value = 0 };

if (string.IsNullOrEmpty(level))
return def;

if (SpeedLevels == null) return def;

foreach(var it in SpeedLevels)
{
if (it.Key.IndexOf(level, StringComparison.OrdinalIgnoreCase) != -1)
return it.Value;
}

return def;
}
}
}
2 changes: 1 addition & 1 deletion railessentials/railessentials.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"SimulationMode": false,
"SimulationMode": true,
"SimulationData": "Demos\\Ecos\\ecosJson.txt",
"RootWorkspace": "Workspaces\\",
"RecentWorkspace": "Basement",
Expand Down

0 comments on commit e166666

Please sign in to comment.