-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
6 changed files
with
57 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,36 @@ | ||
#include "CaseLightControl.h" | ||
#include "includes.h" | ||
|
||
static uint8_t caseLightBrightness = 0; | ||
static uint8_t lastCaseLightBrightness = 0; | ||
static bool lastCaseLightState = true; | ||
static bool caseLightState = true; | ||
static uint8_t caseLightBrightness = 0; | ||
|
||
static bool lightQueryWait = false; | ||
static bool caseLight_applied = false; | ||
|
||
// Sends a query (M355) to the printer asking for the current brightness | ||
void caseLightValueQuery(void) | ||
bool caseLightGetState(void) | ||
{ | ||
if (infoMachineSettings.caseLightsBrightness == ENABLED && infoHost.connected && | ||
!infoHost.wait && !lightQueryWait) | ||
{ | ||
lightQueryWait = storeCmd("M355\n"); | ||
} | ||
return caseLightState; | ||
} | ||
|
||
void caseLightSetState(bool state) | ||
{ | ||
caseLightState = state; | ||
} | ||
|
||
void caseLightSetBrightness(uint8_t brightness) | ||
{ | ||
caseLightBrightness = NOBEYOND(0, brightness, 255); | ||
} | ||
|
||
void caseLightChangeBrightness(int8_t brightness_delta) | ||
{ | ||
caseLightBrightness = NOBEYOND(0, caseLightBrightness + brightness_delta, 255); | ||
} | ||
|
||
void caseLightChangeBrightnessPrecent(int8_t brightness_delta_percent) | ||
{ | ||
brightness_delta_percent = NOBEYOND(-100, brightness_delta_percent, 100); | ||
caseLightBrightness = NOBEYOND(0, (caseLightGetBrightnessPercent() + brightness_delta_percent) * 255 / 100.0f, 255); | ||
} | ||
|
||
void caseLightQuerySetWait(bool wait) | ||
{ | ||
lightQueryWait = wait; | ||
} | ||
|
||
uint8_t caseLightGetBrightness(void) | ||
{ | ||
return caseLightBrightness; | ||
} | ||
|
||
uint8_t caseLightGetBrightnessPercent(void) | ||
{ | ||
return (caseLightBrightness * 100.0f) / 255 + 0.5f; | ||
} | ||
|
||
bool caseLightGetState(void) | ||
void caseLightSetBrightness(uint8_t brightness) | ||
{ | ||
return caseLightState; | ||
caseLightBrightness = NOBEYOND(0, brightness, 255); | ||
} | ||
|
||
void caseLightApplied(bool applied) | ||
uint8_t caseLightGetBrightnessPercent(void) | ||
{ | ||
caseLight_applied = applied; | ||
return (caseLightBrightness * 100.0f) / 255 + 0.5f; | ||
} | ||
|
||
void loopCaseLight(void) | ||
void caseLightSetBrightnessPercent(int8_t unit) | ||
{ | ||
if (lastCaseLightBrightness != caseLightBrightness || lastCaseLightState != caseLightState) | ||
{ | ||
if (caseLight_applied == false) | ||
{ | ||
caseLight_applied = storeCmd("M355 S%d P%d\n", caseLightState ? 1 : 0, caseLightBrightness); | ||
} | ||
|
||
if (caseLight_applied == true) | ||
{ | ||
lastCaseLightBrightness = caseLightBrightness; | ||
lastCaseLightState = caseLightState; | ||
caseLight_applied = false; | ||
} | ||
} | ||
unit = NOBEYOND(-100, unit, 100); | ||
caseLightBrightness = NOBEYOND(0, (caseLightGetBrightnessPercent() + unit) * 255 / 100.0f, 255); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -978,7 +978,6 @@ void sendQueueCmd(void) | |
{ | ||
caseLightSetBrightness(cmd_value()); | ||
} | ||
caseLightApplied(true); | ||
break; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters