miscellaneous changes
This commit is contained in:
parent
195fe4d98a
commit
09d9ccb628
|
@ -1,5 +1,4 @@
|
||||||
using Crc;
|
|
||||||
|
|
||||||
namespace libsharperang {
|
namespace libsharperang {
|
||||||
public abstract class Base {
|
public abstract class Base {
|
||||||
public enum ConnectionType {
|
public enum ConnectionType {
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using Crc;
|
|
||||||
|
|
||||||
namespace libsharperang {
|
namespace libsharperang {
|
||||||
public class DataTransforms {
|
public class DataTransforms {
|
||||||
|
|
|
@ -5,8 +5,11 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CrcDotNET" Version="1.0.3" />
|
|
||||||
<PackageReference Include="LibUsbDotNet" Version="2.2.29" />
|
<PackageReference Include="LibUsbDotNet" Version="2.2.29" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Properties\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -21,7 +21,7 @@ namespace libsharperang {
|
||||||
|
|
||||||
public enum Opcode {
|
public enum Opcode {
|
||||||
SessionBegin = 10,
|
SessionBegin = 10,
|
||||||
SessionEnd,
|
Feed,
|
||||||
PrintBegin = 20,
|
PrintBegin = 20,
|
||||||
PrintContinue,
|
PrintContinue,
|
||||||
CrcTransmit = 30
|
CrcTransmit = 30
|
||||||
|
@ -31,6 +31,7 @@ namespace libsharperang {
|
||||||
private byte[] ResolveOpcode(Opcode opcode) {
|
private byte[] ResolveOpcode(Opcode opcode) {
|
||||||
switch (opcode) {
|
switch (opcode) {
|
||||||
case Opcode.SessionBegin: return new byte[] { 0x06, 0x00, 0x02, 0x00 };
|
case Opcode.SessionBegin: return new byte[] { 0x06, 0x00, 0x02, 0x00 };
|
||||||
|
case Opcode.Feed: return new byte[] { 0x1a, 0x00, 0x02, 0x00 };
|
||||||
case Opcode.CrcTransmit: return new byte[] { 0x18, 0x01, 0x04, 0x00 };
|
case Opcode.CrcTransmit: return new byte[] { 0x18, 0x01, 0x04, 0x00 };
|
||||||
default: throw new NullReferenceException();
|
default: throw new NullReferenceException();
|
||||||
}
|
}
|
||||||
|
@ -73,7 +74,6 @@ namespace libsharperang {
|
||||||
public USBPrinter() {
|
public USBPrinter() {
|
||||||
ActiveConnectionType=ConnectionType.USB;
|
ActiveConnectionType=ConnectionType.USB;
|
||||||
ImageWidth=48;
|
ImageWidth=48;
|
||||||
Initialise();
|
|
||||||
}
|
}
|
||||||
~USBPrinter() {
|
~USBPrinter() {
|
||||||
Close();
|
Close();
|
||||||
|
@ -149,22 +149,22 @@ namespace libsharperang {
|
||||||
public void TransmitCrcKey() => WriteBytes(builder.BuildTransmitCrc());
|
public void TransmitCrcKey() => WriteBytes(builder.BuildTransmitCrc());
|
||||||
public void StartSession() => StartSession(new byte[2] { 0, 0 });
|
public void StartSession() => StartSession(new byte[2] { 0, 0 });
|
||||||
public void StartSession(byte[] data) => WriteBytes(builder.Build(Frame.Opcode.SessionBegin, data));
|
public void StartSession(byte[] data) => WriteBytes(builder.Build(Frame.Opcode.SessionBegin, data));
|
||||||
public void EndSession() => EndSession(new byte[2] { 0, 0 });
|
|
||||||
public void EndSession(byte[] data) => WriteBytes(builder.Build(Frame.Opcode.SessionEnd, data));
|
|
||||||
public void InitPrinter() {
|
public void InitPrinter() {
|
||||||
TransmitCrcKey();
|
TransmitCrcKey();
|
||||||
EndSession();
|
NoOp();
|
||||||
PollPrinter();
|
PollPrinter();
|
||||||
}
|
}
|
||||||
public void PollPrinter() {
|
public void PollPrinter() {
|
||||||
StartSession();
|
StartSession();
|
||||||
EndSession();
|
NoOp();
|
||||||
}
|
}
|
||||||
public void Feed() => EndSession(new byte[2] { 0x64, 0x00 });
|
public void Feed() => Feed(100);
|
||||||
public void Feed(int milliseconds) => EndSession(BitConverter.GetBytes(transform.SwapEndianness(
|
//Feed 0 is equivalent to a no-op, though on the P2 model it appears to engage the roller even though it doesn't ultimately result in any rotation
|
||||||
|
public void NoOp() => Feed(0);
|
||||||
|
public void Feed(int milliseconds) => WriteBytes(builder.Build(Frame.Opcode.Feed, BitConverter.GetBytes(transform.SwapEndianness(
|
||||||
0x00000000 | (((((
|
0x00000000 | (((((
|
||||||
(uint)milliseconds & 0xFFU) << 16) |
|
(uint)milliseconds & 0xFFU) << 16) |
|
||||||
(uint)milliseconds) & 0xFFFF00U) >> 8))).Skip(2).ToArray());
|
(uint)milliseconds) & 0xFFFF00U) >> 8))).Skip(2).ToArray()));
|
||||||
public void PrintBytes(byte[] data, bool autofeed=true) {
|
public void PrintBytes(byte[] data, bool autofeed=true) {
|
||||||
List<byte[]> datas = data
|
List<byte[]> datas = data
|
||||||
.Select((b, i) => new {Index = i, Value = b })
|
.Select((b, i) => new {Index = i, Value = b })
|
||||||
|
@ -174,8 +174,6 @@ namespace libsharperang {
|
||||||
datas.ForEach(b => WriteBytes(builder.Build(transform.GeneratePrintOpcode(b), b)));
|
datas.ForEach(b => WriteBytes(builder.Build(transform.GeneratePrintOpcode(b), b)));
|
||||||
if (autofeed) Feed(60);
|
if (autofeed) Feed(60);
|
||||||
}
|
}
|
||||||
public void PrintTestA(byte[] data) => WriteBytes(builder.Build(Frame.Opcode.PrintBegin, data));
|
|
||||||
public void PrintTestB(byte[] data) => WriteBytes(builder.Build(Frame.Opcode.PrintContinue, data));
|
|
||||||
public bool IsPrinterPresent() => (Devices != null && Devices.Count > 0);
|
public bool IsPrinterPresent() => (Devices != null && Devices.Count > 0);
|
||||||
bool IPrinter.Initialised() => Initialised();
|
bool IPrinter.Initialised() => Initialised();
|
||||||
byte[] IPrinter.ReadBytes() => ReadBytes();
|
byte[] IPrinter.ReadBytes() => ReadBytes();
|
||||||
|
|
|
@ -12,7 +12,7 @@ namespace sharperang {
|
||||||
set {
|
set {
|
||||||
if (value == _LogBuffer) return;
|
if (value == _LogBuffer) return;
|
||||||
if (value == "!clearlog") _LogBuffer = "";
|
if (value == "!clearlog") _LogBuffer = "";
|
||||||
else _LogBuffer += value + "\n";
|
else _LogBuffer = value + "\n" + _LogBuffer;
|
||||||
OnPropertyChanged("LogBuffer");
|
OnPropertyChanged("LogBuffer");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ namespace sharperang {
|
||||||
logger.ClearBuffer();
|
logger.ClearBuffer();
|
||||||
private void BtInitUSB_Click(object sender, RoutedEventArgs e) {
|
private void BtInitUSB_Click(object sender, RoutedEventArgs e) {
|
||||||
logger.Info("USB Initialising");
|
logger.Info("USB Initialising");
|
||||||
|
printer.Initialise();
|
||||||
//printer = new LibSharperang(logger);
|
//printer = new LibSharperang(logger);
|
||||||
logger.Debug("IsPrinterPresent => "+printer.IsPrinterPresent());
|
logger.Debug("IsPrinterPresent => "+printer.IsPrinterPresent());
|
||||||
logger.Debug("FoundPrinterGuids => "+printer.FoundPrinterGuids());
|
logger.Debug("FoundPrinterGuids => "+printer.FoundPrinterGuids());
|
||||||
|
@ -36,21 +37,30 @@ namespace sharperang {
|
||||||
printer.InitPrinter();
|
printer.InitPrinter();
|
||||||
logger.Debug("Printer initialised and ready");
|
logger.Debug("Printer initialised and ready");
|
||||||
}
|
}
|
||||||
private void BtTestLine_Click(object sender, RoutedEventArgs e) => printer.Feed(200);
|
private void BtTestLine_Click(object sender, RoutedEventArgs e) => printer.Feed(200);
|
||||||
private void BtLoadImage_Click(object sender, RoutedEventArgs e) {
|
private void BtLoadImage_Click(object sender, RoutedEventArgs e) {
|
||||||
|
logger.Debug("Loading image for print");
|
||||||
OpenFileDialog r = new OpenFileDialog {
|
OpenFileDialog r = new OpenFileDialog {
|
||||||
Title="Select 1 (one) image file",
|
Title="Select 1 (one) image file",
|
||||||
Multiselect=false,
|
Multiselect=false,
|
||||||
Filter="PNG files (*.png)|*.png|JPEG files (*.jpe?g)|*.jpg *.jpeg|Jraphics Interchange Format files (*.gif)|*.gif|Bitte-Mappe files (*.bmp)|*.bmp|All of the above|*.jpg *.jpeg *.png *.gif *.bmp",
|
Filter="PNG files (*.png)|*.png|JPEG files (*.jpe?g)|*.jpg *.jpeg|Jraphics Interchange Format files (*.gif)|*.gif|Bitte-Mappe files (*.bmp)|*.bmp|All of the above|*.jpg *.jpeg *.png *.gif *.bmp",
|
||||||
AutoUpgradeEnabled=true
|
AutoUpgradeEnabled=true
|
||||||
};
|
};
|
||||||
r.ShowDialog();
|
if (r.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) {
|
||||||
|
logger.Debug("Image load cancelled");
|
||||||
|
return;
|
||||||
|
}
|
||||||
Image _=Image.FromFile(r.FileName);
|
Image _=Image.FromFile(r.FileName);
|
||||||
r.Dispose();
|
logger.Debug("Loaded image " + r.FileName);
|
||||||
|
r.Dispose();
|
||||||
|
logger.Debug("Disposed of dialog");
|
||||||
bimg=new Bitmap(_,
|
bimg=new Bitmap(_,
|
||||||
(printer.ImageWidth*8), (int)((double)(printer.ImageWidth*8)*(double)((double)_.Height/(double)_.Width)));
|
(printer.ImageWidth*8), (int)((double)(printer.ImageWidth*8)*(double)((double)_.Height/(double)_.Width)));
|
||||||
_.Dispose();
|
logger.Debug("Loaded image as Bitmap");
|
||||||
|
_.Dispose();
|
||||||
|
logger.Debug("Disposed of Image");
|
||||||
bimg=CopyToBpp(bimg);
|
bimg=CopyToBpp(bimg);
|
||||||
|
logger.Debug("Converted Bitmap to Bitmap with 1-bit colour depth");
|
||||||
//BitArray img = new BitArray(bimg.Height*96*8);
|
//BitArray img = new BitArray(bimg.Height*96*8);
|
||||||
byte[] iimg = new byte[bimg.Height*printer.ImageWidth];
|
byte[] iimg = new byte[bimg.Height*printer.ImageWidth];
|
||||||
byte[] img;
|
byte[] img;
|
||||||
|
@ -58,14 +68,20 @@ namespace sharperang {
|
||||||
bimg.Save(s, ImageFormat.Bmp);
|
bimg.Save(s, ImageFormat.Bmp);
|
||||||
img=s.ToArray();
|
img=s.ToArray();
|
||||||
}
|
}
|
||||||
int startoffset=img.Length-((bimg.Width/8)+(bimg.Height*48));
|
logger.Debug("Got bitmap's bytes");
|
||||||
|
int startoffset=img.Length-((bimg.Width/8)+(bimg.Height*printer.ImageWidth));
|
||||||
|
logger.Debug("Processing bytes with offset " + startoffset);
|
||||||
for(int h=0;h<bimg.Height;h++) {
|
for(int h=0;h<bimg.Height;h++) {
|
||||||
for (int w=0;w<printer.ImageWidth;w++) {
|
for (int w=0;w<printer.ImageWidth;w++) {
|
||||||
iimg[(printer.ImageWidth*(bimg.Height-1-h))+(printer.ImageWidth-1-w)]=(byte)~
|
iimg[(printer.ImageWidth*(bimg.Height-1-h))+(printer.ImageWidth-1-w)]=(byte)~
|
||||||
(img[startoffset+(printer.ImageWidth*h)+(printer.ImageWidth-1-w)]);
|
(img[startoffset+(printer.ImageWidth*h)+(printer.ImageWidth-1-w)]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
logger.Debug("Have print data of length " + iimg.Length);
|
||||||
|
bimg.Dispose();
|
||||||
|
logger.Debug("Disposed of Bitmap");
|
||||||
printer.PrintBytes(iimg, false);
|
printer.PrintBytes(iimg, false);
|
||||||
|
logger.Debug("Feeding for 200ms");
|
||||||
printer.Feed(200);
|
printer.Feed(200);
|
||||||
}
|
}
|
||||||
static uint BitSwap1(uint x) => ((x & 0x55555555u) << 1) | ((x & (~0x55555555u)) >> 1);
|
static uint BitSwap1(uint x) => ((x & 0x55555555u) << 1) | ((x & (~0x55555555u)) >> 1);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
|
<package id="LibUsbDotNet" version="2.2.29" targetFramework="net472" />
|
||||||
<package id="Microsoft.Win32.Registry" version="4.5.0" targetFramework="net472" />
|
<package id="Microsoft.Win32.Registry" version="4.5.0" targetFramework="net472" />
|
||||||
<package id="System.Collections" version="4.3.0" targetFramework="net472" />
|
<package id="System.Collections" version="4.3.0" targetFramework="net472" />
|
||||||
<package id="System.Collections.Specialized" version="4.3.0" targetFramework="net472" />
|
<package id="System.Collections.Specialized" version="4.3.0" targetFramework="net472" />
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||||
<Deterministic>true</Deterministic>
|
<Deterministic>true</Deterministic>
|
||||||
|
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||||
<PublishUrl>publish\</PublishUrl>
|
<PublishUrl>publish\</PublishUrl>
|
||||||
<Install>true</Install>
|
<Install>true</Install>
|
||||||
<InstallFrom>Disk</InstallFrom>
|
<InstallFrom>Disk</InstallFrom>
|
||||||
|
@ -26,7 +27,6 @@
|
||||||
<MapFileExtensions>true</MapFileExtensions>
|
<MapFileExtensions>true</MapFileExtensions>
|
||||||
<ApplicationRevision>0</ApplicationRevision>
|
<ApplicationRevision>0</ApplicationRevision>
|
||||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
|
||||||
<UseApplicationTrust>false</UseApplicationTrust>
|
<UseApplicationTrust>false</UseApplicationTrust>
|
||||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
@ -50,6 +50,9 @@
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="LibUsbDotNet.LibUsbDotNet, Version=2.2.0.0, Culture=neutral, PublicKeyToken=c677239abe1e02a9, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\LibUsbDotNet.2.2.29\lib\net45\LibUsbDotNet.LibUsbDotNet.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="Microsoft.Win32.Registry, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
<Reference Include="Microsoft.Win32.Registry, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\Microsoft.Win32.Registry.4.5.0\lib\net461\Microsoft.Win32.Registry.dll</HintPath>
|
<HintPath>..\packages\Microsoft.Win32.Registry.4.5.0\lib\net461\Microsoft.Win32.Registry.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
|
Loading…
Reference in New Issue