diff --git a/module/mod.py b/module/mod.py index 03e6e24..952285a 100644 --- a/module/mod.py +++ b/module/mod.py @@ -1,18 +1,7 @@ """ Python module for the Vision module. """ from client.comm import BaseComm from common.frame_enum import FrameType - -# TODO: make a PR for this frame type - - -class FRAMETYPE: - def __init__(self): - self.msg = "" - self.width = 0 - self.height = 0 - self.distance = 0 - self.x_offset = 0 - self.y_offset = 0 +from common.frames import FrameQrcodeData class Vision: @@ -45,34 +34,29 @@ def reset_reader(self, new_reader): def process(self): """ The process function that's provided by the template. This generates QR codes from a video frame and puts them on the bus by request. """ - # self.comm.send(FrameType.BUTTON_STATE, (1,2,3)) - - video_frame = self.video_feed.get_frame() - self.qr_reader.read_qr_codes(video_frame, self.cp) - - frames = list() - codes = self.qr_reader.get_qr_codes() - if codes: - for code in codes: - frame = FRAMETYPE() - frame.msg = code.get_value("Data") - frame.width = code.get_value("Width") - frame.height = code.get_value("Height") - frame.distance = code.get_distance() - center = code.get_center_offset() - if center: - frame.x_offset = center[0] - frame.y_offset = center[1] - frames.append(frame) - - if 1: # TODO: this 'if' should trigger on data request - for frame in frames: - print(" width {} height {} distance {} offsetx {} offsety {}".format( - frame.width, frame.height, frame.distance, frame.x_offset, frame.y_offset)) - # self.comm.send(frame) - while self.comm.has_data(): - print(self.comm.get_data()) + frame = self.comm.get_data() + + # if its a request we process the current video feed frame + if frame.request: + video_frame = self.video_feed.get_frame() + self.qr_reader.read_qr_codes(video_frame, self.cp) + frames = list() + codes = self.qr_reader.get_qr_codes() + + # if we found codes we make a frame based on the code and add it to the list to send off + if codes: + for code in codes: + center = code.get_center_offset() + frame = FrameQrcodeData() + byte_string = bytes(code.get_value("Data"), 'utf-8') + frame.set_data(byte_string, int(code.get_value("Width")), int(code.get_value( + "Height")), int(center[0]), int(center[1]), int(code.get_distance())) + self.comm.send(frame) + + # send off the frames + for frame in frames: + self.comm.send(frame) def stop(self): """ Stop function provided by the template. """