Hercules
Functions | Variables
main.cpp File Reference
#include <mbed.h>
#include "LCD_DISCO_F746NG.h"
#include "TS_DISCO_F746NG.h"
#include "DHT.h"
#include "display.h"
#include <iostream>
#include "stm32746g_discovery_sd.h"
#include "stm32746g_discovery_sdram.h"
#include "rtos.h"
#include "FileSystem.h"
Include dependency graph for main.cpp:

Go to the source code of this file.

Functions

Serial usbCom (USBTX, USBRX)
 
DigitalOut led1 (LED1)
 
DigitalOut led2 (D2)
 
DigitalOut buzzer (D4)
 
DHT dhtSensor (A0, SEN51035P)
 
AnalogIn vibrationSensor (A1)
 
AnalogIn lightSensor (A2)
 
AnalogIn soundSensor (A3)
 
void counterTick ()
 Increases the current count or resets when counter_max is hit. More...
 
void clearDisplay ()
 Clears the main display & sets default colors. More...
 
int earthQuakeDetected ()
 Detects earth quakes. Sets the red led to ON/OFF. More...
 
void displayCurrentHT ()
 Displays temperature & humidity (humidity) More...
 
void displayLightStatus ()
 Says "godnat" when dark, "goddag" when light. More...
 
void noiseWarning ()
 Displays a warning when the noise is too much. More...
 
void displayEarthQuakeStatus ()
 Displays current earthquake status. More...
 
void drawButton (uint16_t xPos, u_int16_t yPos, uint8_t *Text, int dia=10, int xOffset=5, int yOffset=7)
 Draw a round button on screen. More...
 
bool buttonHit (uint16_t xPos, uint16_t yPos, uint16_t cursor_x, uint16_t cursor_y, uint16_t hitBoxAera=20)
 Checks if a button has been hit. More...
 
void deviceSetup ()
 Initial device setup view. More...
 
void counter_thread ()
 Counter task. More...
 
void view1 ()
 View 1 logic. More...
 
void view2 ()
 View 2 logic. More...
 
void setView (int viewNumber)
 Set the View object. More...
 
void switchView ()
 Switches the current view. More...
 
void boot ()
 Setup for app. More...
 
void gui_thread ()
 Gui Thread. More...
 
int main ()
 Application entry point. More...
 

Variables

LCD_DISCO_F746NG lcd
 
TS_DISCO_F746NG ts
 
int currentView = 1
 
int viewCount = 2
 
int tempScale = 0
 
TS_StateTypeDef TS_State
 
uint16_t x
 
uint16_t y
 
uint8_t text [30]
 
uint8_t status
 
uint8_t idx
 
uint8_t cleared = 0
 
uint8_t prev_nb_touches = 0
 
int counter_max = 9999
 
int counter_current = 0
 
int roomNumber
 
int buildingNumber
 
Thread noiseThread
 
bool noiseThreadStarted = false
 
int device_setup_building_no = 0
 
int device_setup_room_no = 0
 
Thread counterThread
 
bool counterThreadStarted = false
 
Thread guiThread
 

Function Documentation

◆ boot()

void boot ( )

Setup for app.

Definition at line 546 of file main.cpp.

547 {
548  led1 = 1;
549  lcd.Init();
550  buzzer = 0;
551 
552  //uint8_t *image = (uint8_t *)fallout;
553  //lcd.DrawBitmap(0, 0, image);
554 
555  lcd.DisplayStringAt(0, LINE(1), (uint8_t *)"Booting Hercules...", CENTER_MODE);
556  lcd.DisplayStringAt(0, LINE(4), (uint8_t *)"Please wait", CENTER_MODE);
557 
558  if (BSP_SD_IsDetected())
559  {
560  BSP_SD_Init();
561  lcd.DisplayStringAt(0, LINE(6), (uint8_t *)"SD Card detected", CENTER_MODE);
562  }
563  else
564  {
565  lcd.DisplayStringAt(0, LINE(6), (uint8_t *)"SD Card not detected", CENTER_MODE);
566  }
567 
568  wait(1.0f);
569 
570  clearDisplay();
571 }
LCD_DISCO_F746NG lcd
Definition: main.cpp:16
DigitalOut led1(LED1)
void clearDisplay()
Clears the main display & sets default colors.
Definition: main.cpp:86
DigitalOut buzzer(D4)

