private async Task ColorAsync(TimeSpan dueTime, TimeSpan interval, CancellationToken token) { if (interval.TotalMilliseconds == 0) { return; } Stopwatch ColorTH = new Stopwatch(); ColorTH.Start(); // Initial wait time before we begin the periodic loop. if (dueTime > TimeSpan.Zero) { await Task.Delay(dueTime, token); } DateTime LocalTimestamp = Timestamp; WSRColor color = new WSRColor(); // Repeat this loop until cancelled. while (!token.IsCancellationRequested) { // Skip already work with given data if (Timestamp == LocalTimestamp) { await Task.Delay(interval, token); continue; } // Timestamp data LocalTimestamp = Timestamp; ColorWatch.Again(); // Do Job try { CopyColorData = true; var rgb = color.GetMostProminentColor(ColorData); if (RGB == null || rgb.r > 50 && rgb.g > 50 && rgb.b > 50) { RGB = rgb; } if (WSRConfig.GetInstance().ColorTH.Milliseconds > 0 && ColorTH.Elapsed > WSRConfig.GetInstance().ColorTH) { WSRHttpManager.GetInstance().SendRequest("http://127.0.01:8080/sarah/hue?r=" + RGB.r + "&g=" + RGB.g + "&b=" + RGB.b); ColorTH.Restart(); } } catch (Exception ex) { WSRConfig.GetInstance().logError("COLOR", ex); } ColorWatch.Stop(); // Wait to repeat again. if (interval > TimeSpan.Zero) { await Task.Delay(interval, token); } } }
// ========================================== // VIRTUAL // ========================================== public virtual void HandleRequest(String url, String path) { if (null != path) { WSRHttpManager.GetInstance().SendUpoad(url, path); } else { WSRHttpManager.GetInstance().SendRequest(url); } }
// Perform cleanup on application exit public virtual void Dispose() { // Stop RTP Client DisposeRTPClient(); // Stop HttpServer WSRHttpManager.GetInstance().Dispose(); // Stop Speech Manager WSRSpeechManager.GetInstance().Dispose(); // Stop Speaker WSRSpeakerManager.GetInstance().Dispose(); }
// ------------------------------------------ // CONSTRUCTOR // ------------------------------------------ private WSRProfileManager() { var path = @"profile\profile.json"; if (!File.Exists(path)) { return; } var json = File.ReadAllText(path, Encoding.UTF8); Profiles = JsonConvert.DeserializeObject <List <WSRProfile> >(json); WSRConfig.GetInstance().logInfo("PROFILE", json); WSRHttpManager.GetInstance().SendPost("http://127.0.0.1:8080/profiles", "profiles", json); }
// ========================================== // CONSTRUCTOR // ========================================== public virtual void Init() { // Start RTP Client StartRTPClient(); // Start HttpServer WSRHttpManager.GetInstance().StartHttpServer(); // Start Speech Manager WSRSpeechManager.GetInstance().Init(); InitSpeechEngine(); // Start Speaker Manager WSRSpeakerManager.GetInstance(); // Start Timeout RestartTimeout(); }
private async Task GestureAsync(TimeSpan dueTime, TimeSpan interval, CancellationToken token) { if (interval.TotalMilliseconds == 0) { return; } Stopwatch GestureTH = new Stopwatch(); GestureTH.Start(); // Initial wait time before we begin the periodic loop. if (dueTime > TimeSpan.Zero) { await Task.Delay(dueTime, token); } DateTime LocalTimestamp = Timestamp; if (null == GestureManager) { GestureManager = new GestureManager(this); GestureManager.Load(); } // Repeat this loop until cancelled. while (!token.IsCancellationRequested) { // Skip already work with given data if (Timestamp == LocalTimestamp) { await Task.Delay(interval, token); continue; } if (WSRConfig.GetInstance().StandByGesture) { await Task.Delay(interval, token); continue; } // Timestamp data LocalTimestamp = Timestamp; GestureWatch.Again(); // Do Job try { CopySkeletons = true; Gesture gesture = GestureManager.CheckGestures(Skeletons); if (null != gesture && GestureTH.Elapsed > WSRConfig.GetInstance().GestureTH) { WSRHttpManager.GetInstance().SendRequest(gesture.Url); GestureTH.Restart(); } } catch (Exception ex) { WSRConfig.GetInstance().logError("GESTURE", ex); } GestureWatch.Stop(); // Wait to repeat again. if (interval > TimeSpan.Zero) { await Task.Delay(interval, token); } } }
private async Task QRCodeAsync(TimeSpan dueTime, TimeSpan interval, CancellationToken token) { if (interval.TotalMilliseconds == 0) { return; } Stopwatch QRCodeTH = new Stopwatch(); QRCodeTH.Start(); // Initial wait time before we begin the periodic loop. if (dueTime > TimeSpan.Zero) { await Task.Delay(dueTime, token); } DateTime LocalTimestamp = Timestamp; QRCodeMatcher matcher = new QRCodeMatcher(ColorW, ColorH); // Repeat this loop until cancelled. while (!token.IsCancellationRequested) { // Skip already work with given data if (Timestamp == LocalTimestamp) { await Task.Delay(interval, token); continue; } // Skip if skeleton Tracking if (null != GestureManager && null != GestureManager.Skeleton) { await Task.Delay(interval, token); continue; } // Timestamp data LocalTimestamp = Timestamp; QRCodeWatch.Again(); // Do Job try { CopyColorData = true; String match = matcher.CheckQRCode(ColorData); if (match != null && QRCodeTH.Elapsed > WSRConfig.GetInstance().QRCodeTH) { WSRConfig.GetInstance().logInfo("QRCODE", "Match: " + match); WSRHttpManager.GetInstance().SendRequest(match); QRCodeTH.Restart(); } } catch (Exception ex) { WSRConfig.GetInstance().logError("QRCODE", ex); } QRCodeWatch.Stop(); // Wait to repeat again. await Task.Delay(interval, token); } }
private async Task MotionAsync(TimeSpan dueTime, TimeSpan interval, CancellationToken token) { if (interval.TotalMilliseconds == 0) { return; } // Initial wait time before we begin the periodic loop. if (dueTime > TimeSpan.Zero) { await Task.Delay(dueTime, token); } DateTime LocalTimestamp = Timestamp; short[] depth1 = new short[DepthData.Length]; Array.Copy(DepthData, depth1, depth1.Length); Stopwatch StandByWatch = new Stopwatch(); // Repeat this loop until cancelled. while (!token.IsCancellationRequested) { // Skip already work with given data // if (Timestamp == LocalTimestamp) { // await Task.Delay(interval, token); // continue; // } // Timestamp data // LocalTimestamp = Timestamp; MotionWatch.Again(); // Do Job var tmp = StandBy; try { Motion = DepthManager.CompareDepth(depth1, DepthData); Array.Copy(DepthData, depth1, depth1.Length); // Backup if (Motion > WSRConfig.GetInstance().MotionTH) { StandByWatch.Restart(); StandBy = false; } else if (StandByWatch.Elapsed > WSRConfig.GetInstance().StandBy) { StandByWatch.Stop(); StandBy = true; } if (tmp != StandBy) { WSRHttpManager.GetInstance().SendRequest("http://127.0.0.1:8080/standby?motion=" + !StandBy); } } catch (Exception ex) { WSRConfig.GetInstance().logError("MOTION", ex); } MotionWatch.Stop(); // Wait to repeat again. await Task.Delay(interval, token); } }