public static void Init(string path, Action flushCallback = null) { try { FlushCallback = flushCallback; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } IEnumerable filesEnumerator = Directory.EnumerateFiles(path); string fullpath; int filesCount = 0; foreach (object file in filesEnumerator) { filesCount++; } fullpath = path + @"\traceLog" + filesCount + ".log"; writer = new StreamWriter(fullpath, append: true); queue.Start(); } catch (Exception ex) { FrontDisplay.RefreshLEDs(LedType.Red); Logger.Error(ex, "file logger init"); } }
internal static void ResetBoard() { Logger.Trace("Board will reset in 2 seconds!!!"); FrontDisplay.RefreshLEDs(LedType.RedBlinking, append: true); LedBlinkingQueueThreadWorker.Enqueue(new LedBlinkingItem(orangeLed, 2, 200)); requestIgnitionStateTimer?.Dispose(); UnmountMassStorage(); FrontDisplay.RefreshLEDs(LedType.Empty); #if OnBoardMonitorEmulator System.Windows.MessageBox.Show("Board was resetted"); #endif #if DEBUG || DebugOnRealDeviceOverFTDI if (Debugger.IsAttached) { return; } #endif if (resetPin == null) { resetPin = new OutputPort(Pin.ResetPin, false); } }
public static void CheckStatus() { while (true) { try { Execute("ping"); Logger.Trace("CheckStatus: Volumio READY!"); FrontDisplay.RefreshLEDs(LedType.Green); CheckStatusThread.Suspend(); } catch (Exception ex) { FrontDisplay.RefreshLEDs(LedType.OrangeBlinking, append: true); Logger.Trace("CheckStatus: Volumio isn't ready yet."); Thread.Sleep(1000); } } }
public static void Init() { //player = new iPodViaHeadset(Cpu.Pin.GPIO_NONE); //player = new BluetoothOVC3860(Serial.COM2/*, sd != null ? sd + @"\contacts.vcf" : null*/); Logger.Debug("Creating VolumioRestApiPlayer."); Cpu.Pin chipSelect_RT = FEZPandaIII.Gpio.D27; Cpu.Pin externalInterrupt_WS = FEZPandaIII.Gpio.D24; Cpu.Pin reset_BR = FEZPandaIII.Gpio.D26; Player = new VolumioRestApiPlayer(chipSelect_RT, externalInterrupt_WS, reset_BR); Logger.Debug("VolumioRestApiPlayer created."); FrontDisplay.RefreshLEDs(LedType.GreenBlinking); if (settings.MenuMode != Tools.MenuMode.RadioCDC /* || Manager.FindDevice(DeviceAddress.OnBoardMonitor, 10000)*/) { //if (player is BluetoothWT32) //{ // ((BluetoothWT32)player).NowPlayingTagsSeparatedRows = true; //} if (settings.MenuMode == MenuMode.BordmonitorCDC) { Emulator = new CDChanger(Player); Logger.Debug("CDChanger media emulator created"); if (settings.NaviVersion == NaviVersion.MK2) { Localization.Current = new RadioLocalization(); SettingsScreen.Instance.CanChangeLanguage = false; } Bordmonitor.NaviVersion = settings.NaviVersion; //BordmonitorMenu.FastMenuDrawing = settings.NaviVersion == NaviVersion.MK4; BordmonitorMenu.Init(Emulator); Logger.Debug("BordmonitorMenu inited"); } else { //emulator = new BordmonitorAUX(player); } } else { //Localization.Current = new RadioLocalization(); //SettingsScreen.Instance.CanChangeLanguage = false; //MultiFunctionSteeringWheel.EmulatePhone = true; //Radio.HasMID = Manager.FindDevice(DeviceAddress.MultiInfoDisplay); //var menu = RadioMenu.Init(new CDChanger(player)); //menu.TelephoneModeForNavigation = settings.MenuMFLControl; //Logger.Info("Radio menu inited" + (Radio.HasMID ? " with MID" : "")); } Thread.Sleep(200); FrontDisplay.RefreshLEDs(LedType.Green); greenLed.Write(true); //nextButton = new InterruptPort((Cpu.Pin)FEZPandaIII.Gpio.Ldr1, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeHigh); //nextButton.OnInterrupt += (p, s, t) => //{ // Emulator.Player.Next(); //}; //prevButton = new InterruptPort((Cpu.Pin)FEZPandaIII.Gpio.Ldr0, true, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeHigh); //prevButton.OnInterrupt += (p, s, t) => //{ // if (!Emulator.IsEnabled) // { // Emulator.IsEnabled = true; // return; // } // if (Emulator.Player.IsPlaying) // { // Emulator.Pause(); // } // else // { // Emulator.Play(); // } //}; }
public static void Launch(LaunchMode launchMode = LaunchMode.MicroFramework) { try { Comfort.Init(); IntegratedHeatingAndAirConditioning.Init(); _resetCause = GHI.Processor.Watchdog.LastResetCause; blueLed = new OutputPort(FEZPandaIII.Gpio.Led1, false); greenLed = new OutputPort(FEZPandaIII.Gpio.Led2, false); orangeLed = new OutputPort(FEZPandaIII.Gpio.Led3, _resetCause == GHI.Processor.Watchdog.ResetCause.Watchdog); redLed = new OutputPort(FEZPandaIII.Gpio.Led4, false); #if (NETMF && RELEASE) || (OnBoardMonitorEmulator && !DebugOnRealDeviceOverFTDI) _useWatchdog = true; #endif if (_useWatchdog) { GHI.Processor.Watchdog.Enable(watchDogTimeoutInMilliseconds); } settings = Settings.Instance; FileLogger.Create(); InitManagers(); InstrumentClusterElectronics.DateTimeChanged += DateTimeChanged; Logger.Debug("Watchdog.ResetCause: " + (_resetCause == GHI.Processor.Watchdog.ResetCause.Normal ? "Normal" : "Watchdog")); if (_useWatchdog) { Logger.Debug("Watchdog enabled with timeout: " + watchDogTimeoutInMilliseconds); } //SettingsScreen.Instance.Status = version.Length > 11 ? version.Replace(" ", "") : version; //Localization.SetCurrent(RussianLocalization.SystemName); //Localization.SetCurrent(settings.Language); //Comfort.AutoLockDoors = settings.AutoLockDoors; //Comfort.AutoUnlockDoors = settings.AutoUnlockDoors; //Comfort.AutoCloseWindows = settings.AutoCloseWindows; //Comfort.AutoCloseSunroof = settings.AutoCloseSunroof; #region MassStorage //Controller.DeviceConnectFailed += (sss, eee) => //{ // Logger.Error("DeviceConnectFailed!"); // LedBlinkingQueueThreadWorker.Enqueue(new LedBlinkingItem(redLed, 1, 100)); // ControllerState = UsbMountState.DeviceConnectFailed; // _removableMediaInsertedSync.Set(); //}; //Controller.UnknownDeviceConnected += (ss, ee) => //{ // Logger.Error("UnknownDeviceConnected!"); // LedBlinkingQueueThreadWorker.Enqueue(new LedBlinkingItem(redLed, 2, 100)); // ControllerState = UsbMountState.UnknownDeviceConnected; // _removableMediaInsertedSync.Set(); //}; //Controller.MassStorageConnected += (sender, massStorage) => //{ // Logger.Debug("Controller MassStorageConnected!"); // LedBlinkingQueueThreadWorker.Enqueue(new LedBlinkingItem(orangeLed, 2, 100)); // ControllerState = UsbMountState.MassStorageConnected; RemovableMedia.Insert += (s, e) => { LedBlinkingQueueThreadWorker.Enqueue(new LedBlinkingItem(orangeLed, 3, 100)); string rootDirectory = VolumeInfo.GetVolumes()[0].RootDirectory; settings = Settings.Init(rootDirectory + "\\imBMW.ini"); FileLogger.Init(rootDirectory + "\\logs", () => VolumeInfo.GetVolumes()[0].FlushAll()); Logger.Debug("Logger initialized."); MassStorageMountState = MassStorageMountState.Mounted; _removableMediaInsertedSync.Set(); }; RemovableMedia.Eject += (s, e) => { FileLogger.Eject(); Logger.Print("RemovableMedia Ejected!"); LedBlinkingQueueThreadWorker.Enqueue(new LedBlinkingItem(greenLed, 3, 100)); MassStorageMountState = MassStorageMountState.Unmounted; }; //_massStorage = massStorage; _massStorage = new SDCard(SDCard.SDInterface.SPI); _massStorage.Mount(); //}; #if RELEASE //Controller.Start(); #else #if NETMF // WARNING! Be aware, without this line you can get 'Controller -> DeviceConnectFailed' each time when you start debugging... if (Debugger.IsAttached) #endif { //Controller.Start(); } #endif #endregion LedBlinkingQueueThreadWorker.Enqueue(new LedBlinkingItem(orangeLed, 1, 200)); bool isSignalled = _removableMediaInsertedSync.WaitOne(Debugger.IsAttached ? 10000 : 10000, true); if (!isSignalled) // No Storage inserted { InstrumentClusterElectronics.ShowNormalTextWithGong(MassStorageMountState.ToStringValue()); FrontDisplay.RefreshLEDs(LedType.RedBlinking, append: true); LedBlinkingQueueThreadWorker.Enqueue(new LedBlinkingItem(redLed, 3, 100)); } else { if (MassStorageMountState == MassStorageMountState.DeviceConnectFailed || MassStorageMountState == MassStorageMountState.UnknownDeviceConnected) { InstrumentClusterElectronics.ShowNormalTextWithGong(MassStorageMountState.ToStringValue()); FrontDisplay.RefreshLEDs(LedType.Red, append: true); LedBlinkingQueueThreadWorker.Enqueue(new LedBlinkingItem(redLed, 4, 100)); ResetBoard(); } } Logger.Debug("MassStorage state: " + MassStorageMountState.ToStringValue()); InstrumentClusterElectronics.RequestDateTime(); Init(); Logger.Debug("Started!"); BordmonitorMenu.MenuButtonHold += () => { FrontDisplay.RefreshLEDs(LedType.Empty); if (Emulator.IsEnabled) { Emulator.PlayerIsPlayingChanged += (s, isPlayingChangedValue) => { if (!isPlayingChangedValue) { ResetBoard(); } }; Radio.PressOnOffToggle(); //Emulator.IsEnabled = false; } else { ResetBoard(); } }; BordmonitorMenu.PhoneButtonHold += () => { VolumioRestApiPlayer.Reboot(); Logger.Warning("Reboot request sent."); }; BordmonitorMenu.EjectButtonHold += () => { UnmountMassStorage(); _massStorage = null; Logger.Warning("UNMOUNTED!"); }; Manager.Instance.AddMessageReceiverForSourceDevice(DeviceAddress.InstrumentClusterElectronics, m => { if (m.Data[0] == 0x11 && m.Data.Length == 2) // Ignition status { GHI.Processor.Watchdog.ResetCounter(); } }); requestIgnitionStateTimer = new Timer(RequestIgnitionStateTimerHandler, null, 0, requestIgnitionStateTimerPeriod); imBMWTest(); Logger.Debug("Actions inited!"); if (launchMode == LaunchMode.MicroFramework) { Thread.Sleep(Timeout.Infinite); } } catch (Exception ex) { LedBlinking(new LedBlinkingItem(redLed, 5, 200)); Thread.Sleep(200); redLed.Write(true); Logger.Error(ex, "while modules initialization"); ResetBoard(); } }