-
Hi Gordon,
I did a fresh factory reset after downgrading to 2V19 so everything is freshly installed from the app store with minify apps turned off. My main issue was weird behaviour I described above with the launcher not working and the Anton clock acting like an app instead of a watchface. Maybe something weird happened during flashing but the checksum was okay so I am not sure what happened.
I'll do an upgrade to 2v21 now and let you know. -
I've just upgraded from version 2V18 and I've had a lot of issues with 2V20.
First I had to do a factory reset to get it to work after updating as the app manager couldn't communicate with the watch anymore.
After the factory reset I can't seem to access the launcher at all (Anton clock) and the clock widget showed up that shows up when you run an app. Strange stuff.
So I've downgraded to 2V19 and did another factory reset and stuff seems to work again.
Not sure what changed in 2V20 but somethings are really messed up.
Anyone else have similar issues? -
-
@glemco thank you. I don't have much free time but I'll have a look when I have time.
-
I was actually not aware of the Cards app. Yeah, would be cool to have it all in one place.
@glemco 's code seems to follow similar principles. I take a bit more advantage of the checksum for error checking, thus allowing for "bad" scaling but otherwise pretty similar. -
Okay. I had a bit of time today so I added the code 128 support.
You can find the code here: https://github.com/Akisame-AI/Bangle-js-2-Barcode
Next time I have some time to kill I'll create a settings page where you can add your barcodes.
Todo:
support Bangle 1
Make it actually usable (allow switching of barcodes)
Settings page
Scaling of everything
Display name of barcodesThe code is a bit long (12.8 kb, 295 lines of code) and can probably be optimized further.
For Code-128 the max length varies based on how many times you switch between codeset. If you only use numbers you can fit 24 characters (since every 2 numbers is 1 set), If you only use letters and symbols you can fit 12 characters. Every switch between the two codesets will cost you a character. If you go below 4 sets (so 8 numbers or 4 characters) it will automatically scale up. -
@MaBe yeah, EAN is actually quite clever in its error correction with the L, G and R encoding.
The barcodes used differs per country. In Europe you need EAN-13, EAN-8, code 39, code 128 or a QR code. In my and my wife's wallet I found mainly code 128 and EAN-13 cards.
Code 128 and 39 are usually only numbers with rarely an asterisk symbol in there so the look up table should be doable. Still big though with 106 unique items.
Longest code 128 I was able to find was 19 characters in 128C. That should fit on the bangle 2 but it will be small as there isn't any option to scale it
The smallest code 128 I found is 11 symbols and can also not be scaled.
Hmm. I will have to do a field test to see if the scanners are able to scan these tiny code 128 barcodes.
If they can then there's no issue. -
@Ganblejs yes. Bangle 1 has AA support. I thought bangle 2 doesn't.
@MaBe qrcode only does qrcodes right? The goal is to be able to emulate loyalty cards, employee cards and other barcode systems that required you to carry barcodes with you.
I have a set of 6 cards that I used to carry in my pebble.
So far EAN-13 works but it requires the build in error checking to do so. This is because the scaling can't be 1:1 with the resolution of the bangle 2. It works perfectly on the bangle 1 though without using the error checking. -
-
Thanks. I see he's taking the pre-generated image approach. With the bangle js 2's resolution I foresee issues with misinterpreting the R encoded portion for EAN-13 barcodes.
But I don't see anything new on this topic from him since 2 years ago when he was working on a code 128 barcode generator for the Bangle 1. I don't think we can get code 128 working on the Bangle 2 with the resolution it provides and the decreased error correcting bit. -
So, I've been working for the last 15-20 minutes on a barcode displayer for the Bangle JS 2 (since my pebble died and I miss the Skunk app). I've started with implementing EAN-13 barcodes first.
It works but on 1:1 scaling it is too small and due to the resolution of the screen I have to depend on the parity bit to fix the errors that occur when scaling it up to the full size of the screen.
An EAN-13 barcode has 95 lines and with a resolution of 176 I can't do perfect scaling.
The alternative would be to split it into 2 sections and depend on the decoding algorithms of barcode scanners. This would exclude non-laser barcode scanners though.
Are people interested in this kind of app? If so I'll probably develop it further and put it in the app store.
If not then I'll just make it functional for my barcodes and leave it at that.
This is the code so far:g.clear(); // Function to generate EAN-13 barcode function generateEAN13(barcode) { const lineWidth = 1.8; // Adjust as needed. 1.8 fills the screen but causes errors that need to be fixed with the parity check. // Table for encoding the first digit var table_encoding = [ ["000000", 0], ["001011", 1], ["001101", 2], ["001110", 3], ["010011", 4], ["011001", 5], ["011100", 6], ["010101", 7], ["010110", 8], ["011010", 9] ]; // Encoding dictionary for L, G, and R patterns var dict = [ ["0001101", "0011001", "0010011", "0111101", "0100011", "0110001", "0101111", "0111011", "0110111", "0001011"], // L ["0100111", "0110011", "0011011", "0100001", "0011101", "0111001", "0000101", "0010001", "0001001", "0010111"], // G ["1110010", "1100110", "1101100", "1000010", "1011100", "1001110", "1010000", "1000100", "1001000", "1110100"] // R ]; if (barcode.length !== 13) { console.error("Barcode must be a string of length 13"); return ""; } var firstDigit = parseInt(barcode[0]); var encoding = table_encoding[firstDigit][0]; var ean13 = "101"; // Start marker // Encode the first 6 digits using the determined encoding for (var j = 1; j < 7; j++) { var usageIndex = parseInt(encoding[j-1]); console.log(usageIndex); ean13 += dict[usageIndex][parseInt(barcode[j])]; if (j === 6) { ean13 += "01010"; // Center marker } } // Encode the last 6 digits using the R pattern for (var k = 7; k < 13; k++) { var rIndex = parseInt(barcode[k]); ean13 += dict[2][rIndex]; } ean13 += "101"; // End marker for (let i = 0; i < ean13.length; i++) { const binaryDigit = ean13[i]; const x = i * lineWidth+3; if (binaryDigit === "1") { const startY = 10; // Starting y-coordinate var height = 100; // Height of the line, adjust as needed if (i<4 || i>91) { height = 110; // height of start and end marker, adjust as needed } g.fillRect(x, startY, x+lineWidth-1, startY + height); } } g.setFont("6x8",2.4); g.drawString(barcode, 10, 115); // Render the graphics on the display g.flip(); } // Example usage var barcodeDigits = "4055334874045"; // Replace with desired 13-digit EAN-13 barcode generateEAN13(barcodeDigits);
-
Thanks Gordon. It has been nearly 2 decades since I used js at all.
That is at least one step closer. Now it is executing the drawing function sequentially but it is doing it 5 times with the final value of "a".
It seems it is passing the reference of "a" in stead of the value of "a" to the promise function...
I forgot the mess javascripts references were in...
I completely forgot how to pass a variable to a promise without referencing to itself...
Am I forced to use an array and passing that to the promise function to resolve this or is there a better way to do this?
So far I have tried quite a few things but it seems all that is passed to the promise function is the final value of "a" -
Hey there,
I'm having some issues with promise chaining and I am wondering if anyone can tell me what am doing wrong.
I have a function that returns a new promise and resolves when an interval function has been cleared.
Something like this:function func_a(var1, var2, var3, var4) { return new Promise((resolve, reject)=>{ //math var pos = 0; var end_pos = 100; var id = null; function draw(){ if (pos == end_pos){ clearInterval(id); resolve("resolved"); } else { //drawing function pos++ } } id = setInterval(draw, var4); }); }
now I have a for loop that is supposed to execute func_a sequentially but no matter how I try with promises it doesn't seem to work.
if (true) { var p = Promise.resolve(); for (a=0;a<100;a=a+20) { p=p.then((res)=>{ func_a(a); }); } }
for example only draws the thing for the last value of a and
if (true) { let p = func_a(0); for (a=20;a<100;a=a+20) { p=p.then((res)=>{ func_a(a); }); } }
draws the first one perfectly followed by the last value of a.
What am I doing wrong?
I checked the references and I couldn't find an async option so I assume that is not a thing for the bangle?Thanks in advance
ps. I am aware I can do:let p = func_a(0).then(()=> func_a(20)).then(()=>func_a(40))
I would just really prefer to do it in a for loop to save a lot of lines of code
-
upgrading to 2v21 was painless. No issues.
Maybe something went wrong during flashing of the 2V20.