Skip to content

Commit

Permalink
multi line display
Browse files Browse the repository at this point in the history
  • Loading branch information
lapshin_1988 committed Dec 4, 2015
1 parent e1fc238 commit 60b9917
Show file tree
Hide file tree
Showing 11 changed files with 192 additions and 153 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
queue
=====

Electronic Queue System
Electronic Queue System
2 changes: 1 addition & 1 deletion sources/Hub/Hub.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
<None Include="app.config.example" />
<None Include="default.config" />
<None Include="packages.config" />
<None Include="Svetovod\doc.pdf" />
<None Include="Svetovod\Quality\doc.pdf" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
Expand Down
5 changes: 5 additions & 0 deletions sources/Hub/Svetovod/Display/ISvetovodDisplayConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@ namespace Queue.Hub.Svetovod
{
public interface ISvetovodDisplayConnection : IDisposable
{
void ShowText(byte sysnum, string text);

void Clear(byte sysnum);

void ShowLines(byte sysnum, ushort[][] lines);
}
}
97 changes: 29 additions & 68 deletions sources/Hub/Svetovod/Display/SvetovodDisplayDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,15 @@ public void ShowText(byte deviceId, string text)

CloseActiveConnection();

if (config.DeviceId != 0 && config.DeviceId != deviceId)
var connection = GetConnectionForDevice(deviceId);
if (connection == null)
{
return;
}

var conf = GetDeviceConfig(deviceId);

switch (conf.Type)
{
case SvetovodDisplayType.Segment:
ShowTextOnSegmentDisplay(deviceId, text, conf);
break;

case SvetovodDisplayType.Matrix:
ShowTextOnMatrixDisplay(deviceId, text, conf);
break;
}
connection.ShowText(deviceId, text);

activeConnection = connection;
CloseActiveConnection();
}

Expand All @@ -56,24 +47,15 @@ public void ShowLines(byte deviceId, ushort[][] lines)

CloseActiveConnection();

if (config.DeviceId != 0 && config.DeviceId != deviceId)
var connection = GetConnectionForDevice(deviceId);
if (connection == null)
{
return;
}

var conf = GetDeviceConfig(deviceId);

switch (conf.Type)
{
case SvetovodDisplayType.Segment:
throw new NotImplementedException();
break;

case SvetovodDisplayType.Matrix:
throw new NotImplementedException();
break;
}
connection.ShowLines(deviceId, lines);

activeConnection = connection;
CloseActiveConnection();
}

Expand All @@ -83,25 +65,38 @@ public void ClearText(byte deviceId)

CloseActiveConnection();

if (config.DeviceId != 0 && config.DeviceId != deviceId)
var connection = GetConnectionForDevice(deviceId);
if (connection == null)
{
return;
}

connection.Clear(deviceId);

activeConnection = connection;
CloseActiveConnection();
}

private ISvetovodDisplayConnection GetConnectionForDevice(byte deviceId)
{
if (config.DeviceId != 0 && config.DeviceId != deviceId)
{
return null;
}

var conf = GetDeviceConfig(deviceId);

switch (conf.Type)
{
case SvetovodDisplayType.Segment:
ClearTextOnSegmentDisplay(deviceId);
break;
return new SvetovodSegmentDisplayConnection(config.Port, conf);

case SvetovodDisplayType.Matrix:
ClearTextOnMatrixDisplay(deviceId, conf);
break;
}
return new SvetovodMatrixDisplayConnection(config.Port, conf);

CloseActiveConnection();
default:
throw new QueueException("Данный вид табло не поддерживается: {0}", conf.Type);
}
}

private SvetovodDisplayConnectionConfig GetDeviceConfig(byte deviceId)
Expand All @@ -112,8 +107,7 @@ private SvetovodDisplayConnectionConfig GetDeviceConfig(byte deviceId)

if (conf == null)
{
conf = connections.Where(c => c.Sysnum == 0)
.FirstOrDefault();
conf = connections.Where(c => c.Sysnum == 0).FirstOrDefault();
}

if (conf == null)
Expand All @@ -124,39 +118,6 @@ private SvetovodDisplayConnectionConfig GetDeviceConfig(byte deviceId)
return conf;
}

private void ShowTextOnSegmentDisplay(byte sysnum, string text, SvetovodDisplayConnectionConfig conf)
{
var connection = new SvetovodSegmentDisplayConnection(config.Port);

connection.ShowNumber(sysnum, text, conf.Width);

activeConnection = connection;
}

private void ClearTextOnSegmentDisplay(byte sysnum)
{
var connection = new SvetovodSegmentDisplayConnection(config.Port);
connection.ClearNumber(sysnum);

activeConnection = connection;
}

private void ShowTextOnMatrixDisplay(byte sysnum, string text, SvetovodDisplayConnectionConfig conf)
{
var connection = new SvetovodMatrixDisplayConnection(config.Port);
connection.ShowText(sysnum, text, conf.Width, conf.Height);

activeConnection = connection;
}

