private BordmonitorMenu(MediaEmulator mediaEmulator) : base(mediaEmulator) { //CurrentScreen = HomeScreen.Instance; // TODO: Refactor this!!! BordcomputerScreen.Instance.MediaEmulator = mediaEmulator; //MusicListScreen.GetMediaEmulator = () => mediaEmulator; CurrentScreen = BordcomputerScreen.Instance; byte titleStartIndex = 0; byte statusStartIndex = 0; //var trackInfo = mediaEmulator.Player.CurrentTrack; // TODO: Refactor this!!! //mediaEmulator.Player.IsPlayingChanged += (s, e) => //{ // if (s.IsPlaying) // { // /*DDEScreen.Instance.TitleCallback = */BordcomputerScreen.Instance.TitleCallback = x => // { // //if (trackInfo.Title != null && trackInfo.Title != "") // //{ // return TrimTextToLength(trackInfo.Title, ref titleStartIndex, 10); // //} // //return TrimTextToLength(trackInfo.FileName, ref titleStartIndex, 10); // }; // /*DDEScreen.Instance.StatusCallback = */BordcomputerScreen.Instance.StatusCallback = x => // { // if (trackInfo.Artist != null && trackInfo.Artist != "") // { // return TrimTextToLength(trackInfo.Artist, ref statusStartIndex, 10); // } // return string.Empty; // }; // InstrumentClusterElectronics.ShowNormalTextWithoutGong(trackInfo.Title); // } //}; mediaEmulator.Player.TrackChanged += (audioPlayer, trackName) => { //titleStartIndex = 0; //statusStartIndex = 0; InstrumentClusterElectronics.ShowNormalTextWithoutGong(trackName, timeout: 5000); if (IsEnabled) { Thread.Sleep(200); Bordmonitor.ShowText(trackName, BordmonitorFields.Title); } }; //mediaEmulator.IsEnabledChanged += mediaEmulator_IsEnabledChanged; //Radio.OnOffChanged += Radio_OnOffChanged; Manager.Instance.AddMessageReceiverForDestinationDevice(DeviceAddress.Radio, ProcessToRadioMessage); }
//Message lastTitle; protected override void DrawHeader() { if (isHeaderDrawing || !mediaEmulator.IsEnabled) { return; // TODO test } lock (drawLock) { isHeaderDrawing = true; base.DrawHeader(); var messages = new ArrayList(); //var n = 0; // TODO: refactor string title = CurrentScreen.Title; string status = CurrentScreen.Status; if (!StringHelpers.IsNullOrEmpty(title)) { messages.Add(Bordmonitor.ShowText(title, BordmonitorFields.Title, 0, false, false)); } if (!StringHelpers.IsNullOrEmpty(CurrentScreen.T1Field)) { messages.Add(Bordmonitor.ShowText(CurrentScreen.T1Field, BordmonitorFields.T1, 1, false, false)); } if (!StringHelpers.IsNullOrEmpty(CurrentScreen.T2Field)) { messages.Add(Bordmonitor.ShowText(CurrentScreen.T2Field, BordmonitorFields.T2, 2, false, false)); } if (!StringHelpers.IsNullOrEmpty(CurrentScreen.T3Field)) { messages.Add(Bordmonitor.ShowText(CurrentScreen.T3Field, BordmonitorFields.T3, 3, false, false)); } if (!StringHelpers.IsNullOrEmpty(CurrentScreen.T4Field)) { messages.Add(Bordmonitor.ShowText(CurrentScreen.T4Field, BordmonitorFields.T4, 4, false, false)); } if (!StringHelpers.IsNullOrEmpty(CurrentScreen.T5Field)) { messages.Add(Bordmonitor.ShowText(CurrentScreen.T5Field, BordmonitorFields.T5, 5, false, false)); } if (!StringHelpers.IsNullOrEmpty(status)) { messages.Add(Bordmonitor.ShowText(status, BordmonitorFields.Status, 6, false, false)); } Manager.Instance.EnqueueMessage((Message[])messages.ToArray(typeof(Message))); isHeaderDrawing = false; } }
static void ProcessToRadioMessage(Message m) { if (m.Data.Compare(MessageRegistry.DataPollRequest)) { var pollResponseMessage = new Message(DeviceAddress.Radio, DeviceAddress.GlobalBroadcastAddress, MessageRegistry.DataPollResponse); Manager.Instance.EnqueueMessage(pollResponseMessage); } if (m.Data.Length == 4 && m.Data.StartsWith(Bordmonitor.DataItemClicked) && m.Data[3] <= 9) { var index = m.Data[3]; byte diskNumber = 1; if (index <= 2) { diskNumber = (byte)(index + 1); } else if (index >= 5 && index <= 7) { diskNumber = (byte)(index - 1); } else { return; } var showTitleMessage = Bordmonitor.ShowText("CD " + diskNumber + "-", BordmonitorFields.Title, send: false); var selectDiskMessage = new Message(DeviceAddress.Radio, DeviceAddress.CDChanger, CDChanger.GetDataSelectDisk(diskNumber)); Manager.Instance.EnqueueMessage(showTitleMessage, selectDiskMessage); } if (m.Data.Length == 8 && m.Data.StartsWith(0x39)) { var diskNumber = m.Data[6]; var trackNumber = m.Data[7]; Bordmonitor.ShowText("CD " + (diskNumber) + "-" + (trackNumber), BordmonitorFields.Title, send: true); } if (m.Data.Length == 2 && m.Data.StartsWith(Radio.DataRadioKnobPressed)) { Manager.Instance.EnqueueMessage(new Message(DeviceAddress.Radio, DeviceAddress.LocalBroadcastAddress, IsEnabled ? Radio.DataRadioOff : Radio.DataRadioOn)); Manager.Instance.EnqueueMessage(new Message(DeviceAddress.Radio, DeviceAddress.CDChanger, IsEnabled ? CDChanger.DataStop : CDChanger.DataPlay)); IsEnabled = !IsEnabled; } if (m.Data.Length == 2 && m.Data.StartsWith(Radio.DataNextPressed)) { var message = new Message(DeviceAddress.Radio, DeviceAddress.CDChanger, CDChanger.DataNext); Manager.Instance.EnqueueMessage(message); } if (m.Data.Length == 2 && m.Data.StartsWith(Radio.DataPrevPressed)) { var message = new Message(DeviceAddress.Radio, DeviceAddress.CDChanger, CDChanger.DataPrev); Manager.Instance.EnqueueMessage(message); } }
protected override void DrawScreen(MenuScreenUpdateEventArgs args) { if (isDrawing) { return; // TODO test } lock (drawLock) { isDrawing = true; skipRefreshScreen = true; skipClearTillRefresh = true; // TODO test no screen items lost base.DrawScreen(args); var messages = new Message[4]; messages[0] = Bordmonitor.ShowText(CurrentScreen.Status ?? String.Empty, BordmonitorFields.Status, 0, false, false); lastTitle = Bordmonitor.ShowText(CurrentScreen.Title ?? String.Empty, BordmonitorFields.Title, 0, false, false); messages[1] = lastTitle; byte[] itemsBytes = null; for (byte i = 0; i < 10; i++) { var index = GetItemIndex(i, true); var item = CurrentScreen.GetItem(index); if (item == null && itemsBytes != null) { itemsBytes = itemsBytes.Combine(0x06); continue; } var s = item.Text; var m = Bordmonitor.ShowText(s ?? String.Empty, BordmonitorFields.Item, i, item != null && item.IsChecked, false); if (itemsBytes == null) { itemsBytes = m.Data; } else { var d = m.Data.Skip(3); d[0] = 0x06; itemsBytes = itemsBytes.Combine(d); } } itemsBytes = itemsBytes.Combine(0x06); // TODO split to 2-3 messages? messages[2] = new Message(DeviceAddress.Radio, DeviceAddress.GraphicsNavigationDriver, "Fill screen items", itemsBytes); messages[3] = Bordmonitor.MessageRefreshScreen; skipRefreshScreen = true; skipClearTillRefresh = true; Manager.EnqueueMessage(messages); isDrawing = false; } }
Message DrawItem(MenuItem item, byte index) { var s = item != null ? item.Text : ""; return(Bordmonitor.ShowText(s ?? String.Empty, BordmonitorFields.Item, index, item != null && item.IsChecked, false)); }
protected override void DrawScreen(MenuScreenUpdateEventArgs args) { if (isDrawing) { return; // TODO test } lock (drawLock) { isDrawing = true; skipRefreshScreen = true; skipClearTillRefresh = true; // TODO test no screen items lost base.DrawScreen(args); var messages = new Message[FastMenuDrawing ? 4 : 13]; var n = 0; messages[n++] = Bordmonitor.ShowText(CurrentScreen.Status ?? String.Empty, BordmonitorFields.Status, 0, false, false); lastTitle = Bordmonitor.ShowText(CurrentScreen.Title ?? String.Empty, BordmonitorFields.Title, 0, false, false); messages[n++] = lastTitle; byte[] itemsBytes = null; for (byte i = 0; i < 10; i++) { var index = GetItemIndex(i, true); var item = CurrentScreen.GetItem(index); if (FastMenuDrawing) { if (item == null && itemsBytes != null) { itemsBytes = itemsBytes.Combine(0x06); continue; } var m = DrawItem(item, i); if (itemsBytes == null) { itemsBytes = m.Data; } else { var d = m.Data.Skip(3); d[0] = 0x06; itemsBytes = itemsBytes.Combine(d); } } else { if (item == null && n > 2) { var prevMess = messages[n - 1]; messages[n - 1] = new Message(prevMess.SourceDevice, prevMess.DestinationDevice, prevMess.ReceiverDescription, prevMess.Data.Combine(0x06)); } else { messages[n++] = DrawItem(item, i); } messages[n - 1].AfterSendDelay = 40; } } if (FastMenuDrawing) { itemsBytes = itemsBytes.Combine(0x06); messages[n++] = new Message(DeviceAddress.Radio, DeviceAddress.GraphicsNavigationDriver, "Fill screen items", itemsBytes); } messages[n++] = Bordmonitor.MessageRefreshScreen; skipRefreshScreen = true; skipClearTillRefresh = true; Manager.EnqueueMessage(messages); isDrawing = false; } }