References buzzer(), clearDisplay(), lcd, and led1().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ buttonHit()

bool buttonHit ( uint16_t  xPos,
uint16_t  yPos,
uint16_t  cursor_x,
uint16_t  cursor_y,
uint16_t  hitBoxAera = 20 
)

Checks if a button has been hit.

Parameters
xPos
yPos
cursor_x
cursor_y
hitBoxAera
Returns
true
false

Definition at line 263 of file main.cpp.

264 {
265  int y_hitbox_min = yPos - hitBoxAera;
266  int y_hitbox_max = yPos + hitBoxAera;
267 
268  int x_hitbox_min = xPos - hitBoxAera;
269  int x_hitbox_max = xPos + hitBoxAera;
270 
271  if ((cursor_y >= y_hitbox_min && cursor_y <= y_hitbox_max) && (cursor_x >= x_hitbox_min && cursor_x <= x_hitbox_max))
272  {
273  return true;
274  }
275 
276  return false;
277 }

Referenced by deviceSetup(), and view2().

Here is the caller graph for this function:

◆ buzzer()

DigitalOut buzzer ( D4  )

Referenced by boot().

Here is the caller graph for this function:

◆ clearDisplay()

void clearDisplay ( )

Clears the main display & sets default colors.

Definition at line 86 of file main.cpp.

87 {
88  for (int i = 0; i <= 10; i++)
89  {
90  lcd.DisplayStringAt(0, LINE(i), (uint8_t *)" ", LEFT_MODE);
91  lcd.DisplayStringAt(0, LINE(i), (uint8_t *)" ", CENTER_MODE);
92  lcd.DisplayStringAt(0, LINE(i), (uint8_t *)" ", RIGHT_MODE);
93 
94  lcd.ClearStringLine(i);
95  }
96 
97  lcd.Clear(LCD_BACKGROUND);
98  lcd.SetBackColor(LCD_TEXT_BACKGROUND);
99  lcd.SetTextColor(LCD_TEXT_COLOR);
100 }
LCD_DISCO_F746NG lcd
Definition: main.cpp:16
#define LCD_TEXT_BACKGROUND
Definition: display.h:7
#define LCD_BACKGROUND
LCD color.
Definition: display.h:6
#define LCD_TEXT_COLOR
Definition: display.h:8

References lcd, LCD_BACKGROUND, LCD_TEXT_BACKGROUND, and LCD_TEXT_COLOR.

Referenced by boot(), gui_thread(), and setView().

Here is the caller graph for this function:

◆ counter_thread()

void counter_thread ( )

Counter task.

Definition at line 377 of file main.cpp.

378 {
379  while (counterThreadStarted)
380  {
381  counterTick();
382 
383  ThisThread::sleep_for(1000);
384  }
385 }
bool counterThreadStarted
Definition: main.cpp:371
void counterTick()
Increases the current count or resets when counter_max is hit.
Definition: main.cpp:59

References counterThreadStarted, and counterTick().

Referenced by view1().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ counterTick()

void counterTick ( )

Increases the current count or resets when counter_max is hit.

Definition at line 59 of file main.cpp.

60 {
62  {
64 
66  {
67  counter_current = 0;
68  }
69  }
70 
71  char display_int[32];
72  sprintf(display_int, "Count: %04u", counter_current);
73 
74  if (1 == currentView)
75  {
76  lcd.DisplayStringAt(0, LINE(4), (uint8_t *)display_int, CENTER_MODE);
77  }
78 }
LCD_DISCO_F746NG lcd
Definition: main.cpp:16
int counter_max
Definition: main.cpp:49
int currentView
Definition: main.cpp:34
int counter_current
Definition: main.cpp:50

References counter_current, counter_max, currentView, and lcd.

Referenced by counter_thread().

Here is the caller graph for this function:

◆ deviceSetup()

void deviceSetup ( )

Initial device setup view.

Definition at line 283 of file main.cpp.

