chore: move all files to file-scoped namespace

This commit is contained in:
Andrew Welker
2025-07-04 16:02:32 -05:00
parent 8b873b7248
commit 6d2cd75cbe
552 changed files with 46137 additions and 46725 deletions

View File

@@ -6,115 +6,114 @@ using Crestron.SimplSharp;
using PepperDash.Core;
namespace PepperDash.Essentials.Core
namespace PepperDash.Essentials.Core;
/// <summary>
/// An incrementer that can use the values of some other object/primitive value to do its thing.
/// It uses an Action to set the value and a Func to get the value from whatever this is
/// attached to.
/// </summary>
public class ActionIncrementer
{
public int ChangeAmount { get; set; }
public int MaxValue { get; set; }
public int MinValue { get; set; }
public uint RepeatDelay { get; set; }
public uint RepeatTime { get; set; }
Action<int> SetAction;
Func<int> GetFunc;
CTimer Timer;
/// <summary>
/// An incrementer that can use the values of some other object/primitive value to do its thing.
/// It uses an Action to set the value and a Func to get the value from whatever this is
/// attached to.
///
/// </summary>
public class ActionIncrementer
/// <param name="changeAmount"></param>
/// <param name="minValue"></param>
/// <param name="maxValue"></param>
/// <param name="repeatDelay"></param>
/// <param name="repeatTime"></param>
/// <param name="setAction">Action that will be called when this needs to set the destination value</param>
/// <param name="getFunc">Func that is called to get the current value</param>
public ActionIncrementer(int changeAmount, int minValue, int maxValue, uint repeatDelay, uint repeatTime, Action<int> setAction, Func<int> getFunc)
{
public int ChangeAmount { get; set; }
public int MaxValue { get; set; }
public int MinValue { get; set; }
public uint RepeatDelay { get; set; }
public uint RepeatTime { get; set; }
SetAction = setAction;
GetFunc = getFunc;
ChangeAmount = changeAmount;
MaxValue = maxValue;
MinValue = minValue;
RepeatDelay = repeatDelay;
RepeatTime = repeatTime;
}
Action<int> SetAction;
Func<int> GetFunc;
CTimer Timer;
/// <summary>
/// Starts incrementing cycle
/// </summary>
public void StartUp()
{
if (Timer != null) return;
Go(ChangeAmount);
}
/// <summary>
///
/// </summary>
/// <param name="changeAmount"></param>
/// <param name="minValue"></param>
/// <param name="maxValue"></param>
/// <param name="repeatDelay"></param>
/// <param name="repeatTime"></param>
/// <param name="setAction">Action that will be called when this needs to set the destination value</param>
/// <param name="getFunc">Func that is called to get the current value</param>
public ActionIncrementer(int changeAmount, int minValue, int maxValue, uint repeatDelay, uint repeatTime, Action<int> setAction, Func<int> getFunc)
/// <summary>
/// Starts decrementing cycle
/// </summary>
public void StartDown()
{
if (Timer != null) return;
Go(-ChangeAmount);
}
/// <summary>
/// Stops the repeat
/// </summary>
public void Stop()
{
if (Timer != null)
Timer.Stop();
Timer = null;
}
/// <summary>
/// Helper that does the work of setting new level, and starting repeat loop, checking against bounds first.
/// </summary>
/// <param name="change"></param>
void Go(int change)
{
int currentLevel = GetFunc();
// Fire once then pause
int newLevel = currentLevel + change;
bool atLimit = CheckLevel(newLevel, out newLevel);
SetAction(newLevel);
if (atLimit) // Don't go past end
Stop();
else if (Timer == null) // Only enter the timer if it's not already running
Timer = new CTimer(o => { Go(change); }, null, RepeatDelay, RepeatTime);
}
/// <summary>
/// Helper to check a new level against min/max. Returns revised level if new level
/// will go out of bounds
/// </summary>
/// <param name="levelIn">The level to check against bounds</param>
/// <param name="levelOut">Revised level if bounds are exceeded. Min or max</param>
/// <returns>true if new level is at or past bounds</returns>
bool CheckLevel(int levelIn, out int levelOut)
{
bool isAtLimit = false;
if (levelIn > MaxValue)
{
SetAction = setAction;
GetFunc = getFunc;
ChangeAmount = changeAmount;
MaxValue = maxValue;
MinValue = minValue;
RepeatDelay = repeatDelay;
RepeatTime = repeatTime;
levelOut = MaxValue;
isAtLimit = true;
}
/// <summary>
/// Starts incrementing cycle
/// </summary>
public void StartUp()
else if (levelIn < MinValue)
{
if (Timer != null) return;
Go(ChangeAmount);
}
/// <summary>
/// Starts decrementing cycle
/// </summary>
public void StartDown()
{
if (Timer != null) return;
Go(-ChangeAmount);
}
/// <summary>
/// Stops the repeat
/// </summary>
public void Stop()
{
if (Timer != null)
Timer.Stop();
Timer = null;
}
/// <summary>
/// Helper that does the work of setting new level, and starting repeat loop, checking against bounds first.
/// </summary>
/// <param name="change"></param>
void Go(int change)
{
int currentLevel = GetFunc();
// Fire once then pause
int newLevel = currentLevel + change;
bool atLimit = CheckLevel(newLevel, out newLevel);
SetAction(newLevel);
if (atLimit) // Don't go past end
Stop();
else if (Timer == null) // Only enter the timer if it's not already running
Timer = new CTimer(o => { Go(change); }, null, RepeatDelay, RepeatTime);
}
/// <summary>
/// Helper to check a new level against min/max. Returns revised level if new level
/// will go out of bounds
/// </summary>
/// <param name="levelIn">The level to check against bounds</param>
/// <param name="levelOut">Revised level if bounds are exceeded. Min or max</param>
/// <returns>true if new level is at or past bounds</returns>
bool CheckLevel(int levelIn, out int levelOut)
{
bool isAtLimit = false;
if (levelIn > MaxValue)
{
levelOut = MaxValue;
isAtLimit = true;
}
else if (levelIn < MinValue)
{
levelOut = MinValue;
isAtLimit = true;
}
else
levelOut = levelIn;
return isAtLimit;
levelOut = MinValue;
isAtLimit = true;
}
else
levelOut = levelIn;
return isAtLimit;
}
}

