Skip to content

Commit d965698

Browse files
committed
added handlebars
1 parent 73c34d9 commit d965698

File tree

5 files changed

+155
-117
lines changed

5 files changed

+155
-117
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
},
4343
"dependencies": {
4444
"ejs": "^3.1.9",
45+
"handlebars": "^4.7.8",
4546
"@capacitor/android": "^7.0.1",
4647
"@capacitor/core": "^7.0.1",
4748
"@fortawesome/fontawesome-free": "^6.5.2",

src/js/tabs/norn_config.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
import ejs from "ejs";
1+
import Handlebars from "handlebars";
22
import { i18n } from "../localization";
33
import GUI, { TABS } from "../gui";
44
import { mspHelper } from "../msp/MSPHelper";
55
import MSP from "../msp";
66
import MSPCodes from "../msp/MSPCodes";
77
import $ from "jquery";
88

9+
// Register Handlebars helpers
10+
Handlebars.registerHelper("eq", function (a, b) {
11+
return a === b;
12+
});
13+
914
// Discover config sources (text-based)
10-
const templateFiles = import.meta.glob("../../norn-configs/template.ejs", { eager: true, as: "raw" });
15+
const templateFiles = import.meta.glob("../../norn-configs/template.hbs", { eager: true, as: "raw" });
1116

1217
const norn_config = {
1318
analyticsChanges: {},
@@ -148,7 +153,8 @@ norn_config.initialize = function (callback) {
148153
let result;
149154
if (templatePath) {
150155
const tpl = readFileRaw(templateFiles, templatePath);
151-
result = ejs.render(tpl, getSelectedKeys());
156+
const template = Handlebars.compile(tpl);
157+
result = template(getSelectedKeys());
152158
} else {
153159
// Fallback to old behavior if template missing
154160
const parts = [];

src/norn-configs/template.ejs

Lines changed: 0 additions & 113 deletions
This file was deleted.

src/norn-configs/template.hbs

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
{{#if fcKey}}# FC: {{fcKey}}
2+
{{/if}}{{#if droneSize}}# Drone Size: {{droneSize}}
3+
{{/if}}{{#if manticoreKey}}# Manticore: {{manticoreKey}}
4+
{{/if}}{{#if vtxKey}}# VTX: {{vtxKey}}
5+
{{/if}}{{#if gpsEnabled}}# GPS: {{gpsEnabled}}
6+
{{/if}}{{#if craftName}}# Craft Name: {{craftName}}
7+
{{/if}}
8+
9+
defaults nosave
10+
11+
batch start
12+
13+
defaults nosave
14+
15+
{{!-- Flight Controller Configuration Blocks --}}
16+
{{#if (eq fcKey 'FLASHHOBBYF405')}}
17+
set pid_process_denom = 2
18+
{{/if}}
19+
20+
{{#if (eq fcKey 'SPEEDYBEEF405V3')}}
21+
set pid_process_denom = 1
22+
{{/if}}
23+
24+
{{#if (eq fcKey 'TAKERF722SE')}}
25+
set pid_process_denom = 1
26+
set cpu_overclock = ON
27+
{{/if}}
28+
29+
{{#if (eq fcKey 'GEPRCF722')}}
30+
set pid_process_denom = 1
31+
set cpu_overclock = ON
32+
{{/if}}
33+
34+
{{!-- Drone Size Configuration Block --}}
35+
{{!-- Motor settings optimized for different frame sizes --}}
36+
{{#if droneSize}}
37+
# Drone Size: {{droneSize}}"
38+
{{#if (eq droneSize '7')}}
39+
set motor_pwm_rate = 32000
40+
set motor_poles = 12
41+
{{/if}}
42+
{{#if (eq droneSize '8')}}
43+
set motor_pwm_rate = 24000
44+
set motor_poles = 14
45+
{{/if}}
46+
{{#if (eq droneSize '9')}}
47+
set motor_pwm_rate = 24000
48+
set motor_poles = 16
49+
{{/if}}
50+
{{#if (eq droneSize '10')}}
51+
set motor_pwm_rate = 16000
52+
set motor_poles = 18
53+
{{/if}}
54+
{{#if (eq droneSize '13')}}
55+
set motor_pwm_rate = 12000
56+
set motor_poles = 20
57+
{{/if}}
58+
{{#if (eq droneSize '15')}}
59+
set motor_pwm_rate = 8000
60+
set motor_poles = 22
61+
{{/if}}
62+
{{/if}}
63+
64+
{{!-- Manticore System Configuration Blocks --}}
65+
{{#if (eq manticoreKey 'UART')}}
66+
# Manticore UART variant
67+
# Configure UART ports for Manticore communication
68+
set uart1_function = RX_SERIAL
69+
set uart2_function = TELEMETRY
70+
{{/if}}
71+
72+
{{#if (eq manticoreKey 'GPIO')}}
73+
# Manticore GPIO variant
74+
# Configure GPIO pins for Manticore interface
75+
set gpio_output = ON
76+
set gpio_mode = ALTERNATE
77+
{{/if}}
78+
79+
{{!-- Video Transmitter (VTX) Configuration Blocks --}}
80+
{{#if (eq vtxKey '5.8VTX')}}
81+
# 5.8GHz VTX settings
82+
# Standard 5.8GHz video transmitter configuration
83+
set vtx_band = A
84+
set vtx_channel = 1
85+
set vtx_power = 25
86+
{{/if}}
87+
88+
{{#if (eq vtxKey '3.3VTX')}}
89+
# 3.3GHz VTX settings
90+
# Long-range 3.3GHz video transmitter configuration
91+
set vtx_band = B
92+
set vtx_channel = 3
93+
set vtx_power = 100
94+
{{/if}}
95+
96+
{{#if (eq vtxKey 'OPTICA')}}
97+
# Optica VTX settings
98+
# Digital video transmitter configuration
99+
set vtx_band = O
100+
set vtx_channel = 2
101+
set vtx_power = 50
102+
{{/if}}
103+
104+
{{!-- GPS Configuration Block --}}
105+
{{#if gpsEnabled}}
106+
# GPS Enabled
107+
# Enable GPS functionality with auto baudrate detection
108+
feature GPS
109+
set gps_baudrate = AUTO
110+
{{/if}}
111+
112+
{{!-- Custom Craft Name Configuration Block --}}
113+
{{#if craftName}}
114+
# Craft name
115+
# Set custom identification name for the craft
116+
set craft_name = {{craftName}}
117+
{{/if}}

yarn.lock

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5941,6 +5941,18 @@ gulplog@^1.0.0:
59415941
dependencies:
59425942
glogg "^1.0.0"
59435943

5944+
handlebars@^4.7.8:
5945+
version "4.7.8"
5946+
resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.7.8.tgz#41c42c18b1be2365439188c77c6afae71c0cd9e9"
5947+
integrity sha512-vafaFqs8MZkRrSX7sFVUdo3ap/eNiLnb4IakshzvP56X5Nr1iGKAIqdX6tMlm6HcNRIkr6AxO5jFEoJzzpT8aQ==
5948+
dependencies:
5949+
minimist "^1.2.5"
5950+
neo-async "^2.6.2"
5951+
source-map "^0.6.1"
5952+
wordwrap "^1.0.0"
5953+
optionalDependencies:
5954+
uglify-js "^3.1.4"
5955+
59445956
har-schema@^2.0.0:
59455957
version "2.0.0"
59465958
resolved "https://registry.yarnpkg.com/har-schema/-/har-schema-2.0.0.tgz#a94c2224ebcac04782a0d9035521f24735b7ec92"
@@ -7588,7 +7600,7 @@ minimatch@^9.0.4:
75887600
dependencies:
75897601
brace-expansion "^2.0.1"
75907602

7591-
minimist@^1.1.0, minimist@^1.2.6:
7603+
minimist@^1.1.0, minimist@^1.2.5, minimist@^1.2.6:
75927604
version "1.2.8"
75937605
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c"
75947606
integrity sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==
@@ -7760,6 +7772,11 @@ needle@^3.1.0:
77607772
iconv-lite "^0.6.3"
77617773
sax "^1.2.4"
77627774

7775+
neo-async@^2.6.2:
7776+
version "2.6.2"
7777+
resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.2.tgz#b4aafb93e3aeb2d8174ca53cf163ab7d7308305f"
7778+
integrity sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==
7779+
77637780
next-tick@^1.1.0:
77647781
version "1.1.0"
77657782
resolved "https://registry.yarnpkg.com/next-tick/-/next-tick-1.1.0.tgz#1836ee30ad56d67ef281b22bd199f709449b35eb"
@@ -10324,6 +10341,11 @@ typedarray@^0.0.6:
1032410341
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
1032510342
integrity sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==
1032610343

10344+
uglify-js@^3.1.4:
10345+
version "3.19.3"
10346+
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.19.3.tgz#82315e9bbc6f2b25888858acd1fff8441035b77f"
10347+
integrity sha512-v3Xu+yuwBXisp6QYTcH4UbH+xYJXqnq2m/LtQVWKWzYc1iehYnLixoQDN9FH6/j9/oybfd6W9Ghwkl8+UMKTKQ==
10348+
1032710349
unbox-primitive@^1.1.0:
1032810350
version "1.1.0"
1032910351
resolved "https://registry.yarnpkg.com/unbox-primitive/-/unbox-primitive-1.1.0.tgz#8d9d2c9edeea8460c7f35033a88867944934d1e2"
@@ -10911,6 +10933,11 @@ word-wrap@^1.2.5:
1091110933
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.5.tgz#d2c45c6dd4fbce621a66f136cbe328afd0410b34"
1091210934
integrity sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==
1091310935

10936+
wordwrap@^1.0.0:
10937+
version "1.0.0"
10938+
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb"
10939+
integrity sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q==
10940+
1091410941
1091510942
version "7.3.0"
1091610943
resolved "https://registry.yarnpkg.com/workbox-background-sync/-/workbox-background-sync-7.3.0.tgz#b6340731a8d5b42b9e75a8a87c8806928e6e6303"

0 commit comments

Comments
 (0)