float get_umidade_relativa() { int uart_descriptor = open_uart(); if (uart_descriptor == -1) return 0; unsigned char buffer[5]; buffer[0] = 0x06; buffer[1] = 3; buffer[2] = 2; buffer[3] = 9; buffer[4] = 8; if (write_uart(uart_descriptor, buffer, 5) == -1) return 0; printf("Escrita completa!\n"); float umidade; if (read_uart(uart_descriptor, (void*) &umidade, 4) == -1) return 0; printf("Leitura completa!\n"); close(uart_descriptor); return umidade; }
void main( void ) { init_uart(); while(1) { print_menu(); switch(read_uart()) { case '1': write_eeprom(1); break; case '2': read_eeprom(1); break; case '3': clear_eeprom(); break; case '4': write_eeprom(0); read_eeprom(0); break; default: writeln_uart("wrong input\r\n"); break; } } }
// transmit_bytes("$ PSRF105,1,*3E\r\n"); int main(void) { printf("UART - READER\n"); // unsigned char expr[] = "$PSRF100,1,4800,1,0*0C\r\n"; // const unsigned char* ptr = checksum(&expr[0]); // printf("%s",ptr); constexpr size_t bufflen = 512u; int handle = setup_uartconn(); unsigned char *buffer = (unsigned char *)malloc(bufflen); if (handle != -1) { set_message_freq(handle); for (int i = 0; i < 100; ++i) { read_uart(handle, buffer, bufflen); sleep(1); } close_uartconn(handle); } free(buffer); return 0; }
/*sets up loop for phase accumulator interrupt to occur in. *Everything Goes on inside this loop*/ void play_sounds(void) { populate_note_buffer(); init_sound_led(); //Set initial waveform //waveForm = &sinLut[0]; //waveForm = &sawLut[0]; //waveForm = &triLut[0]; //waveForm = &squareLut[0]; while(1) { get_POT_set_TWIPOT(); check_low_buttons(); check_high_buttons(); check_switch(); //2 Byte buffer full with a message, read it if (uartCount > 1) { read_uart(); } //Ensure notes off are off if (tword1 == 0) { sound_led_off(); phacc1 = 0; } if (tword2 == 0) { phacc2 = 0; } if (tword3 == 0) { phacc3 = 0; } //NCO 1 will be always the first and last used //Use to trigger the Sound playing LED, and disabling the timeout if (tword1 != 0) { reset_timeout(); sound_led_on(); } } }
void uart_console_isr(struct device *unused) { ARG_UNUSED(unused); while (uart_irq_update(uart_console_dev) && uart_irq_is_pending(uart_console_dev)) { static struct uart_console_input *cmd; uint8_t byte; int rx; if (!uart_irq_rx_ready(uart_console_dev)) { continue; } /* Character(s) have been received */ rx = read_uart(uart_console_dev, &byte, 1); if (rx < 0) { return; } if (uart_irq_input_hook(uart_console_dev, byte) != 0) { /* * The input hook indicates that no further processing * should be done by this handler. */ return; } if (!cmd) { cmd = nano_isr_fifo_get(avail_queue, TICKS_NONE); if (!cmd) return; } /* Handle ANSI escape mode */ if (atomic_test_bit(&esc_state, ESC_ANSI)) { handle_ansi(byte); continue; } /* Handle escape mode */ if (atomic_test_and_clear_bit(&esc_state, ESC_ESC)) { switch (byte) { case ANSI_ESC: atomic_set_bit(&esc_state, ESC_ANSI); atomic_set_bit(&esc_state, ESC_ANSI_FIRST); break; default: break; } continue; } /* Handle special control characters */ if (!isprint(byte)) { switch (byte) { case DEL: if (cur > 0) { del_char(&cmd->line[--cur], end); } break; case ESC: atomic_set_bit(&esc_state, ESC_ESC); break; case '\r': cmd->line[cur + end] = '\0'; uart_poll_out(uart_console_dev, '\r'); uart_poll_out(uart_console_dev, '\n'); cur = 0; end = 0; nano_isr_fifo_put(lines_queue, cmd); cmd = NULL; break; case '\t': if (completion_cb && !end) { cur += completion_cb(cmd->line, cur); } break; default: break; } continue; } /* Ignore characters if there's no more buffer space */ if (cur + end < sizeof(cmd->line) - 1) { insert_char(&cmd->line[cur++], byte, end); } } }
void uart_console_isr(struct device *unused) { ARG_UNUSED(unused); while (uart_irq_update(uart_console_dev) && uart_irq_is_pending(uart_console_dev)) { static struct console_input *cmd; u8_t byte; int rx; if (!uart_irq_rx_ready(uart_console_dev)) { continue; } /* Character(s) have been received */ rx = read_uart(uart_console_dev, &byte, 1); if (rx < 0) { return; } #ifdef CONFIG_UART_CONSOLE_DEBUG_SERVER_HOOKS if (debug_hook_in != NULL && debug_hook_in(byte) != 0) { /* * The input hook indicates that no further processing * should be done by this handler. */ return; } #endif if (!cmd) { cmd = k_fifo_get(avail_queue, K_NO_WAIT); if (!cmd) { return; } } #ifdef CONFIG_UART_CONSOLE_MCUMGR /* Divert this byte from normal console handling if it is part * of an mcumgr frame. */ if (handle_mcumgr(cmd, byte)) { continue; } #endif /* CONFIG_UART_CONSOLE_MCUMGR */ /* Handle ANSI escape mode */ if (atomic_test_bit(&esc_state, ESC_ANSI)) { handle_ansi(byte, cmd->line); continue; } /* Handle escape mode */ if (atomic_test_and_clear_bit(&esc_state, ESC_ESC)) { if (byte == ANSI_ESC) { atomic_set_bit(&esc_state, ESC_ANSI); atomic_set_bit(&esc_state, ESC_ANSI_FIRST); } continue; } /* Handle special control characters */ if (!isprint(byte)) { switch (byte) { case DEL: if (cur > 0) { del_char(&cmd->line[--cur], end); } break; case ESC: atomic_set_bit(&esc_state, ESC_ESC); break; case '\r': cmd->line[cur + end] = '\0'; uart_poll_out(uart_console_dev, '\r'); uart_poll_out(uart_console_dev, '\n'); cur = 0; end = 0; k_fifo_put(lines_queue, cmd); cmd = NULL; break; case '\t': if (completion_cb && !end) { cur += completion_cb(cmd->line, cur); } break; default: break; } continue; } /* Ignore characters if there's no more buffer space */ if (cur + end < sizeof(cmd->line) - 1) { insert_char(&cmd->line[cur++], byte, end); } } }