View File

@@ -4,37 +4,36 @@ using System.Linq;
using System.Text;
using Crestron.SimplSharp;
namespace PepperDash.Essentials.Core
{
public class NumericalHelpers
{
/// <summary>
/// Scales a value
/// </summary>
/// <param name="input"></param>
/// <param name="inMin"></param>
/// <param name="inMax"></param>
/// <param name="outMin"></param>
/// <param name="outMax"></param>
/// <returns></returns>
public static double Scale(double input, double inMin, double inMax, double outMin, double outMax)
namespace PepperDash.Essentials.Core;
public class NumericalHelpers
{
/// <summary>
/// Scales a value
/// </summary>
/// <param name="input"></param>
/// <param name="inMin"></param>
/// <param name="inMax"></param>
/// <param name="outMin"></param>
/// <param name="outMax"></param>
/// <returns></returns>
public static double Scale(double input, double inMin, double inMax, double outMin, double outMax)
{
//Debug.LogMessage(LogEventLevel.Verbose, this, "Scaling (double) input '{0}' with min '{1}'/max '{2}' to output range min '{3}'/max '{4}'", input, inMin, inMax, outMin, outMax);
double inputRange = inMax - inMin;
if (inputRange <= 0)
{
//Debug.LogMessage(LogEventLevel.Verbose, this, "Scaling (double) input '{0}' with min '{1}'/max '{2}' to output range min '{3}'/max '{4}'", input, inMin, inMax, outMin, outMax);
double inputRange = inMax - inMin;
if (inputRange <= 0)
{
throw new ArithmeticException(string.Format("Invalid Input Range '{0}' for Scaling. Min '{1}' Max '{2}'.", inputRange, inMin, inMax));
}
double outputRange = outMax - outMin;
var output = (((input - inMin) * outputRange) / inputRange) + outMin;
// Debug.LogMessage(LogEventLevel.Verbose, this, "Scaled output '{0}'", output);
return output;
throw new ArithmeticException(string.Format("Invalid Input Range '{0}' for Scaling. Min '{1}' Max '{2}'.", inputRange, inMin, inMax));
}
double outputRange = outMax - outMin;
var output = (((input - inMin) * outputRange) / inputRange) + outMin;
// Debug.LogMessage(LogEventLevel.Verbose, this, "Scaled output '{0}'", output);
return output;
}
}

View File

@@ -8,94 +8,93 @@ using Crestron.SimplSharpPro;
using PepperDash.Core;
using Serilog.Events;
namespace PepperDash.Essentials.Core
namespace PepperDash.Essentials.Core;
/// <summary>
/// Attaches to UShortInputSig and does incremental ramping of the signal
/// </summary>
public class UshortSigIncrementer
{
/// <summary>
/// Attaches to UShortInputSig and does incremental ramping of the signal
/// </summary>
public class UshortSigIncrementer
UShortInputSig TheSig;
public ushort ChangeAmount { get; set; }
public int MaxValue { get; set; }
public int MinValue { get; set; }
public uint RepeatDelay { get; set; }
public uint RepeatTime { get; set; }
bool SignedMode;
CTimer Timer;
public UshortSigIncrementer(UShortInputSig sig, ushort changeAmount, int minValue, int maxValue, uint repeatDelay, uint repeatTime)
{
UShortInputSig TheSig;
public ushort ChangeAmount { get; set; }
public int MaxValue { get; set; }
public int MinValue { get; set; }
public uint RepeatDelay { get; set; }
public uint RepeatTime { get; set; }
bool SignedMode;
CTimer Timer;
TheSig = sig;
ChangeAmount = changeAmount;
MaxValue = maxValue;
MinValue = minValue;
if (MinValue < 0 || MaxValue < 0) SignedMode = true;
RepeatDelay = repeatDelay;
RepeatTime = repeatTime;
if (SignedMode && (MinValue < -32768 || MaxValue > 32767))
Debug.LogMessage(LogEventLevel.Debug, "UshortSigIncrementer has signed values that exceed range of -32768, 32767");
}
public UshortSigIncrementer(UShortInputSig sig, ushort changeAmount, int minValue, int maxValue, uint repeatDelay, uint repeatTime)
public void StartUp()
{
if (Timer != null) return;
Go(ChangeAmount);
}
public void StartDown()
{
if (Timer != null) return;
Go(-ChangeAmount);
}
void Go(int change)
{
int level;
if (SignedMode) level = TheSig.ShortValue;
else level = TheSig.UShortValue;
// Fire once then pause
int newLevel = level + change;
bool atLimit = CheckLevel(newLevel, out newLevel);
SetValue((ushort)newLevel);
if (atLimit) // Don't go past end
Stop();
else if (Timer == null) // Only enter the timer if it's not already running
Timer = new CTimer(o => { Go(change); }, null, RepeatDelay, RepeatTime);
}
bool CheckLevel(int levelIn, out int levelOut)
{
bool IsAtLimit = false;
if (levelIn > MaxValue)
{
TheSig = sig;
ChangeAmount = changeAmount;
MaxValue = maxValue;
MinValue = minValue;
if (MinValue < 0 || MaxValue < 0) SignedMode = true;
RepeatDelay = repeatDelay;
RepeatTime = repeatTime;
if (SignedMode && (MinValue < -32768 || MaxValue > 32767))
Debug.LogMessage(LogEventLevel.Debug, "UshortSigIncrementer has signed values that exceed range of -32768, 32767");
levelOut = MaxValue;
IsAtLimit = true;
}
public void StartUp()
else if (levelIn < MinValue)
{
if (Timer != null) return;
Go(ChangeAmount);
levelOut = MinValue;
IsAtLimit = true;
}
else
levelOut = levelIn;
return IsAtLimit;
}
public void StartDown()
{
if (Timer != null) return;
Go(-ChangeAmount);
}
public void Stop()
{
if (Timer != null)
Timer.Stop();
Timer = null;
}
void Go(int change)
{
int level;
if (SignedMode) level = TheSig.ShortValue;
else level = TheSig.UShortValue;
// Fire once then pause
int newLevel = level + change;
bool atLimit = CheckLevel(newLevel, out newLevel);
SetValue((ushort)newLevel);
if (atLimit) // Don't go past end
Stop();
else if (Timer == null) // Only enter the timer if it's not already running
Timer = new CTimer(o => { Go(change); }, null, RepeatDelay, RepeatTime);
}
bool CheckLevel(int levelIn, out int levelOut)
{
bool IsAtLimit = false;
if (levelIn > MaxValue)
{
levelOut = MaxValue;
IsAtLimit = true;
}
else if (levelIn < MinValue)
{
levelOut = MinValue;
IsAtLimit = true;
}
else
levelOut = levelIn;
return IsAtLimit;
}
public void Stop()
{
if (Timer != null)
Timer.Stop();
Timer = null;
}
void SetValue(ushort value)
{
//CrestronConsole.PrintLine("Increment level:{0} / {1}", value, (short)value);
TheSig.UShortValue = value;
}
void SetValue(ushort value)
{
//CrestronConsole.PrintLine("Increment level:{0} / {1}", value, (short)value);
TheSig.UShortValue = value;
}
}