Skip to content

Commit 72beda2

Browse files
committed
updateStatusDisplay function added
1 parent df6d084 commit 72beda2

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed
20 KB
Binary file not shown.
20 KB
Binary file not shown.

pio_workspace/src/display_main.cpp

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ int voltage_buffer_index1 = 0;
7878
float voltage_buffer2[MOVING_AVERAGE_SAMPLES];
7979
int voltage_buffer_index2 = 0;
8080

81+
String status_new = "Touch 2nd row for surprise";
82+
String status_old = "";
83+
8184
// ===== Thruster/Devices Variables =====
8285
uint16_t microseconds[] = {1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500};
8386
int Sthrusters[8];
@@ -112,11 +115,11 @@ Button buttons[] = {
112115
{184, 110, 44, 48, LABEL_COLOR, "FC"},
113116
{230, 110, 44, 48, LABEL_COLOR, "DC"},
114117
{276, 110, 44, 48, LABEL_COLOR, "DVL"},
115-
{0, 164, 320, 30, MAIN_RECT_COLOR, "Touch 2nd row for surprise"},
118+
{0, 164, 320, 30, MAIN_RECT_COLOR, status_new},
116119
{0, 200, 78, 35, RED, "T"},
117120
{80, 200, 78, 35, RED, "DB"},
118121
{160, 200, 78, 35, RED, "Celine"},
119-
{240, 200, 78, 35, RED, "Celine"},
122+
{240, 200, 78, 35, RED, "Mia"},
120123
};
121124

122125
// Thruster buttons for main page
@@ -290,6 +293,28 @@ void thrusterStatus(int Sthrusters[]) {
290293
Sthrusters[i] = 1;
291294
}
292295
}
296+
297+
}
298+
299+
// == Status Update Functions === //
300+
301+
void updateStatusDisplay(String newStatus) {
302+
if (newStatus != status_old) {
303+
tft.fillRoundRect(0, 164, 320, 30, 8, MAIN_RECT_COLOR);
304+
305+
delay(2000);
306+
307+
tft.setTextColor(BLACK);
308+
tft.setTextSize(2);
309+
310+
int16_t x, y;
311+
uint16_t w, h;
312+
tft.getTextBounds(newStatus, 0,0, &x, &y, &w, &h);
313+
tft.setCursor((320-w)/2, 164 + (30 - h) / 2);
314+
tft.print(newStatus);
315+
316+
status_old = newStatus;
317+
}
293318
}
294319

295320
// ===== Thruster/Devices Functions =====
@@ -329,6 +354,14 @@ void devicesDCMessageCallback(const std_msgs::Int32& msg) {
329354
devices_new[6] = msg.data;
330355
}
331356

357+
void statusMessageCallback(const std_msgs::String& msg) {
358+
status_new = msg.data;
359+
updateStatusDisplay(status_new);
360+
361+
}
362+
363+
364+
332365
// ===== ROS Subscribers =====
333366
ros::Subscriber<std_msgs::Int32> sub_tether("/tether/status", &tetherStatusMessageCallback);
334367
ros::Subscriber<std_msgs::Float32> BATT1("/power/batteries/voltage/1", &battery1Callback);
@@ -341,6 +374,7 @@ ros::Subscriber<std_msgs::Int32> DEVICEHYD("/sensors/hydrophones/status", &devic
341374
ros::Subscriber<std_msgs::Int32> DEVICEACT("/sensors/actuator/status", &devicesACTMessageCallback);
342375
ros::Subscriber<std_msgs::Int32> DEVICEFC("/sensors/front_camera/status", &devicesFCMessageCallback);
343376
ros::Subscriber<std_msgs::Int32> DEVICEDC("/sensors/down_camera/status", &devicesDCMessageCallback);
377+
ros::Subscriber<std_msgs::String> STATUS_SUB("/mission_display", &statusMessageCallback);
344378

345379
void thrusters(int T1, int T2, int T3, int T4, int T5, int T6, int T7, int T8) {
346380
if (isInDryTestMode) return;
@@ -527,6 +561,10 @@ void initMainPage() {
527561
tft.print(btn.label);
528562
}
529563
}
564+
565+
//add this line right after the loop to show the surprise
566+
updateStatusDisplay(status_new);
567+
530568
// Force battery display refresh after page change
531569
voltages_old[0] = -1; // Force batt1 to update
532570
voltages_old[1] = -1; // Force batt2 to update
@@ -616,6 +654,7 @@ void display_setup() {
616654
nh.subscribe(DEVICEACT);
617655
nh.subscribe(DEVICEFC);
618656
nh.subscribe(DEVICEDC);
657+
nh.subscribe(STATUS_SUB);
619658

620659
nh.advertise(DEPTH);
621660
nh.advertise(pub);

0 commit comments

Comments
 (0)