messagesoverlay - Replace low memory limit with better automatic predictions
parent
5d66cd26ed
commit
907cc5c35b
|
|
@ -8,18 +8,20 @@ Messages are ephemeral and not stored on the Bangle.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Close app by tapping the X and scroll by swiping. The border of the pop up changes color if the Bangle is locked. The color depends on your currently active theme.
|
Close app by tapping the X and scroll by swiping. The title background of the pop up changes color if the Bangle is locked. The color depends on your currently active theme.
|
||||||
|
|
||||||
## Theme support
|
## Theme support
|
||||||
|
|
||||||
Using the system theme needs more RAM since it uses a 16 bit color buffer for normal message display. Selecting the "low RAM" theme reduces that to a 4 bit buffer.
|
Using the system theme needs more RAM since it uses a 16 bit color buffer for normal message display. Selecting the "low RAM" theme reduces that to a 4 bit buffer.
|
||||||
|
16 bit buffer with a small message takes ~4K RAM blocks while 4 bit buffer only needs about 1.5K.
|
||||||
|
|
||||||
## Low memory mode
|
## Low memory mode
|
||||||
|
|
||||||
If free memory is below a configured number of blocks (default is 4000), the overlay automatically only uses 1 bit depth. Default mode uses roundabout 1300 blocks, while low memory mode uses about 600.
|
If the overlay estimates that showing the next message would get under the configured minimum free memory limit it automatically only tries to use 1 bit depth. Low memory mode uses about 0.8K blocks plus memory needed for messages. If dropping to 1 bit depth is not enough the oldest messages are discarded to keep the overlay working.
|
||||||
|
|
||||||
## Creator
|
## Creator
|
||||||
|
|
||||||
[halemmerich](https://github.com/halemmerich)
|
[halemmerich](https://github.com/halemmerich)
|
||||||
|
|
||||||
Forked from messages_light by Rarder44
|
Forked from messages_light by Rarder44
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,5 @@
|
||||||
"autoclear": 30,
|
"autoclear": 30,
|
||||||
"border": 10,
|
"border": 10,
|
||||||
"minfreemem": 2,
|
"minfreemem": 2,
|
||||||
"lowmem": 4,
|
|
||||||
"systemTheme": true
|
"systemTheme": true
|
||||||
}
|
}
|
||||||
|
|
@ -669,11 +669,37 @@ exports.message = function(type, event) {
|
||||||
if(event.handled) return;
|
if(event.handled) return;
|
||||||
if(event.messagesoverlayignore) return;
|
if(event.messagesoverlayignore) return;
|
||||||
|
|
||||||
|
let free = process.memory().free;
|
||||||
bpp = settings.systemTheme ? 16 : 4;
|
bpp = settings.systemTheme ? 16 : 4;
|
||||||
if (process.memory().free < settings.lowmem)
|
|
||||||
bpp = 1;
|
|
||||||
|
|
||||||
while (process.memory().free < settings.minfreemem && eventQueue.length > 0){
|
let estimatedMemUse = bpp == 16 ? 4096 : (bpp == 4 ? 1536 : 768);
|
||||||
|
// reduce estimation if ovr already exists and uses memory;
|
||||||
|
if (ovr)
|
||||||
|
estimatedMemUse -= ovr.getBPP() == 16 ? 4096 : (ovr.getBPP() == 4 ? 1536 : 768);
|
||||||
|
|
||||||
|
if (process.memory().free - estimatedMemUse < settings.minfreemem * 1024) {
|
||||||
|
// we are going to be under our minfreemem setting if we proceed
|
||||||
|
bpp = 1;
|
||||||
|
if (ovr && ovr.getBPP() > 1){
|
||||||
|
// can reduce memory by going 1 bit
|
||||||
|
let saves = ovr.getBPP() == 16 ? 4096 - 768 : 768;
|
||||||
|
estimatedMemUse -= saves;
|
||||||
|
LOG("Go to 1 bit, saving", saves);
|
||||||
|
} else {
|
||||||
|
estimatedMemUse = 768;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (E.getSizeOf){
|
||||||
|
let e = E.getSizeOf(eventQueue);
|
||||||
|
estimatedMemUse += e;
|
||||||
|
LOG("EventQueue has", e, "blocks");
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG("Free ", free, "estimated use", estimatedMemUse, "for", bpp, "BPP");
|
||||||
|
|
||||||
|
while (process.memory().free - estimatedMemUse < settings.minfreemem * 1024 && eventQueue.length > 0){
|
||||||
const dropped = eventQueue.pop();
|
const dropped = eventQueue.pop();
|
||||||
print("Dropped message because of memory constraints", dropped);
|
print("Dropped message because of memory constraints", dropped);
|
||||||
}
|
}
|
||||||
|
|
@ -682,6 +708,8 @@ exports.message = function(type, event) {
|
||||||
ovr = Graphics.createArrayBuffer(ovrw, ovrh, bpp, {
|
ovr = Graphics.createArrayBuffer(ovrw, ovrh, bpp, {
|
||||||
msb: true
|
msb: true
|
||||||
});
|
});
|
||||||
|
if(E.getSizeOf)
|
||||||
|
LOG("New overlay uses", E.getSizeOf(ovr), "blocks");
|
||||||
}
|
}
|
||||||
|
|
||||||
ovr.reset();
|
ovr.reset();
|
||||||
|
|
@ -713,4 +741,5 @@ exports.message = function(type, event) {
|
||||||
|
|
||||||
if (!isQuiet()) Bangle.setLCDPower(1);
|
if (!isQuiet()) Bangle.setLCDPower(1);
|
||||||
event.handled = true;
|
event.handled = true;
|
||||||
|
g.flip();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -57,16 +57,6 @@
|
||||||
onchange: v => {
|
onchange: v => {
|
||||||
writeSettings("minfreemem",v);
|
writeSettings("minfreemem",v);
|
||||||
}
|
}
|
||||||
},
|
|
||||||
'Low RAM mode': {
|
|
||||||
value: settings.lowmem,
|
|
||||||
min: 0,
|
|
||||||
max: process.memory().total/1000,
|
|
||||||
step: 1,
|
|
||||||
format: v=>v + "k free",
|
|
||||||
onchange: v => {
|
|
||||||
writeSettings("lowmem",v);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return mainmenu;
|
return mainmenu;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue