refactoring

This commit is contained in:
Gordon Williams 2018-02-05 11:55:12 +00:00
parent c6476a34f7
commit db128c19f8
3 changed files with 47 additions and 48 deletions

View File

@ -16,15 +16,15 @@
import pinutils;
info = {
'name' : "JSLCD",
'link' : [ "" ],
'name' : "Pixl.js",
'link' : [ "http://www.espruino.com/Pixl.js" ],
'default_console' : "EV_SERIAL1",
'default_console_tx' : "D1",
'default_console_rx' : "D0",
'default_console_baudrate' : "9600",
'variables' : 2500, # How many variables are allocated for Espruino to use. RAM will be overflowed if this number is too high and code won't compile.
'bootloader' : 1,
'binary_name' : 'espruino_%v_jslcd.bin',
'binary_name' : 'espruino_%v_pixljs.bin',
'build' : {
'optimizeflags' : '-Os',
'libraries' : [
@ -33,15 +33,15 @@ info = {
'GRAPHICS',
'NFC',
'NEOPIXEL',
'JSLCD'
'PIXLJS'
],
'makefile' : [
'DEFINES+=-DHAL_NFC_ENGINEERING_BC_FTPAN_WORKAROUND=1', # Looks like proper production nRF52s had this issue
'DEFINES+=-DBLUETOOTH_NAME_PREFIX=\'"JSLCD"\'',
'DEFINES+=-DBLUETOOTH_NAME_PREFIX=\'"Pixl.js"\'',
'DFU_PRIVATE_KEY=targets/nrf5x_dfu/dfu_private_key.pem',
'DFU_SETTINGS=--application-version 0xff --hw-version 52 --sd-req 0x8C',
'INCLUDE += -I$(ROOT)/libs/jslcd',
'WRAPPERSOURCES += libs/jslcd/jswrap_jslcd.c'
'INCLUDE += -I$(ROOT)/libs/pixljs',
'WRAPPERSOURCES += libs/pixljs/jswrap_pixljs.c'
]
}
};

View File

@ -10,13 +10,11 @@
* ----------------------------------------------------------------------------
* This file is designed to be parsed during the build process
*
* Contains JavaScript interface for the hexagonal Espruino badge
* Contains JavaScript interface for Pixl.js (http://www.espruino.com/Pixl.js)
* ----------------------------------------------------------------------------
*/
/* DO_NOT_INCLUDE_IN_DOCS - this is a special token for common.py */
#include <jswrap_jslcd.h>
#include <jswrap_pixljs.h>
#include "jsinteractive.h"
#include "jsdevices.h"
#include "jsnative.h"
@ -40,22 +38,22 @@ const Pin LCD_MOSI = JSH_PORTH_OFFSET+9;
/*JSON{
"type": "class",
"class" : "LCD"
"class" : "Pixl"
}
Class containing utility functions for accessing IO on the hexagonal badge
Class containing utility functions for [Pixl.js](http://www.espruino.com/Pixl.js)
*/
/*JSON{
"type" : "staticmethod",
"class" : "LCD",
"class" : "Pixl",
"name" : "getBatteryPercentage",
"generate" : "jswrap_jslcd_getBatteryPercentage",
"generate" : "jswrap_pixljs_getBatteryPercentage",
"return" : ["int", "A percentage between 0 and 100" ]
}
Return an approximate battery percentage remaining based on
a normal CR2032 battery (2.8 - 2.2v)
*/
int jswrap_jslcd_getBatteryPercentage() {
int jswrap_pixljs_getBatteryPercentage() {
JsVarFloat v = jswrap_nrf_bluetooth_getBattery();
int pc = (v-2.2)*100/0.6;
if (pc>100) pc=100;
@ -65,16 +63,17 @@ int jswrap_jslcd_getBatteryPercentage() {
void badge_lcd_wr(int data) {
void lcd_wr(int data) {
int bit;
for (bit=7;bit>=0;bit--) {
// TODO: we could push this faster by accessing IO directly
jshPinSetValue(LCD_MOSI, (data>>bit)&1 );
jshPinSetValue(LCD_SCK, 1 );
jshPinSetValue(LCD_SCK, 0 );
}
}
void badge_lcd_flip(JsVar *g) {
void lcd_flip(JsVar *g) {
JsVar *buf = jsvObjectGetChild(g,"buffer",0);
if (!buf) return;
JSV_GET_AS_CHAR_ARRAY(bPtr, bLen, buf);
@ -83,12 +82,12 @@ void badge_lcd_flip(JsVar *g) {
jshPinSetValue(LCD_CS,0);
for (int y=0;y<8;y++) {
jshPinSetValue(LCD_DC,0);
badge_lcd_wr(0xB0|y/* page */);
badge_lcd_wr(0x00/* x lower*/);
badge_lcd_wr(0x10/* x upper*/);
lcd_wr(0xB0|y/* page */);
lcd_wr(0x00/* x lower*/);
lcd_wr(0x10/* x upper*/);
jshPinSetValue(LCD_DC,1);
for (int x=0;x<128;x++)
badge_lcd_wr(*(bPtr++));
lcd_wr(*(bPtr++));
}
jshPinSetValue(LCD_CS,1);
jsvUnLock(buf);
@ -97,47 +96,47 @@ void badge_lcd_flip(JsVar *g) {
/*JSON{
"type" : "staticmethod",
"class" : "LCD",
"class" : "Pixl",
"name" : "setContrast",
"generate" : "jswrap_jslcd_setContrast",
"generate" : "jswrap_pixljs_setContrast",
"params" : [
["c","float","Contrast between 0 and 1"]
]
}
Set the LCD's contrast */
void jswrap_jslcd_setContrast(JsVarFloat c) {
void jswrap_pixljs_setContrast(JsVarFloat c) {
if (c<0) c=0;
if (c>1) c=1;
jshPinSetValue(LCD_CS,0);
jshPinSetValue(LCD_DC,0);
badge_lcd_wr(0x81);
badge_lcd_wr((int)(63*c));
//badge_lcd_wr(0x20|div); div = 0..7
lcd_wr(0x81);
lcd_wr((int)(63*c));
//lcd_wr(0x20|div); div = 0..7
jshPinSetValue(LCD_CS,1);
}
/*JSON{
"type" : "staticmethod",
"class" : "LCD",
"class" : "Pixl",
"name" : "lcdw",
"generate" : "jswrap_jslcd_lcdw",
"generate" : "jswrap_pixljs_lcdw",
"params" : [
["c","int",""]
]
}
Set the LCD's contrast */
void jswrap_jslcd_lcdw(JsVarInt c) {
void jswrap_pixljs_lcdw(JsVarInt c) {
jshPinSetValue(LCD_CS,0);
jshPinSetValue(LCD_DC,0);
badge_lcd_wr(c);
lcd_wr(c);
jshPinSetValue(LCD_CS,1);
}
/*JSON{
"type" : "init",
"generate" : "jswrap_jslcd_init"
"generate" : "jswrap_pixljs_init"
}*/
void jswrap_jslcd_init() {
void jswrap_pixljs_init() {
// LCD Init 1
jshPinOutput(LCD_CS,0);
jshPinOutput(LCD_DC,0);
@ -180,7 +179,7 @@ void jswrap_jslcd_init() {
if (bPtr) memcpy(&bPtr[LCD_IMIT_IMG_OFFSET], LCD_INIT_IMG, sizeof(LCD_INIT_IMG));
jsvUnLock(buf);
// Create 'flip' fn
JsVar *fn = jsvNewNativeFunction((void (*)(void))badge_lcd_flip, JSWAT_VOID|JSWAT_THIS_ARG);
JsVar *fn = jsvNewNativeFunction((void (*)(void))lcd_flip, JSWAT_VOID|JSWAT_THIS_ARG);
jsvObjectSetChildAndUnLock(graphics,"flip",fn);
// LCD init 2
jshDelayMicroseconds(10000);
@ -198,25 +197,25 @@ void jswrap_jslcd_init() {
0xAF // disp on
};
for (unsigned int i=0;i<sizeof(LCD_INIT_DATA);i++)
badge_lcd_wr(LCD_INIT_DATA[i]);
lcd_wr(LCD_INIT_DATA[i]);
jshPinSetValue(LCD_CS,1);
// actually flip the LCD contents
badge_lcd_flip(graphics);
lcd_flip(graphics);
jsvUnLock(graphics);
}
/*JSON{
"type" : "kill",
"generate" : "jswrap_jslcd_kill"
"generate" : "jswrap_pixljs_kill"
}*/
void jswrap_jslcd_kill() {
void jswrap_pixljs_kill() {
}
/*JSON{
"type" : "idle",
"generate" : "jswrap_jslcd_idle"
"generate" : "jswrap_pixljs_idle"
}*/
bool jswrap_jslcd_idle() {
bool jswrap_pixljs_idle() {
return false;
}

View File

@ -8,15 +8,15 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* ----------------------------------------------------------------------------
* Contains JavaScript interface for the hexagonal Espruino badge
* Contains JavaScript interface for Pixl.js (http://www.espruino.com/Pixl.js)
* ----------------------------------------------------------------------------
*/
#include "jspin.h"
int jswrap_jslcd_getBatteryPercentage();
void jswrap_jslcd_lcdw(JsVarInt c);
void jswrap_jslcd_setContrast(JsVarFloat c);
int jswrap_pixljs_getBatteryPercentage();
void jswrap_pixljs_lcdw(JsVarInt c);
void jswrap_pixljs_setContrast(JsVarFloat c);
void jswrap_jslcd_init();
void jswrap_jslcd_kill();
bool jswrap_jslcd_idle();
void jswrap_pixljs_init();
void jswrap_pixljs_kill();
bool jswrap_pixljs_idle();