Skip to content

Commit

Permalink
keep config checkbox to skip nvs partition (#15)
Browse files Browse the repository at this point in the history
* keep config checkbox to skip nvs partition

* make keep config default true

* add missing type annotation

* fixed

* fix: update keepConfig default to false

---------

Co-authored-by: WantClue <[email protected]>
  • Loading branch information
shufps and WantClue authored Feb 1, 2025
1 parent 5168f60 commit 92b3a75
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 13 deletions.
48 changes: 44 additions & 4 deletions src/components/LandingHero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default function LandingHero() {
const textDecoderRef = useRef<TextDecoderStream | null>(null)
const readableStreamClosedRef = useRef<Promise<void> | null>(null)
const logsRef = useRef<string>('')
const [keepConfig, setKeepConfig] = useState(false);

useEffect(() => {
const userAgent = navigator.userAgent.toLowerCase();
Expand Down Expand Up @@ -116,6 +117,10 @@ export default function LandingHero() {
}
}

const handleKeepConfigToggle = (event: React.ChangeEvent<HTMLInputElement>) => {
setKeepConfig(event.target.checked);
};

const startSerialLogging = async () => {
if (!serialPortRef.current) {
setStatus(t('status.connectFirst'));
Expand Down Expand Up @@ -256,11 +261,34 @@ export default function LandingHero() {

setStatus(t('status.flashing', { percent: 0 }))

// On all Bitaxe derivatives the same
const nvsStart = 0x9000;
const nvsSize = 0x6000;

let parts;

if (keepConfig) {
parts = [
{
data: firmwareBinaryString.slice(0, nvsStart), // Data before NVS
address: 0,
},
{
data: firmwareBinaryString.slice(nvsStart + nvsSize), // Data after NVS
address: nvsStart + nvsSize,
},
];
} else {
parts = [
{
data: firmwareBinaryString, // Entire firmware binary
address: 0,
},
];
}

await loader.writeFlash({
fileArray: [{
data: firmwareBinaryString,
address: 0
}],
fileArray: parts,
flashSize: "keep",
flashMode: "keep",
flashFreq: "keep",
Expand Down Expand Up @@ -354,6 +382,18 @@ export default function LandingHero() {
disabled={isConnecting || isFlashing}
/>
)}
<div className="flex items-center gap-2">
<input
type="checkbox"
id="keepConfig"
className="cursor-pointer"
checked={keepConfig}
onChange={handleKeepConfigToggle}
/>
<label htmlFor="keepConfig" className="text-gray-500 dark:text-gray-400 cursor-pointer">
{t('hero.keepConfig')}
</label>
</div>
<Button
className="w-full"
onClick={handleStartFlashing}
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"startLogging": "Logging starten",
"stopLogging": "Logging stoppen",
"downloadLogs": "Logs herunterladen",
"loggingDescription": "Verbinde dein Gerät, protokolliere die seriellen Daten und lade diese später herunter."
"loggingDescription": "Verbinde dein Gerät, protokolliere die seriellen Daten und lade diese später herunter.",
"keepConfig": "Konfiguration behalten"
},
"features": {
"title": "Funktionen",
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"startLogging": "Start Logging",
"stopLogging": "Stop Logging",
"downloadLogs": "Download Logs",
"loggingDescription": "Connect your device, log the serial data and download it later on."
"loggingDescription": "Connect your device, log the serial data and download it later on.",
"keepConfig": "Keep configuration"
},
"features": {
"title": "Key Features",
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"startLogging": "Avvia registrazione Log",
"stopLogging": "Ferma registrazione Log",
"downloadLogs": "Scarica Log",
"loggingDescription": "Collega il tuo dispositivo, registra i dati seriali e scaricali successivamente."
"loggingDescription": "Collega il tuo dispositivo, registra i dati seriali e scaricali successivamente.",
"keepConfig": "Mantieni configurazione"
},
"features": {
"title": "Caratteristiche principali",
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"startLogging": "Iniciar Log",
"stopLogging": "Parar Log",
"downloadLogs": "Baixar Logs",
"loggingDescription": "Conecte seu dispositivo, registre os dados seriais e baixe-os posteriormente."
"loggingDescription": "Conecte seu dispositivo, registre os dados seriais e baixe-os posteriormente.",
"keepConfig": "Manter configuração"
},
"features": {
"title": "Principais Recursos",
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/ro.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"startLogging": "Pornește logarea",
"stopLogging": "Oprește logarea",
"downloadLogs": "Descarcă loguri",
"loggingDescription": "Conectează aparatul, înregistrează datele de pe comunicarea serială și descarcă mai târziu."
"loggingDescription": "Conectează aparatul, înregistrează datele de pe comunicarea serială și descarcă mai târziu.",
"keepConfig": "Păstrează configurația"
},
"features": {
"title": "Funcții importante",
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"startLogging": "Начать ведение журнала",
"stopLogging": "Остановить ведение журнала",
"downloadLogs": "Скачать логи",
"loggingDescription": "Подключи свое устройство, запиши в журнал последовательные данные и загрузи их позже."
"loggingDescription": "Подключи свое устройство, запиши в журнал последовательные данные и загрузи их позже.",
"keepConfig": "Сохранить конфигурацию"
},
"features": {
"title": "Ключевые особенности",
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/sk.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"startLogging": "Spustiť Logovanie",
"stopLogging": "Ukončiť Logovanie",
"downloadLogs": "Stiahniť Logy",
"loggingDescription": "Pripojte Vaše zariadenie, uložte serialové dáta a stiahnite ich neskôr."
"loggingDescription": "Pripojte Vaše zariadenie, uložte serialové dáta a stiahnite ich neskôr.",
"keepConfig": "Zachovať konfiguráciu"
},
"features": {
"title": "Kľučové Funkcie",
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/tlh.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"startLogging": "De' ghItlhchoH",
"stopLogging": "De' ghoSchoH",
"downloadLogs": "De' nIH",
"loggingDescription": "chel jan, ghItlh De', nIH 'ach neH le'vaD."
"loggingDescription": "chel jan, ghItlh De', nIH 'ach neH le'vaD.",
"keepConfig": "nugh rI' choq"
},
"features": {
"title": "nIvmo' chutmey",
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"startLogging": "Loglamaya Başla",
"stopLogging": "Loglamayı Durdur",
"downloadLogs": "Logu İndir",
"loggingDescription": "Cihazınızı seçin, işlemi loglayın ve daha sonra indirin."
"loggingDescription": "Cihazınızı seçin, işlemi loglayın ve daha sonra indirin.",
"keepConfig": "Yapılandırmayı koru"
},
"features": {
"title": "Öne Çıkan Özellikler",
Expand Down

0 comments on commit 92b3a75

Please sign in to comment.