284 {
285  char str_building[32];
286  char str_room[32];
287 
288  sprintf(str_building, "Building: %d", device_setup_building_no);
289  sprintf(str_room, "Room: %d", device_setup_room_no);
290 
291  lcd.DisplayStringAt(125, 75, (uint8_t *)str_building, LEFT_MODE);
292  lcd.DisplayStringAt(125, 150, (uint8_t *)str_room, LEFT_MODE);
293 
294  // Building adjustment
295  uint16_t building_incr_xPos = 300;
296  uint16_t building_incr_yPos = 80;
297  drawButton(building_incr_xPos, building_incr_yPos, (uint8_t *)"+");
298 
299  uint16_t building_decr_xPos = 350;
300  uint16_t building_decr_yPos = 80;
301  drawButton(building_decr_xPos, building_decr_yPos, (uint8_t *)"-");
302 
303  // Room adjustment
304  uint16_t room_incr_xPos = 300;
305  uint16_t room_incr_yPos = 155;
306  drawButton(room_incr_xPos, room_incr_yPos, (uint8_t *)"+");
307 
308  uint16_t room_decr_xPos = 350;
309  uint16_t room_decr_yPos = 155;
310  drawButton(room_decr_xPos, room_decr_yPos, (uint8_t *)"-");
311 
312  // Save button
313  uint16_t save_btn_xPos = 240;
314  uint16_t save_btn_yPos = 230;
315  drawButton(save_btn_xPos, save_btn_yPos, (uint8_t *)"Save", 32, 22);
316 
317  ts.GetState(&TS_State);
318  if (TS_State.touchDetected)
319  {
320  for (idx = 0; idx < TS_State.touchDetected; idx++)
321  {
322  x = TS_State.touchX[idx];
323  y = TS_State.touchY[idx];
324 
325  float btnPressWait = 0.3f;
326 
327  // Building adjustment
328  if (buttonHit(building_incr_xPos, building_incr_yPos, x, y))
329  {
331 
332  wait(btnPressWait);
333  }
334 
335  if (buttonHit(building_decr_xPos, building_decr_yPos, x, y))
336  {
338 
339  wait(btnPressWait);
340  }
341 
342  // Room adjustment
343  if (buttonHit(room_incr_xPos, room_incr_yPos, x, y))
344  {
346 
347  wait(btnPressWait);
348  }
349 
350  if (buttonHit(room_decr_xPos, room_incr_yPos, x, y))
351  {
353 
354  wait(btnPressWait);
355  }
356 
357  if (buttonHit(save_btn_xPos, save_btn_yPos, x, y))
358  {
361 
362  wait(0.5f);
363 
364  cleared = false;
365  }
366  }
367  }
368 }
TS_DISCO_F746NG ts
Definition: main.cpp:18
LCD_DISCO_F746NG lcd
Definition: main.cpp:16
uint8_t cleared
Definition: main.cpp:45
bool buttonHit(uint16_t xPos, uint16_t yPos, uint16_t cursor_x, uint16_t cursor_y, uint16_t hitBoxAera=20)
Checks if a button has been hit.
Definition: main.cpp:263
void drawButton(uint16_t xPos, u_int16_t yPos, uint8_t *Text, int dia=10, int xOffset=5, int yOffset=7)
Draw a round button on screen.
Definition: main.cpp:244
TS_StateTypeDef TS_State
Definition: main.cpp:40
int roomNumber
Definition: main.cpp:52
int device_setup_building_no
Definition: main.cpp:231
uint16_t x
Definition: main.cpp:41
uint16_t y
Definition: main.cpp:41
int device_setup_room_no
Definition: main.cpp:232
int buildingNumber
Definition: main.cpp:53
uint8_t idx
Definition: main.cpp:44

References buildingNumber, buttonHit(), cleared, device_setup_building_no, device_setup_room_no, drawButton(), idx, lcd, roomNumber, ts, TS_State, x, and y.

Referenced by gui_thread().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dhtSensor()

DHT dhtSensor ( A0  ,
SEN51035P   
)

Referenced by displayCurrentHT().

Here is the caller graph for this function:

◆ displayCurrentHT()

void displayCurrentHT ( )

Displays temperature & humidity (humidity)

Definition at line 127 of file main.cpp.

