Skip to content

Commit 1d82a54

Browse files
author
timothy Tamm
committed
added humidity messages
1 parent 0418c5d commit 1d82a54

6 files changed

+99
-19
lines changed

guiModule.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
class GuiModule(rm.ProtoModule):
2222
def __init__(self, addr, port):
23-
self.subscriptions = [MsgType.CAMERA_FRAME_MSG, MsgType.CTRL_MSG]
23+
self.subscriptions = [MsgType.CAMERA_FRAME_MSG, MsgType.CTRL_MSG, MsgType.HUMIDITY_MSG]
2424
super().__init__(addr, port, message_buffers, MsgType, FREQUENCY, self.subscriptions)
2525
self.frames = {}
2626
pygame.init()
@@ -30,6 +30,7 @@ def __init__(self, addr, port):
3030
self.roll = 0
3131
self.yaw = 0
3232
self.pitch = 0
33+
self.humidity = 0
3334

3435
def msg_received(self, msg, msg_type):
3536
# This gets called whenever any message is received
@@ -40,6 +41,8 @@ def msg_received(self, msg, msg_type):
4041
self.roll = msg.roll * 90
4142
self.pitch = msg.pitch * 90
4243
self.yaw = msg.yaw * 90
44+
elif msg_type = MsgType.HUMIDITY_MSG
45+
self.humidity = msg.humidity
4346

4447
def tick(self):
4548
for event in pygame.event.get():
@@ -48,9 +51,14 @@ def tick(self):
4851
self._display_frames()
4952
if self.navball_ticks % int(FREQUENCY/NAVBALL_FREQ) == 0:
5053
self.navball.draw(self.yaw, self.roll, self.pitch)
54+
self._draw_sensor_values()
5155
pygame.display.update()
5256
self.navball_ticks += 1
5357

58+
def _draw_sensor_values(self):
59+
hum_surface = self.font.render('Humidity={1:0.1f}%'.format(self.humidity), True, (255, 255, 255))
60+
self.display.blit(hum_surface, (SCREEN_SIZE[0]-100, SCREEN_SIZE[1]-50))
61+
5462
def _display_frames(self):
5563
cur_x = 0
5664
for frame_id in self.frames:

humidityModule.py

+6-15
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
FREQUENCY = 10
1212
SENSOR_PIN1 = 21
1313

14-
class MockSensorModule(rm.ProtoModule):
14+
class HumidityModule(rm.ProtoModule):
1515
def __init__(self, addr, port):
1616
self.subscriptions = []
1717
super().__init__(addr, port, message_buffers, MsgType, FREQUENCY)
@@ -23,23 +23,14 @@ def msg_received(self, msg, msg_type):
2323
def tick(self):
2424
humidity, temperature = Adafruit_DHT.read_retry(self.sensor, SENSOR_PIN1)
2525

26-
# Note that sometimes you won't get a reading and
27-
# the results will be null (because Linux can't
28-
# guarantee the timing of calls to read the sensor).
29-
# If this happens try again!
3026
if humidity is not None and temperature is not None:
31-
print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature, humidity))
32-
else:
33-
print('Failed to get reading. Try again!')
34-
35-
msg = MockMsg()
36-
msg.mockValue = random.randint(1, 9)
37-
msg = msg.SerializeToString()
38-
self.write(msg, MsgType.MOCK_MSG)
39-
27+
msg = HumidityMsg()
28+
msg.humidity = humidity
29+
msg = msg.SerializeToString()
30+
self.write(msg, MsgType.HUMIDITY_MSG)
4031

4132
def main():
42-
module = MockSensorModule(ADDRESS, PORT)
33+
module = HumidityModule(ADDRESS, PORT)
4334
module.run()
4435

4536
if __name__ == "__main__":

messages/Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
protobuf: mockMsg.proto cameraFrameMsg.proto ctrlMsg.proto
1+
protobuf: mockMsg.proto cameraFrameMsg.proto ctrlMsg.proto humidityMsg.proto
22
protoc -I=./ --python_out=./ ./mockMsg.proto
33
protoc -I=./ --python_out=./ ./cameraFrameMsg.proto
44
protoc -I=./ --python_out=./ ./ctrlMsg.proto
5+
protoc -I=./ --python_out=./ ./humidityMsg.proto

messages/__init__.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22
from .mockMsg_pb2 import MockMsg
33
from .cameraFrameMsg_pb2 import CameraFrameMsg
44
from .ctrlMsg_pb2 import CtrlMsg
5+
from .humidityMsg_pb2 import HumidityMsg
56

67
class MsgType(Enum):
78
MOCK_MSG = 0
89
CAMERA_FRAME_MSG = 1
910
CTRL_MSG = 2
11+
HUMIDITY_MSG = 3
1012

1113
message_buffers = {
1214
MsgType.MOCK_MSG: MockMsg,
1315
MsgType.CAMERA_FRAME_MSG: CameraFrameMsg,
14-
MsgType.CTRL_MSG: CtrlMsg
16+
MsgType.CTRL_MSG: CtrlMsg,
17+
MsgType.HUMIDITY_MSG: HumidityMsg
1518
}
1619

17-
__all__ = ['MsgType', 'message_buffers', 'MockMsg', 'CameraFrameMsg', 'CtrlMsg']
20+
__all__ = ['MsgType', 'message_buffers', 'MockMsg', 'CameraFrameMsg', 'CtrlMsg', 'HumidityMsg']

messages/humidityMsg.proto

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
syntax = "proto2";
2+
3+
package mateROV;
4+
5+
message HumidityMsg {
6+
7+
required float humidity = 1;
8+
}

messages/humidityMsg_pb2.py

+69
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)