improvements to UI

This commit is contained in:
Maff 2019-10-02 16:31:46 +01:00
parent d9f9756dcb
commit 4356367712
4 changed files with 68 additions and 16 deletions

3
.gitignore vendored
View File

@ -338,3 +338,6 @@ ASALocalRun/
# BeatPulse healthcheck temp database
healthchecksdb
# Dither-tool
dither-tool/

View File

@ -29,7 +29,7 @@
</GroupBox>
<GroupBox x:Name="gbOtherFunc" Header="Other Functions" Margin="2,2,2,2" Grid.Column="1" IsEnabled="False">
<Grid Margin="0,0,0,0">
<Slider x:Name="slFeedTime" Margin="10,44,10,0" Maximum="500" Value="80" TickPlacement="Both" SmallChange="5" TickFrequency="5" LargeChange="25" ToolTip="Choose how long, in milliseconds, the printer should feed paper for" IsMoveToPointEnabled="True" IsSnapToTickEnabled="True" Height="33" VerticalAlignment="Top"/>
<Slider x:Name="slFeedTime" Margin="10,44,10,0" Maximum="500" Value="175" TickPlacement="Both" SmallChange="5" TickFrequency="5" LargeChange="25" ToolTip="Choose how long, in milliseconds, the printer should feed paper for" IsMoveToPointEnabled="True" IsSnapToTickEnabled="True" Height="33" VerticalAlignment="Top"/>
<Button x:Name="btFeed" Content="Feed" VerticalAlignment="Top" MinWidth="75" Margin="0,13,12,0" Height="21" Click="BtFeed_Click" Width="73" HorizontalAlignment="Right"/>
<Label x:Name="label" Content="Feed (ms)" Margin="10,10,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Width="79"/>
</Grid>
@ -38,9 +38,9 @@
<Grid Margin="0,0,0,0">
<Button x:Name="btPrintImage" Content="Print Image" HorizontalAlignment="Left" MinWidth="75" Margin="10,0,0,10" Click="BtPrintImage_Click" Height="21" VerticalAlignment="Bottom"/>
<Button x:Name="btPrintText" Content="Print Text" HorizontalAlignment="Left" MinWidth="75" Margin="90,0,0,10" Click="BtPrintText_Click" Height="21" VerticalAlignment="Bottom"/>
<TextBox x:Name="txInput" Margin="180,2,2,2" TextWrapping="Wrap" Text="" AcceptsReturn="True" SpellCheck.IsEnabled="True"/>
<TextBox x:Name="txFont" HorizontalAlignment="Left" Height="23" Margin="10,2,0,0" TextWrapping="Wrap" Text="Consolas" VerticalAlignment="Top" Width="165"/>
<TextBox x:Name="txSzF" HorizontalAlignment="Left" Height="23" Margin="10,30,0,0" Text="12" VerticalAlignment="Top" Width="54" UndoLimit="1" MaxLines="1" IsUndoEnabled="False" MaxLength="3" AllowDrop="False" ToolTip="Please choose a font size"/>
<TextBox x:Name="txInput" Margin="180,2,2,2" TextWrapping="Wrap" Text="" AcceptsReturn="True" SpellCheck.IsEnabled="True"/>
</Grid>
</GroupBox>
</Grid>

View File