private void ClearTextOnMatrixDisplay(byte sysnum, SvetovodDisplayConnectionConfig conf)
{
var connection = new SvetovodMatrixDisplayConnection(config.Port);
connection.ShowText(sysnum, " ", conf.Width, conf.Height);

activeConnection = connection;
}

private void CloseActiveConnection()
{
if (activeConnection == null)
Expand Down
20 changes: 16 additions & 4 deletions sources/Hub/Svetovod/Display/SvetovodMatrixDisplayConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,31 @@ namespace Queue.Hub.Svetovod
{
public class SvetovodMatrixDisplayConnection : SvetovodConnection, ISvetovodDisplayConnection
{
public SvetovodMatrixDisplayConnection(string port) :
private readonly SvetovodDisplayConnectionConfig config;

public SvetovodMatrixDisplayConnection(string port, SvetovodDisplayConnectionConfig config) :
base(port)
{
this.config = config;
}

public void ShowText(byte sysnum, string text, int width, int height)
public void ShowText(byte sysnum, string text)
{
text = GetPreparedText(text, width);
var body = CreateBody(GetTextBytes(text, width, height));
var body = CreateBody(GetTextBytes(GetPreparedText(text, config.Width), config.Width, config.Height));
var header = CreateHeader(sysnum, 0x00, 0x00, (byte)(body.Length - 1));
WriteToPort(header, body);
}

public void Clear(byte sysnum)
{
ShowText(sysnum, " ");
}

public void ShowLines(byte sysnum, ushort[][] lines)
{
throw new NotImplementedException();
}

private string GetPreparedText(string text, int width)
{
var places = width / 8;
Expand Down
116 changes: 77 additions & 39 deletions sources/Hub/Svetovod/Display/SvetovodSegmentDisplayConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,93 @@ namespace Queue.Hub.Svetovod
{
public class SvetovodSegmentDisplayConnection : SvetovodConnection, ISvetovodDisplayConnection
{
public SvetovodSegmentDisplayConnection(string port) :
private readonly SvetovodDisplayConnectionConfig config;

public SvetovodSegmentDisplayConnection(string port, SvetovodDisplayConnectionConfig config) :
base(port)
{
this.config = config;
}

public void ShowText(byte sysnum, string number)
{
var body = CreateBody(GetBlockContent(number, config.Width));
WriteToPort(CreateHeader(sysnum, 0x00, 0x00, (byte)(body.Length - 1)), body);
}

public void ShowNumber(byte sysnum, string number, byte width)
public void ShowLines(byte sysnum, ushort[][] lines)
{
var body = CreateBody(GetBodyContent(sysnum, number, width));
var columnsConfig = config.Columns.Cast<SvetovodDisplayConnectionColumnConfig>().ToArray();
var content = new List<byte>();

foreach (var line in lines.Take(config.Width / columnsConfig.Sum(i => i.Width)))
{
for (int i = 0; i < line.Length; i++)
{
// передали больше колонок
if (i >= columnsConfig.Length)
{
break;
}

content.AddRange(GetBlockContent(line[i].ToString(), columnsConfig[i].Width));
}

//передали меньше колонок - забьем пустотой
if (line.Length < columnsConfig.Length)
{
content.AddRange(new byte[columnsConfig.Skip(line.Length).Sum(i => i.Width)]);
}
}

//дозабиваем нулями
if (content.Count < config.Width)
{
content.AddRange(new byte[config.Width - content.Count]);
}

var body = CreateBody(content.ToArray());
WriteToPort(CreateHeader(sysnum, 0x00, 0x00, (byte)(body.Length - 1)), body);
}

public void Clear(byte sysnum)
{
ShowText(sysnum, "");
}

#region protocol

private static byte[] GetBlockContent(string number, byte width)
{
int length = number.Length;

if (length > width)
{
throw new QueueException();
}

var digits = number.ToCharArray();

var units = new List<byte>();
foreach (var d in digits)
{
units.Add(byte.Parse(d.ToString()));
}

var data = new List<byte>();
for (byte i = 0; i < width - length; i++)
{
data.Add(0);
}

foreach (var s in units)
{
data.Add(GetDigit(s));
}

return data.ToArray();
}

private static byte GetDigit(byte digit)
{
var bits = new[] { true, true, true, true, true, true, false, false };
Expand Down Expand Up @@ -68,42 +142,6 @@ private static byte GetDigit(byte digit)
return bytes.First();
}

private static byte[] GetBodyContent(byte sysnum, string number, byte segments)
{
int lenght = number.Length;

if (lenght > segments)
{
throw new QueueException();
}

var digits = number.ToCharArray();

var units = new List<byte>();
foreach (var d in digits)
{
units.Add(byte.Parse(d.ToString()));
}

var data = new List<byte>();
for (byte i = 0; i < segments - lenght; i++)
{
data.Add(0);
}

foreach (var s in units)
{
data.Add(GetDigit(s));
}

return data.ToArray();
}

#endregion protocol

public void ClearNumber(byte sysnum)
{
//TODO
}
}
}
File renamed without changes.
Loading

0 comments on commit 60b9917

Please sign in to comment.