public static void Init() { try { if (RealTimeClock.GetTime().Year < 2012) { RealTimeClock.SetTime(new DateTime(2012, 01, 01, 12, 0, 0)); } Utility.SetLocalTime(RealTimeClock.GetTime()); bool res = InitLcd(); res |= SetHeap(); res |= SetBoot(); if (res) { PowerState.RebootDevice(false); } #if USE_LED_PWM _ledGreen = new PWM(PWM.Pin.PWM3); _ledGreenValue = 0; _ledGreen.Set(false); _ledRed = new PWM(PWM.Pin.PWM2); _ledRedValue = 0; _ledRed.Set(false); #else _ledGreen = new OutputPort(EMX.Pin.IO49, false); _ledRed = new OutputPort(EMX.Pin.IO50, false); #endif InitNetwork(); LcdBacklightLevel = AppSettings.Instance.LcdBacklightLevel; VsDriver.Init(out _lcdInit, out _lcdSet);//Mp.App.Resources.Plugins.GetBytes(Mp.App.Resources.Plugins.BinaryResources.Flac_v140)); if (_lcdInit.Invoke(48) != 0) { throw new Exception("Could not init LCD backlight"); //IO48 is for LCD backlight } if (_lcdSet.Invoke(LcdBacklightLevel) != 0) { throw new Exception("Could not set LCD backlight level"); } VsDriver.Volume = AppSettings.Instance.Audio.Volume; VsDriver.Balance = AppSettings.Instance.Audio.Balance; VsDriver.Bass = AppSettings.Instance.Audio.Bass; VsDriver.Treble = AppSettings.Instance.Audio.Treble; PowerState.OnRebootEvent += (soft) => { AppSettings.Instance.Save(); }; } catch (Exception) { } }
/// <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; } }
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(); } }
static void dataPort_DataReceived(object sender, SerialDataReceivedEventArgs e) { byte[] buffer = new byte[1]; while (dataPort.BytesToRead > 0) { dataPort.Read(buffer, 0, 1); byte data = buffer[0]; int result; switch (data & (1 << START_BIT)) { case 0: result = rlpStop.Invoke(); Debug.Print("Stopped with result " + result); break; case (1 << START_BIT): result = rlpStart.Invoke(data); Debug.Print("Started with result " + result); break; } } }
/// </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); }
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; }
public int GetPWMRunStatus() { return(PWMStatusProcedure.Invoke()); }
public void PWMOutputEnable() { startProcedure.Invoke(); }
public void PWMOutputDisable() { stopProcedure.Invoke(); }
public void UpdatePWMPulseWidth(float width) { updatePulseProcedure.Invoke(width); }
public void UpdatePWMFrequency(int freq) { updateFreqProcedure.Invoke(freq); }
public void ResetBoard() { resetProcedure.Invoke(); }