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.print_task_function () |
Task function for the task which prints stuff. More... | |
Variables | |
print_task.PT_BUF_SIZE = const (1000) | |
The size of the buffer which will hold characters to be printed when the print task has time to print them. | |
print_task.print_queue | |
This queue holds characters to be printed when the print task gets around to it. 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:
It is intended for educational use only, but its use is not limited thereto. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
def print_task.print_task_function | ( | ) |
Task 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 function 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.
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 |
print_task.print_queue |
This queue holds characters to be printed when the print task gets around to it.
It is always created when print_task is imported as a module.