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 DisplayFull(double currentspeed, double currentdistance, double currentduration, double maxspeed, double avgspeed, string speedUnit, string timeUnit, string distanceUnit) { if (_display.isOnline()) { _bgLayer.clear(); _bgLayer.selectGrayPen(0); _bgLayer.drawBar(0, 0, _w, _h); _bgLayer.selectGrayPen(255); _bgLayer.selectFont("Small.yfm"); _bgLayer.drawText(1, 1 * _h / 5, YDisplayLayer.ALIGN.CENTER_LEFT, String.Format("speed={0:0.0}{1}", currentspeed, speedUnit)); _bgLayer.drawText(1, 2 * _h / 5, YDisplayLayer.ALIGN.CENTER_LEFT, String.Format("(max={0:0.0}{2} avg={1:0.0}{2})", maxspeed, avgspeed, speedUnit)); _bgLayer.drawText(1, 3 * _h / 5, YDisplayLayer.ALIGN.CENTER_LEFT, String.Format("distance = {0:0.0}{1}", currentdistance, distanceUnit)); _bgLayer.drawText(1, 4 * _h / 5, YDisplayLayer.ALIGN.CENTER_LEFT, String.Format("Time = {0:0.0}{1}", currentduration, timeUnit)); RePaint(); } }
private async void onLoad(object sender, RoutedEventArgs e) { try { await YAPI.RegisterHub("usb"); sensor = YWeighScale.FirstWeighScale(); if (sensor == null) { await FatalError("No WeighScale connected"); } display = YDisplay.FirstDisplay(); if (display != null) { //clean up await display.resetAll(); // retreive the display size w = await display.get_displayWidth(); h = await display.get_displayHeight(); // reteive the first layer l0 = await display.get_displayLayer(0); l1 = await display.get_displayLayer(1); // display a text in the middle of the screen await l0.selectFont("Large.yfm"); } await sensor.set_excitation(YWeighScale.EXCITATION_AC); await YAPI.Sleep(3000); await sensor.tare(); unit = await sensor.get_unit(); await sensor.registerValueCallback(sensorValueChangeCallBack); } catch (YAPI_Exception ex) { await FatalError(ex.Message); } timer = new NonReentrantDispatcherTimer(); timer.Interval = new TimeSpan(0, 0, 0, 0, 100); timer.TickTask = async() => { await dispatcherTimer_Tick(); }; timer.Start(); }
/** * <summary> * Selects a font to use for the next text drawing functions, by providing the name of the * font file. * <para> * You can use a built-in font as well as a font file that you have previously * uploaded to the device built-in memory. If you experience problems selecting a font * file, check the device logs for any error message such as missing font file or bad font * file format. * </para> * </summary> * <param name="fontname"> * the font file name, embedded fonts are 8x8.yfm, Small.yfm, Medium.yfm, Large.yfm (not available on * Yocto-MiniDisplay). * </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 selectFont(string fontname) { return(_objptr.selectFont(fontname)); }