128 {
129  int error = 0;
130  float h = 0.0f, c = 0.0f, d = 0.0f;
131 
132  error = dhtSensor.readData();
133  if (0 == error)
134  {
135  c = dhtSensor.ReadTemperature((eScale)tempScale);
136  h = dhtSensor.ReadHumidity();
137  d = dhtSensor.CalcdewPointFast(c, h);
138 
139  char temp[32];
140  char tempScaleSymbol[8];
141  char humid[32];
142  char dew_point[32];
143 
144  switch (tempScale)
145  {
146  case 0:
147  sprintf(tempScaleSymbol, "C");
148  break;
149  case 1:
150  sprintf(tempScaleSymbol, "F");
151  break;
152  case 2:
153  sprintf(tempScaleSymbol, "K");
154  break;
155 
156  default:
157  sprintf(tempScaleSymbol, "C");
158  break;
159  }
160 
161  sprintf(temp, "Temperature: %d %s", (int)c, tempScaleSymbol);
162  sprintf(humid, "Humidity: %d %%", (int)h);
163  sprintf(dew_point, "Dew Point: %d %s", (int)d, tempScaleSymbol);
164 
165  lcd.DisplayStringAt(0, LINE(6), (uint8_t *)temp, CENTER_MODE);
166  lcd.DisplayStringAt(0, LINE(7), (uint8_t *)humid, CENTER_MODE);
167  lcd.DisplayStringAt(0, LINE(8), (uint8_t *)dew_point, CENTER_MODE);
168  }
169 }
LCD_DISCO_F746NG lcd
Definition: main.cpp:16
DHT dhtSensor(A0, SEN51035P)
int tempScale
Definition: main.cpp:37

References dhtSensor(), lcd, and tempScale.

Referenced by view1().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ displayEarthQuakeStatus()

void displayEarthQuakeStatus ( )

Displays current earthquake status.

Definition at line 221 of file main.cpp.

222 {
223  char earth_quake[32];
224  sprintf(earth_quake, "Is Earthquake: %d", earthQuakeDetected());
225 
226  lcd.DisplayStringAt(0, LINE(10), (uint8_t *)earth_quake, CENTER_MODE);
227 }
LCD_DISCO_F746NG lcd
Definition: main.cpp:16
int earthQuakeDetected()
Detects earth quakes. Sets the red led to ON/OFF.
Definition: main.cpp:109

References earthQuakeDetected(), and lcd.

Referenced by view1().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ displayLightStatus()

void displayLightStatus ( )

Says "godnat" when dark, "goddag" when light.

Definition at line 175 of file main.cpp.

176 {
177  float luminence = lightSensor.read();
178 
179  if (luminence < 0.3)
180  {
181  lcd.DisplayStringAt(0, LINE(12), (uint8_t *)"Godnat", CENTER_MODE);
182  }
183  else
184  {
185  lcd.DisplayStringAt(0, LINE(12), (uint8_t *)"Goddag", CENTER_MODE);
186  }
187 }
LCD_DISCO_F746NG lcd
Definition: main.cpp:16
AnalogIn lightSensor(A2)

References lcd, and lightSensor().

Referenced by view1().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ drawButton()

void drawButton ( uint16_t  xPos,
u_int16_t  yPos,
uint8_t *  Text,
int  dia = 10,
int  xOffset = 5,
int  yOffset = 7 
)

Draw a round button on screen.

Parameters
xPos
yPos
Text
dia
xOffset
yOffset

Definition at line 244 of file main.cpp.

245 {
246  lcd.DrawCircle(xPos, yPos, dia);
247  lcd.SetBackColor(LCD_BACKGROUND);
248  lcd.DisplayStringAt((xPos - xOffset), (yPos - yOffset), Text, LEFT_MODE);
249  lcd.SetBackColor(LCD_TEXT_BACKGROUND);
250 }
LCD_DISCO_F746NG lcd
Definition: main.cpp:16
#define LCD_TEXT_BACKGROUND
Definition: display.h:7
#define LCD_BACKGROUND
LCD color.
Definition: display.h:6

References lcd, LCD_BACKGROUND, and LCD_TEXT_BACKGROUND.

Referenced by deviceSetup(), and view2().

Here is the caller graph for this function:

◆ earthQuakeDetected()

int earthQuakeDetected ( )

Detects earth quakes. Sets the red led to ON/OFF.

Returns
int

