Пример #1
0
        static void LoadRLP()
        {
            // Make sure to enable and unlock RLP before use!
            RLP.Enable();

            // Unlock RLP
            RLP.Unlock(rlpUserId, rlpKey);

            // Load RLP driver
            elfImage = Resources.GetBytes(Resources.BinaryResources.PWMGenerator);
            if (elfImage == null)
            {
                throw new Exception("Failed to load ELF image");
            }

            RLP.LoadELF(elfImage);
            RLP.InitializeBSSRegion(elfImage);
        }
        public static void Main()
        {
            RLP.Enable();
            // Unlock RLP
            RLP.Unlock("[email protected]", new byte[] { 0x60, 0xEE, 0xDB, 0x53, 0x8A, 0x31, 0x71, 0x34, 0xAE, 0xB5, 0x6A, 0x4A, 0xA8, 0x54, 0x10, 0xA4, 0x67, 0x24, 0xFA, 0x0B, 0x8A, 0x4C, 0x8A, 0x78, 0x27, 0x1F, 0xBF, 0x59, 0xC3, 0x21, 0x54, 0x1A });
            Debug.EnableGCMessages(false);

            Debug.GC(true);
            byte[] elf_file = Resources.GetBytes(Resources.BinaryResources.RLP_test);
            RLP.LoadELF(elf_file);

            RLP.InitializeBSSRegion(elf_file);

            rlpInit  = RLP.GetProcedure(elf_file, "Init");
            rlpStop  = RLP.GetProcedure(elf_file, "Stop");
            rlpStart = RLP.GetProcedure(elf_file, "Start");
            elf_file = null;
            Debug.GC(true);

            //sets up all analog pins as reading, and pwm pins as pwms
            for (int i = 0; i < 6; i++)
            {
                new AnalogIn((AnalogIn.Pin)i);
                new PWM((PWM.Pin)i + 1);
            }

            dataPort = new SerialPort("COM2", 57600, System.IO.Ports.Parity.None, 8, StopBits.One);
            dataPort.Open();
            dataPort.DataReceived += new SerialDataReceivedEventHandler(dataPort_DataReceived); //open before attaching the event - due to bug in framework
            //found at http://tinyclr.com/forum/2/4426/

            Thread.Sleep(2000); //this makes it easier to install new stuff if anything crashes

            rlpInit.Invoke();
            Thread.Sleep(Timeout.Infinite);
        }
Пример #3
0
        public static void Init(out RLP.Procedure lcdInit, out RLP.Procedure lcdSet, byte[] loadPlugin = null)
        {
            if (initialized)
            {
                throw new Exception("Already initialized");
            }

            //NOTE: use your own unlock code
            RLP.Unlock("[email protected]", new byte[]
            {
                0xFB, 0xCC, 0x7D, 0xDA, 0x8E, 0x87, 0x58, 0xAB,
                0x95, 0x8E, 0x68, 0x02, 0x1F, 0xE6, 0xD6, 0x14,
                0x3C, 0xBD, 0x3E, 0xD1, 0xBE, 0xF0, 0xCE, 0xFB,
                0x1D, 0xD9, 0xC4, 0xEC, 0xE2, 0x2A, 0xFD, 0xCD
            });

            byte[] elf_file = Extension.GetBytes(Extension.BinaryResources.Extension);
            RLP.LoadELF(elf_file);
            RLP.InitializeBSSRegion(elf_file);
            RLP.Procedure VsInit = RLP.GetProcedure(elf_file, "VsInit");
            vsStreamData       = RLP.GetProcedure(elf_file, "VsStreamData");
            vsNoMoreData       = RLP.GetProcedure(elf_file, "VsNoMoreData");
            vsLoadPlugin       = RLP.GetProcedure(elf_file, "VsLoadPluginFromArray");
            vsSetVolume        = RLP.GetProcedure(elf_file, "VsSetVolume");
            vsSetBassAndTreble = RLP.GetProcedure(elf_file, "VsSetBassAndTreble");

            lcdInit = RLP.GetProcedure(elf_file, "LcdInit");
            lcdSet  = RLP.GetProcedure(elf_file, "LcdSetLevel");

            elf_file = null;

            int result;

            if ((result = loadPlugin == null ? VsInit.Invoke() : VsInit.InvokeEx(loadPlugin, loadPlugin.Length)) != 0)
            {
                throw new Exception("Could not init VS Driver. Reason " + result.ToString());
            }
            loadedPlugin = loadPlugin;

            RLP.RLPEvent += (data, time) =>
            {
                switch (data)
                {
                case 0x01:
                    //data was streamed
                    wait.Set();     //notify any waiter
                    break;

                case 0x02:
                    //error when closing stream
                    //this means the VS was reseted,
                    //reload plugin, set volume, bass and treble
                    if (loadedPlugin != null)
                    {
                        vsLoadPlugin.InvokeEx(loadedPlugin, loadedPlugin.Length);
                    }
                    RaiseException("Error closing stream!");
                    break;
                }
            };
            initialized = true;

            balanceGeneral = 0;
            Volume         = 255; //max volume
            trebleGeneral  = 0;
            bassGeneral    = 0;
        }