diff --git a/Display/ConsoleDisplay/ConsoleDisplay.sln b/Display/ConsoleDisplay/ConsoleDisplay.sln new file mode 100644 index 0000000..ca0b5f7 --- /dev/null +++ b/Display/ConsoleDisplay/ConsoleDisplay.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.3.32929.385 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleDisplay", "ConsoleDisplay\ConsoleDisplay.csproj", "{FB027AE4-23B7-4FF2-A29F-A2773A6D36AB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FB027AE4-23B7-4FF2-A29F-A2773A6D36AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FB027AE4-23B7-4FF2-A29F-A2773A6D36AB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FB027AE4-23B7-4FF2-A29F-A2773A6D36AB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FB027AE4-23B7-4FF2-A29F-A2773A6D36AB}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {D9164198-4F73-49F9-9A7C-916DBAFF4802} + EndGlobalSection +EndGlobal diff --git a/Display/ConsoleDisplay/ConsoleDisplay/ConsoleDisplay.csproj b/Display/ConsoleDisplay/ConsoleDisplay/ConsoleDisplay.csproj new file mode 100644 index 0000000..40c60dd --- /dev/null +++ b/Display/ConsoleDisplay/ConsoleDisplay/ConsoleDisplay.csproj @@ -0,0 +1,10 @@ + + + + Exe + net6.0 + enable + enable + + + diff --git a/Display/ConsoleDisplay/ConsoleDisplay/ExternalDomain/IDisplay.cs b/Display/ConsoleDisplay/ConsoleDisplay/ExternalDomain/IDisplay.cs new file mode 100644 index 0000000..df2fac7 --- /dev/null +++ b/Display/ConsoleDisplay/ConsoleDisplay/ExternalDomain/IDisplay.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleDisplay.ExternalDomain +{ + + internal interface IDisplay + { + int Width { get; } + int Height { get; } + + bool IsEnabled { get; } + void Reset(); + void Set(int iX, int iY, bool bState); + + bool Get(int iX, int iY); + + } +} diff --git a/Display/ConsoleDisplay/ConsoleDisplay/ExternalDomain/VirtualBulb.cs b/Display/ConsoleDisplay/ConsoleDisplay/ExternalDomain/VirtualBulb.cs new file mode 100644 index 0000000..d177295 --- /dev/null +++ b/Display/ConsoleDisplay/ConsoleDisplay/ExternalDomain/VirtualBulb.cs @@ -0,0 +1,21 @@ + +namespace ConsoleDisplay.ExternalDomain +{ + internal class VirtualBulb + { + public VirtualBulb( + int x, + int y, + bool isEnabled = false) + { + X = x; + Y = y; + IsEnabled = isEnabled; + } + + public int X { get; set; } + public int Y { get; set; } + public bool IsEnabled { get; set; } + + } +} \ No newline at end of file diff --git a/Display/ConsoleDisplay/ConsoleDisplay/ExternalDomain/VirtualDisplay.cs b/Display/ConsoleDisplay/ConsoleDisplay/ExternalDomain/VirtualDisplay.cs new file mode 100644 index 0000000..98a9b3b --- /dev/null +++ b/Display/ConsoleDisplay/ConsoleDisplay/ExternalDomain/VirtualDisplay.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography.X509Certificates; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleDisplay.ExternalDomain +{ + internal class VirtualDisplay : IDisplay + { + private List BulbList; + + public VirtualDisplay(int iWidth, int iHeight) + { + this.Width = iWidth; + this.Height = iHeight; + + BulbList = new List(); + h_Init(iWidth, iHeight); + IsEnabled = true; + } + + + private void h_Init(int width, int height) + { + for (int ii = 0; ii < width; ii++) { + for (int jj = 0; jj < height; jj++) { + BulbList.Add(new VirtualBulb(ii, jj)); + } + } + } + + + + public int Width { get; } + public int Height { get; } + public bool IsEnabled { get; } + public void Reset() + { + for (int jj = 0; jj < BulbList.Count; jj++) { + BulbList[jj].IsEnabled = false; + } + } + + public void Set(int iX, int iY, bool bState) + { + VirtualBulb vb = h_GetBulb(iX, iY); + if (vb == null) return; + vb.IsEnabled = bState; + } + + private VirtualBulb h_GetBulb(int iX, int iY) + { + for (int jj = 0; jj < BulbList.Count; jj++) { + if (BulbList[jj].X == iX && BulbList[jj].Y == iY) { + return BulbList[jj]; + } + } + + return null; + } + + public bool Get(int iX, int iY) + { + VirtualBulb vb = h_GetBulb(iX, iY); + if (vb == null) return false; + return vb.IsEnabled; + } + } +} diff --git a/Display/ConsoleDisplay/ConsoleDisplay/Model/SmartDisplay.cs b/Display/ConsoleDisplay/ConsoleDisplay/Model/SmartDisplay.cs new file mode 100644 index 0000000..69f836a --- /dev/null +++ b/Display/ConsoleDisplay/ConsoleDisplay/Model/SmartDisplay.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ConsoleDisplay.ExternalDomain; + +namespace ConsoleDisplay.Model +{ + internal class SmartDisplay + { + private readonly IDisplay m_pDisplay; + + public SmartDisplay(IDisplay pDisplay) + { + m_pDisplay = pDisplay; + } + + public void Reset() + { + m_pDisplay.Reset(); + } + + /// + /// + /// + /// отображаемый символ + /// высота символа + /// позиция левого верхнего края прямугольника - X + /// позиция левого верхнего края прямугольника - Y + public void Draw(char ch, int size, int x, int y) + { + // TODO: + // 1. Шрифт + // 2. загрузить символ + // 3. отмасштабировать символ + // 4. последовательно очисить лампочки в прямоугольном поле + // 4. последовательно включить лампочки в прямоугольнике + } + + + public void DisplayToConsole(int X, int Y) + { + if (m_pDisplay is VirtualDisplay) { + VirtualDisplay dd = m_pDisplay as VirtualDisplay; + // TODO: отрисовка в консоли + } + } + + } +} diff --git a/Display/ConsoleDisplay/ConsoleDisplay/Model/TextFile1.txt b/Display/ConsoleDisplay/ConsoleDisplay/Model/TextFile1.txt new file mode 100644 index 0000000..ba0ca5f --- /dev/null +++ b/Display/ConsoleDisplay/ConsoleDisplay/Model/TextFile1.txt @@ -0,0 +1,12 @@ +# Модель дисплея +(светодиодный диплей: отображение в виде лампочек) + +## Микроконтроллер (драйвер) +Включен/выключен +очистить() +установить(x, y) / сбросить(x, y) +состояние(x, y) + +## УДобныйДисплей +Очистить() +Нарисовать символ в позиции (код символа, размер, позиция) \ No newline at end of file diff --git a/Display/ConsoleDisplay/ConsoleDisplay/Program.cs b/Display/ConsoleDisplay/ConsoleDisplay/Program.cs new file mode 100644 index 0000000..1e49236 --- /dev/null +++ b/Display/ConsoleDisplay/ConsoleDisplay/Program.cs @@ -0,0 +1,32 @@ +using ConsoleDisplay.ExternalDomain; +using ConsoleDisplay.Model; + +namespace ConsoleDisplay +{ + internal class Program + { + private static IDisplay _displayInternal = new VirtualDisplay(24, 8); + private static SmartDisplay _display = new SmartDisplay(_displayInternal); + + static void Main(string[] args) + { + // Вариант 1: использование напрямую в функциональном стиле + // _displayInternal.Reset(); + //_displayInternal.Set(3, 1, true); + //_displayInternal.Set(5, 1, true); + //_displayInternal.Set(6, 1, true); + //_displayInternal.Set(8, 1, true); + + + // Вариант 2: использование в ООП-обертке + _display.Reset(); + + string sText = "Привет"; + foreach (var ch in sText) { + _display.Draw(ch, 8, 1, 1); + _display.DisplayToConsole(1, 1); + Thread.Sleep(1000); + } + } + } +} \ No newline at end of file