/*********************************************************************
 *
 *  $Id: svn_id $
 *
 *  Implements YDisplayProxy, the Proxy API for Display
 *
 *  - - - - - - - - - License information: - - - - - - - - -
 *
 *  Copyright (C) 2011 and beyond by Yoctopuce Sarl, Switzerland.
 *
 *  Yoctopuce Sarl (hereafter Licensor) grants to you a perpetual
 *  non-exclusive license to use, modify, copy and integrate this
 *  file into your software for the sole purpose of interfacing
 *  with Yoctopuce products.
 *
 *  You may reproduce and distribute copies of this file in
 *  source or object form, as long as the sole purpose of this
 *  code is to interface with Yoctopuce products. You must retain
 *  this notice in the distributed source file.
 *
 *  You should refer to Yoctopuce General Terms and Conditions
 *  for additional information regarding your rights and
 *  obligations.
 *
 *  THE SOFTWARE AND DOCUMENTATION ARE PROVIDED 'AS IS' WITHOUT
 *  WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
 *  WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS
 *  FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO
 *  EVENT SHALL LICENSOR BE LIABLE FOR ANY INCIDENTAL, SPECIAL,
 *  INDIRECT OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA,
 *  COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR
 *  SERVICES, ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT
 *  LIMITED TO ANY DEFENSE THEREOF), ANY CLAIMS FOR INDEMNITY OR
 *  CONTRIBUTION, OR OTHER SIMILAR COSTS, WHETHER ASSERTED ON THE
 *  BASIS OF CONTRACT, TORT (INCLUDING NEGLIGENCE), BREACH OF
 *  WARRANTY, OR OTHERWISE.
 *
 *********************************************************************/


using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Timers;
using System.Globalization;
using System.Text.RegularExpressions;
using YoctoLib;

namespace YoctoProxyAPI
{
    //--- (YDisplay class start)
    static public partial class YoctoProxyManager
    {
        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;
        }
    }

