A repository for MicroPython code that communicates with and relays information from the Texas Instruments TMP117/119 temperature sensor.
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
class TopicMessage(): "Object containing both a topic and message string attribute. Can convert itself to a string representation" def __init__(self, topic:str = "", message:str = ""): self.topic = topic self.message = message def to_string(self) -> str: return f"{self.topic}: {self.message}"
class TMQueue(): """Simple queue (FIFO) of TopicMessage objects""" def __init__(self): self.data: list[TopicMessage] = list()
def get(self): if not self.is_empty(): item = self.data.pop(0) return item else: raise IndexError
def add(self, item): self.data.append(item)
def is_empty(self): if len(self.data) == 0: return True else: return False
def string_to_topicmessage(s: str): """Convert string to a TopicMessage object""" topic, message = str.split(":", maxsplit = 1) return TopicMessage(topic, message)
|