Exemplo n.º 1
0
        // link the instance to a real YoctoAPI object
        internal override void linkToHardware(string hwdName)
        {
            YPowerOutput hwd = YPowerOutput.FindPowerOutput(hwdName);

            // first redo base_init to update all _func pointers
            base_init(hwd, hwdName);
            // then setup Yocto-API pointers and callbacks
            init(hwd);
        }
Exemplo n.º 2
0
 // perform the 2nd stage setup that requires YoctoAPI object
 protected void init(YPowerOutput hwd)
 {
     if (hwd == null)
     {
         return;
     }
     base.init(hwd);
     InternalStuff.log("registering PowerOutput callback");
     _func.registerValueCallback(valueChangeCallback);
 }
    /**
     * <summary>
     *   Retrieves a dual power  ouput control 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 power ouput control is online at the time
     *   it is invoked. The returned object is nevertheless valid.
     *   Use the method <c>YPowerOutput.isOnline()</c> to test if the power ouput control is
     *   indeed online at a given time. In case of ambiguity when looking for
     *   a dual power  ouput control 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>
     * </summary>
     * <param name="func">
     *   a string that uniquely characterizes the power ouput control
     * </param>
     * <returns>
     *   a <c>YPowerOutput</c> object allowing you to drive the power ouput control.
     * </returns>
     */
    public static YPowerOutput FindPowerOutput(string func)
    {
        YPowerOutput obj;

        obj = (YPowerOutput)YFunction._FindFromCache("PowerOutput", func);
        if (obj == null)
        {
            obj = new YPowerOutput(func);
            YFunction._AddToCache("PowerOutput", func, obj);
        }
        return(obj);
    }
Exemplo n.º 4
0
        public static YPowerOutputProxy FindPowerOutput(string name)
        {
            // cases to handle:
            // name =""  no matching unknwn
            // name =""  unknown exists
            // name != "" no  matching unknown
            // name !="" unknown exists
            YPowerOutput      func = null;
            YPowerOutputProxy res  = (YPowerOutputProxy)YFunctionProxy.FindSimilarUnknownFunction("YPowerOutputProxy");

            if (name == "")
            {
                if (res != null)
                {
                    return(res);
                }
                res = (YPowerOutputProxy)YFunctionProxy.FindSimilarKnownFunction("YPowerOutputProxy");
                if (res != null)
                {
                    return(res);
                }
                func = YPowerOutput.FirstPowerOutput();
                if (func != null)
                {
                    name = func.get_hardwareId();
                    if (func.get_userData() != null)
                    {
                        return((YPowerOutputProxy)func.get_userData());
                    }
                }
            }
            else
            {
                func = YPowerOutput.FindPowerOutput(name);
                if (func.get_userData() != null)
                {
                    return((YPowerOutputProxy)func.get_userData());
                }
            }
            if (res == null)
            {
                res = new YPowerOutputProxy(func, name);
            }
            if (func != null)
            {
                res.linkToHardware(name);
                if (func.isOnline())
                {
                    res.arrival();
                }
            }
            return(res);
        }
Exemplo n.º 5
0
        /**
         * <summary>
         *   Enumerates all functions of type PowerOutput 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>YPowerOutput.FindPowerOutput</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>();
            YPowerOutput  it  = YPowerOutput.FirstPowerOutput();

            while (it != null)
            {
                res.Add(it.get_hardwareId());
                it = it.nextPowerOutput();
            }
            return(res.ToArray());
        }
        public override bool Setup()
        {
            spiPort = YSpiPort.FirstSpiPort();
            if (spiPort == null)
            {
                Console.WriteLine("No Yocto-Spi detected");
                return(false);
            }

            YModule      module       = spiPort.get_module();
            string       errmsg       = "";
            string       serialNumber = module.get_serialNumber();
            YPowerOutput powerOutput  = YPowerOutput.FindPowerOutput(serialNumber + ".powerOutput");

            powerOutput.set_voltage(YPowerOutput.VOLTAGE_OUT3V3);
            spiPort.set_voltageLevel(YSpiPort.VOLTAGELEVEL_TTL3V);
            spiPort.set_spiMode("2000000,0,msb");
            spiPort.set_protocol("Frame:1ms");
            spiPort.set_ssPolarity(YSpiPort.SSPOLARITY_ACTIVE_LOW);
            module.saveToFlash();
            YAPI.Sleep(25, ref errmsg);
            spiPort.writeHex(SET_MODE_4);
            YAPI.Sleep(5, ref errmsg);

            string[] commands = { READ_STATUS, READ_STATUS, READ_STATUS, READ_ID, SET_ANGLES };
            Frame[]  result;
            if (!SendAndReceive(commands, out result))
            {
                Console.WriteLine("Failed to initialize SCL3300 (communication error)");
                return(false);
            }
            if (!_chip_ready)
            {
                Console.WriteLine("SCL3300 startup failed (rs={4})", result[2].rs);
                return(false);
            }
            if ((result[3].data & 0xff) != 0xc1)
            {
                Console.WriteLine("Unexpected SCL3300 identification (WHOAMI={0})", (result[3].data & 0xff));
                return(false);
            }
            if (!DecodeStatus(result[2]))
            {
                Console.WriteLine("SCL3300 Status bad, chip reset is required");
                return(false);
            }
            Console.WriteLine("SCL3300 is ready");
            return(true);
        }
Exemplo n.º 7
0
 // 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 = (YPowerOutput)hwd;
     base.base_init(hwd, instantiationName);
 }
Exemplo n.º 8
0
        //--- (end of YPowerOutput definitions)

        //--- (YPowerOutput implementation)
        internal YPowerOutputProxy(YPowerOutput hwd, string instantiationName) : base(hwd, instantiationName)
        {
            InternalStuff.log("PowerOutput " + instantiationName + " instantiation");
            base_init(hwd, instantiationName);
        }
 /**
  * <summary>
  *   Retrieves a dual power  ouput control 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 power ouput control is online at the time
  *   it is invoked. The returned object is nevertheless valid.
  *   Use the method <c>YPowerOutput.isOnline()</c> to test if the power ouput control is
  *   indeed online at a given time. In case of ambiguity when looking for
  *   a dual power  ouput control 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>
  * </summary>
  * <param name="func">
  *   a string that uniquely characterizes the power ouput control
  * </param>
  * <returns>
  *   a <c>YPowerOutput</c> object allowing you to drive the power ouput control.
  * </returns>
  */
 public static YPowerOutput FindPowerOutput(string func)
 {
     YPowerOutput obj;
     obj = (YPowerOutput) YFunction._FindFromCache("PowerOutput", func);
     if (obj == null) {
         obj = new YPowerOutput(func);
         YFunction._AddToCache("PowerOutput", func, obj);
     }
     return obj;
 }