Skip to content

Commit 49f740f

Browse files
committed
Get settings from legacy endpoint and populate the Settings component
1 parent ba28812 commit 49f740f

File tree

1 file changed

+150
-29
lines changed

1 file changed

+150
-29
lines changed

src/components/Settings.vue

Lines changed: 150 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<v-toolbar-title>Impostazioni</v-toolbar-title>
88
<v-spacer></v-spacer>
99
<v-toolbar-items>
10-
<v-btn flat>
10+
<v-btn flat @click="save">
1111
<v-icon>save</v-icon>
1212
Salva
1313
</v-btn>
@@ -28,7 +28,7 @@
2828
<h3 class="text-xs-left">Sistema </h3>
2929
<v-card>
3030
<div class="cardContent">
31-
<v-text-field v-model="cbName" label="Nome CoderBot"></v-text-field>
31+
<v-text-field v-model="settings.cbName" label="Nome CoderBot"></v-text-field>
3232
<br>
3333
<div v-for="(value, key, index) in cbInfo">
3434
{{ key }}: <code>{{ value }}</code>
@@ -65,14 +65,14 @@
6565
<h3 class="text-xs-left">Configurazione di Rete</h3>
6666
<v-card>
6767
<div class="cardContent">
68-
<v-radio-group v-model="wifiMode" column>
69-
<v-radio label="Connetti ad una rete WiFi già esistente (client)" value="wificlient"></v-radio>
70-
<v-radio label="Lascia che CoderBot configuri la propria rete WiFi locale (ad-hoc)" value="wifiadhoc"></v-radio>
71-
<div v-if="wifiMode == 'wificlient'">
72-
<v-text-field v-model="wifiSSID" label="SSID"></v-text-field>
73-
<v-text-field v-model="wifiPsw" label="Password"></v-text-field>
68+
<v-radio-group v-model="settings.wifiMode" column>
69+
<v-radio label="Connetti ad una rete WiFi già esistente (client)" value="client"></v-radio>
70+
<v-radio label="Lascia che CoderBot configuri la propria rete WiFi locale (ad-hoc)" value="ap"></v-radio>
71+
<div v-if="settings.wifiMode == 'client'">
72+
<v-text-field v-model="settings.wifiSSID" label="SSID"></v-text-field>
73+
<v-text-field v-model="settings.wifiPsw" label="Password"></v-text-field>
7474
</div>
75-
<div v-if="wifiMode =='wifiadhoc'"> SSID: <code> coderbot </code> Password: <code>coderb0t01 </code> </div>
75+
<div v-if="settings.wifiMode =='ap'"> SSID: <code> coderbot </code> Password: <code>coderb0t01 </code> </div>
7676
</v-radio-group>
7777
</div>
7878
</v-card>
@@ -90,21 +90,21 @@
9090
<h3 class="text-xs-left">Step timing | distance / angle</h3>
9191
<v-card>
9292
<div class="cardContent">
93-
<v-text-field v-model="fwdSpeed" label="Forward speed" />
94-
<v-text-field v-model="fwdElapse" label="Forward elapse / distance" />
95-
<v-text-field v-model="turnSpeed" label="Turn speed" />
96-
<v-text-field v-model="turnElapse" label="Turn elapse / angle" />
93+
<v-text-field v-model="settings.fwdSpeed" label="Forward speed" />
94+
<v-text-field v-model="settings.fwdElapse" label="Forward elapse / distance" />
95+
<v-text-field v-model="settings.turnSpeed" label="Turn speed" />
96+
<v-text-field v-model="settings.turnElapse" label="Turn elapse / angle" />
9797
</div>
9898
</v-card>
9999
<br><br>
100100
<h3 class="text-xs-left">Parametri Motori</h3>
101101
<v-card>
102102
<div class="cardContent">
103-
<v-text-field v-model="motorMode" label="Motor control mode" />
104-
<v-text-field v-model="trimFactor" label="Trim factor (1.0 = center)" />
105-
<v-text-field v-model="power[0]" label="Power (target angle -15)" />
106-
<v-text-field v-model="power[1]" label="Power (target angle -4)" />
107-
<v-text-field v-model="power[2]" label="Power (target angle -1)" />
103+
<v-text-field v-model="settings.motorMode" label="Motor control mode" />
104+
<v-text-field v-model="settings.trimFactor" label="Trim factor (1.0 = center)" />
105+
<v-text-field v-model="settings.power[0]" label="Power (target angle -15)" />
106+
<v-text-field v-model="settings.power[1]" label="Power (target angle -4)" />
107+
<v-text-field v-model="settings.power[2]" label="Power (target angle -1)" />
108108
</div>
109109
</v-card>
110110
</v-flex>
@@ -119,10 +119,10 @@
119119
<h3 class="text-xs-left">Suoni personalizzati</h3>
120120
<v-card>
121121
<div class="cardContent">
122-
<v-text-field v-model="startSound" label="Avvio" />
123-
<v-text-field v-model="stopSound" label="Stop" />
124-
<v-text-field v-model="shutterSound" label="Otturatore" />
125-
</div>
122+
<v-text-field v-model="settings.startSound" label="Avvio" />
123+
<v-text-field v-model="settings.stopSound" label="Stop" />
124+
<v-text-field v-model="settings.shutterSound" label="Otturatore" />
125+
</div>
126126
</v-card>
127127
</v-flex>
128128
</v-layout>
@@ -136,7 +136,7 @@
136136
<h3 class="text-xs-left">Funzione pulsante fisico</h3>
137137
<v-card>
138138
<div class="cardContent">
139-
<v-radio-group v-model="btnFun" column>
139+
<v-radio-group v-model="settings.btnFun" column>
140140
<v-radio label="Nessuno" value="none" />
141141
<v-radio label="Inizia/Interrompi programma corrente" value="startstop" />
142142
</v-radio-group>
@@ -146,7 +146,7 @@
146146
<h3 class="text-xs-left">Carica all'avvio</h3>
147147
<v-card>
148148
<div class="cardContent">
149-
<v-text-field v-model="startupProgram" label="Nome script" />
149+
<v-text-field v-model="settings.startupProgram" label="Nome script" />
150150
</div>
151151
</v-card>
152152
</v-flex>
@@ -155,6 +155,13 @@
155155
</v-tab-item>
156156
</v-tabs-items>
157157
</v-content>
158+
<!-- Notification Snackbar -->
159+
<v-snackbar v-model="snackbar">
160+
{{ snackText }}
161+
<v-btn color="pink" flat @click="snackbar = false">
162+
Chiudi
163+
</v-btn>
164+
</v-snackbar>
158165
</v-app>
159166
</div>
160167
</template>
@@ -164,19 +171,133 @@ import sidebar from "../components/Sidebar"
164171
export default {
165172
components: { sidebar },
166173
name: 'HelloWorld',
174+
mounted() {
175+
let axios = this.$axios
176+
let settings = this.$data.settings
177+
178+
// Prepopulate settings
179+
axios.get(this.$data.CBv1 + '/config')
180+
.then(function(response) {
181+
// handle success
182+
let data = this.$data.settings
183+
console.log(response.data);
184+
let remoteConfig = response.data
185+
/*
186+
button_func: "none"
187+
camera_color_object_size_max: "160000"
188+
camera_color_object_size_min: "4000"
189+
camera_exposure_mode: "auto"
190+
camera_framerate: "30"
191+
camera_jpeg_bitrate: "1000000"
192+
camera_jpeg_quality: "5"
193+
camera_path_object_size_max: "160000"
194+
camera_path_object_size_min: "4000"
195+
cnn_default_model: ""
196+
ctrl_fw_elapse: "-1"
197+
ctrl_fw_speed: "99"
198+
ctrl_hud_image: ""
199+
ctrl_tr_elapse: "-1"
200+
ctrl_tr_speed: "80"
201+
cv_image_factor: "2"
202+
load_at_start: ""
203+
move_fw_elapse: "1"
204+
move_fw_speed: "100"
205+
move_motor_mode: "dc"
206+
move_motor_trim: "1"
207+
move_power_angle_1: "45"
208+
move_power_angle_2: "60"
209+
move_power_angle_3: "60"
210+
move_tr_elapse: "0.5"
211+
move_tr_speed: "85"
212+
prog_level: "adv"
213+
prog_maxblocks: "-1"
214+
prog_scrollbars: "true"
215+
show_control_move_commands: "true"
216+
show_page_control: "true"
217+
show_page_prefs: "true"
218+
show_page_program: "true"
219+
sound_shutter: "$shutter.mp3"
220+
sound_start: "$startup.mp3"
221+
sound_stop: "$shutdown.mp3"
222+
*/
223+
224+
data.power= [remoteConfig.move_power_angle_1,remoteConfig.move_power_angle_2 ,remoteConfig.move_power_angle_3],
225+
data.btnFun=remoteConfig.button_func,
226+
// ?
227+
data.wifiMode= remoteConfig.wifi_mode
228+
229+
data.wifiSSID= remoteConfig.wifi_ssid
230+
data.wifiPsw= remoteConfig.wifi_psk
231+
data.fwdElapse = remoteConfig.move_fw_elapse
232+
data.fwdSpeed = remoteConfig.move_fw_speed
233+
data.turnSpeed= remoteConfig.ctrl_tr_speed
234+
data.turnElapse= remoteConfig.ctrl_tr_elapse
235+
data.motorMode= remoteConfig.move_motor_mode
236+
data.trimFactor= remoteConfig.move_motor_trim
237+
data.startSound= remoteConfig.sound_start
238+
data.stopSound= remoteConfig.sound_stop
239+
data.shutterSound= remoteConfig.sound_shutter
240+
data.startupProgram= remoteConfig.load_at_start
241+
}.bind(this))
242+
},
167243
methods: {
244+
save: function() {
245+
let qs = this.$qs
246+
let selectedTab = this.$data.tab
247+
let axios = this.$axios
248+
let CBv1 = this.$data.CBv1
249+
250+
if (selectedTab == 1) {
251+
var valuesAsString = qs.stringify({
252+
'wifi_mode': this.$data.settings.wifiMode,
253+
'wifi_ssid': this.$data.settings.wifiSSID,
254+
'wifi_psk': this.$data.settings.wifiPsw,
255+
})
256+
// Send post with URL encoded parameters
257+
axios.post(CBv1 + '/wifi', valuesAsString)
258+
.then(function() {
259+
console.log("Sent")
260+
this.$data.snackText = "Impostazioni di rete aggiornate"
261+
this.$data.snackbar = true
262+
}.bind(this))
263+
264+
}
265+
},
168266
toggleSidebar: function() {
169267
let currentStatus = this.$store.getters.drawerStatus
170268
this.$store.commit('toggleDrawer', !currentStatus)
171269
}
172270
},
173271
data() {
174272
return {
175-
power: [null, null, null],
176-
startupProgram: null,
177-
btnFun: null,
178-
cbName: 'CoderBot di Antonio',
179-
wifiMode: 'wifiadhoc',
273+
CB: process.env.CB_ENDPOINT + process.env.APIv2,
274+
CBv1: process.env.CB_ENDPOINT,
275+
snackbar: null,
276+
snackText: null,
277+
// TODO: Prepopulate this
278+
settings: {
279+
cbName: 'CoderBot di Antonio',
280+
power: [null, null, null],
281+
startupProgram: null,
282+
btnFun: null,
283+
wifiMode: 'ap',
284+
wifiSSID: null,
285+
wifiPsw: null,
286+
fwdSpeed: null,
287+
fwdElapse: null,
288+
turnSpeed: null,
289+
turnElapse: null,
290+
motorMode: null,
291+
trimFactor: null,
292+
startSound: null,
293+
stopSound: null,
294+
shutterSound: null,
295+
startupProgram: null,
296+
},
297+
298+
299+
300+
180301
cbInfo: {
181302
'Modello': 'CDRBT-01-2017-1',
182303
'Seriale': '740129387591e',

0 commit comments

Comments
 (0)