fix bug for LOAD, SLEEP and TYPE commands

Signed-off-by: Michel-FK <michel.stempin@funkey-project.com>
This commit is contained in:
Michel-FK 2021-04-05 11:02:16 +02:00
parent 7f08a1da67
commit 0f61df32cc
3 changed files with 18 additions and 60 deletions

View File

@ -110,9 +110,6 @@ static uint32_t current_gpio_mask;
/* Total bytes read from the FIFO */
static size_t total_bytes = 0;
/* Total bytes to write to the FIFO */
static size_t bytes_to_write = 0;
/* FIFO buffer */
char fifo_buffer[256];
@ -296,8 +293,8 @@ void deinit_gpio_mapping(void)
void handle_gpio_mapping(mapping_list_t *list)
{
int result, gpio, int_status, max_fd, fd, val_int_bank_3;
ssize_t read_bytes, bytes_written;
fd_set read_fds, write_fds, except_fds;
ssize_t read_bytes;
fd_set read_fds, except_fds;
uint32_t interrupt_mask, previous_gpio_mask;
bool pcal6416a_interrupt = false;
bool axp209_interrupt = false;
@ -309,11 +306,9 @@ void handle_gpio_mapping(mapping_list_t *list)
previous_gpio_mask = current_gpio_mask;
current_gpio_mask = 0;
/* Listen to FIFO read/write availability */
/* Listen to FIFO read availability */
FD_ZERO(&read_fds);
FD_SET(fd_fifo, &read_fds);
FD_ZERO(&write_fds);
FD_SET(fd_fifo, &write_fds);
/* Listen to interrupt exceptions */
FD_ZERO(&except_fds);
@ -333,11 +328,11 @@ void handle_gpio_mapping(mapping_list_t *list)
/* Select with debug (slow) timeout */
struct timeval timeout = {TIMEOUT_SEC_SANITY_CHECK_GPIO_EXP, 0};
result = select(max_fd + 1, &read_fds, &write_fds, &except_fds, &timeout);
result = select(max_fd + 1, &read_fds, NULL, &except_fds, &timeout);
#else
/* Select with no timeout */
result = select(max_fd + 1, &read_fds, &write_fds, &except_fds, NULL);
result = select(max_fd + 1, &read_fds, NULL, &except_fds, NULL);
#endif
if (result == 0) {
@ -385,27 +380,6 @@ void handle_gpio_mapping(mapping_list_t *list)
}
}
/* Check if we can write something to the FIFO */
if (FD_ISSET(fd_fifo, &write_fds)) {
while (bytes_to_write) {
bytes_written = write(fd_fifo, fifo_buffer, bytes_to_write);;
if (bytes_written > 0) {
bytes_to_write -= bytes_written;
LOG_DEBUG("Wrote %d bytes to FIFO: \"%.*s\"\n",
(int) bytes_written, (int) bytes_written, fifo_buffer);
} else if (errno == EWOULDBLOCK) {
/* FIFO is full */
LOG_DEBUG("FIFO is full, %d bytes left to write\n",
(int) bytes_to_write);
break;
} else {
LOG_ERROR("Cannot write to FIFO: %s\n", strerror(errno));
return;
}
}
}
/* Check which file descriptor is available for read */
for (fd = 0; fd <= max_fd; fd++) {
if (FD_ISSET(fd, &except_fds)) {

View File

@ -277,36 +277,25 @@ bool parse_config_line(char *line, mapping_list_t *list,
case STATE_DUMP:
break;
case STATE_LOAD:
state = STATE_FILE;
break;
case STATE_SLEEP:
state = STATE_DELAY;
break;
case STATE_KEYUP:
case STATE_KEYDOWN:
case STATE_KEYPRESS:
state = STATE_KEY;
break;
case STATE_TYPE:
state = STATE_TEXT;
break;
case STATE_DELAY:
for (s = token; *s; s++) {
if (!isdigit(*s)) {
LOG_ERROR("Invalid delay \"%s\"\n", token);
return false;
}
}
case STATE_FILE:
case STATE_TEXT:
case STATE_LOAD:
case STATE_TYPE:
strncpy(buffer, token, MAX_LINE_LENGTH);
break;
case STATE_KEYUP:
case STATE_KEYDOWN:
case STATE_KEYPRESS:
state = STATE_KEY;
break;
case STATE_FUNCTION:
state = lookup_function(token);
if (state == STATE_INVALID) {
@ -359,17 +348,18 @@ bool parse_config_line(char *line, mapping_list_t *list,
reset_mapping_list(list);
break;
case STATE_FILE:
case STATE_LOAD:
LOG_DEBUG("LOAD file \"%s\"\n", buffer);
return parse_config_file(buffer, list, monitored_gpio_mask);
break;
case STATE_DELAY:
case STATE_SLEEP:
LOG_DEBUG("SLEEP delay %s ms\n", buffer);
usleep(atoi(buffer) * 1000);
break;
case STATE_TEXT:
case STATE_TYPE:
LOG_DEBUG("TYPE \"%s\"\n", buffer);
break;
case STATE_KEY:
@ -452,9 +442,6 @@ bool parse_config_line(char *line, mapping_list_t *list,
break;
case STATE_MAP:
case STATE_LOAD:
case STATE_SLEEP:
case STATE_TYPE:
break;
default:

View File

@ -63,14 +63,11 @@ typedef enum {GPIOS} button_t;
X(STATE_UNMAP, "UNMAP") \
X(STATE_RESET, "RESET") \
X(STATE_LOAD, "LOAD") \
X(STATE_FILE, "FILE") \
X(STATE_SLEEP, "SLEEP") \
X(STATE_DELAY, "DELAY") \
X(STATE_KEYUP, "KEYUP") \
X(STATE_KEYDOWN, "KEYDOWN") \
X(STATE_KEYPRESS, "KEYPRESS") \
X(STATE_TYPE, "TYPE") \
X(STATE_TEXT, "TEXT") \
X(STATE_FUNCTION, "FUNCTION") \
X(STATE_KEY, "KEY") \
X(STATE_COMMAND, "COMMAND")\