mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-15 20:54:55 +00:00
Added Async fire to Feedbacks; fixed mock display to use async feedback
This commit is contained in:
@@ -64,14 +64,14 @@ namespace PepperDash.Essentials.Core
|
|||||||
if (!PowerIsOnFeedback.BoolValue && !_IsWarmingUp && !_IsCoolingDown)
|
if (!PowerIsOnFeedback.BoolValue && !_IsWarmingUp && !_IsCoolingDown)
|
||||||
{
|
{
|
||||||
_IsWarmingUp = true;
|
_IsWarmingUp = true;
|
||||||
IsWarmingUpFeedback.FireUpdate();
|
IsWarmingUpFeedback.InvokeFireUpdate();
|
||||||
// Fake power-up cycle
|
// Fake power-up cycle
|
||||||
WarmupTimer = new CTimer(o =>
|
WarmupTimer = new CTimer(o =>
|
||||||
{
|
{
|
||||||
_IsWarmingUp = false;
|
_IsWarmingUp = false;
|
||||||
_PowerIsOn = true;
|
_PowerIsOn = true;
|
||||||
IsWarmingUpFeedback.FireUpdate();
|
IsWarmingUpFeedback.InvokeFireUpdate();
|
||||||
PowerIsOnFeedback.FireUpdate();
|
PowerIsOnFeedback.InvokeFireUpdate();
|
||||||
}, WarmupTime);
|
}, WarmupTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -84,14 +84,14 @@ namespace PepperDash.Essentials.Core
|
|||||||
{
|
{
|
||||||
_IsCoolingDown = true;
|
_IsCoolingDown = true;
|
||||||
_PowerIsOn = false;
|
_PowerIsOn = false;
|
||||||
PowerIsOnFeedback.FireUpdate();
|
PowerIsOnFeedback.InvokeFireUpdate();
|
||||||
IsCoolingDownFeedback.FireUpdate();
|
IsCoolingDownFeedback.InvokeFireUpdate();
|
||||||
// Fake cool-down cycle
|
// Fake cool-down cycle
|
||||||
CooldownTimer = new CTimer(o =>
|
CooldownTimer = new CTimer(o =>
|
||||||
{
|
{
|
||||||
Debug.Console(2, this, "Cooldown timer ending");
|
Debug.Console(2, this, "Cooldown timer ending");
|
||||||
_IsCoolingDown = false;
|
_IsCoolingDown = false;
|
||||||
IsCoolingDownFeedback.FireUpdate();
|
IsCoolingDownFeedback.InvokeFireUpdate();
|
||||||
}, CooldownTime);
|
}, CooldownTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -117,20 +117,20 @@ namespace PepperDash.Essentials.Core
|
|||||||
|
|
||||||
public void SetVolume(ushort level)
|
public void SetVolume(ushort level)
|
||||||
{
|
{
|
||||||
_FakeVolumeLevel = level;
|
_FakeVolumeLevel = level;
|
||||||
VolumeLevelFeedback.FireUpdate();
|
VolumeLevelFeedback.InvokeFireUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void MuteOn()
|
public void MuteOn()
|
||||||
{
|
{
|
||||||
_IsMuted = true;
|
_IsMuted = true;
|
||||||
MuteFeedback.FireUpdate();
|
MuteFeedback.InvokeFireUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void MuteOff()
|
public void MuteOff()
|
||||||
{
|
{
|
||||||
_IsMuted = false;
|
_IsMuted = false;
|
||||||
MuteFeedback.FireUpdate();
|
MuteFeedback.InvokeFireUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public BoolFeedback MuteFeedback { get; private set; }
|
public BoolFeedback MuteFeedback { get; private set; }
|
||||||
@@ -170,7 +170,7 @@ namespace PepperDash.Essentials.Core
|
|||||||
public void MuteToggle()
|
public void MuteToggle()
|
||||||
{
|
{
|
||||||
_IsMuted = !_IsMuted;
|
_IsMuted = !_IsMuted;
|
||||||
MuteFeedback.FireUpdate();
|
MuteFeedback.InvokeFireUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -28,8 +28,19 @@ namespace PepperDash.Essentials.Core
|
|||||||
Cue = cue;
|
Cue = cue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fires an update synchronously
|
||||||
|
/// </summary>
|
||||||
public abstract void FireUpdate();
|
public abstract void FireUpdate();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fires the update asynchronously within a CrestronInvoke
|
||||||
|
/// </summary>
|
||||||
|
public void InvokeFireUpdate()
|
||||||
|
{
|
||||||
|
CrestronInvoke.BeginInvoke(o => FireUpdate());
|
||||||
|
}
|
||||||
|
|
||||||
protected void OnOutputChange()
|
protected void OnOutputChange()
|
||||||
{
|
{
|
||||||
if (OutputChange != null) OutputChange(this, EventArgs.Empty);
|
if (OutputChange != null) OutputChange(this, EventArgs.Empty);
|
||||||
|
|||||||
@@ -4,5 +4,5 @@
|
|||||||
[assembly: AssemblyCompany("PepperDash Technology Corp")]
|
[assembly: AssemblyCompany("PepperDash Technology Corp")]
|
||||||
[assembly: AssemblyProduct("PepperDashEssentials")]
|
[assembly: AssemblyProduct("PepperDashEssentials")]
|
||||||
[assembly: AssemblyCopyright("Copyright © PepperDash Technology Corp 2017")]
|
[assembly: AssemblyCopyright("Copyright © PepperDash Technology Corp 2017")]
|
||||||
[assembly: AssemblyVersion("1.0.11.*")]
|
[assembly: AssemblyVersion("1.0.12.*")]
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using System.Text;
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
using Crestron.SimplSharp.CrestronIO;
|
using Crestron.SimplSharp.CrestronIO;
|
||||||
|
using Crestron.SimplSharpPro.CrestronThread;
|
||||||
using Crestron.SimplSharpPro;
|
using Crestron.SimplSharpPro;
|
||||||
using Crestron.SimplSharp.Net.Http;
|
using Crestron.SimplSharp.Net.Http;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
@@ -25,6 +26,8 @@ namespace PepperDash.Essentials
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
CEvent PostLockEvent = new CEvent(true, true);
|
CEvent PostLockEvent = new CEvent(true, true);
|
||||||
|
|
||||||
|
Thread SseWorkerThread;
|
||||||
|
|
||||||
CotijaConfig Config;
|
CotijaConfig Config;
|
||||||
|
|
||||||
HttpClient Client;
|
HttpClient Client;
|
||||||
@@ -211,57 +214,63 @@ namespace PepperDash.Essentials
|
|||||||
/// <param name="o">object to be serialized and sent in post body</param>
|
/// <param name="o">object to be serialized and sent in post body</param>
|
||||||
public void PostToServer(EssentialsRoomBase room, JObject o)
|
public void PostToServer(EssentialsRoomBase room, JObject o)
|
||||||
{
|
{
|
||||||
var ready = PostLockEvent.Wait(2000);
|
CrestronInvoke.BeginInvoke(oo =>
|
||||||
if (!ready)
|
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "PostToServer failed to enter after 2 seconds. Ignoring");
|
var ready = PostLockEvent.Wait(2000);
|
||||||
return;
|
if (!ready)
|
||||||
}
|
|
||||||
|
|
||||||
PostLockEvent.Reset();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (Client == null || NeedNewClient)
|
|
||||||
{
|
{
|
||||||
NeedNewClient = false;
|
Debug.Console(1, this, "PostToServer failed to enter after 2 seconds. Ignoring");
|
||||||
Client = new HttpClient();
|
return;
|
||||||
}
|
}
|
||||||
Client.Verbose = false;
|
|
||||||
Client.KeepAlive = true;
|
|
||||||
|
|
||||||
HttpClientRequest request = new HttpClientRequest();
|
PostLockEvent.Reset();
|
||||||
request.RequestType = RequestType.Post;
|
try
|
||||||
string url = string.Format("http://{0}/api/system/{1}/status", Config.ServerUrl, SystemUuid);
|
{
|
||||||
request.Url.Parse(url);
|
if (Client == null || NeedNewClient)
|
||||||
request.KeepAlive = true;
|
{
|
||||||
request.Header.ContentType = "application/json";
|
NeedNewClient = false;
|
||||||
// Ignore any null objects when serializing and remove formatting
|
Client = new HttpClient();
|
||||||
string ignored = JsonConvert.SerializeObject(o, Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
|
}
|
||||||
Debug.Console(1, this, "Posting to '{0}':\n{1}", url, ignored);
|
Client.Verbose = false;
|
||||||
request.ContentString = ignored;
|
Client.KeepAlive = true;
|
||||||
request.FinalizeHeader();
|
|
||||||
Client.DispatchAsync(request, (r, err) => {
|
|
||||||
Debug.Console(1, this, "POST result: {0}", err);
|
|
||||||
|
|
||||||
if (err == HTTP_CALLBACK_ERROR.COMPLETED)
|
HttpClientRequest request = new HttpClientRequest();
|
||||||
|
request.RequestType = RequestType.Post;
|
||||||
|
string url = string.Format("http://{0}/api/system/{1}/status", Config.ServerUrl, SystemUuid);
|
||||||
|
request.Url.Parse(url);
|
||||||
|
request.KeepAlive = true;
|
||||||
|
request.Header.ContentType = "application/json";
|
||||||
|
// Ignore any null objects when serializing and remove formatting
|
||||||
|
string ignored = JsonConvert.SerializeObject(o, Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
|
||||||
|
Debug.Console(1, this, "Posting to '{0}':\n{1}", url, ignored);
|
||||||
|
request.ContentString = ignored;
|
||||||
|
request.FinalizeHeader();
|
||||||
|
Client.DispatchAsync(request, (r, err) =>
|
||||||
{
|
{
|
||||||
Debug.Console(1, this, "Status Response Code: {0}", r.Code);
|
Debug.Console(1, this, "POST result: {0}", err);
|
||||||
PostLockEvent.Set();
|
|
||||||
}
|
if (err == HTTP_CALLBACK_ERROR.COMPLETED)
|
||||||
else
|
{
|
||||||
{
|
Debug.Console(1, this, "Status Response Code: {0}", r.Code);
|
||||||
// Try again. This client is hosed.
|
PostLockEvent.Set();
|
||||||
NeedNewClient = true;
|
}
|
||||||
PostLockEvent.Set();
|
else
|
||||||
PostToServer(room, o);
|
{
|
||||||
}
|
// Try again. This client is hosed.
|
||||||
});
|
NeedNewClient = true;
|
||||||
}
|
PostLockEvent.Set();
|
||||||
catch(Exception e)
|
PostToServer(room, o);
|
||||||
{
|
}
|
||||||
Debug.Console(1, this, "Error Posting to Server: {0}", e);
|
});
|
||||||
PostLockEvent.Set();
|
}
|
||||||
}
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Debug.Console(1, this, "Error Posting to Server: {0}", e);
|
||||||
|
PostLockEvent.Set();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -406,13 +415,11 @@ namespace PepperDash.Essentials
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
void SSEClient_LineReceived(object sender, GenericCommMethodReceiveTextArgs e)
|
void SSEClient_LineReceived(object sender, GenericCommMethodReceiveTextArgs e)
|
||||||
{
|
{
|
||||||
//Debug.Console(1, this, "Received from Server: '{0}'", e.Text);
|
|
||||||
|
|
||||||
if(e.Text.IndexOf("data:") > -1)
|
if(e.Text.IndexOf("data:") > -1)
|
||||||
{
|
{
|
||||||
var message = e.Text.Substring(6);
|
var message = e.Text.Substring(6);
|
||||||
|
|
||||||
Debug.Console(1, this, "Message: '{0}'", message);
|
Debug.Console(1, this, "Message RX: '{0}'", message);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user