Beispiel #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);
        }
Beispiel #2
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);
        }
        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);
        }