mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-15 20:54:55 +00:00
Tested basic messaging with Simpl code; worked out join ranges for most messages; adding config data
This commit is contained in:
@@ -50,6 +50,11 @@ namespace PepperDash.Essentials
|
|||||||
|
|
||||||
bool NeedNewClient;
|
bool NeedNewClient;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Used to count retries in PostToServer
|
||||||
|
/// </summary>
|
||||||
|
int RetryCounter;
|
||||||
|
|
||||||
public CotijaSystemController(string key, string name, CotijaConfig config) : base(key, name)
|
public CotijaSystemController(string key, string name, CotijaConfig config) : base(key, name)
|
||||||
{
|
{
|
||||||
Config = config;
|
Config = config;
|
||||||
@@ -252,11 +257,26 @@ namespace PepperDash.Essentials
|
|||||||
{
|
{
|
||||||
Debug.Console(1, this, "Status Response Code: {0}", r.Code);
|
Debug.Console(1, this, "Status Response Code: {0}", r.Code);
|
||||||
PostLockEvent.Set();
|
PostLockEvent.Set();
|
||||||
|
RetryCounter = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Try again. This client is hosed.
|
// Try again. This client is hosed.
|
||||||
NeedNewClient = true;
|
NeedNewClient = true;
|
||||||
|
RetryCounter++;
|
||||||
|
// instant retry on first try.
|
||||||
|
if (RetryCounter >= 2 && RetryCounter < 5)
|
||||||
|
CrestronEnvironment.Sleep(1000);
|
||||||
|
else if (RetryCounter >= 5 && RetryCounter <= 10)
|
||||||
|
CrestronEnvironment.Sleep(5000);
|
||||||
|
// give up
|
||||||
|
else if (RetryCounter > 10)
|
||||||
|
{
|
||||||
|
Debug.Console(1, this, "Giving up on server POST");
|
||||||
|
RetryCounter = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Debug.Console(1, this, "POST retry #{0}", RetryCounter);
|
||||||
PostLockEvent.Set();
|
PostLockEvent.Set();
|
||||||
PostToServer(o);
|
PostToServer(o);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,38 +17,56 @@ namespace PepperDash.Essentials.Room.Cotija
|
|||||||
{
|
{
|
||||||
public class BoolJoin
|
public class BoolJoin
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// 1
|
|
||||||
/// </summary>
|
|
||||||
public const uint GetStatus = 1;
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 2
|
/// 2
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const uint RoomIsOn = 2;
|
public const uint RoomIsOn = 301;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 3
|
/// 51
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const uint DefaultSourcePress = 3;
|
public const uint ActivitySharePress = 51;
|
||||||
|
/// <summary>
|
||||||
|
/// 52
|
||||||
|
/// </summary>
|
||||||
|
public const uint ActivityPhoneCallPress = 52;
|
||||||
|
/// <summary>
|
||||||
|
/// 53
|
||||||
|
/// </summary>
|
||||||
|
public const uint ActivityVideoCallPress = 53;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 4
|
/// 4
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const uint MasterVolumeIsMuted = 4;
|
public const uint MasterVolumeIsMuted = 1;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 4
|
/// 4
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const uint MasterVolumeMuteToggle = 4;
|
public const uint MasterVolumeMuteToggle = 1;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 21
|
/// 61
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const uint ShutdownStart = 21;
|
public const uint ShutdownCancel = 61;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 22
|
/// 62
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const uint ShutdownEnd = 22;
|
public const uint ShutdownEnd = 62;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 23
|
/// 63
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const uint ShutdownCancel = 23;
|
public const uint ShutdownStart = 63;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 71
|
||||||
|
/// </summary>
|
||||||
|
public const uint SourceHasChanged = 71;
|
||||||
|
/// <summary>
|
||||||
|
/// 501
|
||||||
|
/// </summary>
|
||||||
|
public const uint ConfigIsReady = 501;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class UshortJoin
|
public class UshortJoin
|
||||||
@@ -56,7 +74,9 @@ namespace PepperDash.Essentials.Room.Cotija
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const uint MasterVolumeLevel = 4;
|
public const uint MasterVolumeLevel = 1;
|
||||||
|
|
||||||
|
public const uint ShutdownPromptDuration = 61;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class StringJoin
|
public class StringJoin
|
||||||
@@ -64,7 +84,28 @@ namespace PepperDash.Essentials.Room.Cotija
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const uint SetSource = 3;
|
public const uint SelectedSourceKey = 3;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 501
|
||||||
|
/// </summary>
|
||||||
|
public const uint ConfigRoomName = 501;
|
||||||
|
/// <summary>
|
||||||
|
/// 502
|
||||||
|
/// </summary>
|
||||||
|
public const uint ConfigHelpMessage = 502;
|
||||||
|
/// <summary>
|
||||||
|
/// 503
|
||||||
|
/// </summary>
|
||||||
|
public const uint ConfigHelpNumber = 503;
|
||||||
|
/// <summary>
|
||||||
|
/// 504
|
||||||
|
/// </summary>
|
||||||
|
public const uint ConfigRoomPhoneNumber = 504;
|
||||||
|
/// <summary>
|
||||||
|
/// 505
|
||||||
|
/// </summary>
|
||||||
|
public const uint ConfigRoomURI = 505;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -72,6 +113,8 @@ namespace PepperDash.Essentials.Room.Cotija
|
|||||||
|
|
||||||
CotijaSystemController Parent;
|
CotijaSystemController Parent;
|
||||||
|
|
||||||
|
public bool ConfigIsLoaded { get; private set; }
|
||||||
|
|
||||||
public CotijaDdvc01RoomBridge(string key, string name, uint ipId)
|
public CotijaDdvc01RoomBridge(string key, string name, uint ipId)
|
||||||
: base(key, name)
|
: base(key, name)
|
||||||
{
|
{
|
||||||
@@ -105,6 +148,7 @@ namespace PepperDash.Essentials.Room.Cotija
|
|||||||
|
|
||||||
SetupFunctions();
|
SetupFunctions();
|
||||||
SetupFeedbacks();
|
SetupFeedbacks();
|
||||||
|
EISC.SigChange += EISC_SigChange;
|
||||||
return base.CustomActivate();
|
return base.CustomActivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,12 +158,16 @@ namespace PepperDash.Essentials.Room.Cotija
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
void SetupFunctions()
|
void SetupFunctions()
|
||||||
{
|
{
|
||||||
Parent.AddAction(@"/room/room1/status", new Action(() =>
|
Parent.AddAction(@"/room/room1/status", new Action(SendFullStatus));
|
||||||
EISC.PulseBool(BoolJoin.GetStatus)));
|
|
||||||
Parent.AddAction(@"/room/room1/source", new Action<SourceSelectMessageContent>(c =>
|
Parent.AddAction(@"/room/room1/source", new Action<SourceSelectMessageContent>(c =>
|
||||||
EISC.SetString(StringJoin.SetSource, c.SourceListItem)));
|
{
|
||||||
Parent.AddAction(@"/room/room1/defaultsource", new Action(() =>
|
EISC.SetString(StringJoin.SelectedSourceKey, c.SourceListItem);
|
||||||
EISC.PulseBool(BoolJoin.DefaultSourcePress)));
|
EISC.PulseBool(BoolJoin.SourceHasChanged);
|
||||||
|
}));
|
||||||
|
|
||||||
|
Parent.AddAction(@"/room/room1/activityshare", new Action(() =>
|
||||||
|
EISC.PulseBool(BoolJoin.ActivitySharePress)));
|
||||||
|
|
||||||
Parent.AddAction(@"/room/room1/masterVolumeLevel", new Action<ushort>(u =>
|
Parent.AddAction(@"/room/room1/masterVolumeLevel", new Action<ushort>(u =>
|
||||||
EISC.SetUshort(UshortJoin.MasterVolumeLevel, u)));
|
EISC.SetUshort(UshortJoin.MasterVolumeLevel, u)));
|
||||||
@@ -139,12 +187,21 @@ namespace PepperDash.Essentials.Room.Cotija
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
void SetupFeedbacks()
|
void SetupFeedbacks()
|
||||||
{
|
{
|
||||||
EISC.SetStringSigAction(StringJoin.SetSource, s =>
|
// Power
|
||||||
|
EISC.SetBoolSigAction(BoolJoin.RoomIsOn, b =>
|
||||||
PostStatusMessage(new
|
PostStatusMessage(new
|
||||||
{
|
{
|
||||||
selectedSourceKey = s
|
isOn = b
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// Source change things
|
||||||
|
EISC.SetSigTrueAction(BoolJoin.SourceHasChanged, () =>
|
||||||
|
PostStatusMessage(new
|
||||||
|
{
|
||||||
|
selectedSourceKey = EISC.StringOutput[StringJoin.SelectedSourceKey].StringValue
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Volume things
|
||||||
EISC.SetUShortSigAction(UshortJoin.MasterVolumeLevel, u =>
|
EISC.SetUShortSigAction(UshortJoin.MasterVolumeLevel, u =>
|
||||||
PostStatusMessage(new
|
PostStatusMessage(new
|
||||||
{
|
{
|
||||||
@@ -157,16 +214,64 @@ namespace PepperDash.Essentials.Room.Cotija
|
|||||||
masterVolumeMuteState = b
|
masterVolumeMuteState = b
|
||||||
}));
|
}));
|
||||||
|
|
||||||
EISC.SetSigTrueAction(BoolJoin.GetStatus, () =>
|
// shutdown things
|
||||||
|
EISC.SetSigTrueAction(BoolJoin.ShutdownCancel, new Action(() =>
|
||||||
|
PostStatusMessage(new
|
||||||
|
{
|
||||||
|
state = "wasCancelled"
|
||||||
|
})));
|
||||||
|
EISC.SetSigTrueAction(BoolJoin.ShutdownEnd, new Action(() =>
|
||||||
|
PostStatusMessage(new
|
||||||
|
{
|
||||||
|
state = "hasFinished"
|
||||||
|
})));
|
||||||
|
EISC.SetSigTrueAction(BoolJoin.ShutdownStart, new Action(() =>
|
||||||
|
PostStatusMessage(new
|
||||||
|
{
|
||||||
|
state = "hasStarted",
|
||||||
|
duration = EISC.UShortOutput[UshortJoin.ShutdownPromptDuration].UShortValue
|
||||||
|
})));
|
||||||
|
|
||||||
|
// Config things
|
||||||
|
EISC.SetSigTrueAction(BoolJoin.ConfigIsReady, LoadConfigValues);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads in config values when the Simpl program is ready
|
||||||
|
/// </summary>
|
||||||
|
void LoadConfigValues()
|
||||||
|
{
|
||||||
|
ConfigIsLoaded = false;
|
||||||
|
ConfigIsLoaded = true;
|
||||||
|
|
||||||
|
// send config changed status???
|
||||||
|
}
|
||||||
|
|
||||||
|
void SendFullStatus()
|
||||||
|
{
|
||||||
|
if (ConfigIsLoaded)
|
||||||
|
{
|
||||||
PostStatusMessage(new
|
PostStatusMessage(new
|
||||||
{
|
{
|
||||||
isOn = EISC.BooleanOutput[BoolJoin.RoomIsOn].BoolValue,
|
isOn = EISC.BooleanOutput[BoolJoin.RoomIsOn].BoolValue,
|
||||||
selectedSourceKey = EISC.StringOutput[StringJoin.SetSource].StringValue,
|
selectedSourceKey = EISC.StringOutput[StringJoin.SelectedSourceKey].StringValue,
|
||||||
masterVolumeLevel = EISC.UShortOutput[UshortJoin.MasterVolumeLevel].UShortValue,
|
masterVolumeLevel = EISC.UShortOutput[UshortJoin.MasterVolumeLevel].UShortValue,
|
||||||
masterVolumeMuteState = EISC.BooleanOutput[BoolJoin.MasterVolumeIsMuted].BoolValue
|
masterVolumeMuteState = EISC.BooleanOutput[BoolJoin.MasterVolumeIsMuted].BoolValue
|
||||||
}));
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PostStatusMessage(new
|
||||||
|
{
|
||||||
|
error = "systemNotReady"
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Helper for posting status message
|
/// Helper for posting status message
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -179,5 +284,24 @@ namespace PepperDash.Essentials.Room.Cotija
|
|||||||
content = contentObject
|
content = contentObject
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="currentDevice"></param>
|
||||||
|
/// <param name="args"></param>
|
||||||
|
void EISC_SigChange(object currentDevice, Crestron.SimplSharpPro.SigEventArgs args)
|
||||||
|
{
|
||||||
|
if (Debug.Level == 2)
|
||||||
|
Debug.Console(2, this, "Sig change: {0} {1}={2}", args.Sig.Type, args.Sig.Number, args.Sig.StringValue);
|
||||||
|
var uo = args.Sig.UserObject;
|
||||||
|
if (uo is Action<bool>)
|
||||||
|
(uo as Action<bool>)(args.Sig.BoolValue);
|
||||||
|
else if (uo is Action<ushort>)
|
||||||
|
(uo as Action<ushort>)(args.Sig.UShortValue);
|
||||||
|
else if (uo is Action<string>)
|
||||||
|
(uo as Action<string>)(args.Sig.StringValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user