From 17eae752de46cb3c5e36a6665a87e9caba2757f4 Mon Sep 17 00:00:00 2001 From: Marco Date: Mon, 23 May 2022 21:29:17 +0200 Subject: [PATCH] Add commands for manipulating pins. And other CRAAAAAZY stuff. --- src/commands.c | 55 ++++++++++++++++++++++++++++++++++++------ src/include/commands.h | 2 +- src/inverter.c | 10 ++++++-- 3 files changed, 56 insertions(+), 11 deletions(-) diff --git a/src/commands.c b/src/commands.c index 0608257..a1053ad 100644 --- a/src/commands.c +++ b/src/commands.c @@ -3,7 +3,8 @@ #include #include -#include "include/commands.h" +#include "commands.h" +#include "pins.h" cmd_t command = { .buf = {0}, @@ -48,8 +49,8 @@ void cmd_handle(cmd_t *command) if (0 == strcmp(tok1, "set")) cmd_handle_set(tok2, tok3); - if (0 == strcmp(tok1, "switch")) - cmd_handle_switch(); + if (0 == strcmp(tok1, "switch") || 0 == strcmp(tok1, "sw")) + cmd_handle_switch(tok2, tok3); } void cmd_handle_set(char *op1, char *op2) @@ -93,12 +94,50 @@ void cmd_handle_set(char *op1, char *op2) } } -void cmd_handle_switch(void) +void cmd_handle_switch(char *op1, char *op2) { - int state = 0; + if (0 == strcmp(op1, "pd6")) { + if (0 == strcmp(op2, "on")) + setPin(&PORTD, PD6); + else if (0 == strcmp(op2, "off")) + unsetPin(&PORTD, PD6); + else + togglePin(&PORTD, PD6); + } - PORTD ^= (1<1) { - _delay_us(1); + _delay_ms(5); PORTB &= ~(1<