/**
 * <summary>
 *   The <c>YDisplay</c> class allows to drive Yoctopuce displays.
 * <para>
 *   Yoctopuce display interface has been designed to easily
 *   show information and images. The device provides built-in
 *   multi-layer rendering. Layers can be drawn offline, individually,
 *   and freely moved on the display. It can also replay recorded
 *   sequences (animations).
 * </para>
 * <para>
 *   In order to draw on the screen, you should use the
 *   <c>display.get_displayLayer</c> method to retrieve the layer(s) on
 *   which you want to draw, and then use methods defined in
 *   <c>YDisplayLayer</c> to draw on the layers.
 * </para>
 * <para>
 * </para>
 * </summary>
 */
    public class YDisplayProxy : YFunctionProxy
    {
        /**
         * <summary>
         *   Retrieves a display for a given identifier.
         * <para>
         *   The identifier can be specified using several formats:
         * </para>
         * <para>
         * </para>
         * <para>
         *   - FunctionLogicalName
         * </para>
         * <para>
         *   - ModuleSerialNumber.FunctionIdentifier
         * </para>
         * <para>
         *   - ModuleSerialNumber.FunctionLogicalName
         * </para>
         * <para>
         *   - ModuleLogicalName.FunctionIdentifier
         * </para>
         * <para>
         *   - ModuleLogicalName.FunctionLogicalName
         * </para>
         * <para>
         * </para>
         * <para>
         *   This function does not require that the display is online at the time
         *   it is invoked. The returned object is nevertheless valid.
         *   Use the method <c>YDisplay.isOnline()</c> to test if the display is
         *   indeed online at a given time. In case of ambiguity when looking for
         *   a display by logical name, no error is notified: the first instance
         *   found is returned. The search is performed first by hardware name,
         *   then by logical name.
         * </para>
         * <para>
         *   If a call to this object's is_online() method returns FALSE although
         *   you are certain that the matching device is plugged, make sure that you did
         *   call registerHub() at application initialization time.
         * </para>
         * <para>
         * </para>
         * </summary>
         * <param name="func">
         *   a string that uniquely characterizes the display, for instance
         *   <c>YD128X32.display</c>.
         * </param>
         * <returns>
         *   a <c>YDisplay</c> object allowing you to drive the display.
         * </returns>
         */
        public static YDisplayProxy FindDisplay(string func)
        {
            return YoctoProxyManager.FindDisplay(func);
        }
        //--- (end of YDisplay class start)
        //--- (YDisplay definitions)
        public const int _Enabled_INVALID = 0;
        public const int _Enabled_FALSE = 1;
        public const int _Enabled_TRUE = 2;
        public const string _StartupSeq_INVALID = YAPI.INVALID_STRING;
        public const int _Brightness_INVALID = -1;
        public const int _AutoInvertDelay_INVALID = -1;
        public const int _Orientation_INVALID = 0;
        public const int _Orientation_LEFT = 1;
        public const int _Orientation_UP = 2;
        public const int _Orientation_RIGHT = 3;
        public const int _Orientation_DOWN = 4;
        public const string _DisplayPanel_INVALID = YAPI.INVALID_STRING;
        public const int _DisplayWidth_INVALID = -1;
        public const int _DisplayHeight_INVALID = -1;
        public const int _DisplayType_INVALID = 0;
        public const int _DisplayType_MONO = 1;
        public const int _DisplayType_EPAPER_BW = 2;
        public const int _DisplayType_EPAPER_BWR = 3;
        public const int _DisplayType_EPAPER_BWRY = 4;
        public const int _LayerWidth_INVALID = -1;
        public const int _LayerHeight_INVALID = -1;
        public const int _LayerCount_INVALID = -1;
        public const string _Command_INVALID = YAPI.INVALID_STRING;
        public const int _FASTREFRESH_INVALID = 0;
        public const int _FASTREFRESH_WHENEVER_POSSIBLE = 1;
        public const int _FASTREFRESH_WHENEVER_SUPPORTED = 2;
        public const int _FASTREFRESH_NEVER = 3;

        private int _FASTREFRESH2Int(YDisplay.FASTREFRESH realenum)
        {
            switch (realenum) {
                case YDisplay.FASTREFRESH.WHENEVER_POSSIBLE:
                    return _FASTREFRESH_WHENEVER_POSSIBLE;
                case YDisplay.FASTREFRESH.WHENEVER_SUPPORTED:
                    return _FASTREFRESH_WHENEVER_SUPPORTED;
                case YDisplay.FASTREFRESH.NEVER:
                    return _FASTREFRESH_NEVER;
                case YDisplay.FASTREFRESH.INVALID:
                default:
                    return _FASTREFRESH_INVALID;
            }
        }

        private YDisplay.FASTREFRESH _Int2FASTREFRESH(int value)
        {
            switch (value) {
                case _FASTREFRESH_WHENEVER_POSSIBLE:
                    return YDisplay.FASTREFRESH.WHENEVER_POSSIBLE;
                case _FASTREFRESH_WHENEVER_SUPPORTED:
                    return YDisplay.FASTREFRESH.WHENEVER_SUPPORTED;
                case _FASTREFRESH_NEVER:
                    return YDisplay.FASTREFRESH.NEVER;
                case _FASTREFRESH_INVALID:
                default:
                    return YDisplay.FASTREFRESH.INVALID;
            }
        }
        public const int _REGENERATE_INVALID = 0;
        public const int _REGENERATE_ON_REQUEST_ONLY = 1;
        public const int _REGENERATE_EVERY_DAY = 2;
        public const int _REGENERATE_EVERY_12H = 3;
        public const int _REGENERATE_EVERY_6H = 4;
        public const int _REGENERATE_EVERY_3H = 5;
        public const int _REGENERATE_EVERY_2H = 6;
        public const int _REGENERATE_EVERY_HOUR = 7;
        public const int _REGENERATE_EVERY_30MIN = 8;
        public const int _REGENERATE_EVERY_15MIN = 9;
        public const int _REGENERATE_EVERY_480 = 10;
        public const int _REGENERATE_EVERY_432 = 11;
        public const int _REGENERATE_EVERY_360 = 12;
        public const int _REGENERATE_EVERY_288 = 13;
        public const int _REGENERATE_EVERY_240 = 14;
        public const int _REGENERATE_EVERY_192 = 15;
        public const int _REGENERATE_EVERY_144 = 16;
        public const int _REGENERATE_EVERY_96 = 17;
        public const int _REGENERATE_EVERY_48 = 18;
        public const int _REGENERATE_EVERY_36 = 19;
        public const int _REGENERATE_EVERY_24 = 20;
        public const int _REGENERATE_EVERY_12 = 21;
        public const int _REGENERATE_EVERY_10 = 22;
        public const int _REGENERATE_EVERY_8 = 23;
        public const int _REGENERATE_EVERY_6 = 24;
        public const int _REGENERATE_EVERY_4 = 25;
        public const int _REGENERATE_ALWAYS = 26;

        private int _REGENERATE2Int(YDisplay.REGENERATE realenum)
        {
            switch (realenum) {
                case YDisplay.REGENERATE.ON_REQUEST_ONLY:
                    return _REGENERATE_ON_REQUEST_ONLY;
                case YDisplay.REGENERATE.EVERY_DAY:
                    return _REGENERATE_EVERY_DAY;
                case YDisplay.REGENERATE.EVERY_12H:
                    return _REGENERATE_EVERY_12H;
                case YDisplay.REGENERATE.EVERY_6H:
                    return _REGENERATE_EVERY_6H;
                case YDisplay.REGENERATE.EVERY_3H:
                    return _REGENERATE_EVERY_3H;
                case YDisplay.REGENERATE.EVERY_2H:
                    return _REGENERATE_EVERY_2H;
                case YDisplay.REGENERATE.EVERY_HOUR:
                    return _REGENERATE_EVERY_HOUR;
                case YDisplay.REGENERATE.EVERY_30MIN:
                    return _REGENERATE_EVERY_30MIN;
                case YDisplay.REGENERATE.EVERY_15MIN:
                    return _REGENERATE_EVERY_15MIN;
                case YDisplay.REGENERATE.EVERY_480:
                    return _REGENERATE_EVERY_480;
                case YDisplay.REGENERATE.EVERY_432:
                    return _REGENERATE_EVERY_432;
                case YDisplay.REGENERATE.EVERY_360:
                    return _REGENERATE_EVERY_360;
                case YDisplay.REGENERATE.EVERY_288:
                    return _REGENERATE_EVERY_288;
                case YDisplay.REGENERATE.EVERY_240:
                    return _REGENERATE_EVERY_240;
                case YDisplay.REGENERATE.EVERY_192:
                    return _REGENERATE_EVERY_192;
                case YDisplay.REGENERATE.EVERY_144:
                    return _REGENERATE_EVERY_144;
                case YDisplay.REGENERATE.EVERY_96:
                    return _REGENERATE_EVERY_96;
                case YDisplay.REGENERATE.EVERY_48:
                    return _REGENERATE_EVERY_48;
                case YDisplay.REGENERATE.EVERY_36:
                    return _REGENERATE_EVERY_36;
                case YDisplay.REGENERATE.EVERY_24:
                    return _REGENERATE_EVERY_24;
                case YDisplay.REGENERATE.EVERY_12:
                    return _REGENERATE_EVERY_12;
                case YDisplay.REGENERATE.EVERY_10:
                    return _REGENERATE_EVERY_10;
                case YDisplay.REGENERATE.EVERY_8:
                    return _REGENERATE_EVERY_8;
                case YDisplay.REGENERATE.EVERY_6:
                    return _REGENERATE_EVERY_6;
                case YDisplay.REGENERATE.EVERY_4:
                    return _REGENERATE_EVERY_4;
                case YDisplay.REGENERATE.ALWAYS:
                    return _REGENERATE_ALWAYS;
                case YDisplay.REGENERATE.INVALID:
                default:
                    return _REGENERATE_INVALID;
            }
        }

        private YDisplay.REGENERATE _Int2REGENERATE(int value)
        {
            switch (value) {
                case _REGENERATE_ON_REQUEST_ONLY:
                    return YDisplay.REGENERATE.ON_REQUEST_ONLY;
                case _REGENERATE_EVERY_DAY:
                    return YDisplay.REGENERATE.EVERY_DAY;
                case _REGENERATE_EVERY_12H:
                    return YDisplay.REGENERATE.EVERY_12H;
                case _REGENERATE_EVERY_6H:
                    return YDisplay.REGENERATE.EVERY_6H;
                case _REGENERATE_EVERY_3H:
                    return YDisplay.REGENERATE.EVERY_3H;
                case _REGENERATE_EVERY_2H:
                    return YDisplay.REGENERATE.EVERY_2H;
                case _REGENERATE_EVERY_HOUR:
                    return YDisplay.REGENERATE.EVERY_HOUR;
                case _REGENERATE_EVERY_30MIN:
                    return YDisplay.REGENERATE.EVERY_30MIN;
                case _REGENERATE_EVERY_15MIN:
                    return YDisplay.REGENERATE.EVERY_15MIN;
                case _REGENERATE_EVERY_480:
                    return YDisplay.REGENERATE.EVERY_480;
                case _REGENERATE_EVERY_432:
                    return YDisplay.REGENERATE.EVERY_432;
                case _REGENERATE_EVERY_360:
                    return YDisplay.REGENERATE.EVERY_360;
                case _REGENERATE_EVERY_288:
                    return YDisplay.REGENERATE.EVERY_288;
                case _REGENERATE_EVERY_240:
                    return YDisplay.REGENERATE.EVERY_240;
                case _REGENERATE_EVERY_192:
                    return YDisplay.REGENERATE.EVERY_192;
                case _REGENERATE_EVERY_144:
                    return YDisplay.REGENERATE.EVERY_144;
                case _REGENERATE_EVERY_96:
                    return YDisplay.REGENERATE.EVERY_96;
                case _REGENERATE_EVERY_48:
                    return YDisplay.REGENERATE.EVERY_48;
                case _REGENERATE_EVERY_36:
                    return YDisplay.REGENERATE.EVERY_36;
                case _REGENERATE_EVERY_24:
                    return YDisplay.REGENERATE.EVERY_24;
                case _REGENERATE_EVERY_12:
                    return YDisplay.REGENERATE.EVERY_12;
                case _REGENERATE_EVERY_10:
                    return YDisplay.REGENERATE.EVERY_10;
                case _REGENERATE_EVERY_8:
                    return YDisplay.REGENERATE.EVERY_8;
                case _REGENERATE_EVERY_6:
                    return YDisplay.REGENERATE.EVERY_6;
                case _REGENERATE_EVERY_4:
                    return YDisplay.REGENERATE.EVERY_4;
                case _REGENERATE_ALWAYS:
                    return YDisplay.REGENERATE.ALWAYS;
                case _REGENERATE_INVALID:
                default:
                    return YDisplay.REGENERATE.INVALID;
            }
        }
        public const int _DISPLAYSTATE_INVALID = 0;
        public const int _DISPLAYSTATE_FAILURE = 1;
        public const int _DISPLAYSTATE_OFF = 2;
        public const int _DISPLAYSTATE_POWERING = 3;
        public const int _DISPLAYSTATE_IDLE = 4;
        public const int _DISPLAYSTATE_REFRESHING = 5;

        private int _DISPLAYSTATE2Int(YDisplay.DISPLAYSTATE realenum)
        {
            switch (realenum) {
                case YDisplay.DISPLAYSTATE.FAILURE:
                    return _DISPLAYSTATE_FAILURE;
                case YDisplay.DISPLAYSTATE.OFF:
                    return _DISPLAYSTATE_OFF;
                case YDisplay.DISPLAYSTATE.POWERING:
                    return _DISPLAYSTATE_POWERING;
                case YDisplay.DISPLAYSTATE.IDLE:
                    return _DISPLAYSTATE_IDLE;
                case YDisplay.DISPLAYSTATE.REFRESHING:
                    return _DISPLAYSTATE_REFRESHING;
                case YDisplay.DISPLAYSTATE.INVALID:
                default:
                    return _DISPLAYSTATE_INVALID;
            }
        }

        private YDisplay.DISPLAYSTATE _Int2DISPLAYSTATE(int value)
        {
            switch (value) {
                case _DISPLAYSTATE_FAILURE:
                    return YDisplay.DISPLAYSTATE.FAILURE;
                case _DISPLAYSTATE_OFF:
                    return YDisplay.DISPLAYSTATE.OFF;
                case _DISPLAYSTATE_POWERING:
                    return YDisplay.DISPLAYSTATE.POWERING;
                case _DISPLAYSTATE_IDLE:
                    return YDisplay.DISPLAYSTATE.IDLE;
                case _DISPLAYSTATE_REFRESHING:
                    return YDisplay.DISPLAYSTATE.REFRESHING;
                case _DISPLAYSTATE_INVALID:
                default:
                    return YDisplay.DISPLAYSTATE.INVALID;
            }
        }

        // reference to real YoctoAPI object
        protected new YDisplay _func;
        // property cache
        protected string _startupSeq = _StartupSeq_INVALID;
        protected int _brightness = _Brightness_INVALID;
        protected int _autoInvertDelay = _AutoInvertDelay_INVALID;
        protected int _orientation = _Orientation_INVALID;
        protected string _displayPanel = _DisplayPanel_INVALID;
        protected int _displayWidth = _DisplayWidth_INVALID;
        protected int _displayHeight = _DisplayHeight_INVALID;
        protected int _displayType = _DisplayType_INVALID;
        protected int _layerWidth = _LayerWidth_INVALID;
        protected int _layerHeight = _LayerHeight_INVALID;
        protected int _layerCount = _LayerCount_INVALID;
        //--- (end of YDisplay definitions)

        //--- (YDisplay implementation)
        internal YDisplayProxy(YDisplay hwd, string instantiationName) : base(hwd, instantiationName)
        {
            InternalStuff.log("Display " + instantiationName + " instantiation");
            base_init(hwd, instantiationName);
        }

        // perform the initial setup that may be done without a YoctoAPI object (hwd can be null)
        internal override void base_init(YFunction hwd, string instantiationName)
        {
            _func = (YDisplay) hwd;
           	base.base_init(hwd, instantiationName);
        }

        // link the instance to a real YoctoAPI object
        internal override void linkToHardware(string hwdName)
        {
            YDisplay hwd = YDisplay.FindDisplay(hwdName);
            // first redo base_init to update all _func pointers
            base_init(hwd, hwdName);
            // then setup Yocto-API pointers and callbacks
            init(hwd);
        }

        // perform the 2nd stage setup that requires YoctoAPI object
        protected void init(YDisplay hwd)
        {
            if (hwd == null) return;
            base.init(hwd);
            InternalStuff.log("registering Display callback");
            _func.registerValueCallback(valueChangeCallback);
        }

        /**
         * <summary>
         *   Enumerates all functions of type Display available on the devices
         *   currently reachable by the library, and returns their unique hardware ID.
         * <para>
         *   Each of these IDs can be provided as argument to the method
         *   <c>YDisplay.FindDisplay</c> to obtain an object that can control the
         *   corresponding device.
         * </para>
         * </summary>
         * <returns>
         *   an array of strings, each string containing the unique hardwareId
         *   of a device function currently connected.
         * </returns>
         */
        public static new string[] GetSimilarFunctions()
        {
            List<string> res = new List<string>();
            YDisplay it = YDisplay.FirstDisplay();
            while (it != null)
            {
                res.Add(it.get_hardwareId());
                it = it.nextDisplay();
            }
            return res.ToArray();
        }

        protected override void functionArrival()
        {
            base.functionArrival();
            _displayWidth = _func.get_displayWidth();
            _displayHeight = _func.get_displayHeight();
            _displayType = _func.get_displayType()+1;
            _layerWidth = _func.get_layerWidth();
            _layerHeight = _func.get_layerHeight();
            _layerCount = _func.get_layerCount();
        }

        protected override void moduleConfigHasChanged()
       	{
            base.moduleConfigHasChanged();
            _startupSeq = _func.get_startupSeq();
            _brightness = _func.get_brightness();
            _autoInvertDelay = _func.get_autoInvertDelay();
            _orientation = _func.get_orientation()+1;
            _displayPanel = _func.get_displayPanel();
        }

        /**
         * <summary>
         *   Returns true if the screen is powered, false otherwise.
         * <para>
         * </para>
         * <para>
         * </para>
         * </summary>
         * <returns>
         *   either <c>YDisplay.ENABLED_FALSE</c> or <c>YDisplay.ENABLED_TRUE</c>, according to true if the
         *   screen is powered, false otherwise
         * </returns>
         * <para>
         *   On failure, throws an exception or returns <c>YDisplay.ENABLED_INVALID</c>.
         * </para>
         */
        public int get_enabled()
        {
            if (_func == null) {
                throw new YoctoApiProxyException("No Display connected");
            }
            // our enums start at 0 instead of the 'usual' -1 for invalid
            return _func.get_enabled()+1;
        }

        /**
         * <summary>
         *   Changes the power state of the display.
         * <para>
         * </para>
         * <para>
         * </para>
         * </summary>
         * <param name="newval">
         *   either <c>YDisplay.ENABLED_FALSE</c> or <c>YDisplay.ENABLED_TRUE</c>, according to the power state
         *   of the display
         * </param>
         * <para>
         * </para>
         * <returns>
         *   <c>0</c> if the call succeeds.
         * </returns>
         * <para>
         *   On failure, throws an exception or returns a negative error code.
         * </para>
         */
        public int set_enabled(int newval)
        {
            if (_func == null) {
                throw new YoctoApiProxyException("No Display connected");
            }
            if (newval == _Enabled_INVALID) {
                return YAPI.SUCCESS;
            }
            // our enums start at 0 instead of the 'usual' -1 for invalid
            return _func.set_enabled(newval-1);
        }

        /**
         * <summary>
         *   Returns the name of the sequence to play when the displayed is powered on.
         * <para>
         * </para>
         * <para>
         * </para>
         * </summary>
         * <returns>
         *   a string corresponding to the name of the sequence to play when the displayed is powered on
         * </returns>
         * <para>
         *   On failure, throws an exception or returns <c>YDisplay.STARTUPSEQ_INVALID</c>.
         * </para>
         */
        public string get_startupSeq()
        {
            if (_func == null) {
                throw new YoctoApiProxyException("No Display connected");
            }
            return _func.get_startupSeq();
        }

        /**
         * <summary>
         *   Changes the name of the sequence to play when the display is powered on.
         * <para>
         *   Remember to call the <c>saveToFlash()</c> method of the module if the
         *   modification must be kept.
         * </para>
         * <para>
         * </para>
         * </summary>
         * <param name="newval">
         *   a string corresponding to the name of the sequence to play when the display is powered on
         * </param>
         * <para>
         * </para>
         * <returns>
         *   <c>0</c> if the call succeeds.
         * </returns>
         * <para>
         *   On failure, throws an exception or returns a negative error code.
         * </para>
         */
        public int set_startupSeq(string newval)
        {
            if (_func == null) {
                throw new YoctoApiProxyException("No Display connected");
            }
            if (newval == _StartupSeq_INVALID) {
                return YAPI.SUCCESS;
            }
            return _func.set_startupSeq(newval);
        }

        // property with cached value for instant access (configuration)
        /// <value>Name of the sequence to play when the displayed is powered on.</value>
        public string StartupSeq
        {
            get
            {
                if (_func == null) {
                    return _StartupSeq_INVALID;
                }
                if (_online) {
                    return _startupSeq;
                }
                return _StartupSeq_INVALID;
            }
            set
            {
                setprop_startupSeq(value);
            }
        }

        // private helper for magic property
        private void setprop_startupSeq(string newval)
        {
            if (_func == null) {
                return;
            }
            if (!(_online)) {
                return;
            }
            if (newval == _StartupSeq_INVALID) {
                return;
            }
            if (newval == _startupSeq) {
                return;
            }
            _func.set_startupSeq(newval);
            _startupSeq = newval;
        }

        /**
         * <summary>
         *   Returns the luminosity of the  module informative LEDs (from 0 to 100).
         * <para>
         * </para>
         * <para>
         * </para>
         * </summary>
         * <returns>
         *   an integer corresponding to the luminosity of the  module informative LEDs (from 0 to 100)
         * </returns>
         * <para>
         *   On failure, throws an exception or returns <c>YDisplay.BRIGHTNESS_INVALID</c>.
         * </para>
         */
        public int get_brightness()
        {
            int res;
            if (_func == null) {
                throw new YoctoApiProxyException("No Display connected");
            }
            res = _func.get_brightness();
            if (res == YAPI.INVALID_INT) {
                res = _Brightness_INVALID;
            }
            return res;
        }

        /**
         * <summary>
         *   Changes the brightness of the display.
         * <para>
         *   The parameter is a value between 0 and
         *   100. Remember to call the <c>saveToFlash()</c> method of the module if the
         *   modification must be kept.
         * </para>
         * <para>
         * </para>
         * </summary>
         * <param name="newval">
         *   an integer corresponding to the brightness of the display
         * </param>
         * <para>
         * </para>
         * <returns>
         *   <c>0</c> if the call succeeds.
         * </returns>
         * <para>
         *   On failure, throws an exception or returns a negative error code.
         * </para>
         */
        public int set_brightness(int newval)
        {
            if (_func == null) {
                throw new YoctoApiProxyException("No Display connected");
            }
            if (newval == _Brightness_INVALID) {
                return YAPI.SUCCESS;
            }
            return _func.set_brightness(newval);
        }

        // property with cached value for instant access (configuration)
        /// <value>Luminosity of the  module informative LEDs (from 0 to 100).</value>
        public int Brightness
        {
            get
            {
                if (_func == null) {
                    return _Brightness_INVALID;
                }
                if (_online) {
                    return _brightness;
                }
                return _Brightness_INVALID;
            }
            set
            {
                setprop_brightness(value);
            }
        }

        // private helper for magic property
        private void setprop_brightness(int newval)
        {
            if (_func == null) {
                return;
            }
            if (!(_online)) {
                return;
            }
            if (newval == _Brightness_INVALID) {
                return;
            }
            if (newval == _brightness) {
                return;
            }
            _func.set_brightness(newval);
            _brightness = newval;
        }

        /**
         * <summary>
         *   Returns the interval between automatic display inversions, or 0 if automatic
         *   inversion is disabled.
         * <para>
         *   Using the automatic inversion mechanism reduces the
         *   burn-in that occurs on OLED screens over long periods when the same content
         *   remains displayed on the screen.
         * </para>
         * <para>
         * </para>
         * </summary>
         * <returns>
         *   an integer corresponding to the interval between automatic display inversions, or 0 if automatic
         *   inversion is disabled
         * </returns>
         * <para>
         *   On failure, throws an exception or returns <c>YDisplay.AUTOINVERTDELAY_INVALID</c>.
         * </para>
         */
        public int get_autoInvertDelay()
        {
            int res;
            if (_func == null) {
                throw new YoctoApiProxyException("No Display connected");
            }
            res = _func.get_autoInvertDelay();
            if (res == YAPI.INVALID_INT) {
                res = _AutoInvertDelay_INVALID;
            }
            return res;
        }

        /**
         * <summary>
         *   Changes the interval between automatic display inversions.
         * <para>
         *   The parameter is the number of seconds, or 0 to disable automatic inversion.
         *   Using the automatic inversion mechanism reduces the burn-in that occurs on OLED
         *   screens over long periods when the same content remains displayed on the screen.
         *   Remember to call the <c>saveToFlash()</c> method of the module if the
         *   modification must be kept.
         * </para>
         * <para>
         * </para>
         * </summary>
         * <param name="newval">
         *   an integer corresponding to the interval between automatic display inversions
         * </param>
         * <para>
         * </para>
         * <returns>
         *   <c>0</c> if the call succeeds.
         * </returns>
         * <para>
         *   On failure, throws an exception or returns a negative error code.
         * </para>
         */
        public int set_autoInvertDelay(int newval)
        {
            if (_func == null) {
                throw new YoctoApiProxyException("No Display connected");
            }
            if (newval == _AutoInvertDelay_INVALID) {
                return YAPI.SUCCESS;
            }
            return _func.set_autoInvertDelay(newval);
        }

        // property with cached value for instant access (configuration)
        /// <value>Interval between automatic display inversions, or 0 if automatic</value>
        public int AutoInvertDelay
        {
            get
            {
                if (_func == null) {
                    return _AutoInvertDelay_INVALID;
                }
                if (_online) {
                    return _autoInvertDelay;
                }
                return _AutoInvertDelay_INVALID;
            }
            set
            {
                setprop_autoInvertDelay(value);
            }
        }

        // private helper for magic property
        private void setprop_autoInvertDelay(int newval)
        {
            if (_func == null) {
                return;
            }
            if (!(_online)) {
                return;
            }
            if (newval == _AutoInvertDelay_INVALID) {
                return;
            }
            if (newval == _autoInvertDelay) {
                return;
            }
            _func.set_autoInvertDelay(newval);
            _autoInvertDelay = newval;
        }

        /**
         * <summary>
         *   Returns the currently selected display orientation.
         * <para>
         *   The orientation is defined as the side of the screen where the
         *   USB connector (for OLED displays) or the ribbon cable (for ePaper panels) is located when the
         *   display is up straight.
         * </para>
         * <para>
         * </para>
         * </summary>
         * <returns>
         *   a value among <c>YDisplay.ORIENTATION_LEFT</c>, <c>YDisplay.ORIENTATION_UP</c>,
         *   <c>YDisplay.ORIENTATION_RIGHT</c> and <c>YDisplay.ORIENTATION_DOWN</c> corresponding to the
         *   currently selected display orientation
         * </returns>
         * <para>
         *   On failure, throws an exception or returns <c>YDisplay.ORIENTATION_INVALID</c>.
         * </para>
         */
        public int get_orientation()
        {
            if (_func == null) {
                throw new YoctoApiProxyException("No Display connected");
            }
            // our enums start at 0 instead of the 'usual' -1 for invalid
            return _func.get_orientation()+1;
        }

        /**
         * <summary>
         *   Changes the display orientation.
         * <para>
         *   he orientation is defined as the side of the screen where the
         *   USB connector (for OLED displays) or the ribbon cable (for ePaper panels) is located when the
         *   display is up straight. Remember to call the <c>saveToFlash()</c>
         *   method of the module if the modification must be kept.
         * </para>
         * <para>
         * </para>
         * </summary>
         * <param name="newval">
         *   a value among <c>YDisplay.ORIENTATION_LEFT</c>, <c>YDisplay.ORIENTATION_UP</c>,
         *   <c>YDisplay.ORIENTATION_RIGHT</c> and <c>YDisplay.ORIENTATION_DOWN</c> corresponding to the display orientation
         * </param>
         * <para>
         * </para>
         * <returns>
         *   <c>0</c> if the call succeeds.
         * </returns>
         * <para>
         *   On failure, throws an exception or returns a negative error code.
         * </para>
         */
        public int set_orientation(int newval)
        {
            if (_func == null) {
                throw new YoctoApiProxyException("No Display connected");
            }
            if (newval == _Orientation_INVALID) {
                return YAPI.SUCCESS;
            }
            // our enums start at 0 instead of the 'usual' -1 for invalid
            return _func.set_orientation(newval-1);
        }

        // property with cached value for instant access (configuration)
        /// <value>Currently selected display orientation. The orientation is defined as the side of the screen where the</value>
        public int Orientation
        {
            get
            {
                if (_func == null) {
                    return _Orientation_INVALID;
                }
                if (_online) {
                    return _orientation;
                }
                return _Orientation_INVALID;
            }
            set
            {
                setprop_orientation(value);
            }
        }

        // private helper for magic property
        private void setprop_orientation(int newval)
        {
            if (_func == null) {
                return;
            }
            if (!(_online)) {
                return;
            }
            if (newval == _Orientation_INVALID) {
                return;
            }
            if (newval == _orientation) {
                return;
            }
            // our enums start at 0 instead of the 'usual' -1 for invalid
            _func.set_orientation(newval-1);
            _orientation = newval;
        }

        /**
         * <summary>
         *   Returns the exact model of the display panel.
         * <para>
         * </para>
         * <para>
         * </para>
         * </summary>
         * <returns>
         *   a string corresponding to the exact model of the display panel
         * </returns>
         * <para>
         *   On failure, throws an exception or returns <c>YDisplay.DISPLAYPANEL_INVALID</c>.
         * </para>
         */
        public string get_displayPanel()
        {
            if (_func == null) {
                throw new YoctoApiProxyException("No Display connected");
            }
            return _func.get_displayPanel();
        }

        /**
         * <summary>
         *   Changes the model of display to match the connected display panel.
         * <para>
         *   This function has no effect if the module does not support the selected
         *   display panel. Remember to call the <c>saveToFlash()</c>
         *   method of the module if the modification must be kept.
         * </para>
         * <para>
         * </para>
         * </summary>
         * <param name="newval">
         *   a string corresponding to the model of display to match the connected display panel
         * </param>
         * <para>
         * </para>
         * <returns>
         *   <c>0</c> if the call succeeds.
         * </returns>
         * <para>
         *   On failure, throws an exception or returns a negative error code.
         * </para>
         */
        public int set_displayPanel(string newval)
        {
            if (_func == null) {
                throw new YoctoApiProxyException("No Display connected");
            }
            if (newval == _DisplayPanel_INVALID) {
                return YAPI.SUCCESS;
            }
            return _func.set_displayPanel(newval);
        }

        // property with cached value for instant access (configuration)
        /// <value>Exact model of the display panel.</value>
        public string DisplayPanel
        {
            get
            {
                if (_func == null) {
                    return _DisplayPanel_INVALID;
                }
                if (_online) {
                    return _displayPanel;
                }
                return _DisplayPanel_INVALID;
            }
            set
            {
                setprop_displayPanel(value);
            }
        }

        // private helper for magic property
        private void setprop_displayPanel(string newval)
        {
            if (_func == null) {
                return;
            }
            if (!(_online)) {
                return;
            }
            if (newval == _DisplayPanel_INVALID) {
                return;
            }
            if (newval == _displayPanel) {
                return;
            }
            _func.set_displayPanel(newval);
            _displayPanel = newval;
        }

        /**
         * <summary>
         *   Returns the display width, in pixels.
         * <para>
         * </para>
         * <para>
         * </para>
         * </summary>
         * <returns>
         *   an integer corresponding to the display width, in pixels
         * </returns>
         * <para>
         *   On failure, throws an exception or returns <c>YDisplay.DISPLAYWIDTH_INVALID</c>.
         * </para>
         */
        public int get_displayWidth()
        {
            int res;
            if (_func == null) {
                throw new YoctoApiProxyException("No Display connected");
            }
            res = _func.get_displayWidth();
            if (res == YAPI.INVALID_INT) {
                res = _DisplayWidth_INVALID;
            }
            return res;
        }

        // property with cached value for instant access (constant value)
        /// <value>Display width, in pixels.</value>
        public int DisplayWidth
        {
            get
            {
                if (_func == null) {
                    return _DisplayWidth_INVALID;
                }
                if (_online) {
                    return _displayWidth;
                }
                return _DisplayWidth_INVALID;
            }
        }

        /**
         * <summary>
         *   Returns the display height, in pixels.
         * <para>
         * </para>
         * <para>
         * </para>
         * </summary>
         * <returns>
         *   an integer corresponding to the display height, in pixels
         * </returns>
         * <para>
         *   On failure, throws an exception or returns <c>YDisplay.DISPLAYHEIGHT_INVALID</c>.
         * </para>
         */
        public int get_displayHeight()
        {
            int res;
            if (_func == null) {
                throw new YoctoApiProxyException("No Display connected");
            }
            res = _func.get_displayHeight();
            if (res == YAPI.INVALID_INT) {
                res = _DisplayHeight_INVALID;
            }
            return res;
        }

        // property with cached value for instant access (constant value)
        /// <value>Display height, in pixels.</value>
        public int DisplayHeight
        {
            get
            {
                if (_func == null) {
                    return _DisplayHeight_INVALID;
                }
                if (_online) {
                    return _displayHeight;
                }
                return _DisplayHeight_INVALID;
            }
        }

        /**
         * <summary>
         *   Returns the display type: monochrome OLED, black and white ePaper, color ePaper, and so on.
         * <para>
         * </para>
         * <para>
         * </para>
         * </summary>
         * <returns>
         *   a value among <c>YDisplay.DISPLAYTYPE_MONO</c>, <c>YDisplay.DISPLAYTYPE_EPAPER_BW</c>,
         *   <c>YDisplay.DISPLAYTYPE_EPAPER_BWR</c> and <c>YDisplay.DISPLAYTYPE_EPAPER_BWRY</c> corresponding to
         *   the display type: monochrome OLED, black and white ePaper, color ePaper, and so on
         * </returns>
         * <para>
         *   On failure, throws an exception or returns <c>YDisplay.DISPLAYTYPE_INVALID</c>.
         * </para>
         */
        public int get_displayType()
        {
            if (_func == null) {
                throw new YoctoApiProxyException("No Display connected");
            }
            // our enums start at 0 instead of the 'usual' -1 for invalid
            return _func.get_displayType()+1;
        }

        // property with cached value for instant access (constant value)
        /// <value>Display type: monochrome OLED, black and white ePaper, color ePaper, and so on.</value>
        public int DisplayType
        {
            get
            {
                if (_func == null) {
                    return _DisplayType_INVALID;
                }
                if (_online) {
                    return _displayType;
                }
                return _DisplayType_INVALID;
            }
        }

        /**
         * <summary>
         *   Returns the width of the layers to draw on, in pixels.
         * <para>
         * </para>
         * <para>
         * </para>
         * </summary>
         * <returns>
         *   an integer corresponding to the width of the layers to draw on, in pixels
         * </returns>
         * <para>
         *   On failure, throws an exception or returns <c>YDisplay.LAYERWIDTH_INVALID</c>.
         * </para>
         */
        public int get_layerWidth()
        {
            int res;
            if (_func == null) {
                throw new YoctoApiProxyException("No Display connected");
            }
            res = _func.get_layerWidth();
            if (res == YAPI.INVALID_INT) {
                res = _LayerWidth_INVALID;
            }
            return res;
        }

        // property with cached value for instant access (constant value)
        /// <value>Width of the layers to draw on, in pixels.</value>
        public int LayerWidth
        {
            get
            {
                if (_func == null) {
                    return _LayerWidth_INVALID;
                }
                if (_online) {
                    return _layerWidth;
                }
                return _LayerWidth_INVALID;
            }
        }

        /**
         * <summary>
         *   Returns the height of the layers to draw on, in pixels.
         * <para>
         * </para>
         * <para>
         * </para>
         * </summary>
         * <returns>
         *   an integer corresponding to the height of the layers to draw on, in pixels
         * </returns>
         * <para>
         *   On failure, throws an exception or returns <c>YDisplay.LAYERHEIGHT_INVALID</c>.
         * </para>
         */
        public int get_layerHeight()
        {
            int res;
            if (_func == null) {
                throw new YoctoApiProxyException("No Display connected");
            }
            res = _func.get_layerHeight();
            if (res == YAPI.INVALID_INT) {
                res = _LayerHeight_INVALID;
            }
            return res;
        }

        // property with cached value for instant access (constant value)
        /// <value>Height of the layers to draw on, in pixels.</value>
        public int LayerHeight
        {
            get
            {
                if (_func == null) {
                    return _LayerHeight_INVALID;
                }
                if (_online) {
                    return _layerHeight;
                }
                return _LayerHeight_INVALID;
            }
        }

        /**
         * <summary>
         *   Returns the number of available layers to draw on.
         * <para>
         * </para>
         * <para>
         * </para>
         * </summary>
         * <returns>
         *   an integer corresponding to the number of available layers to draw on
         * </returns>
         * <para>
         *   On failure, throws an exception or returns <c>YDisplay.LAYERCOUNT_INVALID</c>.
         * </para>
         */
        public int get_layerCount()
        {
            int res;
            if (_func == null) {
                throw new YoctoApiProxyException("No Display connected");
            }
            res = _func.get_layerCount();
            if (res == YAPI.INVALID_INT) {
                res = _LayerCount_INVALID;
            }
            return res;
        }

        // property with cached value for instant access (constant value)
        /// <value>Number of available layers to draw on.</value>
        public int LayerCount
        {
            get
            {
                if (_func == null) {
                    return _LayerCount_INVALID;
                }
                if (_online) {
                    return _layerCount;
                }
                return _LayerCount_INVALID;
            }
        }

        /**
         * <summary>
         *   Returns the fast refresh usage policy in use (ePaper displays only).
         * <para>
         *   This setting is combined with the regenerate policy to determine when the screen
         *   should be updated using a fast update versus or regenerated using a slower,
         *   flickering full refresh.
         * </para>
         * <para>
         * </para>
         * </summary>
         * <returns>
         *   a value among the <c>YDisplay.FASTREFRESH</c> enumeration
         *   (<c>YDisplay.FASTREFRESH_WHENEVER_POSSIBLE</c>,
         *   <c>YDisplay.FASTREFRESH_WHENEVER_SUPPORTED</c>,
         *   <c>YDisplay.FASTREFRESH_NEVER</c>).
         * </returns>
         * <para>
         *   On failure, throws an exception or returns <c>YDisplay.FASTREFRESH_INVALID</c>.
         * </para>
         */
        public virtual int get_fastRefreshPolicy()
        {
            if (_func == null) {
                throw new YoctoApiProxyException("No Display connected");
            }
            return _FASTREFRESH2Int(_func.get_fastRefreshPolicy());
        }

        /**
         * <summary>
         *   Returns the display regeneration minimal frequency (ePaper displays only).
         * <para>
         *   This setting is combined with the fast refresh usage policy to determine
         *   when the screen should be updated using a fast update versus or regenerated
         *   using a slower, flickering full refresh. To change the display regeneration minimal
         *   frequency, use methode <c>set_fastRefreshPolicy()</c>.
         * </para>
         * <para>
         * </para>
         * </summary>
         * <returns>
         *   a value among the <c>YDisplay.REGENERATE</c> enumeration
         *   (<c>YDisplay.REGENERATE_ON_REQUEST_ONLY</c>,
         *   <c>YDisplay.REGENERATE_EVERY_DAY</c>, <c>YDisplay.REGENERATE_EVERY_12H</c>,
         *   <c>YDisplay.REGENERATE_EVERY_6H</c>, <c>YDisplay.REGENERATE_EVERY_3H</c>,
         *   <c>YDisplay.REGENERATE_EVERY_2H</c>, <c>YDisplay.REGENERATE_EVERY_HOUR</c>,
         *   <c>YDisplay.REGENERATE_EVERY_30MIN</c>, <c>YDisplay.REGENERATE_EVERY_15MIN</c>,
         *   <c>YDisplay.REGENERATE_EVERY_480</c>, <c>YDisplay.REGENERATE_EVERY_432</c>,
         *   <c>YDisplay.REGENERATE_EVERY_360</c>, <c>YDisplay.REGENERATE_EVERY_288</c>,
         *   <c>YDisplay.REGENERATE_EVERY_240</c>, <c>YDisplay.REGENERATE_EVERY_192</c>,
         *   <c>YDisplay.REGENERATE_EVERY_144</c>, <c>YDisplay.REGENERATE_EVERY_96</c>,
         *   <c>YDisplay.REGENERATE_EVERY_48</c>, <c>YDisplay.REGENERATE_EVERY_36</c>,
         *   <c>YDisplay.REGENERATE_EVERY_24</c>, <c>YDisplay.REGENERATE_EVERY_12</c>,
         *   <c>YDisplay.REGENERATE_EVERY_10</c>, <c>YDisplay.REGENERATE_EVERY_8</c>,
         *   <c>YDisplay.REGENERATE_EVERY_6</c>, <c>YDisplay.REGENERATE_EVERY_4</c>,
         *   <c>YDisplay.REGENERATE_ALWAYS</c>).
         * </returns>
         * <para>
         *   On failure, throws an exception or returns <c>YDisplay.REGENERATE_INVALID</c>.
         * </para>
         */
        public virtual int get_regeneratePolicy()
        {
            if (_func == null) {
                throw new YoctoApiProxyException("No Display connected");
            }
            return _REGENERATE2Int(_func.get_regeneratePolicy());
        }

        /**
         * <summary>
         *   Changes the fast refresh usage policy and display regeneration minimal frequency
         *   (ePaper displays only).
         * <para>
         *   These settings jointly determine when the screen should be
         *   updated using a fast update versus or regenerated using a slower, flickering full
         *   refresh.
         * </para>
         * <para>
         * </para>
         * </summary>
         * <param name="fastRefresh">
         *   a value among the <c>YDisplay.FASTREFRESH</c> enumeration
         *   (<c>YDisplay.FASTREFRESH_WHENEVER_POSSIBLE</c>,
         *   <c>YDisplay.FASTREFRESH_WHENEVER_SUPPORTED</c>,
         *   <c>YDisplay.FASTREFRESH_NEVER</c>),
         *   corresponding to the policy for using fast refresh.
         * </param>
         * <param name="regenerate">
         *   a value among the enumeration <c>YRefFrame.REGENERATE</c>
         *   (<c>YDisplay.REGENERATE_ON_REQUEST_ONLY</c>,
         *   <c>YDisplay.REGENERATE_EVERY_DAY</c>, <c>YDisplay.REGENERATE_EVERY_12H</c>,
         *   <c>YDisplay.REGENERATE_EVERY_6H</c>, <c>YDisplay.REGENERATE_EVERY_3H</c>,
         *   <c>YDisplay.REGENERATE_EVERY_2H</c>, <c>YDisplay.REGENERATE_EVERY_HOUR</c>,
         *   <c>YDisplay.REGENERATE_EVERY_30MIN</c>, <c>YDisplay.REGENERATE_EVERY_15MIN</c>,
         *   <c>YDisplay.REGENERATE_EVERY_480</c>, <c>YDisplay.REGENERATE_EVERY_432</c>,
         *   <c>YDisplay.REGENERATE_EVERY_360</c>, <c>YDisplay.REGENERATE_EVERY_288</c>,
         *   <c>YDisplay.REGENERATE_EVERY_240</c>, <c>YDisplay.REGENERATE_EVERY_192</c>,
         *   <c>YDisplay.REGENERATE_EVERY_144</c>, <c>YDisplay.REGENERATE_EVERY_96</c>,
         *   <c>YDisplay.REGENERATE_EVERY_48</c>, <c>YDisplay.REGENERATE_EVERY_36</c>,
         *   <c>YDisplay.REGENERATE_EVERY_24</c>, <c>YDisplay.REGENERATE_EVERY_12</c>,
         *   <c>YDisplay.REGENERATE_EVERY_10</c>, <c>YDisplay.REGENERATE_EVERY_8</c>,
         *   <c>YDisplay.REGENERATE_EVERY_6</c>, <c>YDisplay.REGENERATE_EVERY_4</c>,
         *   <c>YDisplay.REGENERATE_ALWAYS</c>),
         *   corresponding to the display minimal regeneration frequency.
         * </param>
         * <para>
         *   Remember to call the <c>saveToFlash()</c>
         *   method of the module if the modification must be kept.
         * </para>
         * <para>
         *   On failure, throws an exception or returns a negative error code.
         * </para>
         */
        public virtual int set_fastRefreshPolicy(int fastRefresh, int regenerate)
        {
            if (_func == null) {
                throw new YoctoApiProxyException("No Display connected");
            }
            return _func.set_fastRefreshPolicy(_Int2FASTREFRESH(fastRefresh), _Int2REGENERATE(regenerate));
        }

        /**
         * <summary>
         *   Clears the display screen and resets all display layers to their default state.
         * <para>
         *   Using this function in a sequence will kill the sequence play-back. Do not use that
         *   function to reset the display at sequence start-up.
         * </para>
         * <para>
         * </para>
         * </summary>
         * <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 resetAll()
        {
            if (_func == null) {
                throw new YoctoApiProxyException("No Display connected");
            }
            return _func.resetAll();
        }

        /**
         * <summary>
         *   Forces an ePaper screen to perform a regenerative update using the slow
         *   update method.
         * <para>
         *   Periodic use of the slow method (total panel update with
         *   multiple inversions) prevents ghosting effects and improves contrast.
         * </para>
         * <para>
         * </para>
         * </summary>
         * <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 regenerateDisplay()
        {
            if (_func == null) {
                throw new YoctoApiProxyException("No Display connected");
            }
            return _func.regenerateDisplay();
        }

        /**
         * <summary>
         *   Returns the current state of an ePaper display, specifically to
         *   determine whether an update is in progress or whether a
         *   configuration issue has been detected.
         * <para>
         *   If a display configuration
         *   error has been detected, the error message can be retrieved.
         * </para>
         * <para>
         * </para>
         * </summary>
         * <returns>
         *   a value among the enumeration <c>YDisplay.DISPLAYSTATE</c>
         *   (<c>YDisplay.DISPLAYSTATE_FAILURE</c>, <c>YDisplay.DISPLAYSTATE_OFF</c>,
         *   <c>YDisplay.DISPLAYSTATE_POWERING</c>, <c>YDisplay.DISPLAYSTATE_IDLE</c>,
         *   <c>YDisplay.DISPLAYSTATE_REFRESHING</c>)
         *   corresponding to the current display state.
         * </returns>
         */
        public virtual int get_ePaperState(ref string errmsg)
        {
            if (_func == null) {
                throw new YoctoApiProxyException("No Display connected");
            }
            return _DISPLAYSTATE2Int(_func.get_ePaperState(ref errmsg));
        }

        /**
         * <summary>
         *   Disables screen refresh for a short period of time.
         * <para>
         *   The combination of
         *   <c>postponeRefresh</c> and <c>triggerRefresh</c> can be used as an
         *   alternative to double-buffering to avoid flickering during display updates.
         * </para>
         * </summary>
         * <param name="duration">
         *   duration of deactivation in milliseconds (max. 30 seconds)
         * </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 postponeRefresh(int duration)
        {
            if (_func == null) {
                throw new YoctoApiProxyException("No Display connected");
            }
            return _func.postponeRefresh(duration);
        }

        /**
         * <summary>
         *   Triggers an immediate screen refresh.
         * <para>
         *   The combination of
         *   <c>postponeRefresh</c> and <c>triggerRefresh</c> can be used as an
         *   alternative to double-buffering to avoid flickering during display updates.
         * </para>
         * </summary>
         * <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 triggerRefresh()
        {
            if (_func == null) {
                throw new YoctoApiProxyException("No Display connected");
            }
            return _func.triggerRefresh();
        }

        /**
         * <summary>
         *   Smoothly changes the brightness of the screen to produce a fade-in or fade-out
         *   effect.
         * <para>
         * </para>
         * </summary>
         * <param name="brightness">
         *   the new screen brightness
         * </param>
         * <param name="duration">
         *   duration of the brightness transition, in milliseconds.
         * </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 fade(int brightness, int duration)
        {
            if (_func == null) {
                throw new YoctoApiProxyException("No Display connected");
            }
            return _func.fade(brightness, duration);
        }

        /**
         * <summary>
         *   Starts to record all display commands into a sequence, for later replay.
         * <para>
         *   The name used to store the sequence is specified when calling
         *   <c>saveSequence()</c>, once the recording is complete.
         * </para>
         * </summary>
         * <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 newSequence()
        {
            if (_func == null) {
                throw new YoctoApiProxyException("No Display connected");
            }
            return _func.newSequence();
        }

        /**
         * <summary>
         *   Stops recording display commands and saves the sequence into the specified
         *   file on the display internal memory.
         * <para>
         *   The sequence can be later replayed
         *   using <c>playSequence()</c>.
         * </para>
         * </summary>
         * <param name="sequenceName">
         *   the name of the newly created sequence
         * </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 saveSequence(string sequenceName)
        {
            if (_func == null) {
                throw new YoctoApiProxyException("No Display connected");
            }
            return _func.saveSequence(sequenceName);
        }

        /**
         * <summary>
         *   Replays a display sequence previously recorded using
         *   <c>newSequence()</c> and <c>saveSequence()</c>.
         * <para>
         * </para>
         * </summary>
         * <param name="sequenceName">
         *   the name of the newly created sequence
         * </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 playSequence(string sequenceName)
        {
            if (_func == null) {
                throw new YoctoApiProxyException("No Display connected");
            }
            return _func.playSequence(sequenceName);
        }

        /**
         * <summary>
         *   Waits for a specified delay (in milliseconds) before playing next
         *   commands in current sequence.
         * <para>
         *   This method can be used while
         *   recording a display sequence, to insert a timed wait in the sequence
         *   (without any immediate effect). It can also be used dynamically while
         *   playing a pre-recorded sequence, to suspend or resume the execution of
         *   the sequence. To cancel a delay, call the same method with a zero delay.
         * </para>
         * </summary>
         * <param name="delay_ms">
         *   the duration to wait, in milliseconds
         * </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 pauseSequence(int delay_ms)
        {
            if (_func == null) {
                throw new YoctoApiProxyException("No Display connected");
            }
            return _func.pauseSequence(delay_ms);
        }

        /**
         * <summary>
         *   Stops immediately any ongoing sequence replay.
         * <para>
         *   The display is left as is.
         * </para>
         * </summary>
         * <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 stopSequence()
        {
            if (_func == null) {
                throw new YoctoApiProxyException("No Display connected");
            }
            return _func.stopSequence();
        }

        /**
         * <summary>
         *   Uploads an arbitrary file (for instance a GIF file) to the display, to the
         *   specified full path name.
         * <para>
         *   If a file already exists with the same path name,
         *   its content is overwritten.
         * </para>
         * </summary>
         * <param name="pathname">
         *   path and name of the new file to create
         * </param>
         * <param name="content">
         *   binary buffer with the content to set
         * </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 upload(string pathname, byte[] content)
        {
            if (_func == null) {
                throw new YoctoApiProxyException("No Display connected");
            }
            return _func.upload(pathname, content);
        }

        /**
         * <summary>
         *   Copies the whole content of a layer to another layer.
         * <para>
         *   The color and transparency
         *   of all the pixels from the destination layer are set to match the source pixels.
         *   This method only affects the displayed content, but does not change any
         *   property of the layer object.
         *   Note that layer 0 has no transparency support (it is always completely opaque).
         * </para>
         * </summary>
         * <param name="srcLayerId">
         *   the identifier of the source layer (a number in range 0..layerCount-1)
         * </param>
         * <param name="dstLayerId">
         *   the identifier of the destination 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 copyLayerContent(int srcLayerId, int dstLayerId)
        {
            if (_func == null) {
                throw new YoctoApiProxyException("No Display connected");
            }
            return _func.copyLayerContent(srcLayerId, dstLayerId);
        }

        /**
         * <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);
        }

        /**
         * <summary>
         *   Returns a YDisplayLayer object that can be used to draw on the specified
         *   layer.
         * <para>
         *   The content is displayed only when the layer is active on the
         *   screen (and not masked by other overlapping layers).
         * </para>
         * </summary>
         * <param name="layerId">
         *   the identifier of the layer (a number in range 0..layerCount-1)
         * </param>
         * <returns>
         *   an <c>YDisplayLayer</c> object
         * </returns>
         * <para>
         *   On failure, throws an exception or returns <c>null</c>.
         * </para>
         */
        public virtual YDisplayLayerProxy get_displayLayer(int layerId)
        {
            if (_func == null) {
                throw new YoctoApiProxyException("No Display connected");
            }
            return new YDisplayLayerProxy(_func.get_displayLayer(layerId));
        }

        /**
         * <summary>
         *   Returns a color image with the current content of the display.
         * <para>
         *   The image is returned as a binary object, where each byte represents a pixel,
         *   from left to right and from top to bottom. The palette used to map byte
         *   values to RGB colors is filled into the list provided as argument.
         *   In all cases, the first palette entry (value 0) corresponds to the
         *   screen default background color.
         *   The image dimensions are given by the display width and height.
         * </para>
         * </summary>
         * <param name="palette">
         *   a list to be filled with the image palette
         * </param>
         * <returns>
         *   a binary object if the call succeeds.
         * </returns>
         * <para>
         *   On failure, throws an exception or returns an empty binary object.
         * </para>
         */
        public virtual byte[] readDisplay(int[] palette)
        {
            if (_func == null) {
                throw new YoctoApiProxyException("No Display connected");
            }
            return _func.readDisplay(new List<int>(palette));
        }
    }
    //--- (end of YDisplay implementation)
}

