further refactoring
This commit is contained in:
parent
46012df5d5
commit
be368f398c
|
@ -0,0 +1,9 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace libpaperang {
|
||||||
|
public class PrinterNotInitialisedException : InvalidOperationException { }
|
||||||
|
public class PrinterNotAvailableException : NullReferenceException { }
|
||||||
|
public class PrinterVariantNotSupportedException : NotSupportedException { }
|
||||||
|
public class CrcNotAvailableException : MissingMemberException { }
|
||||||
|
public class InvalidOperationException : ArgumentOutOfRangeException { }
|
||||||
|
}
|
|
@ -9,7 +9,7 @@ namespace libpaperang.Helpers {
|
||||||
private uint poly = 0xedb88320;
|
private uint poly = 0xedb88320;
|
||||||
private uint[] crctable;
|
private uint[] crctable;
|
||||||
public bool IsInitialised=false;
|
public bool IsInitialised=false;
|
||||||
public CRC() { this.iv=0; }
|
public CRC() { iv=0; }
|
||||||
public CRC(uint iv) => this.iv=iv;
|
public CRC(uint iv) => this.iv=iv;
|
||||||
public void Initialise() {
|
public void Initialise() {
|
||||||
crctable=Enumerable.Range(0, 256).Select(i => {
|
crctable=Enumerable.Range(0, 256).Select(i => {
|
||||||
|
|
|
@ -7,6 +7,15 @@ namespace libpaperang.Helpers {
|
||||||
Frame=FrameConstruction;
|
Frame=FrameConstruction;
|
||||||
Op=Operations;
|
Op=Operations;
|
||||||
}
|
}
|
||||||
|
public byte[] Oper(BaseTypes.Operations Operation) {
|
||||||
|
switch (Operation) {
|
||||||
|
case BaseTypes.Operations.NoOp: return Op.NoOp;
|
||||||
|
case BaseTypes.Operations.LineFeed: return Op.LineFeed;
|
||||||
|
case BaseTypes.Operations.CrcTransmit: return Op.TransmitCrc;
|
||||||
|
case BaseTypes.Operations.Print: return Op.Print;
|
||||||
|
default: throw new InvalidOperationException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,10 +36,10 @@ namespace libpaperang {
|
||||||
Print
|
Print
|
||||||
}
|
}
|
||||||
public struct Opcodes {
|
public struct Opcodes {
|
||||||
byte[] NoOp;
|
public byte[] NoOp;
|
||||||
byte[] LineFeed;
|
public byte[] LineFeed;
|
||||||
byte[] Print;
|
public byte[] Print;
|
||||||
byte[] TransmitCrc;
|
public byte[] TransmitCrc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
interface IPrinter {
|
interface IPrinter {
|
||||||
|
|
|
@ -1,23 +1,51 @@
|
||||||
using System;
|
using System;
|
||||||
|
using LibUsbDotNet;
|
||||||
|
using LibUsbDotNet.Main;
|
||||||
|
|
||||||
namespace libpaperang {
|
namespace libpaperang {
|
||||||
public class USB : IPrinter {
|
public class USB : IPrinter {
|
||||||
public short LineWidth => throw new NotImplementedException();
|
// constants
|
||||||
|
private const ushort iV = 0x4348;
|
||||||
|
private const ushort iP = 0x5584;
|
||||||
|
private const short MaxDataSize = 1008;
|
||||||
|
|
||||||
public BaseTypes.Connection ConnectionMethod => throw new NotImplementedException();
|
// types
|
||||||
|
private struct UsbComms {
|
||||||
|
Guid id;
|
||||||
|
UsbDevice handle;
|
||||||
|
UsbEndpointReader rx;
|
||||||
|
UsbEndpointWriter tx;
|
||||||
|
}
|
||||||
|
private UsbComms Printer;
|
||||||
|
private BaseTypes.Model iModel;
|
||||||
|
public short LineWidth { get {
|
||||||
|
switch (iModel) {
|
||||||
|
case BaseTypes.Model.P1: return 48;
|
||||||
|
case BaseTypes.Model.P2: return 72;
|
||||||
|
case BaseTypes.Model.P2S: return 72; //assumption
|
||||||
|
case BaseTypes.Model.T1: throw new PrinterVariantNotSupportedException();
|
||||||
|
default: throw new InvalidOperationException();
|
||||||
|
}
|
||||||
|
} }
|
||||||
|
|
||||||
public BaseTypes.Model PrinterVariant => throw new NotImplementedException();
|
public BaseTypes.Connection ConnectionMethod { get => BaseTypes.Connection.USB; }
|
||||||
|
public BaseTypes.Model PrinterVariant { get => iModel; }
|
||||||
|
|
||||||
public BaseTypes.State Status => throw new NotImplementedException();
|
public BaseTypes.State Status => throw new NotImplementedException();
|
||||||
|
|
||||||
public bool ClosePrinter() => throw new NotImplementedException();
|
public bool ClosePrinter() => throw new NotImplementedException();
|
||||||
public bool Deinitialise() => throw new NotImplementedException();
|
public bool Deinitialise() => throw new NotImplementedException();
|
||||||
public bool Initialise() => throw new NotImplementedException();
|
public bool Initialise() {
|
||||||
|
if (!IsPrinterAvailable()) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
public bool IsPrinterAvailable() => throw new NotImplementedException();
|
public bool IsPrinterAvailable() => throw new NotImplementedException();
|
||||||
public bool IsPrinterInitialised() => throw new NotImplementedException();
|
public bool IsPrinterInitialised() => throw new NotImplementedException();
|
||||||
public bool OpenPrinter() => throw new NotImplementedException();
|
public bool OpenPrinter() => throw new NotImplementedException();
|
||||||
public bool[] ReadBytes() => throw new NotImplementedException();
|
public bool[] ReadBytes() => throw new NotImplementedException();
|
||||||
public bool WriteBytes(byte[] packet) => throw new NotImplementedException();
|
public bool WriteBytes(byte[] packet) => throw new NotImplementedException();
|
||||||
public bool WriteBytes(byte[] packet, int delay) => throw new NotImplementedException();
|
public bool WriteBytes(byte[] packet, int delay) => throw new NotImplementedException();
|
||||||
|
|
||||||
|
public USB(BaseTypes.Model model) => iModel = model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue