From 7c385836d322b430d85bd14e870bcb3030f1889c Mon Sep 17 00:00:00 2001 From: Thomas Ballmann Date: Sat, 14 Mar 2020 09:35:56 +0100 Subject: [PATCH] code clean up --- app/src/App.vue | 131 +++++++++++++++++++++++-------------- app/src/api/device.js | 63 +++++++++++++++++- app/src/plugins/vuetify.js | 27 ++++++++ include/display.h | 1 + platformio.ini | 4 +- src/app.cpp | 2 +- src/faceCalendar.cpp | 4 +- 7 files changed, 176 insertions(+), 56 deletions(-) diff --git a/app/src/App.vue b/app/src/App.vue index 0c49a0c..d1b2e5a 100644 --- a/app/src/App.vue +++ b/app/src/App.vue @@ -13,39 +13,38 @@ app > - + + - +
update in 2min
+
heyfromjonathan@gmail.com
+ -->
+ + + {{ playlistRemaining }} + + - paperdash.io + {{ stats.playlist.current }} - Weather + 8. March 2020 -
- - 40 - -
- @@ -76,29 +75,16 @@ - - 19% + Total: {{ stats.device.fs.total | prettyBytes }}
+ Free: {{ stats.device.fs.free | prettyBytes }} + + +
- - - - $device @@ -121,14 +106,11 @@ - - + @@ -142,7 +124,7 @@ diff --git a/app/src/api/device.js b/app/src/api/device.js index 11b46e8..7bdd68e 100644 --- a/app/src/api/device.js +++ b/app/src/api/device.js @@ -11,8 +11,14 @@ const _settings = { playlist: { timer: 60 }, - api: { - owm: "" + weather: { + api: "", + location: 2766824, + lang: "de", + unit: "metric" + }, + datetime: { + gmt_offset: 3600 }, cloud: { mode: "active", @@ -21,6 +27,43 @@ const _settings = { } } +// eslint-disable-next-line +const _stats = { + "wifi": { + "ssid": "xd-design.info", + "connected": true, + "ip": "192.168.178.62", + "mac": "30:AE:A4:21:20:40", + "channel": 1, + "dns": "192.168.178.1", + "gateway": "192.168.178.1" + }, + "device": { + "heap": 120496, + "bootCycle": 1, + "screen": { + "width": 640, + "height": 384 + }, + "fs": { + "total": 1860161, + "used": 1107663, + "free": 752498 + } + }, + "playlist": { + "current": "Calendar", + "remaining": 22 + }, + "capability": [ + "png", + "wbmp" + ], + "cloud": { + "sleep": 10 + } +} + // eslint-disable-next-line const _wifiScan = [{ "rssi": -59, "ssid": "xd-design.info", "bssid": "38:10:D5:34:80:1B", "channel": 11, "secure": 3 }, { "rssi": -75, "ssid": "FRITZ!Box 7430 JI", "bssid": "38:10:D5:5D:FE:7C", "channel": 1, "secure": 3 }, { "rssi": -87, "ssid": "Vodafone Hotspot", "bssid": "AA:0E:14:BD:50:ED", "channel": 1, "secure": 0 }, { "rssi": -88, "ssid": "WLAN-548426", "bssid": "E0:60:66:55:7F:C5", "channel": 1, "secure": 3 }, { "rssi": -89, "ssid": "Familie Kalinowski", "bssid": "C8:0E:14:BD:50:ED", "channel": 1, "secure": 3 }, { "rssi": -91, "ssid": "WLAN-507287", "bssid": "E0:60:66:48:6C:6B", "channel": 1, "secure": 3 }, { "rssi": -94, "ssid": "TP-LINK_7238", "bssid": "A4:2B:B0:D8:72:38", "channel": 3, "secure": 3 }] @@ -87,5 +130,19 @@ export default { } }) .then(response => cb(response.data)) - } + }, + + + /** + * @param cb + * @returns {PromiseLike | Promise} + */ + getStats(cb) { + //return cb(_stats); + + // eslint-disable-next-line + return axios + .get('/stats') + .then(response => cb(response.data)) + }, } diff --git a/app/src/plugins/vuetify.js b/app/src/plugins/vuetify.js index 8e697aa..916ce71 100644 --- a/app/src/plugins/vuetify.js +++ b/app/src/plugins/vuetify.js @@ -3,5 +3,32 @@ import Vuetify from 'vuetify/lib' Vue.use(Vuetify) +// usage: {{ file.size | prettyBytes }} +Vue.filter('prettyBytes', function (num) { + // jacked from: https://github.com/sindresorhus/pretty-bytes + if (typeof num !== 'number' || isNaN(num)) { + throw new TypeError('Expected a number'); + } + + var exponent; + var unit; + var neg = num < 0; + var units = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; + + if (neg) { + num = -num; + } + + if (num < 1) { + return (neg ? '-' : '') + num + ' B'; + } + + exponent = Math.min(Math.floor(Math.log(num) / Math.log(1000)), units.length - 1); + num = (num / Math.pow(1000, exponent)).toFixed(2) * 1; + unit = units[exponent]; + + return (neg ? '-' : '') + num + ' ' + unit; +}); + export default new Vuetify({ }) diff --git a/include/display.h b/include/display.h index 56b8e2f..5a62057 100644 --- a/include/display.h +++ b/include/display.h @@ -1,6 +1,7 @@ #ifndef DISPLAY_H #define DISPLAY_H +//#include "EPD2_BW.h" #include #include diff --git a/platformio.ini b/platformio.ini index d0e05f8..86f8b7a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -1,8 +1,10 @@ [env:lolin32] -platform = espressif32 +;platform = espressif32 +platform = https://github.com/platformio/platform-espressif32.git board = lolin32 framework = arduino monitor_speed = 115200 +monitor_filters = esp32_exception_decoder ; https://camo.githubusercontent.com/62eafe3a5c9bf3cdc31d6db740b7e58eaa1a3ab1/687474703a2f2f7777772e6275696c646c6f672e6e65742f626c6f672f77702d636f6e74656e742f75706c6f6164732f323032302f30322f6964655f73732e706e67 ; https://docs.platformio.org/en/latest/platforms/espressif32.html#partition-tables ; https://github.com/espressif/arduino-esp32/tree/master/tools/partitions diff --git a/src/app.cpp b/src/app.cpp index 3b763de..0e2a979 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -166,7 +166,7 @@ void setupSettingsPost() } /** - * + * get current screen */ void setupCurrentImage() { diff --git a/src/faceCalendar.cpp b/src/faceCalendar.cpp index 92d0b43..b01b884 100644 --- a/src/faceCalendar.cpp +++ b/src/faceCalendar.cpp @@ -89,7 +89,7 @@ bool downloadRandomePicture() pictureUrl += "&fit=crop"; // crop to needed size pictureUrl += "&duotone=000000,FFFFFF"; // grayscale to save bytes - //downloadFile(pictureUrl, faceCalendarPicture); + downloadFile(pictureUrl, faceCalendarPicture); return true; } @@ -104,7 +104,7 @@ bool downloadRandomePicture() bool updateCalendarData() { //downloadFile("https://images.unsplash.com/photo-1582225764554-a82806fe9f30?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjExMDM0OH0&w=390&h=384&fm=png&fit=crop&duotone=000000,FFFFFF", "/tom"); - return false; + //return false; if (downloadRandomePicture()) {