Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/flight-controller/receiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,11 @@ void FlushRadioBuffer() {
}

bool IsDroneArmed() { return armed; }

int GetDroneThrottle() { return throttle; }

int GetDroneRoll() { return roll; }

int GetDronePitch() { return pitch; }

int GetDroneYaw() { return yaw; }
8 changes: 7 additions & 1 deletion src/flight-controller/receiver.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#pragma once

// Reference variables:
bool IsDroneArmed();
void FlushRadioBuffer();
int GetDroneThrottle();
int GetDroneRoll();
int GetDronePitch();
int GetDroneYaw();

void FlushRadioBuffer();
3 changes: 3 additions & 0 deletions src/flight-controller/view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,8 @@ void UpdateView() {
Image ledDisplay = Image(LED_DISPLAY_SIZE, LED_DISPLAY_SIZE);
viewBatteryLevel(ledDisplay);
DisplayArmed(IsDroneArmed(), ledDisplay);
DisplayThrottle(GetDroneThrottle(), ledDisplay);
DisplayPitchRoll(GetDroneRoll(), GetDronePitch(), ledDisplay);
DisplayYaw(GetDroneYaw(), ledDisplay);
uBit.display.print(ledDisplay);
}
32 changes: 3 additions & 29 deletions src/hand-controller/view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,14 @@

// MicroBit display
const uint16_t LED_DISPLAY_SIZE = 5;
const int LED_ON = 255;

static void displayThrottle(Image &ledDisplay) {
int throttle = GetThrottle();
if (throttle == 0) {
return;
} else {
int y = floor(4 - (throttle / 25));
ledDisplay.setPixelValue(0, y, LED_ON);
}
}

static uint16_t angleToDisplayCoord(int angle) {
return static_cast<uint16_t>(std::round((angle + 45) / 22.5));
}

static void displayPitchRoll(Image &ledDisplay) {
uint16_t x = angleToDisplayCoord(GetRoll());
uint16_t y = angleToDisplayCoord(GetPitch());
ledDisplay.setPixelValue(x, y, LED_ON);
}

static void displayYaw(Image &ledDisplay) {
uint16_t x = static_cast<uint16_t>(GetYaw() / 30 + 2);
ledDisplay.setPixelValue(x, 0, LED_ON);
}

void UpdateDisplay() {
uBit.display.clear();

Image ledDisplay = Image(LED_DISPLAY_SIZE, LED_DISPLAY_SIZE);
DisplayArmed(IsArmed(), ledDisplay);
displayThrottle(ledDisplay);
displayPitchRoll(ledDisplay);
displayYaw(ledDisplay);
DisplayThrottle(GetThrottle(), ledDisplay);
DisplayPitchRoll(GetRoll(), GetPitch(), ledDisplay);
DisplayYaw(GetYaw(), ledDisplay);
uBit.display.print(ledDisplay);
}
26 changes: 26 additions & 0 deletions src/utilites.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
static int pulseDirection = 15;
static int armedPulse = 0;

static const int LED_ON = 255;

static uint16_t angleToDisplayCoord(int angle) {
return static_cast<uint16_t>(std::round((angle + 45) / 22.5));
}

static void updatePulse() {
armedPulse += pulseDirection;

Expand All @@ -20,4 +26,24 @@ void DisplayArmed(bool isArmed, Image &ledDisplay) {
} else {
armedPulse = 0;
}
}

void DisplayThrottle(int throttle, Image &ledDisplay) {
if (throttle == 0) {
return;
} else {
int y = floor(4 - (throttle / 25));
ledDisplay.setPixelValue(0, y, LED_ON);
}
}

void DisplayPitchRoll(int roll, int pitch, Image &ledDisplay) {
uint16_t x = angleToDisplayCoord(roll);
uint16_t y = angleToDisplayCoord(pitch);
ledDisplay.setPixelValue(x, y, LED_ON);
}

void DisplayYaw(int yaw, Image &ledDisplay) {
uint16_t x = static_cast<uint16_t>(yaw / 30 + 2);
ledDisplay.setPixelValue(x, 0, LED_ON);
}
8 changes: 7 additions & 1 deletion src/utilities.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#pragma once
#include <MicroBit.h>

void DisplayArmed(bool isArmed, Image &ledDisplay);
void DisplayArmed(bool isArmed, Image &ledDisplay);

void DisplayThrottle(int throttle, Image &ledDisplay);

void DisplayPitchRoll(int roll, int pitch, Image &ledDisplay);

void DisplayYaw(int yaw, Image &ledDisplay);
Loading