further refactoring

This commit is contained in:
Maff 2019-09-12 17:03:16 +01:00
parent 46012df5d5
commit be368f398c
5 changed files with 60 additions and 14 deletions

View File

@ -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 { }
}

View File

@ -9,7 +9,7 @@ namespace libpaperang.Helpers {
private uint poly = 0xedb88320;
private uint[] crctable;
public bool IsInitialised=false;
public CRC() { this.iv=0; }
public CRC() { iv=0; }
public CRC(uint iv) => this.iv=iv;
public void Initialise() {
crctable=Enumerable.Range(0, 256).Select(i => {

View File

@ -7,6 +7,15 @@ namespace libpaperang.Helpers {
Frame=FrameConstruction;
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();
}
}
}
}

View File

@ -36,10 +36,10 @@ namespace libpaperang {
Print
}
public struct Opcodes {
byte[] NoOp;
byte[] LineFeed;
byte[] Print;
byte[] TransmitCrc;
public byte[] NoOp;
public byte[] LineFeed;
public byte[] Print;
public byte[] TransmitCrc;
}
}
interface IPrinter {

View File

@ -1,23 +1,51 @@
using System;
using LibUsbDotNet;
using LibUsbDotNet.Main;
namespace libpaperang {
public class USB : IPrinter {
public short LineWidth => throw new NotImplementedException();
public class USB : IPrinter {
// 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 Deinitialise() => throw new NotImplementedException();
public bool Initialise() => throw new NotImplementedException();
public bool ClosePrinter() => throw new NotImplementedException();
public bool Deinitialise() => throw new NotImplementedException();
public bool Initialise() {
if (!IsPrinterAvailable()) return false;
return true;
}
public bool IsPrinterAvailable() => throw new NotImplementedException();
public bool IsPrinterInitialised() => throw new NotImplementedException();
public bool OpenPrinter() => throw new NotImplementedException();
public bool[] ReadBytes() => throw new NotImplementedException();
public bool WriteBytes(byte[] packet) => throw new NotImplementedException();
public bool WriteBytes(byte[] packet, int delay) => throw new NotImplementedException();
public USB(BaseTypes.Model model) => iModel = model;
}
}