Definition at line 109 of file main.cpp.

110 {
111  if (vibrationSensor.read() > 0.06)
112  {
113  led2 = 1;
114 
115  return 1;
116  }
117 
118  led2 = 0;
119 
120  return 0;
121 }
AnalogIn vibrationSensor(A1)
DigitalOut led2(D2)

References led2(), and vibrationSensor().

Referenced by displayEarthQuakeStatus().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gui_thread()

void gui_thread ( )

Gui Thread.

Definition at line 577 of file main.cpp.

578 {
579  while (true)
580  {
581  if (!buildingNumber && !roomNumber)
582  {
583  deviceSetup();
584  }
585  else
586  {
588  }
589 
590  ts.GetState(&TS_State);
591  if (buildingNumber && roomNumber && TS_State.touchDetected)
592  {
593  for (idx = 0; idx < TS_State.touchDetected; idx++)
594  {
595  x = TS_State.touchX[idx];
596  y = TS_State.touchY[idx];
597 
598  int y_hitbox_min = 240 - 50;
599  int y_hitbox_max = 240 + 50;
600 
601  int x_hitbox_min = 410 - 50;
602  int x_hitbox_max = 410 + 50;
603 
604  if ((y >= y_hitbox_min && y <= y_hitbox_max) && (x >= x_hitbox_min && x <= x_hitbox_max))
605  {
606  switchView();
607  }
608  }
609  }
610  else
611  {
612  if (!cleared)
613  {
614  clearDisplay();
615 
616  char displayView[32];
617  sprintf(displayView, "View: %d", currentView);
618 
619  lcd.DrawHLine(10, 10, 460);
620  lcd.SetFont(&Font8);
621 
622  lcd.SetBackColor(LCD_BACKGROUND);
623  lcd.DisplayStringAt(10, 12, (uint8_t *)"Hercules v1.1", LEFT_MODE);
624  lcd.DrawVLine(80, 10, 11);
625 
626  if (buildingNumber && roomNumber)
627  {
628  char building[32];
629  char room[32];
630 
631  sprintf(building, "Building: %d", buildingNumber);
632  sprintf(room, "Room: %d", roomNumber);
633 
634  lcd.DisplayStringAt(85, 12, (uint8_t *)building, LEFT_MODE);
635  lcd.DisplayStringAt(150, 12, (uint8_t *)room, LEFT_MODE);
636  }
637 
638  lcd.SetBackColor(LCD_TEXT_BACKGROUND);
639 
640  lcd.DrawHLine(10, 20, 460);
641  lcd.SetFont(&Font16);
642 
643  if (buildingNumber && roomNumber)
644  {
645  lcd.DisplayStringAt(10, 240, (uint8_t *)displayView, LEFT_MODE);
646  lcd.DisplayStringAt(410, 240, (uint8_t *)"Next", LEFT_MODE);
647  }
648 
649  cleared = 1;
650  }
651  }
652  }
653 }
TS_DISCO_F746NG ts
Definition: main.cpp:18
LCD_DISCO_F746NG lcd
Definition: main.cpp:16
#define LCD_TEXT_BACKGROUND
Definition: display.h:7
uint8_t cleared
Definition: main.cpp:45
void switchView()
Switches the current view.
Definition: main.cpp:519
void setView(int viewNumber)
Set the View object.
Definition: main.cpp:486
int currentView
Definition: main.cpp:34
void clearDisplay()
Clears the main display & sets default colors.
Definition: main.cpp:86
TS_StateTypeDef TS_State
Definition: main.cpp:40
int roomNumber
Definition: main.cpp:52
#define LCD_BACKGROUND
LCD color.
Definition: display.h:6
void deviceSetup()
Initial device setup view.
Definition: main.cpp:283
uint16_t x
Definition: main.cpp:41
uint16_t y
Definition: main.cpp:41
int buildingNumber
Definition: main.cpp:53
uint8_t idx
Definition: main.cpp:44

References buildingNumber, clearDisplay(), cleared, currentView, deviceSetup(), idx, lcd, LCD_BACKGROUND, LCD_TEXT_BACKGROUND, roomNumber, setView(), switchView(), ts, TS_State, x, and y.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ led1()

DigitalOut led1 ( LED1  )

