commit 590a0e7adbe1f64dc8d804ae126f3d8383bb907f Author: michele Date: Thu Dec 26 19:17:25 2024 +0100 Modified from original ui-digital-clock diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..f544641 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,9 @@ +# Changelog + +## [v1.0.0] - 2022-04-29 + +### Added +- Functional digital clock for the Node-RED Dashboard +- Readme, Changelog and License + +[v1.0.0]: https://github.com/patrickknabe/node-red-contrib-ui-digital-clock/releases/tag/v1.0.0 \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ad0e527 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 patrickknabe + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..8dee3c1 --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +# node-red-contrib-ui-digital-clock + +A digital clock for the Node-RED Dashboard. + +![](digital-clock.png) + +## Installation + +Open Node-RED and select `Manage palette` from the menu to open the Palette Manager. Go to the `Install` tab, search for `node-red-contrib-ui-digital-clock` and click `install`. + +Alternatively, you can run the following command in your Node-RED user directory (typically `~/.node-red`): + +``` +npm i node-red-contrib-ui-digital-clock +``` + +## Example + +![](example.png) + +``` +[{"id":"c09db1ba6ac377de","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"37ec70937bed02a4","type":"ui_digital_clock","z":"c09db1ba6ac377de","name":"","group":"5c79b643fcd37cad","order":0,"width":"6","height":"2","x":710,"y":340,"wires":[]},{"id":"105daf8d29a83f81","type":"inject","z":"c09db1ba6ac377de","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"1","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":490,"y":340,"wires":[["37ec70937bed02a4"]]},{"id":"5c79b643fcd37cad","type":"ui_group","name":"Standard","tab":"f4a9e911ba044f38","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"f4a9e911ba044f38","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}] +``` + +## License + +[MIT](LICENSE) + +## Projects + +Also take a look at my other dashboard projects: + +### [node-red-contrib-ui-clock](https://github.com/patrickknabe/node-red-contrib-ui-clock) + +A simple analog clock for the Node-RED Dashboard. + +![](clock.png) + +### [node-red-contrib-ui-digital-display](https://github.com/patrickknabe/node-red-contrib-ui-digital-display) + +A digital display, with adjustable number of digits and decimals, for the Node-RED Dashboard. + +![](pi.png) \ No newline at end of file diff --git a/clock.html b/clock.html new file mode 100644 index 0000000..525be4e --- /dev/null +++ b/clock.html @@ -0,0 +1,69 @@ + + + + + \ No newline at end of file diff --git a/clock.js b/clock.js new file mode 100644 index 0000000..144e7e8 --- /dev/null +++ b/clock.js @@ -0,0 +1,123 @@ +module.exports = RED => { + let ui; + + RED.nodes.registerType( 'ui_microwave_clock', function( config ) { + RED.nodes.createNode( this, config ); + + if( !ui ) { + try { + ui = RED.require( 'node-red-dashboard' )( RED ); + } catch {} + } + + if( ui && RED.nodes.getNode( config.group ) ) { + this.on( 'close', ui.addWidget( { + node: this, + format: ` + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + `, + width: +config.width || +RED.nodes.getNode( config.group ).config.width, + height: +config.height || 1, + group: config.group, + order: config.order, + beforeEmit: msg => ( { msg } ), + initController: $scope => $scope.$watch( 'msg.payload', payload => { + const total_seconds = +payload || 0; + let remaining_seconds = total_seconds; + + let hours = Math.floor(remaining_seconds / 3600.0); + remaining_seconds -= hours * 3600.0; + let minutes = Math.floor(remaining_seconds / 60.0); + remaining_seconds -= minutes * 60.0; + let seconds = remaining_seconds; + + let s = hours.toString().padStart( 4, ' ' ); + s += minutes.toString().padStart( 2, '0' ); + s += seconds.toString().padStart( 2, '0' ); + s += !( seconds % 2 ) ? ':' : ' '; + s += !( seconds % 2 ) ? ':' : ' '; + + $scope.segs = []; + + for( const c of s ) { + $scope.segs.push( { + '0': [ true, true, true, false, true, true, true ], + '1': [ false, false, true, false, false, true, false ], + '2': [ true, false, true, true, true, false, true ], + '3': [ true, false, true, true, false, true, true ], + '4': [ false, true, true, true, false, true, false ], + '5': [ true, true, false, true, false, true, true ], + '6': [ true, true, false, true, true, true, true ], + '7': [ true, false, true, false, false, true, false ], + '8': [ true, true, true, true, true, true, true ], + '9': [ true, true, true, true, false, true, true ], + ' ': [ false, false, false, false, false, false, false ], + ':': [ true ] + }[ c ] ); + } + } ) + } ) ); + } + } ); +}; \ No newline at end of file diff --git a/clock.png b/clock.png new file mode 100644 index 0000000..0c37231 Binary files /dev/null and b/clock.png differ diff --git a/clock.svg.bak b/clock.svg.bak new file mode 100644 index 0000000..a0ea190 --- /dev/null +++ b/clock.svg.bak @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/digital-clock.png b/digital-clock.png new file mode 100644 index 0000000..bc3b4f5 Binary files /dev/null and b/digital-clock.png differ diff --git a/example.png b/example.png new file mode 100644 index 0000000..a53c2c7 Binary files /dev/null and b/example.png differ diff --git a/package.json b/package.json new file mode 100644 index 0000000..a97aca3 --- /dev/null +++ b/package.json @@ -0,0 +1,37 @@ +{ + "name": "node-red-contrib-ui-microwave-clock", + "description": "A microwave-style digital timer for the Node-RED Dashboard.", + "keywords": [ + "clock", + "dashboard", + "node-red", + "time", + "ui" + ], + "version": "1.0.1", + "license": "MIT", + "author": { + "name": "Patrick Knabe", + "email": "patrickknabe@gmail.com" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/patrickknabe/node-red-contrib-ui-digital-clock.git" + }, + "bugs": { + "url": "https://github.com/patrickknabe/node-red-contrib-ui-digital-clock/issues" + }, + "homepage": "https://github.com/patrickknabe/node-red-contrib-ui-digital-clock#readme", + "peerDependencies": { + "node-red-dashboard": ">=2.23.2" + }, + "node-red": { + "version": ">=2.0.0", + "nodes": { + "ui_digital_clock": "clock.js" + } + }, + "engines": { + "node": ">=12.0.0" + } +} diff --git a/pi.png b/pi.png new file mode 100644 index 0000000..8d01841 Binary files /dev/null and b/pi.png differ