-
Notifications
You must be signed in to change notification settings - Fork 0
/
display.c
109 lines (92 loc) · 3.49 KB
/
display.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// ****************************************************************************
//
// display.c
//
// Support for operating the Orbit OLED display, and displaying flight
// metrics of the helicopter
//
// Authors: T. Rizzi, E. Robinson, S. Meravanage
// Last modified: 21 May 2021
//
// ****************************************************************************
//*****************************************************************************
// Includes
//*****************************************************************************
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
#include "driverlib/gpio.h"
#include "utils/ustdlib.h"
#include "OrbitOLED/OrbitOLEDInterface.h"
#include "utils/ustdlib.h"
#include "stdlib.h"
#include "display.h"
//*****************************************************************************
// Initialise the display module. Alias for OLEDInitialise
//*****************************************************************************
void initDisplay(void)
{
OLEDInitialise();
}
//*****************************************************************************
// Clears all lines on OLED display
//*****************************************************************************
void displayClear(void)
{
char string[17];
usnprintf (string, sizeof(string), " ");
OLEDStringDraw (string, 0, 0);
OLEDStringDraw (string, 0, 1);
OLEDStringDraw (string, 0, 2);
OLEDStringDraw (string, 0, 3);
}
//*****************************************************************************
// Displays helicopter altitude percentage on OLED
//*****************************************************************************
void displayAltitude(int32_t altitude)
{
char string[17];
usnprintf (string, sizeof(string), "Altitude: %3d%% ", altitude);
OLEDStringDraw (string, 0, DISPLAY_ALTITUDE_LINE);
}
//*****************************************************************************
// Displays helicopter yaw in degrees on OLED
//*****************************************************************************
void displayYaw(uint32_t yaw)
{
char string[17];
usnprintf (string, sizeof(string), "Yaw (deg): %3d ", yaw);
OLEDStringDraw (string, 0, DISPLAY_YAW_LINE);
}
//*****************************************************************************
// Displays helicopter PWM duty cycles for main rotor
//*****************************************************************************
void displayMainDuty(uint32_t mainDuty)
{
char string[17];
usnprintf (string, sizeof(string), "Main Duty: %3d%% ", mainDuty);
OLEDStringDraw (string, 0, DISPLAY_MAIN_DUTY_LINE);
}
//*****************************************************************************
// Displays helicopter PWM duty cycles for tail rotor
//*****************************************************************************
void displayTailDuty(uint32_t tailDuty)
{
char string[17];
usnprintf (string, sizeof(string), "Tail Duty: %3d%% ", tailDuty);
OLEDStringDraw (string, 0, DISPLAY_TAIL_DUTY_LINE);
}
//*****************************************************************************
// Updates display with helicopter metrics
//*****************************************************************************
void
updateDisplay(int32_t altitude, uint32_t yaw, uint32_t mainDuty, uint32_t tailDuty)
{
// Draw title
displayYaw(yaw);
displayAltitude(altitude);
displayMainDuty(mainDuty);
displayTailDuty(tailDuty);
}