Referenced by boot().

Here is the caller graph for this function:

◆ led2()

DigitalOut led2 ( D2  )

Referenced by earthQuakeDetected().

Here is the caller graph for this function:

◆ lightSensor()

AnalogIn lightSensor ( A2  )

Referenced by displayLightStatus().

Here is the caller graph for this function:

◆ main()

int main ( )

Application entry point.

Returns
int

Definition at line 662 of file main.cpp.

663 {
664  boot();
665 
666  // The data cache is disabled to avoid screen flickering.
667  SCB_CleanDCache();
668  SCB_DisableDCache();
669 
670  wait(0.25);
671 
672  guiThread.start(gui_thread);
673 }
Thread guiThread
Definition: main.cpp:655
void gui_thread()
Gui Thread.
Definition: main.cpp:577
void boot()
Setup for app.
Definition: main.cpp:546

References boot(), gui_thread(), and guiThread.

Here is the call graph for this function:

◆ noiseWarning()

void noiseWarning ( )

Displays a warning when the noise is too much.

Definition at line 196 of file main.cpp.

197 {
198  while (noiseThreadStarted)
199  {
200  float noiseLevel = soundSensor.read();
201 
202  if (noiseLevel >= 0.5 && 1 == currentView)
203  {
204  lcd.DisplayStringAt(0, LINE(13), (uint8_t *)"Noise warning!", CENTER_MODE);
205  }
206  else
207  {
208  lcd.SetBackColor(LCD_BACKGROUND);
209  lcd.DisplayStringAt(0, LINE(13), (uint8_t *)" ", CENTER_MODE);
210  lcd.SetBackColor(LCD_TEXT_BACKGROUND);
211  }
212 
213  ThisThread::sleep_for(1000);
214  }
215 }
LCD_DISCO_F746NG lcd
Definition: main.cpp:16
#define LCD_TEXT_BACKGROUND
Definition: display.h:7
AnalogIn soundSensor(A3)
int currentView
Definition: main.cpp:34
#define LCD_BACKGROUND
LCD color.
Definition: display.h:6
bool noiseThreadStarted
Definition: main.cpp:190

References currentView, lcd, LCD_BACKGROUND, LCD_TEXT_BACKGROUND, noiseThreadStarted, and soundSensor().

Referenced by view1().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setView()

void setView ( int  viewNumber)

Set the View object.

Parameters
viewNumber

Definition at line 486 of file main.cpp.

487 {
488  if (viewNumber != currentView)
489  {
490  usbCom.printf("[Toggle]: setView viewNumber %d!\n", viewNumber);
491  usbCom.printf("[Toggle]: setView currentView %d!\n", currentView);
492 
493  cleared = 0;
494 
495  clearDisplay();
496  }
497 
498  currentView = viewNumber;
499 
500  switch (viewNumber)
501  {
502  case 1:
503  view1();
504  break;
505  case 2:
506  view2();
507  break;
508 
509  default:
510  usbCom.printf("Unknown view number: %d\n", viewNumber);
511  break;
512  }
513 }
uint8_t cleared
Definition: main.cpp:45
Serial usbCom(USBTX, USBRX)
int currentView
Definition: main.cpp:34
void view2()
View 2 logic.
Definition: main.cpp:416
void clearDisplay()
Clears the main display & sets default colors.
Definition: main.cpp:86
void view1()
View 1 logic.
Definition: main.cpp:391

References clearDisplay(), cleared, currentView, usbCom(), view1(), and view2().

Referenced by gui_thread(), and switchView().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ soundSensor()

AnalogIn soundSensor ( A3  )

Referenced by noiseWarning().

Here is the caller graph for this function:

◆ switchView()

void switchView ( )

Switches the current view.

Definition at line 519 of file main.cpp.

520 {
521  wait(0.1);
522 
523  usbCom.printf("switchView toggled!\n");
524 
525  int viewNumber = currentView;
526 
527  if (currentView < viewCount)
528  {
529  viewNumber++;
530  }
531  else
532  {
533  viewNumber = 1;
534  }
535 
536  usbCom.printf("switchView viewNumber %d!\n", viewNumber);
537  usbCom.printf("switchView currentView %d!\n", currentView);
538 
539  setView(viewNumber);
540 }
Serial usbCom(USBTX, USBRX)
void setView(int viewNumber)
Set the View object.
Definition: main.cpp:486
int currentView
Definition: main.cpp:34
int viewCount
Definition: main.cpp:35

