private async Task UpdateDisplay(string value) { double dval = Convert.ToDouble(value); string txt = String.Format("{0:F2} {1}", dval, unit); CurVal.Text = txt; if (display != null) { long start = DateTime.Now.Ticks; try { await l0.clear(); await l0.drawText(w - 1, h / 2, YDisplayLayer.ALIGN.CENTER_RIGHT, txt); await display.swapLayerContent(0, 1); } catch (YAPI_Exception ex) { await FatalError(ex.Message); } long stop = DateTime.Now.Ticks; long delta = (stop - start) / 1000; if (delta > 50) { Debug.WriteLine("screen update took {0}ms", delta); } } }
/** * <summary> * Swaps the whole content of two layers. * <para> * The color and transparency of all the pixels from * the two layers are swapped. This method only affects the displayed content, but does * not change any property of the layer objects. In particular, the visibility of each * layer stays unchanged. When used between one hidden layer and a visible layer, * this method makes it possible to easily implement double-buffering. * Note that layer 0 has no transparency support (it is always completely opaque). * </para> * </summary> * <param name="layerIdA"> * the first layer (a number in range 0..layerCount-1) * </param> * <param name="layerIdB"> * the second layer (a number in range 0..layerCount-1) * </param> * <returns> * <c>0</c> if the call succeeds. * </returns> * <para> * On failure, throws an exception or returns a negative error code. * </para> */ public virtual int swapLayerContent(int layerIdA, int layerIdB) { if (_func == null) { throw new YoctoApiProxyException("No Display connected"); } return(_func.swapLayerContent(layerIdA, layerIdB)); }
static void Main(string[] args) { Console.WriteLine("Console dotNET Application 0.1.0"); Console.WriteLine("--------------------------------"); Console.WriteLine(""); Console.WriteLine("Using Yoctopuce lib " + YAPI.GetAPIVersion()); string errsmg = ""; if (YAPI.RegisterHub("usb", ref errsmg) != YAPI.SUCCESS) { Console.WriteLine("Unable to register the USB port :" + errsmg); return; } YSensor sensor = YSensor.FirstSensor(); if (sensor == null) { Console.WriteLine("No Yoctopuce sensor find on USB."); return; } YDisplay display = YDisplay.FirstDisplay(); if (display == null) { Console.WriteLine("No Yoctopuce display find on USB."); return; } // display clean up display.resetAll(); YDisplayLayer l1 = display.get_displayLayer(1); l1.hide(); // L1 is hidden, l2 stay visible int w = display.get_displayWidth(); int h = display.get_displayHeight(); while (sensor.isOnline() && display.isOnline()) { string value = sensor.get_currentValue() + " " + sensor.get_unit(); string name = sensor.get_friendlyName(); // display a text in the middle of the screen l1.clear(); l1.selectFont("Large.yfm"); l1.drawText(w / 2, h / 2, YDisplayLayer.ALIGN.CENTER, value); l1.selectFont("Small.yfm"); l1.drawText(w - 1, h - 1, YDisplayLayer.ALIGN.BOTTOM_RIGHT, name); display.swapLayerContent(0, 1); Console.WriteLine(name + " ->" + value); YAPI.Sleep(500, ref errsmg); } YAPI.FreeAPI(); }
public void RePaint() { _display.swapLayerContent(1, 2); }