// Methods /// <summary> /// Get sensor /// </summary> /// <returns></returns> protected override YSensor GetSensor() { string errmsg = ""; if (hardwaredetect == 0) { YAPI.UpdateDeviceList(ref errmsg); } hardwaredetect = (hardwaredetect + 1) % 20; YAPI.HandleEvents(ref errmsg); YSensor sensor = YPressure.FirstPressure(); if (sensor is null) { throw new SensorNotDetectedException(); } else if (!sensor.isOnline()) { throw new SensorOfflineException(); } else { return(sensor); } }
private void timer1_Tick(object sender, EventArgs e) { string errmsg = ""; if (hardwaredetect == 0) { YAPI.UpdateDeviceList(ref errmsg); } hardwaredetect = (hardwaredetect + 1) % 20; YAPI.HandleEvents(ref errmsg); if (sensor == null) { sensor = YSensor.FirstSensor(); } if (sensor != null) { if (sensor.isOnline()) { label1.Text = sensor.get_friendlyName(); label2.Text = sensor.get_currentValue() + " " + sensor.get_unit(); } else { label1.Text = "OFFLINE"; label2.Text = "Sensor is offline"; sensor = null; } } }
async Task dispatcherTimer_Tick() { try { if (hardwaredetect == 0) { await YAPI.UpdateDeviceList(); } hardwaredetect = (hardwaredetect + 1) % 20; await YAPI.HandleEvents(); if (sensor == null) { sensor = YSensor.FirstSensor(); } if (sensor != null) { HwIdTextBox.Text = await sensor.get_friendlyName(); TempTextBox.Text = await sensor.get_currentValue() + await sensor.get_unit(); } } catch (YAPI_Exception ex) { HwIdTextBox.Text = "Sensor is offline"; TempTextBox.Text = "OFFLINE"; sensor = null; } }
private void timer1_Tick(object sender, EventArgs e) { string errmsg = ""; timer1.Stop(); // Handle device plug/unplug events YAPI.UpdateDeviceList(ref errmsg); YAPI.HandleEvents(ref errmsg); if (spiPort != null) { // Yocto-SPI connected, check if a card swipe message was received List <string> msgs = spiPort.readMessages("", 1); if (DEBUG) { for (int i = 0; i < msgs.Count; i++) { Log("Read: " + msgs[i]); } } if (msgs.Count > 0) { // Decode ABA Track 2 data from magnetic card string track2 = this.DecodeTrack2(msgs[0]); string firstChar = track2.Substring(0, 1); string lastChar = track2.Substring(track2.Length - 1); Log("Track 2: " + track2); if (firstChar == "!") { card_id.Text = "Error !"; card_exp.Text = ""; card_extra.Text = track2.Substring(2); } else if (firstChar == ";" && lastChar == "?") { int separator = track2.IndexOf("="); string ident = track2.Substring(1, separator - 1); for (int i = 4; i < ident.Length; i += 5) { ident = ident.Insert(i, " "); } card_id.Text = ident; card_exp.Text = track2.Substring(separator + 3, 2) + "/" + track2.Substring(separator + 1, 2); card_extra.Text = track2.Substring(separator + 8, track2.Length - separator - 9); } else { card_id.Text = "Error !"; card_exp.Text = ""; card_extra.Text = "Bad format, may be a reverse swipe ?"; } // Clear read buffer to catch next swipe spiPort.reset(); } } timer1.Start(); }
public static bool UpdateEvents() { String errorMessage = null; if (YAPI.HandleEvents(ref errorMessage) != YAPI.SUCCESS) { throw new Exception("Failed to handle events! " + errorMessage); } return(true); }
private void YoctoTimer_Tick(object sender, EventArgs e) { string errmsg = ""; if (YoctoTimerCounter == 0) { YAPI.UpdateDeviceList(ref errmsg); } YAPI.HandleEvents(ref errmsg); YoctoTimerCounter = (YoctoTimerCounter + 1) % 15; }
public async void Each_Tick(object sender, object o) { DispatcherTimer timer = (DispatcherTimer)sender; timer.Stop(); try { await YAPI.UpdateDeviceList(); await YAPI.HandleEvents(); } catch (YAPI_Exception ex) { Output.Text += "Error:" + ex.Message; throw; } timer.Start(); }
private void RefreshTimer_Tick(object sender, EventArgs e) { string errmsg = ""; YAPI.HandleEvents(ref errmsg); refreshUI(); ulong now = YAPI.GetTickCount(); if (now - eventTick >= 1000) { for (int i = 0; i < eventCount.Length; i++) { freq[i] = (int)Math.Round(eventCount[i] * 1000.0 / (now - eventTick)); eventCount[i] = 0; } eventTick = now; } }
async Task dispatcherTimer_Tick() { long start = DateTime.Now.Ticks; try { await YAPI.HandleEvents(); } catch (YAPI_Exception ex) { await FatalError(ex.Message); } long stop = DateTime.Now.Ticks; long delta = (stop - start) / 1000; if (delta > 50) { Debug.WriteLine("Long Timer handler :{0}ms", delta); } }
void EfficientApproach() { ulong tm_start = YAPI.GetTickCount(); string errmsg = ""; int res = YAPI.HandleEvents(ref errmsg); if (res != YAPI.SUCCESS) { errorText.text = errmsg; return; } ulong tm_stop = YAPI.GetTickCount(); Debug.Log(string.Format("Get values (r{0:f} p{1:f} took {2:d}ms", _x, _z, tm_stop - tm_start)); Vector3 movement = new Vector3((float)_x, 0.0f, (float)_z); rb.AddForce(movement * speed); }
public Form1() { InitializeComponent(); _t.Interval = 1000; _t.Enabled = true; _t.Tick += (sender, args) => { YAPI.HandleEvents(ref _err); }; YAPI.RegisterHub("USB", ref _err); YAPI.UpdateDeviceList(ref _err); var sensor = YSensor.FirstSensor(); sensor.registerTimedReportCallback(timedReport); _t.Start(); tbLux.Text = sensor.FriendlyName; }
// will cause Timed report to pop private void refreshTimer_Tick(object sender, EventArgs e) { string errmsg = ""; YAPI.HandleEvents(ref errmsg); }