References currentView, setView(), usbCom(), and viewCount.

Referenced by gui_thread().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ usbCom()

Serial usbCom ( USBTX  ,
USBRX   
)

Referenced by setView(), switchView(), and view2().

Here is the caller graph for this function:

◆ vibrationSensor()

AnalogIn vibrationSensor ( A1  )

Referenced by earthQuakeDetected().

Here is the caller graph for this function:

◆ view1()

void view1 ( )

View 1 logic.

Definition at line 391 of file main.cpp.

392 {
396 
398  {
400 
401  counterThreadStarted = true;
402  }
403 
404  if (!noiseThreadStarted)
405  {
406  noiseThread.start(noiseWarning);
407 
408  noiseThreadStarted = true;
409  }
410 }
void displayLightStatus()
Says "godnat" when dark, "goddag" when light.
Definition: main.cpp:175
bool counterThreadStarted
Definition: main.cpp:371
void displayEarthQuakeStatus()
Displays current earthquake status.
Definition: main.cpp:221
Thread noiseThread
Definition: main.cpp:189
void displayCurrentHT()
Displays temperature & humidity (humidity)
Definition: main.cpp:127
void noiseWarning()
Displays a warning when the noise is too much.
Definition: main.cpp:196
bool noiseThreadStarted
Definition: main.cpp:190
Thread counterThread
Definition: main.cpp:370
void counter_thread()
Counter task.
Definition: main.cpp:377

References counter_thread(), counterThread, counterThreadStarted, displayCurrentHT(), displayEarthQuakeStatus(), displayLightStatus(), noiseThread, noiseThreadStarted, and noiseWarning().

Referenced by setView().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ view2()

void view2 ( )

View 2 logic.

Definition at line 416 of file main.cpp.

417 {
418  char i2c_clock[32];
419  sprintf(i2c_clock, "I2C Clock: %d KHz", ((int)I2C_SPEED / 1000));
420  lcd.DisplayStringAt(0, LINE(3), (uint8_t *)i2c_clock, CENTER_MODE);
421 
422  if (BSP_SD_IsDetected())
423  {
424  lcd.DisplayStringAt(0, LINE(7), (uint8_t *)"SD Card detected", CENTER_MODE);
425  }
426  else
427  {
428  lcd.DisplayStringAt(0, LINE(7), (uint8_t *)"SD Card not detected", CENTER_MODE);
429  }
430 
431  lcd.DisplayStringAt(145, 150, (uint8_t *)"Temperature scale", LEFT_MODE);
432 
433  uint16_t tempBtnYpos = 190;
434  uint16_t tempBtnCelsiusPos = 170;
435  uint16_t tempBtnFahrenheitPos = 230;
436  uint16_t tempBtnKelvinPos = 290;
437 
438  drawButton(tempBtnCelsiusPos, tempBtnYpos, (uint8_t *)"C");
439  drawButton(tempBtnFahrenheitPos, tempBtnYpos, (uint8_t *)"F");
440  drawButton(tempBtnKelvinPos, tempBtnYpos, (uint8_t *)"K");
441 
442  ts.GetState(&TS_State);
443  if (TS_State.touchDetected)
444  {
445  for (idx = 0; idx < TS_State.touchDetected; idx++)
446  {
447  x = TS_State.touchX[idx];
448  y = TS_State.touchY[idx];
449 
450  // Building adjustment
451  if (buttonHit(tempBtnCelsiusPos, tempBtnYpos, x, y))
452  {
453  tempScale = 0;
454 
455  usbCom.printf("Temp scale switched to Celcius!");
456 
457  wait(0.5f);
458  }
459 
460  if (buttonHit(tempBtnFahrenheitPos, tempBtnYpos, x, y))
461  {
462  tempScale = 1;
463 
464  usbCom.printf("Temp scale switched to Fahrenheit!");
465 
466  wait(0.5f);
467  }
468 
469  if (buttonHit(tempBtnKelvinPos, tempBtnYpos, x, y))
470  {
471  tempScale = 2;
472 
473  usbCom.printf("Temp scale switched to Kelvin!");
474 
475  wait(0.5f);
476  }
477  }
478  }
479 }
TS_DISCO_F746NG ts
Definition: main.cpp:18
LCD_DISCO_F746NG lcd
Definition: main.cpp:16
bool buttonHit(uint16_t xPos, uint16_t yPos, uint16_t cursor_x, uint16_t cursor_y, uint16_t hitBoxAera=20)
Checks if a button has been hit.
Definition: main.cpp:263
void drawButton(uint16_t xPos, u_int16_t yPos, uint8_t *Text, int dia=10, int xOffset=5, int yOffset=7)
Draw a round button on screen.
Definition: main.cpp:244
Serial usbCom(USBTX, USBRX)
TS_StateTypeDef TS_State
Definition: main.cpp:40
int tempScale
Definition: main.cpp:37
uint16_t x
Definition: main.cpp:41
uint16_t y
Definition: main.cpp:41
uint8_t idx
Definition: main.cpp:44

