diff --git a/apps/bwclk/ChangeLog b/apps/bwclk/ChangeLog index daebecf8f..6a71769f3 100644 --- a/apps/bwclk/ChangeLog +++ b/apps/bwclk/ChangeLog @@ -27,3 +27,4 @@ 0.26: Use clkinfo.addInteractive instead of a custom implementation 0.27: Clean out some leftovers in the remove function after switching to clkinfo.addInteractive that would cause ReferenceError. +0.28: Option to show (1) time only and (2) week of year. \ No newline at end of file diff --git a/apps/bwclk/README.md b/apps/bwclk/README.md index b19e52787..5e2a7b55f 100644 --- a/apps/bwclk/README.md +++ b/apps/bwclk/README.md @@ -3,16 +3,14 @@ A very minimalistic clock. ![](screenshot.png) -## ToDos and known issues -- [ ] The clkinfo is always shown and its, therefore, not possible to only show the time as shown in the screenshot. -- [ ] The weeknumber is currently not an option in clkinfo. -- [ ] Its not possible to run clkinfo items (e.g. trigger home assistant). - ## Features The BW clock implements features that are exposed by other apps through the `clkinfo` module. For example, if you install the HomeAssistant app, this menu item will be shown if you first touch the bottom of the screen and then swipe left/right to the home assistant menu. To select -sub-items simply swipe up/down. +sub-items simply swipe up/down. To run an action (e.g. trigger home assistant), simply select the clkinfo (border) and touch on the item again. See also the screenshot below: + +![](screenshot_3.png) + ## Settings - Screen: Normal (widgets shown), Dynamic (widgets shown if unlocked) or Full (widgets are hidden). diff --git a/apps/bwclk/app.js b/apps/bwclk/app.js index 3f142a066..580c6102e 100644 --- a/apps/bwclk/app.js +++ b/apps/bwclk/app.js @@ -100,12 +100,45 @@ let imgLock = function() { * Clock Info */ let clockInfoItems = clock_info.load(); + +// Add some custom clock-infos +function weekOfYear() { + var date = new Date(); + date.setHours(0, 0, 0, 0); + // Thursday in current week decides the year. + date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7); + // January 4 is always in week 1. + var week1 = new Date(date.getFullYear(), 0, 4); + // Adjust to Thursday in week 1 and count number of weeks from date to week1. + return 1 + Math.round(((date.getTime() - week1.getTime()) / 86400000 + - 3 + (week1.getDay() + 6) % 7) / 7); +} + +clockInfoItems[0].items.unshift({ name : "weekofyear", + get : function() { return { text : "Week " + weekOfYear(), + img : null}}, + show : function() {}, + hide : function() {}, +}) + +// Empty for large time +clockInfoItems[0].items.unshift({ name : "nop", + get : function() { return { text : null, + img : null}}, + show : function() {}, + hide : function() {}, +}) + + + let clockInfoMenu = clock_info.addInteractive(clockInfoItems, { x : 0, y: 135, w: W, h: H-135, draw : (itm, info, options) => { + var isLarge = info.text == null; + g.setColor(g.theme.fg); g.fillRect(options.x, options.y, options.x+options.w, options.y+options.h); @@ -113,11 +146,18 @@ let clockInfoMenu = clock_info.addInteractive(clockInfoItems, { g.setColor(g.theme.bg); if (options.focus){ - g.drawRect(options.x, options.y, options.x+options.w-2, options.y+options.h-1); // show if focused - g.drawRect(options.x+1, options.y+1, options.x+options.w-3, options.y+options.h-2); // show if focused + var y = isLarge ? options.y+20 : options.y+2; + var h = isLarge ? options.h-20 : options.h-2; + g.drawRect(options.x, y, options.x+options.w-2, y+h-1); // show if focused + g.drawRect(options.x+1, y+1, options.x+options.w-3, y+h-2); // show if focused } // Set text and font + if(isLarge){ + drawTime(); + return; + } + var image = info.img; var text = String(info.text); if(text.split('\n').length > 1){ @@ -137,6 +177,8 @@ let clockInfoMenu = clock_info.addInteractive(clockInfoItems, { g.drawImage(image, midx-parseInt(imgWidth*1.3/2)-parseInt(strWidth/2), options.y+6, {scale: scale}); } g.drawString(text, midx+parseInt(imgWidth*1.3/2), options.y+20); + + drawTime(); } }); @@ -187,6 +229,8 @@ let drawDate = function() { let drawTime = function() { + var isLarge = clockInfoMenu.menuA == 0 && clockInfoMenu.menuB == 0; + // Draw background var y1 = getLineY(); var y = y1; @@ -199,13 +243,19 @@ let drawTime = function() { var timeStr = hours + colon + minutes; // Set y coordinates correctly - y += parseInt((H - y)/2)-10; + y += parseInt((H - y)/2) + 5; - // Clear region + if (isLarge){ + g.setLargeFont(); + } else { + y -= 15; + g.setMediumFont(); + } + + // Clear region and draw time g.setColor(g.theme.fg); - g.fillRect(0,y1,W,y+20); + g.fillRect(0,y1,W,y+20 + (isLarge ? 1 : 0)); - g.setMediumFont(); g.setColor(g.theme.bg); g.setFontAlign(0,0); g.drawString(timeStr, W/2, y); diff --git a/apps/bwclk/metadata.json b/apps/bwclk/metadata.json index 2f628a6b9..7c5d285e3 100644 --- a/apps/bwclk/metadata.json +++ b/apps/bwclk/metadata.json @@ -1,7 +1,7 @@ { "id": "bwclk", "name": "BW Clock", - "version": "0.27", + "version": "0.28", "description": "A very minimalistic clock.", "readme": "README.md", "icon": "app.png", diff --git a/apps/bwclk/screenshot.png b/apps/bwclk/screenshot.png index 3a75f13d1..37acf7cc0 100644 Binary files a/apps/bwclk/screenshot.png and b/apps/bwclk/screenshot.png differ diff --git a/apps/bwclk/screenshot_2.png b/apps/bwclk/screenshot_2.png index 31bf6373e..8d2f1717f 100644 Binary files a/apps/bwclk/screenshot_2.png and b/apps/bwclk/screenshot_2.png differ diff --git a/apps/bwclk/screenshot_3.png b/apps/bwclk/screenshot_3.png index 8d982cac4..d52057569 100644 Binary files a/apps/bwclk/screenshot_3.png and b/apps/bwclk/screenshot_3.png differ