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 DisplayError(string msg) { _bgLayer.reset(); _bgLayer.selectGrayPen(255); _bgLayer.drawBar(0, 0, _w, _h); _bgLayer.selectColorPen(0); _bgLayer.drawText(_w / 2, _h / 3, YDisplayLayer.ALIGN.CENTER, "ERROR !"); _bgLayer.drawText(_w / 2, _h * 2 / 3, YDisplayLayer.ALIGN.CENTER, msg); }
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> * Draws a text string at the specified position. * <para> * The point of the text that is aligned * to the specified pixel position is called the anchor point, and can be chosen among * several options. Text is rendered from left to right, without implicit wrapping. * </para> * </summary> * <param name="x"> * the distance from left of layer to the text anchor point, in pixels * </param> * <param name="y"> * the distance from top of layer to the text anchor point, in pixels * </param> * <param name="anchor"> * the text anchor point, chosen among the <c>YDisplayLayer.ALIGN</c> enumeration: * <c>YDisplayLayer.ALIGN_TOP_LEFT</c>, <c>YDisplayLayer.ALIGN_CENTER_LEFT</c>, * <c>YDisplayLayer.ALIGN_BASELINE_LEFT</c>, <c>YDisplayLayer.ALIGN_BOTTOM_LEFT</c>, * <c>YDisplayLayer.ALIGN_TOP_CENTER</c>, <c>YDisplayLayer.ALIGN_CENTER</c>, * <c>YDisplayLayer.ALIGN_BASELINE_CENTER</c>, <c>YDisplayLayer.ALIGN_BOTTOM_CENTER</c>, * <c>YDisplayLayer.ALIGN_TOP_DECIMAL</c>, <c>YDisplayLayer.ALIGN_CENTER_DECIMAL</c>, * <c>YDisplayLayer.ALIGN_BASELINE_DECIMAL</c>, <c>YDisplayLayer.ALIGN_BOTTOM_DECIMAL</c>, * <c>YDisplayLayer.ALIGN_TOP_RIGHT</c>, <c>YDisplayLayer.ALIGN_CENTER_RIGHT</c>, * <c>YDisplayLayer.ALIGN_BASELINE_RIGHT</c>, <c>YDisplayLayer.ALIGN_BOTTOM_RIGHT</c>. * </param> * <param name="text"> * the text string to draw * </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 drawText(int x, int y, int anchor, string text) { return(_objptr.drawText(x, y, _Int2ALIGN(anchor), text)); }