#include <stdio.h>
#include <string.h>
-#include "uart.h"
#include "pico/stdlib.h"
#include "hardware/uart.h"
#define UART_TX_PIN 16
#define UART_RX_PIN 17
-#define MAX_COMMAND_LENGTH 32
-
#define PINA 6
#define PINB 7
#define PINC 8
#define PIND 9
-void set_power_state(char relay, bool on) {
- uint state;
- if (on)
- state = 0;
- else
- state = 1;
-
- uint pin;
- switch (relay) {
- case 'a' :
- pin = PINA;
- break;
- case 'b' :
- pin = PINB;
- break;
- case 'c' :
- pin = PINC;
- break;
- case 'd' :
- pin = PIND;
- break;
- }
-
- gpio_put(pin, state);
-}
-
int main() {
- char command_string[MAX_COMMAND_LENGTH + 1];
- command_string[0] = 0;
- uint command_len = 0;
uart_init(UART_ID, 9600);
gpio_set_function(UART_TX_PIN, GPIO_FUNC_UART);
gpio_put(PINC, 1);
gpio_put(PIND, 1);
- bool eol;
- char word[9];
- char relay;
- while (true) {
- read_word(UART_ID, word, 9, &eol);
- if (strcmp(word, "on") == 0) {
- if (eol) {
- uart_puts(UART_ID, "Missing argument: n");
- continue;
- }
- relay = uart_getc(UART_ID);
- finish_line(UART_ID);
- set_power_state(relay, true);
- } else if (strcmp(word, "off") == 0) {
- if (eol) {
- uart_puts(UART_ID, "Missing argument: n");
- continue;
- }
- relay = uart_getc(UART_ID);
- finish_line(UART_ID);
- set_power_state(relay, false);
- } else if (strcmp(word, "temps") == 0) {
- uart_puts(UART_ID, "Not implemented yet");
+ char last_char;
+ while (true) {
+ last_char = uart_getc(UART_ID);
+ switch (last_char) {
+ case 'a' :
+ gpio_put(PINA, 1);
+ break;
+ case 'b' :
+ gpio_put(PINB, 1);
+ break;
+ case 'c' :
+ gpio_put(PINC, 1);
+ break;
+ case 'd' :
+ gpio_put(PIND, 1);
+ break;
+ case 'A' :
+ gpio_put(PINA, 0);
+ break;
+ case 'B' :
+ gpio_put(PINB, 0);
+ break;
+ case 'C' :
+ gpio_put(PINC, 0);
+ break;
+ case 'D' :
+ gpio_put(PIND, 0);
+ break;
+ case 't' :
+ uart_puts(UART_ID, "Not implemented yet \n");
+ break;
+ default :
+ break;
}
}
}