Implemented state for beans..

Including setting based on received messages.
This commit is contained in:
CiscoTheWolf 2023-05-31 18:56:15 +02:00
parent 4c2dda2211
commit bb23a24fa4
2 changed files with 26 additions and 3 deletions

View file

@ -15,6 +15,7 @@ class ProotState:
cls._instance.frame_canvas_prootScreen_2 = False
cls._instance.frame_canvas_prootScreen_3 = False
cls._instance.matrix = False
cls._instance.bean_states = [False] * 4
return cls._instance
def set_matrix(self, matrix):
@ -78,6 +79,27 @@ class ProotState:
matrix.SwapOnVSync(self.frame_canvas_prootScreen_2)
else:
matrix.SwapOnVSync(self.frame_canvas_prootScreen_3)
def set_bean(self, bean_number, bean_state):
self.bean_states[bean_number] = bean_state
class BeanSet:
def __init__(self, num_beans):
self.num_beans = num_beans
self.bean_states = [False] * num_beans # Initialize all beans as closed
def set_bean_state(self, index, state):
if 0 <= index < self.num_beans:
self.bean_states[index] = state
else:
print("Invalid bean index.")
def get_bean_state(self, index):
if 0 <= index < self.num_beans:
return self.bean_states[index]
else:
print("Invalid bean index.")
def update_screen(self, blinkFrameCanvases, matrix):

View file

@ -136,11 +136,12 @@ def on_connect(client, userdata, flags, response_code):
def on_message(client, userdata, message):
print("Received message '" + str(message.payload) + "' on topic '"
+ message.topic + "' with QoS " + str(message.qos))
pin_number = str(message.payload)[12:13]
pin_state = str(message.payload)[6:10]
print("pin number: " + pin_number+ " pin state: " + pin_state)
bean_number = str(message.payload)[12:13]
bean_state = str(message.payload)[6:10]
print("pin number: " + bean_number + " pin state: " + bean_state)
proot_state = ProotState()
proot_state.blink()
proot_state.set_bean(bean_number, bean_state)
# MQTT broker configuration
broker_address = "10.1.13.173" # Replace with your MQTT broker's address