From 7ab9e342d5fa8d8210201c8bd9ca626e9fd8bdb9 Mon Sep 17 00:00:00 2001 From: Matrixes <46491408+matrixes@users.noreply.github.com> Date: Tue, 29 Mar 2022 09:02:07 +0200 Subject: [PATCH] EAN-8 Barcode clock, INIT --- apps/barcode/ChangeLog | 1 + apps/barcode/README.md | 15 ++ apps/barcode/barcode.app.js | 377 +++++++++++++++++++++++++++++++++ apps/barcode/barcode.clock.png | Bin 0 -> 1907 bytes apps/barcode/barcode.icon.js | 1 + apps/barcode/barcode.icon.png | Bin 0 -> 574 bytes apps/barcode/metadata.json | 16 ++ 7 files changed, 410 insertions(+) create mode 100644 apps/barcode/ChangeLog create mode 100644 apps/barcode/README.md create mode 100644 apps/barcode/barcode.app.js create mode 100644 apps/barcode/barcode.clock.png create mode 100644 apps/barcode/barcode.icon.js create mode 100644 apps/barcode/barcode.icon.png create mode 100644 apps/barcode/metadata.json diff --git a/apps/barcode/ChangeLog b/apps/barcode/ChangeLog new file mode 100644 index 000000000..987688083 --- /dev/null +++ b/apps/barcode/ChangeLog @@ -0,0 +1 @@ +0.01: Please forgive me diff --git a/apps/barcode/README.md b/apps/barcode/README.md new file mode 100644 index 000000000..0396e03ac --- /dev/null +++ b/apps/barcode/README.md @@ -0,0 +1,15 @@ +# Barcode clock(watch)face + +A scannable EAN-8 compatible face for your Bangle 2 + +The format of the bars are + +* Left section: HHmm + * H: Hours + * m: Minutes +* Right section: MM9c + * M: Month + * 9: constant + * c: Calculated EAN-8 digit checksum + +This face is aware of theme choice, so it will adapt to Light/Dark themes. diff --git a/apps/barcode/barcode.app.js b/apps/barcode/barcode.app.js new file mode 100644 index 000000000..99b3f4cc2 --- /dev/null +++ b/apps/barcode/barcode.app.js @@ -0,0 +1,377 @@ +var startOffsetX = 20; +var startOffsetHeight = 40; + +var checkBarWidth = 10; +var checkBarHeight = 140; + +var digitWidth = 14; +var digitHeight = 120; + +var startDigitOffsetX = startOffsetX + checkBarWidth; + +var midCheckBarOffsetX = startOffsetX + checkBarWidth + digitWidth * 4; + +var midDigitOffsetX = startOffsetX + checkBarWidth + digitWidth * 4 + checkBarWidth; + +var endCheckBarOffsetX = startOffsetX + checkBarWidth + digitWidth * 4 + checkBarWidth + digitWidth * 4; + +let intCaster = num => Number(num); + +var drawTimeout; + +Bangle.loadWidgets(); + +function renderWatch(l) { + g.setFont("4x6",2); + + // work out how to display the current time + + var offsetY = l.y; + + var d = new Date(); + var h = d.getHours(), m = d.getMinutes(); + var time = h + ":" + ("0"+m).substr(-2); + var month = ("0" + (d.getMonth()+1)).slice(-2); + var concatTime = ("0"+h).substr(-2) + ("0"+m).substr(-2) + month + 9; + + concatTime = "20510398"; + + const chars = String(concatTime).split("").map((concatTime) => { + return Number(concatTime); + }); + + drawStart(startOffsetX, offsetY); + + drawLDigit(chars[0], 0, offsetY); + drawLDigit(chars[1], 1, offsetY); + drawLDigit(chars[2], 2, offsetY); + drawLDigit(chars[3], 3, offsetY); + + drawMid(midCheckBarOffsetX, offsetY); + + drawRDigit(chars[4], 0, offsetY); + drawRDigit(chars[5], 1, offsetY); + drawRDigit(chars[6], 2, offsetY); + drawRDigit(calculateChecksum(chars), 3, offsetY); + + drawEnd(endCheckBarOffsetX, offsetY); + + // schedule a draw for the next minute + if (drawTimeout) { + clearTimeout(drawTimeout); + } + drawTimeout = setTimeout(function() { + + drawTimeout = undefined; + layout.render(layout.watch); + }, 60000 - (Date.now() % 60000)); +} + +function drawLDigit(digit, index, offsetY) { + switch(digit) { + case 0: + drawLZeroWithOffset(startDigitOffsetX+(digitWidth*index), offsetY); + break; + case 1: + drawLOneWithOffset(startDigitOffsetX+(digitWidth*index), offsetY); + break; + case 2: + drawLTwoWithOffset(startDigitOffsetX+(digitWidth*index), offsetY); + break; + case 3: + drawLThreeWithOffset(startDigitOffsetX+(digitWidth*index), offsetY); + break; + case 4: + drawLFourWithOffset(startDigitOffsetX+(digitWidth*index), offsetY); + break; + case 5: + drawLFiveWithOffset(startDigitOffsetX+(digitWidth*index), offsetY); + break; + case 6: + drawLSixWithOffset(startDigitOffsetX+(digitWidth*index), offsetY); + break; + case 7: + drawLSevenWithOffset(startDigitOffsetX+(digitWidth*index), offsetY); + break; + case 8: + drawLEightWithOffset(startDigitOffsetX+(digitWidth*index), offsetY); + break; + case 9: + drawLNineWithOffset(startDigitOffsetX+(digitWidth*index), offsetY); + break; + } +} + +function drawRDigit(digit, index, offsetY) { + switch(digit) { + case 0: + drawRZeroWithOffset(midDigitOffsetX+(digitWidth*index), offsetY); + break; + case 1: + drawROneWithOffset(midDigitOffsetX+(digitWidth*index), offsetY); + break; + case 2: + drawRTwoWithOffset(midDigitOffsetX+(digitWidth*index), offsetY); + break; + case 3: + drawRThreeWithOffset(midDigitOffsetX+(digitWidth*index), offsetY); + break; + case 4: + drawRFourWithOffset(midDigitOffsetX+(digitWidth*index), offsetY); + break; + case 5: + drawRFiveWithOffset(midDigitOffsetX+(digitWidth*index), offsetY); + break; + case 6: + drawRSixWithOffset(midDigitOffsetX+(digitWidth*index), offsetY); + break; + case 7: + drawRSevenWithOffset(midDigitOffsetX+(digitWidth*index), offsetY); + break; + case 8: + drawREightWithOffset(midDigitOffsetX+(digitWidth*index), offsetY); + break; + case 9: + drawRNineWithOffset(midDigitOffsetX+(digitWidth*index), offsetY); + break; + } +} + +/* +LEAN + +01234567890123 + xxxx xx + xx xxxx + xxxxxxxx xx + xx xxxx + xxxx xx + xx xxxxxxxx + xxxxxx xxxx + xxxx xxxxxx + xx xxxx + xxxx xx +*/ +function drawLOneWithOffset(offset, offsetY) { + let barOneX = 4; + let barTwoX = 12; + g.fillRect(barOneX+offset,offsetY+0,barOneX+3+offset,offsetY+digitHeight); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+1+offset,offsetY+digitHeight); + g.drawString("1",offset+3,offsetY+digitHeight+5); +} + +function drawLTwoWithOffset(offset, offsetY) { + let barOneX = 4; + let barTwoX = 10; + g.fillRect(barOneX+offset,offsetY+0,barOneX+1+offset,offsetY+digitHeight); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+3+offset,offsetY+digitHeight); + g.drawString("2",offset+3,offsetY+digitHeight+5); +} + +function drawLThreeWithOffset(offset, offsetY) { + let barOneX = 2; + let barTwoX = 12; + g.fillRect(barOneX+offset,offsetY+0,barOneX+7+offset,offsetY+digitHeight); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+1+offset,offsetY+digitHeight); + g.drawString("3",offset+3,offsetY+digitHeight+5); +} + +function drawLFourWithOffset(offset, offsetY) { + let barOneX = 2; + let barTwoX = 10; + g.fillRect(barOneX+offset,offsetY+0,barOneX+1+offset,offsetY+digitHeight); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+3+offset,offsetY+digitHeight); + g.drawString("4",offset+3,offsetY+digitHeight+5); +} + +function drawLFiveWithOffset(offset, offsetY) { + let barOneX = 2; + let barTwoX = 12; + g.fillRect(barOneX+offset,offsetY+0,barOneX+3+offset,offsetY+digitHeight); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+1+offset,offsetY+digitHeight); + g.drawString("5",offset+3,offsetY+digitHeight+5); +} + +function drawLSixWithOffset(offset, offsetY) { + let barOneX = 2; + let barTwoX = 6; + g.fillRect(barOneX+offset,offsetY+0,barOneX+1+offset,offsetY+digitHeight); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+7+offset,offsetY+digitHeight); + g.drawString("6",offset+3,offsetY+digitHeight+5); +} + +function drawLSevenWithOffset(offset, offsetY) { + let barOneX = 2; + let barTwoX = 10; + g.fillRect(barOneX+offset,offsetY+0,barOneX+5+offset,offsetY+digitHeight); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+3+offset,offsetY+digitHeight); + g.drawString("7",offset+3,offsetY+digitHeight+5); +} + +function drawLEightWithOffset(offset, offsetY) { + let barOneX = 2; + let barTwoX = 8; + g.fillRect(barOneX+offset,offsetY+0,barOneX+3+offset,offsetY+digitHeight); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+5+offset,offsetY+digitHeight); + g.drawString("8",offset+3,offsetY+digitHeight+5); +} + +function drawLNineWithOffset(offset, offsetY) { + let barOneX = 6; + let barTwoX = 10; + g.fillRect(barOneX+offset,offsetY+0,barOneX+1+offset,offsetY+digitHeight); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+3+offset,offsetY+digitHeight); + g.drawString("9",offset+3,offsetY+digitHeight+5); +} + +function drawLZeroWithOffset(offset, offsetY) { + let barOneX = 6; + let barTwoX = 12; + g.fillRect(barOneX+offset,offsetY+0,barOneX+3+offset,offsetY+digitHeight); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+1+offset,offsetY+digitHeight); + g.drawString("0",offset+3,offsetY+digitHeight+5); +} + + + +/* +REAN + +01234567890123 +xxxx xxxx +xxxx xxxx +xx xx +xx xxxxxx +xx xxxxxx +xx xx +xx xx +xx xx +xxxxxx xx +xxxxxx xx + +*/ +function drawROneWithOffset(offset, offsetY) { + let barOneX = 0; + let barTwoX = 8; + g.fillRect(offset+barOneX,offsetY+0,offset+barOneX+3,offsetY+digitHeight); + g.fillRect(offset+barTwoX,offsetY+0,offset+barTwoX+3,offsetY+digitHeight); + g.drawString("1",offset+2,offsetY+digitHeight+5); +} + +function drawRTwoWithOffset(offset, offsetY) { + let barOneX = 0; + let barTwoX = 6; + g.fillRect(offset+barOneX,offsetY+0,offset+barOneX+3,offsetY+digitHeight); + g.fillRect(offset+barTwoX,offsetY+0,offset+barTwoX+3,offsetY+digitHeight); + g.drawString("2",offset+2,offsetY+digitHeight+5); +} + +function drawRThreeWithOffset(offset, offsetY) { + let barOneX = 0; + let barTwoX = 10; + g.fillRect(barOneX+offset,offsetY+0,barOneX+1+offset,offsetY+digitHeight); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+1+offset,offsetY+digitHeight); + g.drawString("3",offset+2,offsetY+digitHeight+5); +} + +function drawRFourWithOffset(offset, offsetY) { + let barOneX = 0; + let barTwoX = 4; + g.fillRect(barOneX+offset,offsetY+0,barOneX+1+offset,offsetY+digitHeight); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+5+offset,offsetY+digitHeight); + g.drawString("4",offset+2,offsetY+digitHeight+5); +} + +function drawRFiveWithOffset(offset, offsetY) { + let barOneX = 0; + let barTwoX = 6; + g.fillRect(barOneX+offset,offsetY+0,barOneX+1+offset,offsetY+digitHeight); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+5+offset,offsetY+digitHeight); + g.drawString("5",offset+2,offsetY+digitHeight+5); +} + +function drawRSixWithOffset(offset, offsetY) { + let barOneX = 0; + let barTwoX = 4; + g.fillRect(barOneX+offset,offsetY+0,barOneX+1+offset,offsetY+digitHeight); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+1+offset,offsetY+digitHeight); + g.drawString("6",offset+2,offsetY+digitHeight+5); +} + +function drawRSevenWithOffset(offset, offsetY) { + let barOneX = 0; + let barTwoX = 8; + g.fillRect(barOneX+offset,offsetY+0,barOneX+1+offset,offsetY+digitHeight); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+1+offset,offsetY+digitHeight); + g.drawString("7",offset+2,offsetY+digitHeight+5); +} + +function drawREightWithOffset(offset, offsetY) { + let barOneX = 0; + let barTwoX = 6; + g.fillRect(offset+barOneX,offsetY+0,offset+barOneX+1,offsetY+digitHeight); + g.fillRect(offset+barTwoX,offsetY+0,offset+barTwoX+1,offsetY+digitHeight); + g.drawString("8",offset+2,offsetY+digitHeight+5); +} + +function drawRNineWithOffset(offset, offsetY) { + let barOneX = 0; + let barTwoX = 8; + g.fillRect(barOneX+offset,offsetY+0,barOneX+5+offset,offsetY+digitHeight); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+1+offset,offsetY+digitHeight); + g.drawString("9",offset+2,offsetY+digitHeight+5); +} + +function drawRZeroWithOffset(offset, offsetY) { + let barOneX = 0; + let barTwoX = 10; + g.fillRect(barOneX+offset,offsetY+0,barOneX+5+offset,offsetY+digitHeight); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+1+offset,offsetY+digitHeight); + g.drawString("0",offset+2,offsetY+digitHeight+5); +} + + + + + +function drawStart(offset, offsetY) { + let barOneX = 2; + let barTwoX = 6; + g.fillRect(barOneX+offset,offsetY+0,barOneX+1+offset,offsetY+digitHeight+15); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+1+offset,offsetY+digitHeight+15); +} + +function drawMid(offset, offsetY) { + let barOneX = 2; + let barTwoX = 6; + g.fillRect(barOneX+offset,offsetY+0,barOneX+1+offset,offsetY+digitHeight+15); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+1+offset,offsetY+digitHeight+15); +} + +function drawEnd(offset, offsetY) { + let barOneX = 2; + let barTwoX = 6; + g.fillRect(barOneX+offset,offsetY+0,barOneX+1+offset,offsetY+digitHeight+15); + g.fillRect(barTwoX+offset,offsetY+0,barTwoX+1+offset,offsetY+digitHeight+15); +} + +function calculateChecksum(digits) { + let oddSum = digits[6] + digits[4] + digits[2] + digits[0]; + let evenSum = digits[5] + digits[3] + digits[1]; + + let checkSum = (10 - ((3 * oddSum + evenSum) % 10)) % 10; + + return checkSum; +} + +// The layout, referencing the custom renderer +var Layout = require("Layout"); +var layout = new Layout( { + type:"v", c: [ + {type:"custom", render:renderWatch, id:"watch", bgCol:g.theme.bg, fillx:1, filly:1 } + ] +}); + +// Clear the screen once, at startup +g.clear(); +layout.render(); diff --git a/apps/barcode/barcode.clock.png b/apps/barcode/barcode.clock.png new file mode 100644 index 0000000000000000000000000000000000000000..4df621607c8d32f8caf26b8aa52a2d6a6c5e87af GIT binary patch literal 1907 zcmdT?jW^SK9Gzs8CBHZ&}y0-L{n!igahk z@v=mbUeH$Dp&Om$brY75w=pk`Xt}?sb#H&d{XOUR{hssuKA-3N`90r<;Y09R1vPSG@|!=;XwCV%tk;U-Ob*3EHN%n*7Gj28?8qZ4Jnb% z0ky?pW+zao<5!=YoC|UhO6#y+tPpeO_*C|_jl^ z^rI$1fsN&!kV?q$W8%YW))pi*-SILkhECDTBT2tgqdg6&9#YO38?a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