Serial Wombat Arduino Library
SerialWombatQueue.h
Go to the documentation of this file.
1 #pragma once
2 /*
3 Copyright 2020-2021 Broadwell Consulting Inc.
4 
5 "Serial Wombat" is a registered trademark of Broadwell Consulting Inc. in
6 the United States. See SerialWombat.com for usage guidance.
7 
8 Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation
11  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  * and/or sell copies of the Software, and to permit persons to whom the
13  * Software is furnished to do so, subject to the following conditions:
14 
15 The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24  * OTHER DEALINGS IN THE SOFTWARE.
25 */
26 
27 #include <stdint.h>
28 #include "SerialWombat.h"
29 
30 
34 };
35 
38 
39 class SerialWombatQueue : public Stream
40 {
41 public:
44  SerialWombatQueue(SerialWombatChip& serialWombat);
45 
52  int16_t begin(uint16_t index, uint16_t length, SerialWombatQueueType qtype = SerialWombatQueueType::QUEUE_TYPE_RAM_BYTE);
53 
56  int available();
59  int read();
61  void flush();
64  int peek();
68 
69  size_t write(uint8_t data);
70 
81  size_t write(const uint8_t* buffer, size_t size);
82 
85  int availableForWrite();
86 
95  size_t readBytes(char* buffer, size_t length);
96 
97  uint16_t startIndex = 0xFFFF;
98  uint16_t length = 0;
99 
100  void setTimeout(long timeout_mS);
101 
102  //TODO add copy interface
103 private:
104  SerialWombatChip& _sw;
105 
106 
107  uint32_t _timeout = 500;
108 };
SerialWombatChip
Class for a Serial Wombat chip. Each Serial Wombat chip on a project should have its own instance.
Definition: SerialWombat.h:272
SerialWombatQueue::write
size_t write(uint8_t data)
Write a byte to the Serial Wombat Queue.
Definition: SerialWombatQueue.cpp:71
SerialWombatQueue::setTimeout
void setTimeout(long timeout_mS)
Definition: SerialWombatQueue.cpp:240
SerialWombatQueueType::QUEUE_TYPE_RAM_BYTE
@ QUEUE_TYPE_RAM_BYTE
A queue that queues byte-sized data in a queue in the User RAM area.
SerialWombatQueue::startIndex
uint16_t startIndex
Definition: SerialWombatQueue.h:97
SerialWombatQueue::length
uint16_t length
Definition: SerialWombatQueue.h:98
SerialWombatQueue::flush
void flush()
Discard all received bytes.
Definition: SerialWombatQueue.cpp:51
SerialWombat.h
SerialWombatQueue::read
int read()
Reads a byte from the Serial Wombat.
Definition: SerialWombatQueue.cpp:38
SerialWombatQueue::SerialWombatQueue
SerialWombatQueue(SerialWombatChip &serialWombat)
Constructor for SerialWombatWS2812 class.
Definition: SerialWombatQueue.cpp:4
SerialWombatQueue::begin
int16_t begin(uint16_t index, uint16_t length, SerialWombatQueueType qtype=SerialWombatQueueType::QUEUE_TYPE_RAM_BYTE)
Initialize a Serial Wombat Queue (RAM Bytes) in User Memory Area on Serial Wombat Chip.
Definition: SerialWombatQueue.cpp:9
SerialWombatQueueType::QUEUE_TYPE_RAM_BYTE_SHIFT
@ QUEUE_TYPE_RAM_BYTE_SHIFT
A queue that queues byte-sized data in a queue in the User RAM area.
SerialWombatQueueType
SerialWombatQueueType
Definition: SerialWombatQueue.h:31
SerialWombatQueue::readBytes
size_t readBytes(char *buffer, size_t length)
Reads a specified number of bytes from the Serial Wombat Queue.
Definition: SerialWombatQueue.cpp:187
SerialWombatQueue::available
int available()
Queries the Serial Wombat for number bytes available to read.
Definition: SerialWombatQueue.cpp:26
SerialWombatQueue::peek
int peek()
Query the Serial Wombat for the next avaialble byte, but don't remove it from the queue.
Definition: SerialWombatQueue.cpp:56
SerialWombatQueue
A Class representing a Queue in the User Ram area on the Serial Wombat Chip.
Definition: SerialWombatQueue.h:39
SerialWombatQueue::availableForWrite
int availableForWrite()
Queries the Serial Wombat for the amount of free queue space.
Definition: SerialWombatQueue.cpp:175