2015-04-08 15:20:10 -07:00
using MatterHackers.Agg ;
2016-05-06 17:56:27 -07:00
using MatterHackers.Agg.Image ;
2014-09-19 19:17:12 -07:00
using MatterHackers.Agg.ImageProcessing ;
using MatterHackers.Agg.PlatformAbstract ;
using MatterHackers.Agg.UI ;
using MatterHackers.Localizations ;
using MatterHackers.MatterControl.ConfigurationPage.PrintLeveling ;
using MatterHackers.MatterControl.CustomWidgets ;
using MatterHackers.MatterControl.EeProm ;
2015-04-08 15:20:10 -07:00
using MatterHackers.MatterControl.PrinterCommunication ;
using MatterHackers.MatterControl.SlicerConfiguration ;
using System ;
using System.IO ;
2014-09-19 19:17:12 -07:00
namespace MatterHackers.MatterControl.ConfigurationPage
{
2015-04-08 15:20:10 -07:00
public class HardwareSettingsWidget : SettingsViewBase
{
private Button openGcodeTerminalButton ;
private Button openCameraButton ;
2014-09-19 19:17:12 -07:00
2015-04-08 15:20:10 -07:00
private DisableableWidget eePromControlsContainer ;
private DisableableWidget terminalCommunicationsContainer ;
2014-09-23 16:11:06 -07:00
2015-04-08 15:20:10 -07:00
private event EventHandler unregisterEvents ;
2014-09-23 16:11:06 -07:00
2015-04-08 15:20:10 -07:00
public HardwareSettingsWidget ( )
2016-01-18 10:08:47 -08:00
: base ( "Hardware" . Localize ( ) )
2015-04-08 15:20:10 -07:00
{
eePromControlsContainer = new DisableableWidget ( ) ;
eePromControlsContainer . AddChild ( GetEEPromControl ( ) ) ;
terminalCommunicationsContainer = new DisableableWidget ( ) ;
2014-10-10 12:50:59 -07:00
terminalCommunicationsContainer . AddChild ( GetGcodeTerminalControl ( ) ) ;
2014-09-23 16:11:06 -07:00
2015-04-08 15:20:10 -07:00
mainContainer . AddChild ( new HorizontalLine ( separatorLineColor ) ) ;
mainContainer . AddChild ( eePromControlsContainer ) ;
2014-10-10 12:50:59 -07:00
mainContainer . AddChild ( new HorizontalLine ( separatorLineColor ) ) ;
mainContainer . AddChild ( terminalCommunicationsContainer ) ;
2015-01-11 18:32:43 -08:00
DisableableWidget cameraContainer = new DisableableWidget ( ) ;
cameraContainer . AddChild ( GetCameraControl ( ) ) ;
2014-09-19 19:17:12 -07:00
2015-01-11 18:32:43 -08:00
if ( ApplicationSettings . Instance . get ( "HardwareHasCamera" ) = = "true" )
{
mainContainer . AddChild ( new HorizontalLine ( separatorLineColor ) ) ;
mainContainer . AddChild ( cameraContainer ) ;
}
2014-09-19 19:17:12 -07:00
2015-04-08 15:20:10 -07:00
AddChild ( mainContainer ) ;
AddHandlers ( ) ;
SetVisibleControls ( ) ;
}
private TextWidget printLevelingStatusLabel ;
public override void OnClosed ( EventArgs e )
{
2016-05-11 21:27:30 -07:00
unregisterEvents ? . Invoke ( this , null ) ;
2015-04-08 15:20:10 -07:00
base . OnClosed ( e ) ;
}
2015-03-19 10:25:34 -07:00
2015-01-11 18:32:43 -08:00
private FlowLayoutWidget GetCameraControl ( )
{
FlowLayoutWidget buttonRow = new FlowLayoutWidget ( ) ;
buttonRow . HAnchor = HAnchor . ParentLeftRight ;
2015-04-08 15:20:10 -07:00
buttonRow . Margin = new BorderDouble ( 0 , 4 ) ;
2015-01-11 18:32:43 -08:00
2016-05-11 21:27:30 -07:00
ImageBuffer cameraIconImage = StaticData . Instance . LoadIcon ( "camera-24x24.png" , 24 , 24 ) . InvertLightness ( ) ;
2016-05-06 17:56:27 -07:00
cameraIconImage . SetRecieveBlender ( new BlenderPreMultBGRA ( ) ) ;
int iconSize = ( int ) ( 24 * GuiWidget . DeviceScale ) ;
2015-01-11 18:32:43 -08:00
if ( ! ActiveTheme . Instance . IsDarkTheme )
{
2016-05-10 11:12:32 -07:00
cameraIconImage . InvertLightness ( ) ;
2015-01-11 18:32:43 -08:00
}
ImageWidget cameraIcon = new ImageWidget ( cameraIconImage ) ;
2015-03-26 09:14:33 -07:00
cameraIcon . Margin = new BorderDouble ( right : 6 ) ;
2015-01-11 18:32:43 -08:00
2016-05-11 21:27:30 -07:00
TextWidget cameraLabel = new TextWidget ( "Camera Monitoring" . Localize ( ) ) ;
2015-03-26 09:14:33 -07:00
cameraLabel . AutoExpandBoundsToText = true ;
cameraLabel . TextColor = ActiveTheme . Instance . PrimaryTextColor ;
cameraLabel . VAnchor = VAnchor . ParentCenter ;
2015-01-11 18:32:43 -08:00
openCameraButton = textImageButtonFactory . Generate ( "Preview" . Localize ( ) . ToUpper ( ) ) ;
openCameraButton . Click + = new EventHandler ( openCameraPreview_Click ) ;
2015-04-08 15:20:10 -07:00
openCameraButton . Margin = new BorderDouble ( left : 6 ) ;
2015-01-11 18:32:43 -08:00
buttonRow . AddChild ( cameraIcon ) ;
2015-03-26 09:14:33 -07:00
buttonRow . AddChild ( cameraLabel ) ;
2015-01-11 18:32:43 -08:00
buttonRow . AddChild ( new HorizontalSpacer ( ) ) ;
2015-03-26 09:14:33 -07:00
buttonRow . AddChild ( openCameraButton ) ;
2015-04-08 15:20:10 -07:00
#if __ANDROID__
2015-03-26 09:14:33 -07:00
GuiWidget publishImageSwitchContainer = new FlowLayoutWidget ( ) ;
publishImageSwitchContainer . VAnchor = VAnchor . ParentCenter ;
publishImageSwitchContainer . Margin = new BorderDouble ( left : 16 ) ;
2016-06-22 14:09:19 -07:00
CheckBox toggleSwitch = ImageButtonFactory . CreateToggleSwitch ( ActiveSliceSettings . Instance . GetValue < bool > ( SettingsKey . publish_bed_image ) ) ;
2015-04-22 08:57:55 -07:00
toggleSwitch . CheckedStateChanged + = ( sender , e ) = >
2015-03-18 18:47:40 -07:00
{
2015-04-22 08:57:55 -07:00
CheckBox thisControl = sender as CheckBox ;
2016-07-19 11:31:36 -07:00
ActiveSliceSettings . Instance . SetValue ( "PublishBedImage" , thisControl . Checked ? "1" : "0" ) ;
2015-03-18 18:47:40 -07:00
} ;
2015-04-28 12:38:11 -07:00
publishImageSwitchContainer . AddChild ( toggleSwitch ) ;
2015-03-26 09:14:33 -07:00
publishImageSwitchContainer . SetBoundsToEncloseChildren ( ) ;
buttonRow . AddChild ( publishImageSwitchContainer ) ;
2015-03-18 18:47:40 -07:00
#endif
2015-01-11 18:32:43 -08:00
return buttonRow ;
}
2015-04-08 15:20:10 -07:00
private FlowLayoutWidget GetGcodeTerminalControl ( )
2014-10-10 12:50:59 -07:00
{
FlowLayoutWidget buttonRow = new FlowLayoutWidget ( ) ;
buttonRow . HAnchor = HAnchor . ParentLeftRight ;
2015-04-08 15:20:10 -07:00
buttonRow . Margin = new BorderDouble ( 0 , 4 ) ;
2014-10-10 12:50:59 -07:00
2016-05-10 11:12:32 -07:00
ImageBuffer terminalSettingsImage = StaticData . Instance . LoadIcon ( "terminal-24x24.png" , 24 , 24 ) . InvertLightness ( ) ;
2016-05-06 17:56:27 -07:00
terminalSettingsImage . SetRecieveBlender ( new BlenderPreMultBGRA ( ) ) ;
int iconSize = ( int ) ( 24 * GuiWidget . DeviceScale ) ;
2015-04-08 15:20:10 -07:00
if ( ! ActiveTheme . Instance . IsDarkTheme )
{
2016-05-10 11:12:32 -07:00
terminalSettingsImage . InvertLightness ( ) ;
2015-04-08 15:20:10 -07:00
}
2014-12-17 08:41:12 -08:00
2015-04-08 15:20:10 -07:00
ImageWidget terminalIcon = new ImageWidget ( terminalSettingsImage ) ;
terminalIcon . Margin = new BorderDouble ( right : 6 , bottom : 6 ) ;
2014-12-17 08:41:12 -08:00
2016-01-14 14:20:11 -08:00
TextWidget gcodeTerminalLabel = new TextWidget ( "G-Code Terminal" . Localize ( ) ) ;
2014-10-10 12:50:59 -07:00
gcodeTerminalLabel . AutoExpandBoundsToText = true ;
gcodeTerminalLabel . TextColor = ActiveTheme . Instance . PrimaryTextColor ;
gcodeTerminalLabel . VAnchor = VAnchor . ParentCenter ;
openGcodeTerminalButton = textImageButtonFactory . Generate ( "Show Terminal" . Localize ( ) . ToUpper ( ) ) ;
2015-08-28 17:55:50 -07:00
openGcodeTerminalButton . Name = "Show Terminal Button" ;
2014-10-24 13:41:13 -07:00
openGcodeTerminalButton . Click + = new EventHandler ( openGcodeTerminalButton_Click ) ;
2014-10-10 12:50:59 -07:00
2015-04-08 15:20:10 -07:00
buttonRow . AddChild ( terminalIcon ) ;
buttonRow . AddChild ( gcodeTerminalLabel ) ;
2014-10-10 12:50:59 -07:00
buttonRow . AddChild ( new HorizontalSpacer ( ) ) ;
buttonRow . AddChild ( openGcodeTerminalButton ) ;
return buttonRow ;
}
2015-04-08 15:20:10 -07:00
private static EePromMarlinWindow openEePromMarlinWidget = null ;
private static EePromRepetierWindow openEePromRepetierWidget = null ;
private string noEepromMappingMessage = "Oops! There is no eeprom mapping for your printer's firmware." . Localize ( ) + "\n\n" + "You may need to wait a minute for your printer to finish initializing." . Localize ( ) ;
private string noEepromMappingTitle = "Warning - No EEProm Mapping" . Localize ( ) ;
private FlowLayoutWidget GetEEPromControl ( )
{
FlowLayoutWidget buttonRow = new FlowLayoutWidget ( ) ;
buttonRow . HAnchor = HAnchor . ParentLeftRight ;
buttonRow . Margin = new BorderDouble ( 0 , 4 ) ;
2016-01-18 10:08:47 -08:00
TextWidget notificationSettingsLabel = new TextWidget ( "EEProm" . Localize ( ) ) ;
2015-04-08 15:20:10 -07:00
notificationSettingsLabel . AutoExpandBoundsToText = true ;
notificationSettingsLabel . TextColor = ActiveTheme . Instance . PrimaryTextColor ;
notificationSettingsLabel . VAnchor = VAnchor . ParentCenter ;
2016-05-07 17:18:05 -07:00
ImageBuffer levelingImage = StaticData . Instance . LoadIcon ( "leveling_32x32.png" , 24 , 24 ) ;
2016-05-06 17:56:27 -07:00
2015-04-08 15:20:10 -07:00
if ( ! ActiveTheme . Instance . IsDarkTheme )
{
2016-05-10 11:12:32 -07:00
levelingImage . InvertLightness ( ) ;
2015-04-08 15:20:10 -07:00
}
2016-05-06 17:56:27 -07:00
ImageWidget levelingIcon = new ImageWidget ( levelingImage ) ;
levelingIcon . Margin = new BorderDouble ( right : 6 ) ;
2015-04-08 15:20:10 -07:00
Button configureEePromButton = textImageButtonFactory . Generate ( "Configure" . Localize ( ) . ToUpper ( ) ) ;
2015-02-20 12:05:44 -08:00
configureEePromButton . Click + = new EventHandler ( configureEePromButton_Click ) ;
2015-04-08 15:20:10 -07:00
//buttonRow.AddChild(eePromIcon);
buttonRow . AddChild ( notificationSettingsLabel ) ;
buttonRow . AddChild ( new HorizontalSpacer ( ) ) ;
buttonRow . AddChild ( configureEePromButton ) ;
return buttonRow ;
}
private void AddHandlers ( )
{
PrinterConnectionAndCommunication . Instance . CommunicationStateChanged . RegisterEvent ( onPrinterStatusChanged , ref unregisterEvents ) ;
PrinterConnectionAndCommunication . Instance . EnableChanged . RegisterEvent ( onPrinterStatusChanged , ref unregisterEvents ) ;
}
private void openCameraPreview_Click ( object sender , EventArgs e )
2015-01-11 18:32:43 -08:00
{
2015-01-13 10:56:20 -08:00
MatterControlApplication . Instance . OpenCameraPreview ( ) ;
2015-01-11 18:32:43 -08:00
}
2015-04-08 15:20:10 -07:00
private void configureEePromButton_Click ( object sender , EventArgs mouseEvent )
{
2015-06-11 12:06:40 -07:00
UiThread . RunOnIdle ( ( ) = >
2015-04-08 15:20:10 -07:00
{
2014-09-23 16:11:06 -07:00
#if false // This is to force the creation of the repetier window for testing when we don't have repetier firmware.
new MatterHackers . MatterControl . EeProm . EePromRepetierWidget ( ) ;
#else
2015-04-08 15:20:10 -07:00
switch ( PrinterConnectionAndCommunication . Instance . FirmwareType )
{
case PrinterConnectionAndCommunication . FirmwareTypes . Repetier :
if ( openEePromRepetierWidget ! = null )
{
openEePromRepetierWidget . BringToFront ( ) ;
}
else
{
openEePromRepetierWidget = new EePromRepetierWindow ( ) ;
openEePromRepetierWidget . Closed + = ( RepetierWidget , RepetierEvent ) = >
{
openEePromRepetierWidget = null ;
} ;
}
break ;
case PrinterConnectionAndCommunication . FirmwareTypes . Marlin :
if ( openEePromMarlinWidget ! = null )
{
openEePromMarlinWidget . BringToFront ( ) ;
}
else
{
openEePromMarlinWidget = new EePromMarlinWindow ( ) ;
openEePromMarlinWidget . Closed + = ( marlinWidget , marlinEvent ) = >
{
openEePromMarlinWidget = null ;
} ;
}
break ;
default :
StyledMessageBox . ShowMessageBox ( null , noEepromMappingMessage , noEepromMappingTitle , StyledMessageBox . MessageType . OK ) ;
break ;
}
2014-09-23 16:11:06 -07:00
#endif
2015-04-08 15:20:10 -07:00
} ) ;
}
private void openGcodeTerminalButton_Click ( object sender , EventArgs mouseEvent )
2014-10-10 12:50:59 -07:00
{
2015-06-11 12:06:40 -07:00
UiThread . RunOnIdle ( TerminalWindow . Show ) ;
2014-10-10 12:50:59 -07:00
}
2015-04-08 15:20:10 -07:00
private void onPrinterStatusChanged ( object sender , EventArgs e )
{
SetVisibleControls ( ) ;
this . Invalidate ( ) ;
}
private void SetVisibleControls ( )
{
2016-07-21 15:05:59 -07:00
if ( ! ActiveSliceSettings . Instance . PrinterSelected )
2015-04-08 15:20:10 -07:00
{
// no printer selected
eePromControlsContainer . SetEnableLevel ( DisableableWidget . EnableLevel . Disabled ) ;
terminalCommunicationsContainer . SetEnableLevel ( DisableableWidget . EnableLevel . Enabled ) ;
//cloudMonitorContainer.SetEnableLevel(DisableableWidget.EnableLevel.Disabled);
}
else // we at least have a printer selected
{
//cloudMonitorContainer.SetEnableLevel(DisableableWidget.EnableLevel.Enabled);
switch ( PrinterConnectionAndCommunication . Instance . CommunicationState )
{
case PrinterConnectionAndCommunication . CommunicationStates . Disconnecting :
case PrinterConnectionAndCommunication . CommunicationStates . ConnectionLost :
case PrinterConnectionAndCommunication . CommunicationStates . Disconnected :
case PrinterConnectionAndCommunication . CommunicationStates . AttemptingToConnect :
case PrinterConnectionAndCommunication . CommunicationStates . FailedToConnect :
eePromControlsContainer . SetEnableLevel ( DisableableWidget . EnableLevel . Disabled ) ;
terminalCommunicationsContainer . SetEnableLevel ( DisableableWidget . EnableLevel . Enabled ) ;
break ;
case PrinterConnectionAndCommunication . CommunicationStates . FinishedPrint :
case PrinterConnectionAndCommunication . CommunicationStates . Connected :
eePromControlsContainer . SetEnableLevel ( DisableableWidget . EnableLevel . Enabled ) ;
terminalCommunicationsContainer . SetEnableLevel ( DisableableWidget . EnableLevel . Enabled ) ;
break ;
case PrinterConnectionAndCommunication . CommunicationStates . PrintingFromSd :
eePromControlsContainer . SetEnableLevel ( DisableableWidget . EnableLevel . Disabled ) ;
terminalCommunicationsContainer . SetEnableLevel ( DisableableWidget . EnableLevel . Enabled ) ;
break ;
case PrinterConnectionAndCommunication . CommunicationStates . PreparingToPrint :
case PrinterConnectionAndCommunication . CommunicationStates . Printing :
switch ( PrinterConnectionAndCommunication . Instance . PrintingState )
{
case PrinterConnectionAndCommunication . DetailedPrintingState . HomingAxis :
case PrinterConnectionAndCommunication . DetailedPrintingState . HeatingBed :
case PrinterConnectionAndCommunication . DetailedPrintingState . HeatingExtruder :
case PrinterConnectionAndCommunication . DetailedPrintingState . Printing :
eePromControlsContainer . SetEnableLevel ( DisableableWidget . EnableLevel . Disabled ) ;
terminalCommunicationsContainer . SetEnableLevel ( DisableableWidget . EnableLevel . Enabled ) ;
break ;
default :
throw new NotImplementedException ( ) ;
}
break ;
case PrinterConnectionAndCommunication . CommunicationStates . Paused :
eePromControlsContainer . SetEnableLevel ( DisableableWidget . EnableLevel . Enabled ) ;
terminalCommunicationsContainer . SetEnableLevel ( DisableableWidget . EnableLevel . Enabled ) ;
break ;
default :
throw new NotImplementedException ( ) ;
}
}
}
}
2014-09-19 19:17:12 -07:00
}