Skip to content

Commit

Permalink
Pixl.js: Add Pixl.setLCDPower to allow the LCD to be powered off, mor…
Browse files Browse the repository at this point in the history
…e than halving power consumption
  • Loading branch information
gfwilliams committed Aug 30, 2018
1 parent 603add0 commit 87f2ce3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions ChangeLog
Expand Up @@ -68,6 +68,7 @@
Automatically shut down UART if both pin states are changed
Fix `setDeviceClockCmd: Unknown Device` when using `LoopbackB.setConsole()` on WiFi board
Fix non-UART serial regressions (after software serial additions)
Pixl.js: Add Pixl.setLCDPower to allow the LCD to be powered off, more than halving power consumption

1v99 : Increase jslMatch error buffer size to handle "UNFINISHED TEMPLATE LITERAL" string (#1426)
nRF5x: Make FlashWrite cope with flash writes > 4k
Expand Down
31 changes: 30 additions & 1 deletion libs/pixljs/jswrap_pixljs.c
Expand Up @@ -293,6 +293,33 @@ void jswrap_pixljs_setContrast(JsVarFloat c) {
jshPinSetValue(LCD_SPI_CS,1);
}

/*JSON{
"type" : "staticmethod",
"class" : "Pixl",
"name" : "setLCDPower",
"generate" : "jswrap_pixljs_setLCDPower",
"params" : [
["isOn","bool","True if the LCD should be on, false if not"]
]
}
This function can be used to turn Pixl.js's LCD off or on.
* With the LCD off, Pixl.js draws around 0.1mA
* With the LCD on, Pixl.js draws around 0.25mA
*/
void jswrap_pixljs_setLCDPower(bool isOn) {
jshPinSetValue(LCD_SPI_CS,0);
jshPinSetValue(LCD_SPI_DC,0);
if (isOn) {
lcd_wr(0xA4); // cancel pixel on
lcd_wr(0xAF); // display on
} else {
lcd_wr(0xAE); // display off
lcd_wr(0xA5); // all pixels on
}
jshPinSetValue(LCD_SPI_CS,1);
}

/*JSON{
"type" : "staticmethod",
"class" : "Pixl",
Expand Down Expand Up @@ -471,7 +498,8 @@ void jswrap_pixljs_init() {
};

// Create 'flip' fn
JsVar *fn = jsvNewNativeFunction((void (*)(void))lcd_flip, JSWAT_VOID|JSWAT_THIS_ARG|(JSWAT_BOOL << (JSWAT_BITS*1)));
JsVar *fn;
fn = jsvNewNativeFunction((void (*)(void))lcd_flip, JSWAT_VOID|JSWAT_THIS_ARG|(JSWAT_BOOL << (JSWAT_BITS*1)));
jsvObjectSetChildAndUnLock(graphics,"flip",fn);
// LCD init 2
jshDelayMicroseconds(10000);
Expand All @@ -486,6 +514,7 @@ void jswrap_pixljs_init() {
35, // actual contrast (0..63)
0x25, // regulation resistor ratio (0..7)
0x2F, // control power circuits - last 3 bits = VB/VR/VF
0xF8, 1, // Set boost level to 5x - draws maybe 0.04mA more, but much better blacks
0xA0, // start at column 128
0xAF // disp on
};
Expand Down
1 change: 1 addition & 0 deletions libs/pixljs/jswrap_pixljs.h
Expand Up @@ -16,6 +16,7 @@
JsVar *jswrap_pixljs_menu(JsVar *menu);
void jswrap_pixljs_lcdw(JsVarInt c);
void jswrap_pixljs_setContrast(JsVarFloat c);
void jswrap_pixljs_setLCDPower(bool isOn);

void jswrap_pixljs_init();
void jswrap_pixljs_kill();
Expand Down

0 comments on commit 87f2ce3

Please sign in to comment.