8 changed files with 244 additions and 0 deletions
@ -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 |
|||
@ -0,0 +1,10 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<PropertyGroup> |
|||
<OutputType>Exe</OutputType> |
|||
<TargetFramework>net6.0</TargetFramework> |
|||
<ImplicitUsings>enable</ImplicitUsings> |
|||
<Nullable>enable</Nullable> |
|||
</PropertyGroup> |
|||
|
|||
</Project> |
|||
@ -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); |
|||
|
|||
} |
|||
} |
|||
@ -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; } |
|||
|
|||
} |
|||
} |
|||
@ -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<VirtualBulb> BulbList; |
|||
|
|||
public VirtualDisplay(int iWidth, int iHeight) |
|||
{ |
|||
this.Width = iWidth; |
|||
this.Height = iHeight; |
|||
|
|||
BulbList = new List<VirtualBulb>(); |
|||
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; |
|||
} |
|||
} |
|||
} |
|||
@ -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(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
/// <param name="ch">отображаемый символ</param>
|
|||
/// <param name="size">высота символа</param>
|
|||
/// <param name="x">позиция левого верхнего края прямугольника - X</param>
|
|||
/// <param name="y">позиция левого верхнего края прямугольника - Y</param>
|
|||
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: отрисовка в консоли
|
|||
} |
|||
} |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
# Модель дисплея |
|||
(светодиодный диплей: отображение в виде лампочек) |
|||
|
|||
## Микроконтроллер (драйвер) |
|||
Включен/выключен |
|||
очистить() |
|||
установить(x, y) / сбросить(x, y) |
|||
состояние(x, y) |
|||
|
|||
## УДобныйДисплей |
|||
Очистить() |
|||
Нарисовать символ в позиции (код символа, размер, позиция) |
|||
@ -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); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue