miscellaneous changes
This commit is contained in:
parent
195fe4d98a
commit
09d9ccb628
|
@ -1,5 +1,4 @@
|
|||
using Crc;
|
||||
|
||||
|
||||
namespace libsharperang {
|
||||
public abstract class Base {
|
||||
public enum ConnectionType {
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using Crc;
|
||||
|
||||
namespace libsharperang {
|
||||
public class DataTransforms {
|
||||
|
|
|
@ -5,8 +5,11 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CrcDotNET" Version="1.0.3" />
|
||||
<PackageReference Include="LibUsbDotNet" Version="2.2.29" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Properties\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace libsharperang {
|
|||
|
||||
public enum Opcode {
|
||||
SessionBegin = 10,
|
||||
SessionEnd,
|
||||
Feed,
|
||||
PrintBegin = 20,
|
||||
PrintContinue,
|
||||
CrcTransmit = 30
|
||||
|
@ -31,6 +31,7 @@ namespace libsharperang {
|
|||
private byte[] ResolveOpcode(Opcode opcode) {
|
||||
switch (opcode) {
|
||||
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 };
|
||||
default: throw new NullReferenceException();
|
||||
}
|
||||
|
@ -73,7 +74,6 @@ namespace libsharperang {
|
|||
public USBPrinter() {
|
||||
ActiveConnectionType=ConnectionType.USB;
|
||||
ImageWidth=48;
|
||||
Initialise();
|
||||
}
|
||||
~USBPrinter() {
|
||||
Close();
|
||||
|
@ -149,22 +149,22 @@ namespace libsharperang {
|
|||
public void TransmitCrcKey() => WriteBytes(builder.BuildTransmitCrc());
|
||||
public void StartSession() => StartSession(new byte[2] { 0, 0 });
|
||||
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() {
|
||||
TransmitCrcKey();
|
||||
EndSession();
|
||||
NoOp();
|
||||
PollPrinter();
|
||||
}
|
||||
public void PollPrinter() {
|
||||
StartSession();
|
||||
EndSession();
|
||||
NoOp();
|
||||
}
|
||||
public void Feed() => EndSession(new byte[2] { 0x64, 0x00 });
|
||||
public void Feed(int milliseconds) => EndSession(BitConverter.GetBytes(transform.SwapEndianness(
|
||||
public void Feed() => Feed(100);
|
||||
//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 | (((((
|
||||
(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) {
|
||||
List<byte[]> datas = data
|
||||
.Select((b, i) => new {Index = i, Value = b })
|
||||
|
@ -174,8 +174,6 @@ namespace libsharperang {
|
|||
datas.ForEach(b => WriteBytes(builder.Build(transform.GeneratePrintOpcode(b), b)));
|
||||
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);
|
||||
bool IPrinter.Initialised() => Initialised();
|
||||
byte[] IPrinter.ReadBytes() => ReadBytes();
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace sharperang {
|
|||
set {
|
||||
if (value == _LogBuffer) return;
|
||||
if (value == "!clearlog") _LogBuffer = "";
|
||||
else _LogBuffer += value + "\n";
|
||||
else _LogBuffer = value + "\n" + _LogBuffer;
|
||||
OnPropertyChanged("LogBuffer");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace sharperang {
|
|||
logger.ClearBuffer();
|
||||
private void BtInitUSB_Click(object sender, RoutedEventArgs e) {
|
||||
logger.Info("USB Initialising");
|
||||
printer.Initialise();
|
||||
//printer = new LibSharperang(logger);
|
||||
logger.Debug("IsPrinterPresent => "+printer.IsPrinterPresent());
|
||||
logger.Debug("FoundPrinterGuids => "+printer.FoundPrinterGuids());
|
||||
|
@ -36,21 +37,30 @@ namespace sharperang {
|
|||
printer.InitPrinter();
|
||||
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) {
|
||||
logger.Debug("Loading image for print");
|
||||
OpenFileDialog r = new OpenFileDialog {
|
||||
Title="Select 1 (one) image file",
|
||||
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",
|
||||
AutoUpgradeEnabled=true
|
||||
};
|
||||
r.ShowDialog();
|
||||
if (r.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) {
|
||||
logger.Debug("Image load cancelled");
|
||||
return;
|
||||
}
|
||||
Image _=Image.FromFile(r.FileName);
|
||||
r.Dispose();
|
||||
logger.Debug("Loaded image " + r.FileName);
|
||||
r.Dispose();
|
||||
logger.Debug("Disposed of dialog");
|
||||
bimg=new Bitmap(_,
|
||||
(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);
|
||||
logger.Debug("Converted Bitmap to Bitmap with 1-bit colour depth");
|
||||
//BitArray img = new BitArray(bimg.Height*96*8);
|
||||
byte[] iimg = new byte[bimg.Height*printer.ImageWidth];
|
||||
byte[] img;
|
||||
|
@ -58,14 +68,20 @@ namespace sharperang {
|
|||
bimg.Save(s, ImageFormat.Bmp);
|
||||
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 w=0;w<printer.ImageWidth;w++) {
|
||||
iimg[(printer.ImageWidth*(bimg.Height-1-h))+(printer.ImageWidth-1-w)]=(byte)~
|
||||
(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);
|
||||
logger.Debug("Feeding for 200ms");
|
||||
printer.Feed(200);
|
||||
}
|
||||
static uint BitSwap1(uint x) => ((x & 0x55555555u) << 1) | ((x & (~0x55555555u)) >> 1);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="LibUsbDotNet" version="2.2.29" 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.Specialized" version="4.3.0" targetFramework="net472" />
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
<WarningLevel>4</WarningLevel>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Deterministic>true</Deterministic>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
|
@ -26,7 +27,6 @@
|
|||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
|
@ -50,6 +50,9 @@
|
|||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<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">
|
||||
<HintPath>..\packages\Microsoft.Win32.Registry.4.5.0\lib\net461\Microsoft.Win32.Registry.dll</HintPath>
|
||||
</Reference>
|
||||
|
|
Loading…
Reference in New Issue