Simple terminal-based user interface based on ncurses. See sensor_simulator.h.
More...
#include <pthread.h>
#include <ncurses.h>
#include <stdlib.h>
#include <string.h>
#include "sensor_simulator.h"
#include "include/api/schedule.h"
#include "util.h"
#include "low_level_platform.h"
Simple terminal-based user interface based on ncurses. See sensor_simulator.h.
- Author
- Edward A. Lee
- Copyright
- (c) 2020-2023, The University of California at Berkeley and UT Dallas. License in BSD 2-clause
◆ LF_SENSOR_TRIGGER_TABLE_SIZE
#define LF_SENSOR_TRIGGER_TABLE_SIZE 96 |
◆ WGETCHR_TIMEOUT
#define WGETCHR_TIMEOUT 1000 |
◆ _lf_sensor_message_t
typedef struct _lf_sensor_message_t _lf_sensor_message_t |
◆ _lf_sensor_message_type
Enumerator |
---|
_lf_sensor_message | |
_lf_sensor_tick | |
_lf_sensor_close_windows | |
◆ _lf_print_message_function()
void _lf_print_message_function |
( |
const char * | format, |
|
|
va_list | args ) |
Function to register to handle printing of messages in util.h/c. This acquires the mutex lock.
◆ _lf_sensor_post_message()
Post a message to be displayed. This acquires the mutex lock.
- Parameters
-
type | The message type, one of _lf_sensor_message, _lf_sensor_tick, or _lf_sensor_close_window. |
body | The message, or NULL for exit type. |
◆ _lf_sensor_read_input()
void * _lf_sensor_read_input |
( |
void * | ignored | ) |
|
Thread to read input characters until an EOF is received. For each character received, if there is a registered trigger for that character, schedule that trigger with a payload equal to the character that was typed. Otherwise, the character is ignored.
◆ _lf_sensor_simulator_thread()
void * _lf_sensor_simulator_thread |
( |
void * | ignored | ) |
|
Thread to display strings in either the tick window or the message window.
◆ _lf_show_message()
void _lf_show_message |
( |
const char * | message_lines[], |
|
|
int | number_of_lines ) |
Put a persistent message in the upper left of the terminal window. The message will be left justified, with each string in the specified array on a new line. This should not be called directly by the user. It assumes the mutex lock is held.
- Parameters
-
message_lines | The message lines. |
number_of_lines | The number of lines. |
◆ _lf_start_print_window()
void _lf_start_print_window |
( |
int | above, |
|
|
int | right ) |
Start a window on the bottom left of the terminal window for printed messages from the application. This should not be called directly by the user. It assumes the mutex lock is held.
- Parameters
-
above | Space to leave above the window. |
right | Space to leave to the right of the window. |
◆ _lf_start_tick_window()
void _lf_start_tick_window |
( |
int | width | ) |
|
Start a tick window on the right of the terminal window. This should not be called directly by the user. It assumes the mutex lock is held.
- Parameters
-
width | The width of the window. |
◆ end_sensor_simulator()
void end_sensor_simulator |
( |
| ) |
|
End ncurses control of the terminal.
◆ register_sensor_key()
int register_sensor_key |
( |
char | key, |
|
|
void * | action ) |
Register a keyboard key to trigger the specified action. Printable ASCII characters (codes 32 to 127) are supported plus '
' and '\0', where the latter registers a trigger to invoked when any key is pressed. If a specific key is registered and any key ('\0') is also registered, the any key trigger will be scheduled after the specific key is scheduled. If these triggers belong to different reactors, they could be invoked in parallel. This will fail if the specified key has already been registered (error code 1), or the key is not a supported key or a newline ‘
’ or any key '\0' (error code 2) or if the trigger is NULL (error code 3).
- Parameters
-
key | The key to register. |
action | The action to trigger when the key is pressed (a pointer to an lf_action_based_t struct). |
- Returns
- 0 for success, error code for failure.
◆ show_tick()
void show_tick |
( |
const char * | character | ) |
|
Place a tick (usually a single character) in the tick window.
- Parameters
-
character | The tick character. |
◆ start_sensor_simulator()
int start_sensor_simulator |
( |
const char * | message_lines[], |
|
|
int | number_of_lines, |
|
|
int | tick_window_width, |
|
|
char * | log_file, |
|
|
int | log_level ) |
Start the sensor simulator if it has not been already started. This must be called at least once before any call to register_sensor_key. The specified message is an initial message to display at the upper left, typically a set of instructions, that remains displayed throughout the lifetime of the window. Please ensure that the message_lines array and its contained strings are not on the stack because they will be used later in a separate thread.
- Parameters
-
message_lines | The message lines. |
number_of_lines | The number of lines. |
tick_window_width | The width of the tick window or 0 for none. |
log_file | If non-NULL, the name of a file to which to write logging messages. |
log_level | The level of log messages to redirect to the file. The level should be one of LOG_LEVEL_ERROR, LOG_LEVEL_WARNING, LOG_LEVEL_INFO, LOG_LEVEL_LOG, LOG_LEVEL_DEBUG, or LOG_LEVEL_ALL. |
- Returns
- 0 for success, error code for failure.
◆ [struct]
struct { ... } _lf_sensor |
◆ _lf_sensor_any_key_trigger
◆ _lf_sensor_mutex
◆ _lf_sensor_sensor_newline_trigger
Trigger for the newline character '
', which is platform dependent.
◆ _lf_sensor_simulator_cond_var
◆ _lf_sensor_trigger_table
Table of Lingua Franca trigger objects to schedule in response to keypresses.
◆ default_window
Default window from which to get input characters. If show_welcome_message() is called, this will be the welcome message window. Otherwise, it will be stdscr, the default curses window.
◆ input_thread_id
◆ log_file
File to which to write log data, or NULL to send to window.
◆ message_q
◆ message_recycle_q
◆ output_thread_id
◆ print_cursor_x
◆ print_cursor_y
◆ print_window
◆ print_window_height
◆ thread_created
◆ tick_cursor_x
Keep track of the tick cursor position directly so it doesn't get as messed up by printf() calls.
◆ tick_cursor_y
◆ tick_window
◆ tick_window_width
The width of the tick window.
◆ welcome_message
const char** welcome_message |
◆ welcome_message_length
int welcome_message_length |
The length of the welcome message.