mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-01-31 13:25:00 +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)
|
||||
{
|
||||
_IsWarmingUp = true;
|
||||
IsWarmingUpFeedback.FireUpdate();
|
||||
IsWarmingUpFeedback.InvokeFireUpdate();
|
||||
// Fake power-up cycle
|
||||
WarmupTimer = new CTimer(o =>
|
||||
{
|
||||
_IsWarmingUp = false;
|
||||
_PowerIsOn = true;
|
||||
IsWarmingUpFeedback.FireUpdate();
|
||||
PowerIsOnFeedback.FireUpdate();
|
||||
IsWarmingUpFeedback.InvokeFireUpdate();
|
||||
PowerIsOnFeedback.InvokeFireUpdate();
|
||||
}, WarmupTime);
|
||||
}
|
||||
}
|
||||
@@ -84,14 +84,14 @@ namespace PepperDash.Essentials.Core
|
||||
{
|
||||
_IsCoolingDown = true;
|
||||
_PowerIsOn = false;
|
||||
PowerIsOnFeedback.FireUpdate();
|
||||
IsCoolingDownFeedback.FireUpdate();
|
||||
PowerIsOnFeedback.InvokeFireUpdate();
|
||||
IsCoolingDownFeedback.InvokeFireUpdate();
|
||||
// Fake cool-down cycle
|
||||
CooldownTimer = new CTimer(o =>
|
||||
{
|
||||
Debug.Console(2, this, "Cooldown timer ending");
|
||||
_IsCoolingDown = false;
|
||||
IsCoolingDownFeedback.FireUpdate();
|
||||
IsCoolingDownFeedback.InvokeFireUpdate();
|
||||
}, CooldownTime);
|
||||
}
|
||||
}
|
||||
@@ -117,20 +117,20 @@ namespace PepperDash.Essentials.Core
|
||||
|
||||
public void SetVolume(ushort level)
|
||||
{
|
||||
_FakeVolumeLevel = level;
|
||||
VolumeLevelFeedback.FireUpdate();
|
||||
_FakeVolumeLevel = level;
|
||||
VolumeLevelFeedback.InvokeFireUpdate();
|
||||
}
|
||||
|
||||
public void MuteOn()
|
||||
{
|
||||
_IsMuted = true;
|
||||
MuteFeedback.FireUpdate();
|
||||
MuteFeedback.InvokeFireUpdate();
|
||||
}
|
||||
|
||||
public void MuteOff()
|
||||
{
|
||||
_IsMuted = false;
|
||||
MuteFeedback.FireUpdate();
|
||||
MuteFeedback.InvokeFireUpdate();
|
||||
}
|
||||
|
||||
public BoolFeedback MuteFeedback { get; private set; }
|
||||
@@ -170,7 +170,7 @@ namespace PepperDash.Essentials.Core
|
||||
public void MuteToggle()
|
||||
{
|
||||
_IsMuted = !_IsMuted;
|
||||
MuteFeedback.FireUpdate();
|
||||
MuteFeedback.InvokeFireUpdate();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -28,8 +28,19 @@ namespace PepperDash.Essentials.Core
|
||||
Cue = cue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fires an update synchronously
|
||||
/// </summary>
|
||||
public abstract void FireUpdate();
|
||||
|
||||
/// <summary>
|
||||
/// Fires the update asynchronously within a CrestronInvoke
|
||||
/// </summary>
|
||||
public void InvokeFireUpdate()
|
||||
{
|
||||
CrestronInvoke.BeginInvoke(o => FireUpdate());
|
||||
}
|
||||
|
||||
protected void OnOutputChange()
|
||||
{
|
||||
if (OutputChange != null) OutputChange(this, EventArgs.Empty);
|
||||
|
||||
@@ -4,5 +4,5 @@
|
||||
[assembly: AssemblyCompany("PepperDash Technology Corp")]
|
||||
[assembly: AssemblyProduct("PepperDashEssentials")]
|
||||
[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 Crestron.SimplSharp;
|
||||
using Crestron.SimplSharp.CrestronIO;
|
||||
using Crestron.SimplSharpPro.CrestronThread;
|
||||
using Crestron.SimplSharpPro;
|
||||
using Crestron.SimplSharp.Net.Http;
|
||||
using Newtonsoft.Json;
|
||||
@@ -25,6 +26,8 @@ namespace PepperDash.Essentials
|
||||
/// </summary>
|
||||
CEvent PostLockEvent = new CEvent(true, true);
|
||||
|
||||
Thread SseWorkerThread;
|
||||
|
||||
CotijaConfig Config;
|
||||
|
||||
HttpClient Client;
|
||||
@@ -211,57 +214,63 @@ namespace PepperDash.Essentials
|
||||
/// <param name="o">object to be serialized and sent in post body</param>
|
||||
public void PostToServer(EssentialsRoomBase room, JObject o)
|
||||
{
|
||||
var ready = PostLockEvent.Wait(2000);
|
||||
if (!ready)
|
||||
CrestronInvoke.BeginInvoke(oo =>
|
||||
{
|
||||
Debug.Console(1, this, "PostToServer failed to enter after 2 seconds. Ignoring");
|
||||
return;
|
||||
}
|
||||
|
||||
PostLockEvent.Reset();
|
||||
try
|
||||
{
|
||||
if (Client == null || NeedNewClient)
|
||||
var ready = PostLockEvent.Wait(2000);
|
||||
if (!ready)
|
||||
{
|
||||
NeedNewClient = false;
|
||||
Client = new HttpClient();
|
||||
Debug.Console(1, this, "PostToServer failed to enter after 2 seconds. Ignoring");
|
||||
return;
|
||||
}
|
||||
Client.Verbose = false;
|
||||
Client.KeepAlive = true;
|
||||
|
||||
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, "POST result: {0}", err);
|
||||
PostLockEvent.Reset();
|
||||
try
|
||||
{
|
||||
if (Client == null || NeedNewClient)
|
||||
{
|
||||
NeedNewClient = false;
|
||||
Client = new HttpClient();
|
||||
}
|
||||
Client.Verbose = false;
|
||||
Client.KeepAlive = true;
|
||||
|
||||
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);
|
||||
PostLockEvent.Set();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Try again. This client is hosed.
|
||||
NeedNewClient = true;
|
||||
PostLockEvent.Set();
|
||||
PostToServer(room, o);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Debug.Console(1, this, "Error Posting to Server: {0}", e);
|
||||
PostLockEvent.Set();
|
||||
}
|
||||
Debug.Console(1, this, "POST result: {0}", err);
|
||||
|
||||
if (err == HTTP_CALLBACK_ERROR.COMPLETED)
|
||||
{
|
||||
Debug.Console(1, this, "Status Response Code: {0}", r.Code);
|
||||
PostLockEvent.Set();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Try again. This client is hosed.
|
||||
NeedNewClient = true;
|
||||
PostLockEvent.Set();
|
||||
PostToServer(room, o);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Console(1, this, "Error Posting to Server: {0}", e);
|
||||
PostLockEvent.Set();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -406,13 +415,11 @@ namespace PepperDash.Essentials
|
||||
/// <param name="e"></param>
|
||||
void SSEClient_LineReceived(object sender, GenericCommMethodReceiveTextArgs e)
|
||||
{
|
||||
//Debug.Console(1, this, "Received from Server: '{0}'", e.Text);
|
||||
|
||||
if(e.Text.IndexOf("data:") > -1)
|
||||
{
|
||||
var message = e.Text.Substring(6);
|
||||
|
||||
Debug.Console(1, this, "Message: '{0}'", message);
|
||||
Debug.Console(1, this, "Message RX: '{0}'", message);
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user