New app, and correction on widgets

pull/2404/head
dapgo 2022-12-15 13:02:10 +01:00
parent af51bedb65
commit cb4534a2af
19 changed files with 212 additions and 12 deletions

View File

@ -0,0 +1 @@
0.01: 1st version: saves values to csv

View File

@ -0,0 +1,40 @@
# Temperature Monitor (with logging)
Temperature monitor that shows temperature on real time but also allows to store in a file for a later process.
Compatible with BangleJS1,BangleJS2,and EMSCRIPTENx emulators
## Pictures:
Bangle JS1
![](photo_banglejs1.jpg)
Screenshot BJS2
![](ss_emul_bjs2.png)
Screenshot BJS1
![](ss_emul_bjs1.png)
## Usage
Open and see a temperature in the screen
Download the CSV file and process in your favourite spreadsheet software
## Features
Colours, all inputs , graph, widgets loaded
Counter for Times Display
## Controls
exit: left side
## Creator
Daniel Perez

BIN
apps/tempmonitor/app.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

@ -0,0 +1,15 @@
{
"id": "tempmonitor",
"name": "Temperature monitor",
"version": "0.01",
"description": "Displays the current temperature and stores in a CSV file",
"icon": "app.png",
"tags": "tool",
"supports": ["BANGLEJS", "BANGLEJS2"],
"screenshots": [{"url":"photo_banglejs1.jpg"}],
"allow_emulator": true,
"storage": [
{"name":"tempmonitor.app.js","url":"tempmonitor.app.js"},
{"name":"tempmonitor.img","url":"tempmonitor.img","evaluate":true}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -0,0 +1,136 @@
// Temperature monitor that saves a log of measures
// Version 001 standalone for developer
// PEND
//test with small savefreq
var v_mode_debug=0; //, 0=no, 1 min, 2 prone detail
//var required for drawing with dynamic screen
var rect = Bangle.appRect;
var history = [];
var readFreq=5000; //ms //PEND add to settings
var saveFreq=30000; //ms
var v_saveToFile='Y'; //Y save //N
//with upload file º is not displayed properly
//with upload RAM º is displayed
var v_t_symbol="";//ºC
var v_saved_entries=0;
var filename ="temphistory.csv";
var lastMeasure = new String();
var v_model=process.env.BOARD;
//EMSCRIPTEN,EMSCRIPTEN2
if (v_model=='BANGLEJS'||v_model=='EMSCRIPTEN') {
v_font_size1=16;
v_font_size2=60;
//g.setColor("#0ff"); //light color
}else{
v_font_size1=10;
v_font_size2=40;
//g.setColor("#000"); //black or dark
}
function onTemperature(v_temp) {
if (v_mode_debug>1) console.log("v_temp in "+v_temp);
ClearBox();
//g.setFont("6x8",2).setFontAlign(0,0);
g.setFontVector(v_font_size1).setFontAlign(0,0);
var x = (rect.x+rect.x2)/2;
var y = (rect.y+rect.y2)/2 + 20;
g.drawString("Records:"+v_saved_entries, x, rect.y+30);
g.drawString("Temperature:", x, rect.y+35+v_font_size1);
//dynamic font (g.getWidth() > 200 ? 60 : 40)
g.setFontVector(v_font_size2).setFontAlign(0,0);
// Avg of temperature readings
while (history.length>4) history.shift();
history.push(v_temp);
var avrTemp = E.sum(history) / history.length;
//var t = require('locale').temp(avrTemp);
//.replace("'","°");
lastMeasure=avrTemp.toString();
if (lastMeasure.length>4) lastMeasure=lastMeasure.substr(0,4);
//DRAW temperature in the center
g.drawString(v_temp+v_t_symbol, x, y);
g.flip();
}
// from: BJS2 pressure sensor, BJS1 inbuilt thermistor
function drawTemperature() {
if(v_model.substr(0,10)!='EMSCRIPTEN'){
if (Bangle.getPressure) {
Bangle.getPressure().then(p =>{if (p) onTemperature(p);});
} else onTemperature(E.getTemperature());
}
else onTemperature(11);//fake temp for emulators
}
function saveToFile() {
//input global vars: lastMeasure
var a=new Date();
var strlastSaveTime=new String();
var strlastSaveTime=a.toISOString();
//strlastSaveTime=strlastSaveTime.concat(a.getFullYear(),a.getMonth()+1,a.getDate(),a.getHours(),a.getMinutes());;
if (v_mode_debug==1) console.log("saving="+strlastSaveTime+","+lastMeasure);
if (v_saveToFile=='Y'){
require("Storage").open(filename,"a").write(strlastSaveTime+","+lastMeasure+"\n");
//(getTime()+",");
v_saved_entries=v_saved_entries+1;
}
}
function drawGraph(){
var img_obj_thermo = {
width : 36, height : 36, bpp : 3,
transparent : 0,
buffer : require("heatshrink").decompress(atob("AEFt2AMKm3bsAMJjdt23ABhEB+/7tgaJ///DRUP//7tuADRP923YDRXbDRfymwaJhu/koaK7eyiwaK3cLDRlWDRY1NKBY1Ztu5kjmJg3cyVI7YMHgdu5Mkyu2fxHkyVJjdgDRFJkmRDRPsDQNbDQ5QBGoONKBJrBoxQIQwO2eRcbtu24AMIFIQLJAH4AMA=="))
};
g.drawImage(img_obj_thermo,rect.x2-50,rect.y2/2);
g.flip();
}
function ClearScreen(){
//avoid widget areas
g.reset(1).clearRect(rect.x, rect.y+24, rect.x2, rect.y2-24);
g.flip();
}
function ClearBox(){
//custom boxarea , left space for static graph at right
g.reset(1).clearRect(rect.x, rect.y+24, rect.x2-50, rect.y2-24);
g.flip();
}
function introPage(){
//g.setFont("6x8",2).setFontAlign(0,0);
g.setFontVector(v_font_size1).setFontAlign(-1,0);
//x alignment. -1=left (default), 0=center, 1=right
var x=3;
//dynamic positions as height for BJS1 is double than BJS2
var y = (rect.y+rect.y2)/2 + 10;
g.drawString(" Default values ", x, y - ((v_font_size1*3)+2));
g.drawString("--------------------", x, y - ((v_font_size1*2)+2));
g.drawString("Mode debug: "+v_mode_debug, x, y - ((v_font_size1*1)+2));
g.drawString("Read freq(ms): "+readFreq, x, y );
g.drawString("Save to file: "+v_saveToFile, x, y+ ((v_font_size1*1)+2) );
g.drawString("Save freq(ms):"+saveFreq, x, y+((v_font_size1*2)+2) );
fr=require("Storage").read(filename+"\1");//suffix required
if (fr) g.drawString("Current filesize:"+fr.length.toString()+"kb", x, y+((v_font_size1*3)+2) )
else g.drawString("File not exist", x, y+((v_font_size1*3)+2));
}
//MAIN
Bangle.loadWidgets();
Bangle.setUI({
mode : "custom",
back : function() {load();}
});
ClearScreen();
introPage();
setInterval(function() {
drawTemperature();
}, readFreq); //ms
if (v_saveToFile=="Y") {
setInterval(function() {
saveToFile();
}, saveFreq); //ms
}
setTimeout(ClearScreen, 3500);
setTimeout(drawGraph,4000);
setTimeout(drawTemperature,4500);

Binary file not shown.

View File

@ -0,0 +1 @@
{"id":"tempmonitor","name":"tempmonitor","src":"tempmonitor.app.js","icon":"tempmonitor.img","version":"0.01","files":"tempmonitor.info,tempmonitor.app.js,tempmonitor.img"}

View File

@ -43,7 +43,7 @@ Colours, font, user input, image, load widgets
- Press center area - Prints Touch3
- Swipe Left - Displays Switch OFF image
- Swipe Right - Displays Switch ON image
- BTN1 - Prints Button1
- BTN1 - Prints Button1, Down (moves selection to next row)
- BTN2 - Prints Button2
- BTN3 - Quit to Launcher

View File

@ -2,3 +2,5 @@
0.02: Modification for bottom widget area and text color
0.03: based in widclk v0.05 compatible at same time, bottom area and color
0.04: refactored to use less memory, and allow turning on/off when quick-switching apps
0.05: Different font size for bangle.js2 and bangle.js1

View File

@ -2,7 +2,7 @@
"id": "widclkbttm",
"name": "Digital clock (Bottom) widget",
"shortName": "Digital clock Bottom Widget",
"version": "0.04",
"version": "0.05",
"description": "Displays time in the bottom of the screen (may not be compatible with some apps)",
"icon": "widclkbttm.png",
"type": "widget",

View File

@ -0,0 +1 @@
{"id":"widclkbttm.wid.js","name":"Digital clock bttom widget","type":"widget","version":"0.05","files":"widclkbttm.info,widclkbttm.wid.js"}

View File

@ -1,10 +1,12 @@
WIDGETS["wdclkbttm"]={area:"br",width:Bangle.CLOCK?0:60,draw:function() {
if (!Bangle.CLOCK == !this.width) { // if we're the wrong size for if we have a clock or not...
this.width = Bangle.CLOCK?0:60;
this.width = Bangle.CLOCK?0:60;
return setTimeout(Bangle.drawWidgets,1); // widget changed size - redraw
}
if (!this.width) return; // if size not right, return
g.reset().setFont("6x8", 2).setFontAlign(-1, 0).setColor("#0ff"); // cyan
if (process.env.BOARD=='BANGLEJS'||process.env.BOARD=='EMSCRIPTEN') v_font_size=16
else v_font_size=13;
g.reset().setFontVector(v_font_size).setFontAlign(-1, 0);
var time = require("locale").time(new Date(),1);
g.drawString(time, this.x, this.y+11, true); // 5 * 6*2 = 60
// queue draw in one minute

View File

@ -1,2 +1,2 @@
0.01: 1st ver, inspired in some code from widclkbttm (Digital clock bttom widget)
0.02: Correction, intervals, dynamic color and font size depending on device

View File

@ -2,7 +2,7 @@
"id": "widhwbttm",
"name": "HW stats (Bottom) widget",
"shortName": "Digital clock Bottom Widget",
"version": "0.01",
"version": "0.02",
"description": "Displays technical info and mem stats in the bottom of the screen (may not be compatible with some apps)",
"icon": "widhwbttm.png",
"type": "widget",

View File

@ -1 +1 @@
{"id":"widhwbttm.wid.js","name":"hw stats bttom widget","type":"widget","version":"0.01","files":"widhwbttm.info,widhwbttm.wid.js"}
{"id":"widhwbttm.wid.js","name":"hw stats bttom widget","type":"widget","version":"0.02","files":"widhwbttm.info,widhwbttm.wid.js"}

View File

@ -1,7 +1,8 @@
(function() {
let intervalRef = null;
var v_switch; // show stats
if (process.env.BOARD=='BANGLEJS'||process.env.BOARD=='EMSCRIPTEN') v_font_size=16
else v_font_size=13;
if (process.env.BOARD=='BANGLEJS'||process.env.BOARD=='EMSCRIPTEN') v_font_size=15
else v_font_size=12;
var v_str_hw=new String();
if (v_switch == null || v_switch == '') v_switch=0;
function draw(){
@ -35,11 +36,12 @@
v_switch=0;
}
}
g.reset().setFontVector(v_font_size).setFontAlign(-1, 0).setColor("#0ff");
//clean a longer previous string
g.drawString(" ", this.x, this.y+11, true);
g.reset().setFontVector(v_font_size).setFontAlign(-1, 0);
//clean a longer previous string, care with br widgets
g.drawString(" ", this.x, this.y+11, true);
g.drawString(v_str_hw, this.x, this.y+11, true);
} //end draw
WIDGETS["wdhwbttm"]={area:"bl",width:Bangle.CLOCK?0:60,draw:draw};
if (Bangle.isLCDOn) intervalRef = setInterval(()=>WIDGETS["wdhwbttm"].draw(), 10*1000);
})()