Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/libs/esptoolv2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ref, reactive, computed, watch } from 'vue'
import { ESPLoader, Transport } from 'esptool-js'

const firmwareUrl = import.meta.env.VITE_FIRMWARE_URL
const boardsUrl = import.meta.env.VITE_BOARDS_URL
let firmwareVersion = ref('')
let devices = ref([])
let device = ref(null)
Expand Down Expand Up @@ -155,6 +156,14 @@ export function useEsptool() {
reader.readAsBinaryString(fileBlob)
}

const getBoardConfigs = async () => {
return fetch(boardsUrl, {
headers: {
'Cache-Control': 'no-cache'
}
}).then((res) => res.json())
}

const setDevices = async (ports) => {
console.log('setDevices', ports)
devices.value = ports
Expand Down Expand Up @@ -346,6 +355,19 @@ export function useEsptool() {
// startSerial()
}

const toBoardCommand = (config) => {
return Object.keys(config).reduce((command, key) => {
const value = typeof config[key] === 'number' ? config[key] : `"${config[key]}"`
return command += ` --${key} ${value}`
}, 'board')
}

const setBoardConfig = (config) => {
const command = toBoardCommand(config)
writeSerial(command)
setTimeout(() => reset(), 1500)
}

const findNetworks = () => {
findNetworksTask = setInterval(() => {
writeSerial('networks')
Expand Down Expand Up @@ -403,6 +425,8 @@ export function useEsptool() {
stopSerialTask,
disconnect,
writeSerial,
getBoardConfigs,
setBoardConfig,
findNetworks,
join,
stopJoin,
Expand Down
5 changes: 5 additions & 0 deletions src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ const router = createRouter({
name: 'start',
component: () => import('../views/StartView.vue')
},
{
path: '/select-board',
name: 'select-board',
component: () => import('../views/SelectBoardView.vue')
},
{
path: '/select-device',
name: 'select-device',
Expand Down
2 changes: 1 addition & 1 deletion src/views/FirmwareUploadedView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<p>Se actualizó el firmware correctamente, ahora es necesario configurar la conexión a internet.</p>
<div class="flex">
<img class="icon" src="@/assets/success.svg" alt="success" />
<RouterLink class="btn" to="/setup-connection">Configurar conexión</RouterLink>
<RouterLink class="btn" to="/select-board">Configurar hardware</RouterLink>
</div>
</template>

Expand Down
9 changes: 8 additions & 1 deletion src/views/SelectActionView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
<p>Actualiza el firmware o ve directamente a la configuración de red.</p>
<div class="flex">
<RouterLink class="btn" to="/upload-firmware">Actualizar firmware</RouterLink>
<RouterLink to="/setup-connection">Configurar conexión</RouterLink>
<RouterLink class="link" to="/select-board">Configurar hardware</RouterLink>
<RouterLink class="link" to="/setup-connection">Configurar conexión</RouterLink>
</div>
</template>

<style scoped>
.link {
margin: 4px 0;
}
</style>

<script setup>
import { RouterLink } from 'vue-router'
</script>
57 changes: 57 additions & 0 deletions src/views/SelectBoardView.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<template>
<form class="flex" @submit.prevent="select">
<div v-if="boardConfigs.list.length">
<h2>Seleccionar tarjeta </h2>
<p>Selecciona el modelo de tu tarjeta de desarrollo.</p>
<select v-model="boardConfigs.board">
<option v-for="n in boardConfigs.list" :key="n" :value="n.name">
{{ n.name }}
</option>
</select>
<div class="flex">
<!-- <input type="checkbox" v-model="customConfig" /> -->
<label v-if="customConfig">
<span>Configuración manual</span>
</label>
<button>Continuar</button>
</div>
</div>
<div class="flex" v-else>
<img class="loader" src="@/assets/loading.svg" alt="loading" />
<p class="status">Cargando tarjetas</p>
</div>
</form>
</template>

<script setup>
import { onMounted, ref, reactive, watch } from 'vue'
import { useRouter } from 'vue-router'
import { useEsptool } from '@/libs/esptoolv2'

const router = useRouter()

const customConfig = ref(false)

const boardConfigs = reactive({
list: [],
board: null
})

const {
getBoardConfigs,
setBoardConfig
} = useEsptool()

watch(() => boardConfigs.board, (config) => {
setBoardConfig(config)
})

const select = () => {
console.log('selected board', boardConfigs.board)
router.push('/setup-connection')
}

onMounted(async () => {
boardConfigs.list = await getBoardConfigs()
})
</script>