Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new features to HUD #147

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "client_display_subsystem.hpp"

#include "tap/communication/sensors/buzzer/buzzer.hpp"

namespace subsystems::control
{
ClientDisplaySubsystem::ClientDisplaySubsystem(src::Drivers* drivers, TurretSubsystem* turret)
: Subsystem(drivers),
drivers(drivers),
turret(turret),
currentGraphics(drivers)
{
}

void ClientDisplaySubsystem::initialize()
{
// graphic::graphic_circle circle2(drivers);
// graphic::graphic_circle* circle = new graphic::graphic_circle(drivers);
// graphic::graphic_reticle* reticle = new graphic::graphic_reticle(drivers, turret);
// currentGraphics.emplace_back(circle);
// currentGraphics = circle2;
// currentGraphics = reticle;
*numGraphics = 2;
}

void ClientDisplaySubsystem::refresh() {}

void ClientDisplaySubsystem::runHardwareTests() {}

} // namespace subsystems::control
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#pragma once

#include <vector>

#include "tap/communication/sensors/buzzer/buzzer.hpp"
#include "tap/control/command.hpp"
#include "tap/control/subsystem.hpp"

#include "control/client-display/graphics/graphic_abstract.hpp"
#include "control/client-display/graphics/graphic_circle.hpp"
#include "control/client-display/graphics/graphic_reticle.hpp"
#include "subsystems/turret/turret_subsystem.hpp"

#include "drivers.hpp"

using subsystems::turret::TurretSubsystem;

namespace subsystems::control
{
class ClientDisplaySubsystem : public tap::control::Subsystem
{
public:
ClientDisplaySubsystem(src::Drivers*, TurretSubsystem* turret);

// add graphics desired here
void initialize() override;

void refresh() override;

// function to get the vector of graphics
// std::vector<graphic::graphic_abstract*> getGraphics() {return currentGraphics;};
graphic::graphic_abstract* getGraphics() { return &currentGraphics; };

void runHardwareTests() override;

const char* getName() override { return "Client Display subsystem"; }

private:
// std::vector<graphic::graphic_abstract*> currentGraphics;
graphic::graphic_abstract* graphics[10];
uint8_t* numGraphics;
src::Drivers* drivers;
TurretSubsystem* turret;
graphic::graphic_circle currentGraphics;
};
} // namespace subsystems::control
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include "command_client_display.hpp"

namespace commands
{

void CommandClientDisplay::initialize()
{
tap::buzzer::playNote(&drivers->pwm, 440);
// restart();

// RefSerialTransmitter::configGraphicGenerics(
// &msg.graphicData,
// graphicId,
// RefSerialData::Tx::GRAPHIC_ADD,
// 0,
// RefSerialData::Tx::GraphicColor::PINK);

// // RESOLUTION HAS TO BE 1920x1080 OR HUD WILL NOT WORK PROPERLY
// RefSerialTransmitter::configCircle(10, 1920 / 2, 1080 / 2, 100, &msg.graphicData);
// std::vector<graphic::graphic_abstract*> currentGraphics = client->getGraphics();
// for (graphic::graphic_abstract* graphic : currentGraphics)
// {
// graphic->initialize();
// }

graphic = client->getGraphics();
graphic->initialize();
}

void CommandClientDisplay::execute() { run(); }

void CommandClientDisplay::end(bool)
{
tap::buzzer::silenceBuzzer(&drivers->pwm);
}

bool CommandClientDisplay::isFinished() const { return false; }

bool CommandClientDisplay::run()
{
// float t = sinf(tap::arch::clock::getTimeMilliseconds() / 1000.0f * 4.0f) * 0.5f + 0.5f;
// graphic = client->getGraphics();

PT_BEGIN();

// PT_WAIT_UNTIL(drivers->refSerial.getRefSerialReceivingData());

// // setup new graphic (GRAPHIC_ADD operation)
// PT_CALL(refSerialTransmitter.sendGraphic(&msg));

// while (true)
// {
// msg.graphicData.operation = RefSerialData::Tx::GRAPHIC_MODIFY;
// msg.graphicData.lineWidth = 5.0f + 25.0f * t;
// msg.graphicData.radius = 100.0f + 300.0f * t;

// // modify existing graphic based on the ID (GRAPHIC_MODIFY operation)
// PT_CALL(refSerialTransmitter.sendGraphic(&msg));
// }

// PT_END();
// std::vector<graphic::graphic_abstract*> currentGraphics = client->getGraphics();
// for (graphic::graphic_abstract* graphic : currentGraphics)
// {
// graphic->run();
// }
PT_CALL(graphic->run());

PT_END();
}
} // namespace commands
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#pragma once

