new ntrip client

This commit is contained in:
2022-09-21 12:50:01 +02:00
parent af6cb98898
commit a1a976be57
15 changed files with 658 additions and 251 deletions
+144 -17
View File
@@ -16,18 +16,143 @@ MenuIntInput::MenuIntInput(int16_t values[], char *names, uint8_t length, MenuIn
this->names = names;
this->length = length;
this->wrapper = wrapper;
this->min = new int16_t[this->length];
this->max = new int16_t[this->length];
this->originalValues = new int16_t[this->length];
this->stepsPerInput = new uint8_t[this->length];
for (uint8_t i = 0; i < this->length; i++) {
this->min[i] = INT16_MIN;
this->max[i] = INT16_MAX;
this->originalValues[i] = this->values[i];
this->stepsPerInput[i] = 1;
}
}
MenuIntInput::MenuIntInput(uint8_t length, MenuIntInputWrapper *wrapper) {
this->length = length;
this->wrapper = wrapper;
this->values = new int16_t[this->length];
this->names = (char*) new char[this->length][MAX_NAME_LENGTH];
this->min = new int16_t[this->length];
this->max = new int16_t[this->length];
this->originalValues = new int16_t[this->length];
this->stepsPerInput = new uint8_t[this->length];
for (uint8_t i = 0; i < this->length; i++) {
this->min[i] = INT16_MIN;
this->max[i] = INT16_MAX;
this->values[i] = 0;
this->originalValues[i] = 0;
this->stepsPerInput[i] = 1;
strcpy(this->names + MAX_NAME_LENGTH * i, "Default");
}
}
MenuIntInput::~MenuIntInput() {
delete this->min;
delete this->max;
delete this->originalValues;
delete this->stepsPerInput;
delete this->values;
delete this->names;
}
void MenuIntInput::setEntry(uint8_t valueNumber, const char* name, int16_t startValue) {
if (this->length < valueNumber)
return;
if (strlen(name) > MAX_NAME_LENGTH)
return;
strcpy(this->names + MAX_NAME_LENGTH * valueNumber, name);
this->values[valueNumber] = startValue;
this->originalValues[valueNumber] = startValue;
}
void MenuIntInput::setMin(uint8_t valueNumber, int16_t min) {
if (this->length < valueNumber)
return;
this->min[valueNumber] = min;
}
void MenuIntInput::setMax(uint8_t valueNumber, int16_t max) {
if (this->length < valueNumber)
return;
this->max[valueNumber] = max;
}
void MenuIntInput::setMinMax(uint8_t valueNumber, int16_t min, int16_t max) {
this->setMin(valueNumber, min);
this->setMax(valueNumber, max);
}
void MenuIntInput::setMin(int16_t min) {
for (uint8_t i = 0; i < this->length; i++)
this->min[i] = min;
}
void MenuIntInput::setMax(int16_t max) {
for (uint8_t i = 0; i < this->length; i++)
this->max[i] = max;
}
void MenuIntInput::setMinMax(int16_t min, int16_t max) {
this->setMin(min);
this->setMax(max);
}
void MenuIntInput::setMinMaxSteps(uint8_t valueNumber, int16_t min, int16_t max, uint8_t steps) {
this->setMin(valueNumber, min);
this->setMax(valueNumber, max);
this->setStepsPerInput(valueNumber, steps);
}
void MenuIntInput::setMinMaxSteps(int16_t min, int16_t max, uint8_t steps) {
this->setMin(min);
this->setMax(max);
this->setStepsPerInput(steps);
}
void MenuIntInput::setStepsPerInput(uint8_t valueNumber, uint8_t steps) {
if (this->length < valueNumber)
return;
this->stepsPerInput[valueNumber] = steps;
}
void MenuIntInput::setStepsPerInput(uint8_t steps) {
for (uint8_t i = 0; i < this->length; i++)
this->stepsPerInput[i] = steps;
}
void MenuIntInput::down() {
if (values[currentPosition] > this->min)
values[currentPosition]--;
if (this->values[this->currentPosition]
- this->stepsPerInput[this->currentPosition]
>= this->min[currentPosition])
{
this->values[this->currentPosition] -= this->stepsPerInput[this->currentPosition];
} else {
this->values[this->currentPosition] = this->max[this->currentPosition];
}
this->printMenu();
}
void MenuIntInput::up() {
if (values[currentPosition] < this->max)
values[currentPosition]++;
if (this->values[this->currentPosition]
+ this->stepsPerInput[this->currentPosition]
<= this->max[this->currentPosition])
{
this->values[this->currentPosition] += this->stepsPerInput[this->currentPosition];
} else {
this->values[this->currentPosition] = this->min[this->currentPosition];
}
this->printMenu();
}
@@ -51,37 +176,42 @@ void MenuIntInput::left() {
}
void MenuIntInput::no() {
if (parentMenu)
for (uint8_t i = 0; i < this->length; i++)
this->values[i] = this->originalValues[i];
this->currentPosition = 0;
if (this->parentMenu)
this->parentMenu->printMenu();
}
void MenuIntInput::yes() {
this->wrapper->action(this->values, this->length);
if (parentMenu)
if (this->parentMenu)
this->parentMenu->printMenu();
}
void MenuIntInput::printMenu() {
// TODO: Name max 12 chars
char bufferName[17];
if (this->currentPosition == 0 && this->length == 1) {
// No arrow
sprintf(bufferName, " %s ", this->names[this->currentPosition]);
sprintf(bufferName, " %s ", this->names + 12 * this->currentPosition);
} else if (this->currentPosition > 0 && this->length - 1 == this->currentPosition) {
// Left arrow only
sprintf(bufferName, "< %s ", this->names[this->currentPosition]);
sprintf(bufferName, "< %s ", this->names + 12 * this->currentPosition);
} else if (this->currentPosition == 0 && this->length > 1) {
// Right arrow only
sprintf(bufferName, " %s >", this->names[this->currentPosition]);
sprintf(bufferName, " %s >", this->names + 12 * this->currentPosition);
} else {
// Both arrow
sprintf(bufferName, "< %s >", this->names[this->currentPosition]);
sprintf(bufferName, "< %s >", this->names + 12 * this->currentPosition);
}
char bufferValue[17];
sprintf(bufferValue, " -> %5.d", this->values[this->currentPosition]);
if (this->values[this->currentPosition])
sprintf(bufferValue, " -> %5.d", this->values[this->currentPosition]);
else
sprintf(bufferValue, " -> 0");
if (this->lcd) {
lcd->clear();
@@ -92,6 +222,3 @@ void MenuIntInput::printMenu() {
}
std::cout << bufferName << " : " << bufferValue << std::endl;
}