From b9df8e7e301e5b75e40ed6ea6ef36895dbc46b3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Thu, 10 Dec 2020 18:19:51 +0100 Subject: [PATCH] application: add segment selector --- application.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/application.c b/application.c index 6270d6b..9df6f49 100644 --- a/application.c +++ b/application.c @@ -673,6 +673,52 @@ static void command_bed_power(void* argument) } } +/** switch transistors to power to TEC segments + * @param[in] argument pointer to unsigned integer: 0 to power all off + */ +static void command_bed_segment(void* argument) +{ + + if (argument) { // segment has been provided + const int32_t segment = *(int32_t*)argument; // get while segment to turn on/off + switch (segment) { + case 0: // switch all off + gpio_set(GPIO_PORT(MBLK019_CH26_PIN), GPIO_PIN(MBLK019_CH26_PIN)); + gpio_set(GPIO_PORT(MBLK019_CH14_PIN), GPIO_PIN(MBLK019_CH14_PIN)); + gpio_set(GPIO_PORT(MBLK019_CH35_PIN), GPIO_PIN(MBLK019_CH35_PIN)); + break; + case 1: + gpio_clear(GPIO_PORT(MBLK019_CH26_PIN), GPIO_PIN(MBLK019_CH26_PIN)); + break; + case -1: + gpio_set(GPIO_PORT(MBLK019_CH26_PIN), GPIO_PIN(MBLK019_CH26_PIN)); + break; + case 2: + gpio_clear(GPIO_PORT(MBLK019_CH14_PIN), GPIO_PIN(MBLK019_CH14_PIN)); + break; + case -2: + gpio_set(GPIO_PORT(MBLK019_CH14_PIN), GPIO_PIN(MBLK019_CH14_PIN)); + break; + case 3: + gpio_clear(GPIO_PORT(MBLK019_CH35_PIN), GPIO_PIN(MBLK019_CH35_PIN)); + break; + case -3: + gpio_set(GPIO_PORT(MBLK019_CH35_PIN), GPIO_PIN(MBLK019_CH35_PIN)); + break; + default: + printf("unknown segment: %d\n", segment); + break; + } + sleep_ms(1); // wait to take effect + } + + // print segment status + printf("CH26: %s CH14: %s CH35: %s\n", \ + gpio_get(GPIO_PORT(MBLK019_CH26_PIN), GPIO_PIN(MBLK019_CH26_PIN)) ? "off" : "on", \ + gpio_get(GPIO_PORT(MBLK019_CH14_PIN), GPIO_PIN(MBLK019_CH14_PIN)) ? "off" : "on", \ + gpio_get(GPIO_PORT(MBLK019_CH35_PIN), GPIO_PIN(MBLK019_CH35_PIN)) ? "off" : "on"); +} + /** switch power to lid heater * @param[in] argument pointer to unsigned integer: 0 to power off, 1 to power on */ @@ -780,6 +826,14 @@ static const struct menu_command_t menu_commands[] = { .argument_description = "[+-temp]", .command_handler = &command_bed_power, }, + { + .shortcut = 's', + .name = "segment", + .command_description = "TEC segment configuration", + .argument = MENU_ARGUMENT_SIGNED, + .argument_description = "[+-0,1,2,3]", + .command_handler = &command_bed_segment, + }, { .shortcut = 'L', .name = "lid_power",