#include <vector>
#include "tap/communication/sensors/buzzer/buzzer.hpp"
#include "tap/communication/serial/ref_serial_data.hpp"
#include "tap/communication/serial/ref_serial_transmitter.hpp"
#include "tap/control/command.hpp"

#include "control/client-display/client_display_subsystem.hpp"
#include "control/client-display/graphics/graphic_abstract.hpp"

#include "modm/processing/protothread.hpp"
#include "modm/processing/resumable.hpp"
#include "subsystems/flywheel/flywheel_subsystem.hpp"

#include "drivers.hpp"

using namespace tap::control;
using namespace tap::communication::serial;

using subsystems::control::ClientDisplaySubsystem;
using subsystems::flywheel::FlywheelSubsystem;

namespace commands
{
class CommandClientDisplay : public Command, modm::pt::Protothread
{
public:
CommandClientDisplay(src::Drivers *drivers, ClientDisplaySubsystem* client)
: Command(),
drivers(drivers),
// refSerialTransmitter(drivers),
client(client)
{
addSubsystemRequirement(client);
}

bool run();

void initialize() override;
void execute() override;
void end(bool) override;
bool isFinished() const override;
const char *getName() const override { return "client display"; }

//Plan to make a new class, called graphic
//in it, there contains virtual functions
//initialize, run (PT threads)
//within each of the derived classes, there would be a refSerialTransmitter
//also the corresponding subsystem to get the proper infomation

//then only one command to call on the list of derived graphics, initialize all of them, run all of them
//I think it should be a vector of classes?

//1. Make Graphic class, derived class
//2. Create a vector of these classes within the subsystem initialize (not command), revert this command into subsystem with client_display()
//3. Within this command, it should now have complete vector of the graphics, and corresponding calls the initalize, and run functions (execute)

//Possibility to create a command to hide graphics?

private:

src::Drivers *drivers;
ClientDisplaySubsystem* client;
graphic::graphic_abstract* graphic;
// RefSerialTransmitter refSerialTransmitter;
// const uint8_t graphicId[3] = {0, 0, 1}; // 3 byte identifier for this graphic element
// RefSerialData::Tx::Graphic1Message msg;

};
} // namespace commands
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#pragma once
#include "tap/communication/serial/ref_serial_data.hpp"
#include "tap/communication/serial/ref_serial_transmitter.hpp"
#include "tap/control/command.hpp"

#include "modm/processing/protothread.hpp"
#include "modm/processing/resumable.hpp"

#include "drivers.hpp"

using namespace tap::communication::serial;
using modm::NestedResumable;
using modm::ResumableResult;

namespace graphic
{

class graphic_abstract : protected NestedResumable<2>
{
public:
graphic_abstract(src::Drivers* drivers, uint8_t id)
: drivers(drivers),
refSerialTransmitter(drivers)
{
graphicId[0] = id & 0x01;
graphicId[1] = id & 0x02;
graphicId[2] = id & 0x04;
};
virtual void initialize() = 0;
virtual ResumableResult<bool> run() = 0;

// virtual ~graphic_abstract();

protected:
src::Drivers* drivers;
RefSerialTransmitter refSerialTransmitter;
uint8_t graphicId[3]; // 3 byte identifier for this graphic element
RefSerialData::Tx::Graphic1Message msg;
};

} // namespace graphic
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#pragma once
#include "graphic_abstract.hpp"

