Exemplo n.º 1
0
        /// <summary>
        /// Release used resources.
        /// </summary>
        public void Dispose()
        {
            // Stop thread
            if (thread != null)
            {
                terminated = true;
                thread.Join();
                thread = null;
            }

            // Deinit RLP driver
            if (deinitProcedure != null)
            {
                deinitProcedure.Invoke();
                deinitProcedure = null;
                initProcedure = null;
                queryProcedure = null;
            }
        }       
Exemplo n.º 2
0
        /// <summary>
        /// Release used resources.
        /// </summary>
        public void Dispose()
        {
            // Stop thread
            if (thread != null)
            {
                terminated = true;
                thread.Join();
                thread = null;
            }

            // Deinit RLP driver
            if (deinitProcedure != null)
            {
                deinitProcedure.Invoke();
                deinitProcedure = null;
                initProcedure   = null;
                queryProcedure  = null;
            }
        }
        public SensorPoller()
        {
            if (_dataProcedure == null)
            {
                InitRLP();
                _dataProcedure = GetDataProcedure();
            }

            US = new IRangeFinder[USDetectorPins.Length];
            for (int i = 0; i < US.Length; i++)
            {
                US[i] = new NativeUSSensor(USDetectorPins[i]);
            }

            IR = new IIntensityDetector[IRDetectorPins.Length];
            for (int i = 0; i < IR.Length; i++)
            {
                IR[i] = new NativeIRSensor(IRDetectorPins[i]);
            }
        }
Exemplo n.º 4
0
        static void Configure()
        {
            try
            {
                LoadRLP();

                // Blink board LED
                RLP.Procedure PwmStop  = RLP.GetProcedure(elfImage, "PwmStop");
                RLP.Procedure PWMStart = RLP.GetProcedure(elfImage, "PWMRun");

                PwmStop.Invoke();

                if (currentEnergyMode == ScanEnergyMode.Dual)
                {
                    Reset.Write(true);
                    Preset.Write(true);
                }
                else if (currentEnergyMode == ScanEnergyMode.High)
                {
                    Reset.Write(true);
                    Preset.Write(false);
                }
                else
                {
                    Reset.Write(false);
                    Preset.Write(true);
                }

                RLP.Procedure PWMBlink = RLP.GetProcedure(elfImage, "PWMBlink");

                pc.Initialize(elfImage);

                PWMBlink.Invoke(currentStaticPulseFreq, PulseWidthsDutyCycle[(int)currentPulseWidth - 1], 1);

                PWMStart.Invoke();
            }
            catch { }
            finally { UnloadRLP(); }
        }
Exemplo n.º 5
0
        /// </summary>
        /// <param name="elfImage">elf image library</param>
        public void Initialize(byte[] elfImage)
        {
            // Load procedures
            initProcedure        = RLP.GetProcedure(elfImage, "Init");
            deinitProcedure      = RLP.GetProcedure(elfImage, "Deinit");
            queryProcedure       = RLP.GetProcedure(elfImage, "Query");
            updateFreqProcedure  = RLP.GetProcedure(elfImage, "PWMUpdateFreq");
            updatePulseProcedure = RLP.GetProcedure(elfImage, "PWMUpdatePulse");
            resetProcedure       = RLP.GetProcedure(elfImage, "WDReset");
            stopProcedure        = RLP.GetProcedure(elfImage, "PwmStop");
            startProcedure       = RLP.GetProcedure(elfImage, "PWMRun");
            PWMStatusProcedure   = RLP.GetProcedure(elfImage, "QueryPWMStatus");

            // Init RLP driver
            if (initProcedure.Invoke() != 0)
            {
                throw new Exception("Driver initialisation failed");
            }

            // Start thread
            thread = new Thread(ThreadProc);
            thread.Start();
        }
        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);
        }
        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);
        }
Exemplo n.º 8
0
        /// </summary>
        /// <param name="elfImage">elf image library</param>
        public void Initialize(byte[] elfImage)
        {
            // Load procedures
            initProcedure = RLP.GetProcedure(elfImage, "Init");
            deinitProcedure = RLP.GetProcedure(elfImage, "Deinit");
            queryProcedure = RLP.GetProcedure(elfImage, "Query");
            updateFreqProcedure = RLP.GetProcedure(elfImage, "PWMUpdateFreq");
            updatePulseProcedure = RLP.GetProcedure(elfImage, "PWMUpdatePulse");
            resetProcedure = RLP.GetProcedure(elfImage, "WDReset");
            stopProcedure = RLP.GetProcedure(elfImage, "PwmStop");
            startProcedure = RLP.GetProcedure(elfImage, "PWMRun");
            PWMStatusProcedure = RLP.GetProcedure(elfImage, "QueryPWMStatus");

            // Init RLP driver
            if (initProcedure.Invoke() != 0)
            {
                throw new Exception("Driver initialisation failed");
            }

            // Start thread
            thread = new Thread(ThreadProc);
            thread.Start();
        }
Exemplo n.º 9
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;
        }
Exemplo n.º 10
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;
        }