stdin: add btstack_stdin_read() and use in examples

This commit is contained in:
Matthias Ringwald 2016-11-30 11:29:55 +01:00
parent d198cb2001
commit a1dc4edb43
6 changed files with 21 additions and 6 deletions

View File

@ -335,7 +335,7 @@ static void show_usage(void){
}
static void stdin_process(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type){
read(ds->fd, &cmd, 1);
cmd = btstack_stdin_read();
switch (cmd){
case 'a':
log_info("USER:\'%c\'", cmd);

View File

@ -152,7 +152,8 @@ static void show_usage(void){
}
static void stdin_process(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type){
read(ds->fd, &cmd, 1);
cmd = btstack_stdin_read();
if (cmd >= '0' && cmd <= '9'){
printf("DTMF Code: %c\n", cmd);

View File

@ -121,8 +121,8 @@ static void show_usage(void){
#ifdef HAVE_POSIX_STDIN
static void stdin_process(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type){
char buffer;
read(ds->fd, &buffer, 1);
char buffer = btstack_stdin_read();
switch (buffer){
case 'c':

View File

@ -121,8 +121,8 @@ static void show_usage(void){
#ifdef HAVE_POSIX_STDIN
static void stdin_process(btstack_data_source_t *ds, btstack_data_source_callback_type_t callback_type){
char buffer;
read(ds->fd, &buffer, 1);
char buffer = btstack_stdin_read();
switch (buffer){
case 'c':

View File

@ -37,6 +37,8 @@
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include "btstack_run_loop.h"
#include <stdlib.h>
@ -89,6 +91,7 @@ void btstack_stdin_reset(void){
#endif
}
#if 0
static int getstring(char *line, int size)
{
int i = 0;
@ -109,4 +112,12 @@ static int getstring(char *line, int size)
line[i] = 0;
return i;
}
#endif
// read single byte after data source callback was triggered
char btstack_stdin_read(void){
char buffer;
read(stdin_source.fd, &buffer, 1);
return buffer;
}

View File

@ -47,6 +47,9 @@ extern "C" {
// setup handler for command line interface
void btstack_stdin_setup(void (*stdin_handler)(btstack_data_source_t *_ds, btstack_data_source_callback_type_t callback_type));
// read single byte after data source callback was triggered
char btstack_stdin_read(void);
// gets called by main.c
void btstack_stdin_reset(void);