This file contains code for a task which prints things from a queue. More...
Functions | |
| def | print_task.put (a_string) |
| Put a string into the print queue so it can be printed by the printing task whenever that task gets a chance. More... | |
| def | print_task.put_bytes (b_arr) |
Put bytes from a bytearray or bytes into the print queue. More... | |
| def | print_task.run () |
| Run function for the task which prints stuff. More... | |
Variables | |
| print_task.BUF_SIZE = const (100) | |
| The size of the buffer which will hold characters to be printed when the print task has time to print them. | |
| bool | print_task.THREAD_PROTECT = True |
| A flag which is passed to the queue constructor to control whether the queue will protect puts and gets from being corrupted by interrupts. | |
| bool | print_task.PROFILE = True |
| A flag which controls if the printing task is to be profiled. | |
| print_task.print_queue | |
| This queue holds characters to be printed when the print task gets around to it. More... | |
| print_task.print_task | |
| This is the task which schedules printing. More... | |
This file contains code for a task which prints things from a queue.
It helps to reduce latency in a system having tasks which print because it sends things to be printed out the serial port one character at a time, even when other tasks put whole strings into the queue at once. When run as a low-priority task, this allows higher priority tasks to interrupt the printing between characters, even when all the tasks are being cooperatively scheduled with a priority-based scheduler.
Example code:
| def print_task.put | ( | a_string | ) |
Put a string into the print queue so it can be printed by the printing task whenever that task gets a chance.
If the print queue is full, characters are lost; this is better than blocking to wait for space in the queue, as we'd block the printing task and space would never open up. When a character has been put into the queue, the go() method of the print task is called so that the run method will be called as soon as the print task is run by the task scheduler.
| a_string | A string to be put into the queue |
| def print_task.put_bytes | ( | b_arr | ) |
Put bytes from a bytearray or bytes into the print queue.
When characters have been put into the queue, the go() method of the print task is called so that the run method will be called as soon as the print task is run by the task scheduler.
| b_arr | The bytearray whose contents go into the queue |
| def print_task.run | ( | ) |
Run function for the task which prints stuff.
This function checks for any characters to be printed in the queue; if any characters are found then one character is printed, after which the print task yields so other tasks can run. This functino must be called periodically; the normal way is to make it the run function of a low priority task in a cooperatively multitasked system so that the task scheduler calls this function when the higher priority tasks don't need to run.
| print_task.print_queue |
This queue holds characters to be printed when the print task gets around to it.
| print_task.print_task |
This is the task which schedules printing.