make sure we don't sleep when printing
This commit is contained in:
parent
c023f6b865
commit
a6fbfa9cd7
3 changed files with 43 additions and 5 deletions
|
|
@ -47,7 +47,7 @@ namespace MatterHackers.MatterControl
|
|||
|
||||
public void TakePhoto(string imageFileName)
|
||||
{
|
||||
ImageBuffer noCameraImage = new ImageBuffer(640, 480);
|
||||
var noCameraImage = new ImageBuffer(640, 480);
|
||||
Graphics2D graphics = noCameraImage.NewGraphics2D();
|
||||
graphics.Clear(Color.White);
|
||||
graphics.DrawString("No Camera Detected", 320, 240, pointSize: 24, justification: Agg.Font.Justification.Center);
|
||||
|
|
@ -59,14 +59,14 @@ namespace MatterHackers.MatterControl
|
|||
|
||||
public void OpenCameraPreview()
|
||||
{
|
||||
//Camera launcher placeholder (KP)
|
||||
// Camera launcher placeholder (KP)
|
||||
if (ApplicationSettings.Instance.get(ApplicationSettingsKey.HardwareHasCamera) == "true")
|
||||
{
|
||||
//Do something
|
||||
// Do something
|
||||
}
|
||||
else
|
||||
{
|
||||
//Do something else (like show warning message)
|
||||
// Do something else (like show warning message)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -76,7 +76,7 @@ namespace MatterHackers.MatterControl
|
|||
{
|
||||
using (var mediaStream = StaticData.Instance.OpenStream(Path.Combine("Sounds", fileName)))
|
||||
{
|
||||
(new System.Media.SoundPlayer(mediaStream)).Play();
|
||||
new System.Media.SoundPlayer(mediaStream).Play();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1978,6 +1978,7 @@ namespace MatterHackers.MatterControl
|
|||
}
|
||||
|
||||
public bool Allow32BitReSlice { get; set; }
|
||||
public Action<bool> KeepAwake { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Archives MCX and validates GCode results before starting a print operation
|
||||
|
|
@ -2233,8 +2234,14 @@ namespace MatterHackers.MatterControl
|
|||
UiThread.RunOnIdle(() => this.ShellFileOpened?.Invoke(this, file));
|
||||
}
|
||||
|
||||
private void KeepAwakeIfNeeded()
|
||||
{
|
||||
KeepAwake?.Invoke(AnyPrintTaskRunning);
|
||||
}
|
||||
|
||||
public void Connection_PrintStarted(object sender, EventArgs e)
|
||||
{
|
||||
KeepAwakeIfNeeded();
|
||||
AnyPrintStarted?.Invoke(sender, e);
|
||||
}
|
||||
|
||||
|
|
@ -2248,6 +2255,7 @@ namespace MatterHackers.MatterControl
|
|||
printHistoryEditor.CollectInfoPrintFinished();
|
||||
}
|
||||
|
||||
KeepAwakeIfNeeded();
|
||||
AnyPrintComplete?.Invoke(sender, null);
|
||||
}
|
||||
|
||||
|
|
@ -2261,6 +2269,7 @@ namespace MatterHackers.MatterControl
|
|||
printHistoryEditor.CollectInfoPrintCanceled();
|
||||
}
|
||||
|
||||
KeepAwakeIfNeeded();
|
||||
AnyPrintCanceled?.Invoke(sender, e);
|
||||
}
|
||||
|
||||
|
|
|
|||
29
Program.cs
29
Program.cs
|
|
@ -50,6 +50,20 @@ namespace MatterHackers.MatterControl
|
|||
{
|
||||
public class Program
|
||||
{
|
||||
[FlagsAttribute]
|
||||
public enum EXECUTION_STATE : uint
|
||||
{
|
||||
ES_AWAYMODE_REQUIRED = 0x00000040,
|
||||
ES_CONTINUOUS = 0x80000000,
|
||||
ES_DISPLAY_REQUIRED = 0x00000002,
|
||||
ES_SYSTEM_REQUIRED = 0x00000001
|
||||
// Legacy flag, should not be used.
|
||||
// ES_USER_PRESENT = 0x00000004
|
||||
}
|
||||
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags);
|
||||
|
||||
private static EventWaitHandle waitHandle;
|
||||
|
||||
private const int RaygunMaxNotifications = 15;
|
||||
|
|
@ -242,6 +256,8 @@ namespace MatterHackers.MatterControl
|
|||
theme.TabBarBackground,
|
||||
new Color(theme.PrimaryAccentColor, 175));
|
||||
|
||||
ApplicationController.Instance.KeepAwake = KeepAwake;
|
||||
|
||||
systemWindow.ShowAsSystemWindow();
|
||||
}
|
||||
|
||||
|
|
@ -249,6 +265,19 @@ namespace MatterHackers.MatterControl
|
|||
|
||||
private static readonly object locker = new object();
|
||||
|
||||
static void KeepAwake(bool keepAwake)
|
||||
{
|
||||
if (keepAwake)
|
||||
{
|
||||
// Prevent Idle-to-Sleep
|
||||
SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS | EXECUTION_STATE.ES_DISPLAY_REQUIRED);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS);
|
||||
}
|
||||
}
|
||||
|
||||
public class LocalService : IMainService
|
||||
{
|
||||
public void ShellOpenFile(string[] files)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue