public HamsterScreen(string hwid, bool useImperial) { if (hwid == "") { _display = YDisplay.FirstDisplay(); if (_display == null) { throw new Exception("No Yocto-Display connected"); } } else { _display = YDisplay.FindDisplay(hwid); if (!_display.isOnline()) { throw new Exception("No Yocto-Display named " + hwid + "found"); } } _useImperial = useImperial; _display.resetAll(); _w = _display.get_displayWidth(); _h = _display.get_displayHeight(); _fgLayer = _display.get_displayLayer(2); _bgLayer = _display.get_displayLayer(1); }
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 static YDisplayProxy FindDisplay(string name) { // cases to handle: // name ="" no matching unknwn // name ="" unknown exists // name != "" no matching unknown // name !="" unknown exists YDisplay func = null; YDisplayProxy res = (YDisplayProxy)YFunctionProxy.FindSimilarUnknownFunction("YDisplayProxy"); if (name == "") { if (res != null) { return(res); } res = (YDisplayProxy)YFunctionProxy.FindSimilarKnownFunction("YDisplayProxy"); if (res != null) { return(res); } func = YDisplay.FirstDisplay(); if (func != null) { name = func.get_hardwareId(); if (func.get_userData() != null) { return((YDisplayProxy)func.get_userData()); } } } else { func = YDisplay.FindDisplay(name); if (func.get_userData() != null) { return((YDisplayProxy)func.get_userData()); } } if (res == null) { res = new YDisplayProxy(func, name); } if (func != null) { res.linkToHardware(name); if (func.isOnline()) { res.arrival(); } } return(res); }
public bool isOnline() { return(_display.isOnline()); }