@ -1,7 +1,9 @@
using liblogtiny;
using libpaperang;
using libpaperang.Interfaces;
using libpaperang.Main;
using System;
using System.Timers;
using System.Windows;
using System.Windows.Forms;
//testing
@ -14,14 +16,53 @@ namespace paperangapp {
private ILogTiny logger;
private BaseTypes.Connection mmjcx=BaseTypes.Connection.USB;
private BaseTypes.Model mmjmd=BaseTypes.Model.T1;
private Paperang mmj;
private IPrinter prtr=new USB(BaseTypes.Model.T1); // T1 used as a generic, prtr used soley for the PrinterAvailable attr. all paperang devices tested report the exact same USB identifiers.
private Paperang mmj=null;
private System.Timers.Timer usbpoll;
private enum AppState {
UnInitNoDev,
UnInitDev,
InitDev
};
private AppState state=AppState.UnInitNoDev;
// TODO: is it out of scope for this library to provide functionality for printing bitmap data?
public MainWindow() {
InitializeComponent();
logger = new LUITextbox();
gMain.DataContext = (LUITextbox)logger;
logger.Info("Application started");
usbpoll = new System.Timers.Timer(200) {
AutoReset = true
};
usbpoll.Elapsed += evtUsbPoll;
usbpoll.Start();
logger.Verbose("USB presence interval event started");
}
private void evtUsbPoll(object sender, ElapsedEventArgs e) =>_ = Dispatcher.BeginInvoke(new invDgtUsbPoll(dgtUsbPoll));
private delegate void invDgtUsbPoll();
private void dgtUsbPoll() {
try {
if(state == AppState.UnInitNoDev && prtr.PrinterAvailable) {
btInitUSB.IsEnabled = true;
state = AppState.UnInitDev;
logger.Info("Printer plugged in");
} else if(state == AppState.UnInitDev && !prtr.PrinterAvailable) {
btInitUSB.IsEnabled = false;
state = AppState.UnInitNoDev;
logger.Info("Printer unplugged");
} else if(state == AppState.InitDev && !prtr.PrinterAvailable) {
logger.Info("Printer unplugged while initialised");
USBDeInit();
}
} catch(Exception) {
} finally { }
}
~MainWindow() {
logger.Warn("Application closing");
if(mmj!=null) USBDeInit();
}
private void BtClearLog_Click(object sender, RoutedEventArgs e) =>
logger.Raw("!clearlog");
@ -37,7 +78,8 @@ namespace paperangapp {
mmjmd = BaseTypes.Model.T1;
logger.Info("Model type set to T1");
}
private void BtInitUSB_Click(object sender, RoutedEventArgs e) {
private void BtInitUSB_Click(object sender, RoutedEventArgs e) => USBInit();
private void USBInit() {
mmj = new Paperang(mmjcx, mmjmd);
mmj.SetLogContext(logger);
logger.Verbose("# printers found: " + mmj.Printer.AvailablePrinters.Count);
@ -49,20 +91,26 @@ namespace paperangapp {
mmj.Initialise();
logger.Debug("PrinterInitialised? " + mmj.Printer.PrinterInitialised);
logger.Debug("Printer initialised and ready");
state = AppState.InitDev;
btInitUSB.IsEnabled = false;
btDeInitUSB.IsEnabled = true;
gbOtherFunc.IsEnabled = true;
gbPrinting.IsEnabled = true;
}
private void BtDeInitUSB_Click(object sender, RoutedEventArgs e) {
private void BtDeInitUSB_Click(object sender, RoutedEventArgs e) => USBDeInit();
private void USBDeInit() {
logger.Info("De-initialising printer");
mmj.Printer.ClosePrinter();
mmj.Printer.Deinitialise();
mmj = null;
gbPrinting.IsEnabled = false;
gbOtherFunc.IsEnabled = false;
btInitUSB.IsEnabled = true;
btDeInitUSB.IsEnabled = false;
state = AppState.UnInitDev;
try {
gbPrinting.IsEnabled = false;
gbOtherFunc.IsEnabled = false;
btInitUSB.IsEnabled = true;
btDeInitUSB.IsEnabled = false;
} catch(Exception) {
} finally { }
}
private void BtFeed_Click(object sender, RoutedEventArgs e) => mmj.Feed((uint)slFeedTime.Value);
private void BtPrintText_Click(object sender, RoutedEventArgs e) {
@ -128,12 +176,13 @@ namespace paperangapp {
}
logger.Debug($"Have {img.Length} bytes of print data ({mmj.Printer.LineWidth*8}x{hSzImg}@1bpp)");
mmj.PrintBytes(iimg, false);
mmj.Feed(175);
//mmj.Feed(175);
}
static uint BitSwap1(uint x) => ((x & 0x55555555u) << 1) | ((x & (~0x55555555u)) >> 1);
static uint BitSwap2(uint x) => ((x & 0x33333333u) << 2) | ((x & (~0x33333333u)) >> 2);
static uint BitSwap4(uint x) => ((x & 0x0f0f0f0fu) << 4) | ((x & (~0x0f0f0f0fu)) >> 4);
static uint BitSwap(uint x) => BitSwap4(BitSwap2(BitSwap1(x)));
#region GDIBitmap1bpp
static Bitmap CopyToBpp(Bitmap b) {
int w=b.Width, h=b.Height;
IntPtr hbm = b.GetHbitmap();
@ -199,5 +248,6 @@ namespace paperangapp {
public uint[] cols;
}
static uint MAKERGB(int r, int g, int b) => ((uint)(b&255)) | ((uint)((r&255)<<8)) | ((uint)((g&255)<<16));
#endregion
}
}

View File

@ -7,7 +7,7 @@
<ProjectGuid>{677A8867-809E-4476-A9AE-7BEB5CE02F96}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>paperangapp</RootNamespace>
<AssemblyName>paperangapp</AssemblyName>
<AssemblyName>libpaperang-test-ui</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
@ -64,7 +64,7 @@
<GenerateManifests>true</GenerateManifests>
</PropertyGroup>
<PropertyGroup>
<SignManifests>true</SignManifests>
<SignManifests>false</SignManifests>
</PropertyGroup>
<ItemGroup>
<Reference Include="LibUsbDotNet.LibUsbDotNet, Version=2.2.0.0, Culture=neutral, PublicKeyToken=c677239abe1e02a9, processorArchitecture=MSIL">
@ -200,7 +200,6 @@
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="packages.config" />
<None Include="paperangapp_TemporaryKey.pfx" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>