Skip to content

Commit

Permalink
change 'initalize' to 'initialize'
Browse files Browse the repository at this point in the history
  • Loading branch information
Chi-EEE committed Jan 5, 2024
1 parent 204f94a commit 7ed7e23
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 56 deletions.
26 changes: 0 additions & 26 deletions .vscode/launch.json

This file was deleted.

13 changes: 8 additions & 5 deletions app/raspberry_pi/src/car/display/CarConsole.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ using namespace car::system;
using namespace ftxui;

namespace car::display {
static auto button_style = ButtonOption::Animated();
static const ButtonOption button_style = ButtonOption::Animated();
class CarConsole
{
public:
Component MainComponent(std::function<void()> show_exit_modal) {
Component MainComponent(std::function<void()> start_car_system, std::function<void()> show_exit_modal) {
auto component = Container::Vertical({
Button("Start Car Application", start_car_system, button_style),
Button("Quit", show_exit_modal, button_style),
});
// Polish how the two buttons are rendered:
Expand Down Expand Up @@ -69,16 +70,18 @@ namespace car::display {

auto show_exit_modal = [&] { exit_modal_shown = true; };
auto hide_exit_modal = [&] { exit_modal_shown = false; };

auto start_car_system = [&] { this->car_system->start(); };

auto exit = screen.ExitLoopClosure();

auto main_component = MainComponent(show_exit_modal);
auto main_component = MainComponent(start_car_system, show_exit_modal);
auto modal_component = ExitModalComponent(hide_exit_modal, exit);
main_component |= Modal(modal_component, &exit_modal_shown);

Loop loop(&screen, main_component);

this->car_system->initalize();
this->car_system->start();
this->car_system->initialize();
// The main loop:
while (!loop.HasQuitted()) {
this->car_system->update();
Expand Down
47 changes: 25 additions & 22 deletions app/raspberry_pi/src/car/system/CarSystem.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "CarSystem.h"

namespace car::system {
namespace car::system
{
CarSystem::CarSystem(
const std::string& websocket_url,
std::unique_ptr<LidarDevice> lidar_device,
std::unique_ptr<MessagingSystem> messaging_system,
std::unique_ptr<MovementSystem> movement_system
) : lidar_device(std::move(lidar_device)), messaging_system(std::move(messaging_system)), movement_system(std::move(movement_system))
const std::string &websocket_url,
std::unique_ptr<LidarDevice> lidar_device,
std::unique_ptr<MessagingSystem> messaging_system,
std::unique_ptr<MovementSystem> movement_system) : lidar_device(std::move(lidar_device)), messaging_system(std::move(messaging_system)), movement_system(std::move(movement_system))
{
}

Expand All @@ -15,58 +15,61 @@ namespace car::system {
this->terminate();
}

void CarSystem::initalize()
void CarSystem::initialize()
{
this->messaging_system->initalize();
this->messaging_system->initialize();
this->lidar_device->initialize();

this->messaging_system->move_command_signal.connect([this](const MoveCommand move_command) {
this->move(move_command);
});
this->messaging_system->move_command_signal.connect([this](const MoveCommand move_command)
{ this->move(move_command); });

this->messaging_system->turn_command_signal.connect([this](const TurnCommand turn_command) {
this->turn(turn_command);
});
this->messaging_system->turn_command_signal.connect([this](const TurnCommand turn_command)
{ this->turn(turn_command); });
}

void CarSystem::start()
{
this->messaging_system->start();
this->lidar_device->start();
this->running = true;
}

void CarSystem::update()
{
if (!this->running)
{
return;
}
json output_json;
output_json["data"] = json::array();
std::vector<Measure> scan = this->lidar_device->scan();
for (const Measure& measure : scan)
for (const Measure &measure : scan)
{
output_json["data"].push_back(
{
{"distance", measure.distance},
{"angle", measure.angle},
}
);
{"distance", measure.distance},
{"angle", measure.angle},
});
}
this->messaging_system->sendMessage(output_json.dump());
}

void CarSystem::terminate()
{
if (!this->terminated) {
if (!this->terminated)
{
this->terminated = true;
this->lidar_device->terminate();
this->messaging_system->terminate();
}
}

void CarSystem::move(const MoveCommand& move_command)
void CarSystem::move(const MoveCommand &move_command)
{
this->movement_system->move(move_command);
}

void CarSystem::turn(const TurnCommand& turn_command)
void CarSystem::turn(const TurnCommand &turn_command)
{
this->movement_system->turn(turn_command);
}
Expand Down
3 changes: 2 additions & 1 deletion app/raspberry_pi/src/car/system/CarSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace car::system {
CarSystem(const std::string& websocket_url, std::unique_ptr<LidarDevice> lidar_device, std::unique_ptr<MessagingSystem> messaging_system, std::unique_ptr<MovementSystem> movement_system);
~CarSystem();

void initalize();
void initialize();
void start();

void update();
Expand All @@ -38,6 +38,7 @@ namespace car::system {
std::unique_ptr<MessagingSystem> messaging_system;
std::unique_ptr<MovementSystem> movement_system;

bool running = false;
bool terminated = false;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace car::system::messaging {
MessagingSystem(const std::string& websocket_url) : websocket_url(websocket_url) {
};

void initalize()
void initialize()
{
ix::initNetSystem();
this->websocket.setUrl(websocket_url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace car::system::movement {
MovementSystem() {
};

void initalize()
void initialize()
{
this->pwm->init(1, 0x40);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
Expand Down

0 comments on commit 7ed7e23

Please sign in to comment.