fix protoview shift, and add comments to languagehelper (#2268)

This commit is contained in:
Totoo 2024-09-26 03:22:24 +02:00 committed by GitHub
parent 967506fb97
commit 20f45e88f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 53 additions and 13 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2024 HTotoo
* Copyright (C) 2024 HTotoo, zxkmm
*
* This file is part of PortaPack.
*
@ -141,18 +141,19 @@ void ProtoView::draw() {
for (uint16_t i = 0; i < MAXDRAWCNT; i++) waveform_buffer[i] = 0; // reset
// add empty data for padding (so you can shift left/nagetive)
for (int32_t i = 0;
i < ((waveform_shift > 0) ? 0 : -waveform_shift) && drawcnt < MAXDRAWCNT; // this is for shift nagetive (left side)
++i) {
waveform_buffer[drawcnt++] = 0;
if (waveform_shift < 0) {
for (int32_t i = 0; (i < -1 * waveform_shift) && drawcnt < MAXDRAWCNT; // this is for shift nagetive (move to right)
++i) {
waveform_buffer[drawcnt++] = 0;
}
}
for (uint16_t i = ((waveform_shift < 0) ? -waveform_shift : 0); // this is for shift positive aka right side
i < MAXSIGNALBUFFER && drawcnt < MAXDRAWCNT; // prevent out of ranging
uint16_t skipped = 0;
uint16_t to_skip = ((waveform_shift > 0) ? waveform_shift : 0); // when >0 it'll skip some to move left
for (uint16_t i = 0;
i < MAXSIGNALBUFFER && drawcnt < MAXDRAWCNT; // prevent out of ranging
++i) {
uint16_t buffer_index = (i + waveform_shift + MAXSIGNALBUFFER) % MAXSIGNALBUFFER;
state = time_buffer[buffer_index] >= 0;
int32_t timeabs = state ? time_buffer[buffer_index] : -1 * time_buffer[buffer_index];
state = time_buffer[i] >= 0;
int32_t timeabs = state ? time_buffer[i] : -1 * time_buffer[i];
int32_t timesize = timeabs / zoom;
if (timesize == 0) {
remain += timeabs;
@ -170,7 +171,11 @@ void ProtoView::draw() {
remain = 0;
lmax = 0;
for (int32_t ii = 0; ii < timesize && drawcnt < MAXDRAWCNT; ++ii) {
waveform_buffer[drawcnt++] = state;
if (skipped < to_skip) {
skipped++;
} else {
waveform_buffer[drawcnt++] = state;
}
}
}
}

View File

@ -1,7 +1,9 @@
#include "ui_language.hpp"
// use the exact position in this array! the enum's value is the identifier. Best to add to the end
const char* LanguageHelper::englishMessages[] = {"OK", "Cancel", "Error", "Modem setup", "Debug", "Log", "Done", "Start", "Stop", "Scan", "Clear", "Ready", "Data:", "Loop", "Reset", "Pause", "Resume"};
// multi language support will changes (not in use for now)
const char** LanguageHelper::currentMessages = englishMessages;
void LanguageHelper::setLanguage(LanguageList lang) {

View File

@ -1,10 +1,43 @@
/*
* Copyright (C) 2024 HTotoo
*
* This file is part of PortaPack.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
/*
The purpose of this: when creating an ext app it's address will be changed. But the compiler doesn't know this, so when it optimizes literals it can remove something from one ext app, that is included in the other, to save space.
But when we want to run this app, it won't find the literal at the fake address, so the best case we'll get just garbage or nothing instead of the string.
So we must use this Language helper that stores the literals in the fw instead of any ext app, so it'll be always available.
In the first run we must move those string literal here what are not so unique, like "OK".
*/
#ifndef __UI_LANGUAGE_H__
#define __UI_LANGUAGE_H__
// For future multi language support
enum LanguageList {
ENGLISH,
};
// Add an element to this enum when you fill a new value.
// Then add the string literal to the LanguageHelper::englishMessages at the exact position where the enum points to (usualy to the end)
enum LangConsts {
LANG_OK,
LANG_CANCEL,
@ -27,7 +60,7 @@ enum LangConsts {
class LanguageHelper {
public:
static void setLanguage(LanguageList lang);
static void setLanguage(LanguageList lang); // changes the pointer to the currently used language literal container. not used yet.
static const char* getMessage(LangConsts msg);
static const char** currentMessages; // expose, so can link directly too