namespace graphic
{

class graphic_circle : public graphic_abstract
{
public:
graphic_circle(src::Drivers *drivers) : graphic_abstract(drivers, 1) {};
void initialize() override
{
// restart();
RefSerialTransmitter::configGraphicGenerics(
&msg.graphicData,
graphicId,
RefSerialData::Tx::GRAPHIC_ADD,
0,
RefSerialData::Tx::GraphicColor::PINK);

RefSerialTransmitter::configCircle(10, 1920 / 2, 1080 / 2, 100, &msg.graphicData);
};

modm::ResumableResult<bool> run() override
{
float t = sinf(tap::arch::clock::getTimeMilliseconds() / 1000.0f * 4.0f) * 0.5f + 0.5f;
RF_BEGIN();

RF_WAIT_UNTIL(drivers->refSerial.getRefSerialReceivingData());
// // setup new graphic (GRAPHIC_ADD operation)
RF_CALL(refSerialTransmitter.sendGraphic(&msg));
while (true)
{
msg.graphicData.operation = RefSerialData::Tx::GRAPHIC_MODIFY;
msg.graphicData.lineWidth = 5.0f + 25.0f * t;
msg.graphicData.radius = 100.0f + 300.0f * t;

// modify existing graphic based on the ID (GRAPHIC_MODIFY operation)
RF_CALL(refSerialTransmitter.sendGraphic(&msg));
}

RF_END_RETURN(true);
};

private:
float t = 10.0;
};

} // namespace graphic
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#pragma once

#include "graphic_abstract.hpp"
#include "subsystems/flywheel/flywheel_subsystem.hpp"

using subsystems::flywheel::FlywheelSubsystem;
using tap::communication::serial::RefSerialData;
namespace graphic
{

class graphic_flywheel_on : public graphic_abstract
{
public:
graphic_flywheel_on(src::Drivers *drivers, FlywheelSubsystem *flywheel)
: graphic_abstract(drivers, 2), flywheel(flywheel) {};
void initialize() override
{
// restart();

RefSerialTransmitter::configGraphicGenerics(
&word_msg.graphicData,
graphicId,
RefSerialData::Tx::GRAPHIC_ADD,
0,
RefSerialData::Tx::GraphicColor::CYAN);

// RESOLUTION HAS TO BE 1920x1080 OR HUD WILL NOT WORK PROPERLY
// RefSerialTransmitter::configCircle(10, CENTER_X, CENTER_Y, CIRCLE_SIZE, &msg.graphicData);

RefSerialTransmitter::configCharacterMsg(100, 10, CENTER_X, CENTER_Y, "Flywheel on", &word_msg);
};

modm::ResumableResult<bool> run() override
{
RF_BEGIN();

RF_WAIT_UNTIL(drivers->refSerial.getRefSerialReceivingData());

// setup new graphic (GRAPHIC_ADD operation)
RF_CALL(refSerialTransmitter.sendGraphic(&word_msg));

while (true)
{
// msg.graphicData.operation = RefSerialData::Tx::GRAPHIC_MODIFY;
// msg.graphicData.lineWidth = 5.0f + 25.0f * t;
// msg.graphicData.radius = 100.0f + 300.0f * t;
// DROP_DISTANCE = this.turret.getBulletDropReticle();
// msg.graphicData.startY = CENTER_Y - turret->getBulletDropReticle();
; // startY is centerY

// modify existing graphic based on the ID (GRAPHIC_MODIFY operation)
// RF_CALL(refSerialTransmitter.sendGraphic(&msg));
}
RF_END_RETURN(true);
};

private:
static constexpr uint16_t CENTER_X = 1920 / 4;
static constexpr uint16_t CENTER_Y = 1080 / 4;
RefSerialData::Tx::GraphicCharacterMessage word_msg;
FlywheelSubsystem* flywheel;
};

} // namespace graphic
Loading