References buttonHit(), drawButton(), idx, lcd, tempScale, ts, TS_State, usbCom(), x, and y.

Referenced by setView().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ buildingNumber

int buildingNumber

Definition at line 53 of file main.cpp.

Referenced by deviceSetup(), and gui_thread().

◆ cleared

uint8_t cleared = 0

Definition at line 45 of file main.cpp.

Referenced by deviceSetup(), gui_thread(), and setView().

◆ counter_current

int counter_current = 0

Definition at line 50 of file main.cpp.

Referenced by counterTick().

◆ counter_max

int counter_max = 9999

Definition at line 49 of file main.cpp.

Referenced by counterTick().

◆ counterThread

Thread counterThread

Definition at line 370 of file main.cpp.

Referenced by view1().

◆ counterThreadStarted

bool counterThreadStarted = false

Definition at line 371 of file main.cpp.

Referenced by counter_thread(), and view1().

◆ currentView

int currentView = 1

Definition at line 34 of file main.cpp.

Referenced by counterTick(), gui_thread(), noiseWarning(), setView(), and switchView().

◆ device_setup_building_no

int device_setup_building_no = 0

Definition at line 231 of file main.cpp.

Referenced by deviceSetup().

◆ device_setup_room_no

int device_setup_room_no = 0

Definition at line 232 of file main.cpp.

Referenced by deviceSetup().

◆ guiThread

Thread guiThread

Definition at line 655 of file main.cpp.

Referenced by main().

◆ idx

uint8_t idx

Definition at line 44 of file main.cpp.

Referenced by deviceSetup(), gui_thread(), and view2().

◆ lcd

LCD_DISCO_F746NG lcd

◆ noiseThread

Thread noiseThread

Definition at line 189 of file main.cpp.

Referenced by view1().

◆ noiseThreadStarted

bool noiseThreadStarted = false

Definition at line 190 of file main.cpp.

Referenced by noiseWarning(), and view1().

◆ prev_nb_touches

uint8_t prev_nb_touches = 0

Definition at line 46 of file main.cpp.

◆ roomNumber

int roomNumber

Definition at line 52 of file main.cpp.

Referenced by deviceSetup(), and gui_thread().

◆ status

uint8_t status

Definition at line 43 of file main.cpp.

◆ tempScale

int tempScale = 0

Definition at line 37 of file main.cpp.

Referenced by displayCurrentHT(), and view2().

◆ text

uint8_t text[30]

Definition at line 42 of file main.cpp.

Referenced by Display::String().

◆ ts

TS_DISCO_F746NG ts

Definition at line 18 of file main.cpp.

Referenced by deviceSetup(), gui_thread(), and view2().

◆ TS_State

TS_StateTypeDef TS_State

Definition at line 40 of file main.cpp.

Referenced by deviceSetup(), gui_thread(), and view2().

◆ viewCount

int viewCount = 2

Definition at line 35 of file main.cpp.

Referenced by switchView().

◆ x

uint16_t x

Definition at line 41 of file main.cpp.

Referenced by deviceSetup(), gui_thread(), and view2().

◆ y

uint16_t y

Definition at line 41 of file main.cpp.

Referenced by deviceSetup(), gui_thread(), and view2().