From 1b81c2764d73330a949bf7669bec220ec0542482 Mon Sep 17 00:00:00 2001 From: Youen Date: Tue, 15 Aug 2023 12:25:40 +0200 Subject: [PATCH] webmanifest tests (not working) probably not working because it is not served over HTTPS --- ESP32/src/vehicle-monitor.cpp | 14 +++++++++++--- WebApp/package.json | 1 + WebApp/src/app.css | 3 +++ WebApp/src/app.ts | 1 + WebApp/src/index.html | 1 + WebApp/src/manifest.webmanifest | 8 ++++++++ WebApp/webpack.config.js | 8 +++++++- 7 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 WebApp/src/app.css create mode 100644 WebApp/src/manifest.webmanifest diff --git a/ESP32/src/vehicle-monitor.cpp b/ESP32/src/vehicle-monitor.cpp index 11833bb..2a387d4 100644 --- a/ESP32/src/vehicle-monitor.cpp +++ b/ESP32/src/vehicle-monitor.cpp @@ -18,7 +18,7 @@ #include -#define DUMMY_DATA 0 +#define DUMMY_DATA 1 AsyncWebServer server(80); @@ -262,6 +262,11 @@ void setup() // Special case to send index.html without caching server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){ request->send(SPIFFS, "/www/index.html", "text/html"); }); server.serveStatic("/index.html", SPIFFS, "/www/index.html"); + server.on("/manifest.webmanifest", HTTP_GET, [](AsyncWebServerRequest *request){ + AsyncWebServerResponse* response = request->beginResponse(SPIFFS, "/www/manifest.webmanifest", "application/manifest+json; charset=utf-8"); + //response->addHeader("Content-Disposition", "inline"); + request->send(response); + }); // Log files (not cached) server.serveStatic("/api/log", SPIFFS, "/log/"); @@ -493,8 +498,11 @@ void loop() if(altitudeChange > 0) tripAscendingElevation += altitudeChange; - uint32_t newEnergy = entry.batteryVoltage * entry.batteryOutputCurrent * ((float)dt / 1000.0f); - tripMotorEnergy += newEnergy; + static float remainingEnergy = 0.0f; + float newEnergy = entry.batteryVoltage * entry.batteryOutputCurrent * ((float)dt / 1000.0f) + remainingEnergy; + uint32_t newEnergyIntegralJoules = (uint32_t)newEnergy; + remainingEnergy = newEnergy - (float)newEnergyIntegralJoules; + tripMotorEnergy += newEnergyIntegralJoules; } delay(isOnTrip ? 10 : 1000); diff --git a/WebApp/package.json b/WebApp/package.json index e721be2..c65cc32 100644 --- a/WebApp/package.json +++ b/WebApp/package.json @@ -12,6 +12,7 @@ "devDependencies": { "@types/mithril": "^2.0.9", "bulma": "^0.9.3", + "copy-webpack-plugin": "^10.2.4", "css-loader": "^6.7.1", "html-webpack-plugin": "^5.5.0", "mini-css-extract-plugin": "^2.6.0", diff --git a/WebApp/src/app.css b/WebApp/src/app.css new file mode 100644 index 0000000..d4de08d --- /dev/null +++ b/WebApp/src/app.css @@ -0,0 +1,3 @@ +html { + font-size: 3.24vmin; +} diff --git a/WebApp/src/app.ts b/WebApp/src/app.ts index 05957ff..1c83eba 100644 --- a/WebApp/src/app.ts +++ b/WebApp/src/app.ts @@ -5,6 +5,7 @@ import { RawDataPage } from 'pages/raw-data/raw-data-page'; import { DashboardPage } from 'pages/dashboard/dashboard-page'; require('../node_modules/bulma/css/bulma.css'); +require('./app.css'); m.route(document.body, "/raw", { "/dashboard": { render: () => m(Layout, m(DashboardPage)) }, diff --git a/WebApp/src/index.html b/WebApp/src/index.html index 9f252d1..7758fd4 100644 --- a/WebApp/src/index.html +++ b/WebApp/src/index.html @@ -3,6 +3,7 @@ Ordinateur de bord +

Chargement...

diff --git a/WebApp/src/manifest.webmanifest b/WebApp/src/manifest.webmanifest new file mode 100644 index 0000000..4c53ba8 --- /dev/null +++ b/WebApp/src/manifest.webmanifest @@ -0,0 +1,8 @@ +{ + "background_color": "purple", + "description": "Shows random fox pictures. Hey, at least it isn't cats.", + "display": "fullscreen", + "name": "Awesome fox pictures", + "short_name": "Foxes", + "start_url": "/index.html" +} \ No newline at end of file diff --git a/WebApp/webpack.config.js b/WebApp/webpack.config.js index c3a62f9..971a096 100644 --- a/WebApp/webpack.config.js +++ b/WebApp/webpack.config.js @@ -6,6 +6,7 @@ const HtmlWebpackPlugin = require('html-webpack-plugin'); const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const PurgecssPlugin = require('purgecss-webpack-plugin'); const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin'); +const CopyPlugin = require('copy-webpack-plugin'); module.exports = { entry: './src/app.ts', @@ -46,6 +47,11 @@ module.exports = { new PurgecssPlugin({ paths: glob.sync('./src/**/*', { nodir: true }), safelist: ['html', 'body'] - }) + }), + new CopyPlugin({ + patterns: [ + 'src/manifest.webmanifest' + ], + }), ] };