application: improve type result output

This commit is contained in:
King Kévin 2021-03-24 17:33:54 +01:00
parent 2cccdd4d6e
commit 86fd05f52c
1 changed files with 13 additions and 32 deletions

View File

@ -321,8 +321,8 @@ static void command_types(void* argument)
return;
}
puts("signal voltage pulled pull-up pulled pull-down signal\n");
puts(" name raw (V) down (V) (kOhm) up (V) (kOhm) type \n");
puts("measuring voltage on channels when pulled up and down using 2 kOhm resistor\n");
puts("channel no-pull pull-down pull-up type\n");
// just to be sure, reset measurement conditions
gpio_set(GPIO_PORT(SIGNAL_PD_PIN), GPIO_PIN(SIGNAL_PD_PIN)); // ensure pull-down is not active
@ -330,12 +330,13 @@ static void command_types(void* argument)
for (uint8_t i = channel_start; i <= channel_stop; i++) {
printf("CH%02u", i);
puts(" ");
puts(" ");
mux_select(i); // select the channel
voltages = measure_voltages(); // measure raw voltages
print_fpu(voltages[2], 2);
const float raw = voltages[2]; // remember un-pulled voltage
puts(" ");
puts(" ");
gpio_clear(GPIO_PORT(SIGNAL_PD_PIN), GPIO_PIN(SIGNAL_PD_PIN)); // pull down signal
sleep_us(10); // wait a tiny bit for voltage to settle
@ -345,48 +346,28 @@ static void command_types(void* argument)
const bool low = (voltages[2] < 0.5); // remember if we were able to pull it down
const float pullup = (2000.0 * (raw - voltages[2]) / voltages[2]) / 1000.0; // estimate external pull-up
print_fpu(voltages[2], 2);
puts(" ");
if (pullup > 100.0) {
puts(">100");
} else if (pullup < 1.0) {
puts(" <1 ");
} else {
printf(" %02u ", (uint32_t)round(pullup));
}
puts(" ");
puts(" ");
gpio_clear(GPIO_PORT(SIGNAL_PU_PIN), GPIO_PIN(SIGNAL_PU_PIN)); // pull up signal
sleep_us(10); // wait a tiny bit for voltage to settle
voltages = measure_voltages(); // measure pulled up voltages
gpio_set(GPIO_PORT(SIGNAL_PU_PIN), GPIO_PIN(SIGNAL_PU_PIN)); // remove pull-up
voltages[2] = voltages[2] * 2.0 - voltages[1]; // pulling creates a voltage divider (to target)
const bool high = (voltages[2] > 3.2 || voltages[2] > voltages[1] * 0.5); // remember if we were able to pull it up
const bool high = (voltages[2] > 3.0 || voltages[2] > voltages[1] * 0.7); // remember if we were able to pull it up
const float pulldown = (2000.0 * voltages[2] / (voltages[1] - voltages[2])) / 1000.0; // estimate external pull-down
print_fpu(voltages[2], 2);
puts(" ");
if (pulldown > 100.0) {
puts(">100");
} else if (pulldown < 1.0) {
puts(" <1 ");
} else {
printf(" %02u ", (uint32_t)round(pulldown));
}
puts(" ");
puts(" ");
if (low && high) {
if (pullup > 1.0 && pullup < 100.0 && (pulldown < 1.0 || pulldown > 100.0)) {
puts("pulled-up");
} else if (pulldown > 1.0 && pulldown < 100.0 && (pullup < 1.0 || pullup > 100.0)) {
puts("pulled-down");
} else {
puts("floating");
}
if (pullup >= 0.9 && pullup < 100.0 && (pulldown <= 0.9 || pulldown > 100.0)) {
printf("pulled-up (%u kOhm)", (uint32_t)round(pullup));
} else if (pulldown >= 0.9 && pulldown < 100.0 && (pullup <= 0.9 || pullup > 100.0)) {
printf("pulled-down (%u kOhm)", (uint32_t)round(pulldown));
} else if (low) {
puts("low");
} else if (high) {
puts("high");
} else {
puts("unknown");
puts("floating");
}
putc('\n');
}