Merge branch 'master' of github.com:swinginbird/flippr-code
This commit is contained in:
@@ -2,11 +2,6 @@
|
||||
"deactivation_time_milliseconds" : 10,
|
||||
"sounds" :
|
||||
[
|
||||
{
|
||||
"id" : -1, //todo should be 0
|
||||
"address" : 0,
|
||||
"description" : "Deactivate Sound"
|
||||
},
|
||||
{
|
||||
"id" : 0,
|
||||
"address" : "22",
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#ifndef _INCLUDE_FLIPPR_CODE_FLIPPER_H
|
||||
#define _INCLUDE_FLIPPR_CODE_FLIPPER_H
|
||||
|
||||
#include "Item.h"
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
@@ -15,7 +16,7 @@ namespace output
|
||||
namespace items
|
||||
{
|
||||
|
||||
class Flipper
|
||||
class Flipper : public virtual Item
|
||||
{
|
||||
public:
|
||||
virtual ~Flipper() = default;
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace output
|
||||
namespace items
|
||||
{
|
||||
|
||||
class Lamp : public Item
|
||||
class Lamp : public virtual Item
|
||||
{
|
||||
public:
|
||||
virtual ~Lamp() = default;
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace output
|
||||
namespace items
|
||||
{
|
||||
// todo get name? parent calss output_item?
|
||||
class Solenoid : public Item
|
||||
class Solenoid : public virtual Item
|
||||
{
|
||||
public:
|
||||
virtual ~Solenoid() = default;
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace output
|
||||
namespace items
|
||||
{
|
||||
|
||||
class Sound : public Item
|
||||
class Sound : public virtual Item
|
||||
{
|
||||
public:
|
||||
virtual ~Sound() = default;
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#ifndef FLIPPR_DRIVER_DRIVERBOARDPINCONTROLLER_H
|
||||
#define FLIPPR_DRIVER_DRIVERBOARDPINCONTROLLER_H
|
||||
|
||||
#include "OutputPinController.h"
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
@@ -17,11 +16,13 @@ namespace items
|
||||
class DriverBoardItem;
|
||||
}
|
||||
|
||||
class DriverBoardPinController : public OutputPinController
|
||||
class DriverBoardPinController
|
||||
{
|
||||
public:
|
||||
virtual ~DriverBoardPinController() = default;
|
||||
|
||||
virtual void activate(items::DriverBoardItem &driver_board_item) = 0;
|
||||
virtual void deactivate(items::DriverBoardItem &driver_board_item) = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* OutputGPIOInterface.h
|
||||
*
|
||||
* Created on: May 31, 2018
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
|
||||
*/
|
||||
|
||||
#include "OutputPinController.h"
|
||||
|
||||
#include "utility/config.h"
|
||||
|
||||
#include "wiringPi/mcp23017.h"
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
|
||||
void OutputPinController::initialize_i2c_address(uint8_t i2c_address, uint8_t pin_base)
|
||||
{
|
||||
mcp23017Setup(pin_base, i2c_address);
|
||||
}
|
||||
|
||||
void OutputPinController::initialize_pins_output(uint8_t pin_base, std::map<std::string, uint8_t>::iterator begin, std::map<std::string, uint8_t>::iterator end)
|
||||
{
|
||||
for(; begin != end; begin++)
|
||||
{
|
||||
initialize_output_pin(pin_base + begin->second);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* OutputGPIOInterface.h
|
||||
*
|
||||
* Created on: May 31, 2018
|
||||
* Author: Andreas Schneider, Johannes Wendel, Jonas Zeunert
|
||||
*/
|
||||
|
||||
#ifndef SRC_UTILITIES_OUTPUTGPIOINTERFACE_H_
|
||||
#define SRC_UTILITIES_OUTPUTGPIOINTERFACE_H_
|
||||
|
||||
#include "PinController.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
namespace output
|
||||
{
|
||||
|
||||
namespace items
|
||||
{
|
||||
class DriverBoardItem;
|
||||
}
|
||||
class OutputPinController : public PinController
|
||||
{
|
||||
|
||||
public:
|
||||
virtual ~OutputPinController() = default;
|
||||
|
||||
virtual void activate(items::DriverBoardItem &driver_board_item) = 0;
|
||||
virtual void deactivate(items::DriverBoardItem &driver_board_item) = 0;
|
||||
|
||||
protected:
|
||||
static void initialize_i2c_address(uint8_t i2c_address, uint8_t pin_base);
|
||||
static void initialize_pins_output(uint8_t pin_base, std::map<std::string, uint8_t>::iterator begin, std::map<std::string, uint8_t>::iterator end);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -5,7 +5,6 @@
|
||||
#ifndef FLIPPR_DRIVER_OUTPUT_SOUNDBOARDPINCONTROLLER_H
|
||||
#define FLIPPR_DRIVER_OUTPUT_SOUNDBOARDPINCONTROLLER_H
|
||||
|
||||
#include "output/OutputPinController.h"
|
||||
#include "output/items/detail/Sound.h"
|
||||
|
||||
namespace flippR_driver
|
||||
@@ -13,15 +12,10 @@ namespace flippR_driver
|
||||
namespace output
|
||||
{
|
||||
|
||||
namespace items // todo include + fw decl??
|
||||
{
|
||||
class Sound;
|
||||
}
|
||||
class SoundBoardPinController : public OutputPinController
|
||||
class SoundBoardPinController
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void deactivate(items::DriverBoardItem &driver_board_item) = 0;
|
||||
virtual ~SoundBoardPinController() = default;
|
||||
|
||||
virtual void activate(const items::detail::Sound &sound) = 0;
|
||||
virtual void deactivate(const items::detail::Sound &sound) = 0;
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
#include "output/DisplayBoardPinController.h"
|
||||
|
||||
#include "output/OutputPinController.h"
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
@@ -18,7 +17,7 @@ namespace output
|
||||
namespace detail
|
||||
{
|
||||
|
||||
class DisplayBoardPinController : public output::DisplayBoardPinController, public OutputPinController
|
||||
class DisplayBoardPinController : public output::DisplayBoardPinController
|
||||
{
|
||||
public:
|
||||
explicit DisplayBoardPinController(std::map<std::string, uint8_t> pins_display);
|
||||
|
||||
@@ -5,12 +5,11 @@
|
||||
#ifndef FLIPPR_DRIVER_OUTPUT_IMPL_DRIVERBOARDPINCONTROLLER_H
|
||||
#define FLIPPR_DRIVER_OUTPUT_IMPL_DRIVERBOARDPINCONTROLLER_H
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
#include "output/DriverBoardPinController.h"
|
||||
|
||||
#include "output/OutputPinController.h"
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
namespace flippR_driver
|
||||
{
|
||||
|
||||
@@ -32,16 +32,16 @@ void SoundBoardPinController::activate(const items::detail::Sound &sound)
|
||||
|
||||
write_sound_address(sound.get_address());
|
||||
|
||||
fire_sound(true);
|
||||
fire_sound();
|
||||
}
|
||||
|
||||
void SoundBoardPinController::deactivate(const items::detail::Sound &sound)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(*output_item_mutex);
|
||||
|
||||
write_sound_address(sound.get_address());
|
||||
write_sound_address(0);
|
||||
|
||||
fire_sound(false);
|
||||
fire_sound();
|
||||
}
|
||||
|
||||
|
||||
@@ -56,9 +56,11 @@ void SoundBoardPinController::write_sound_address(uint8_t address) const
|
||||
write_pin(pins_sound.at("G"), address & 0b1000000u);
|
||||
}
|
||||
|
||||
void SoundBoardPinController::fire_sound(bool fire) const
|
||||
void SoundBoardPinController::fire_sound() const
|
||||
{
|
||||
PinController::write_pin(pins_sound.at("fire"), fire);
|
||||
PinController::write_pin(pins_sound.at("fire"), true);
|
||||
|
||||
PinController::write_pin(pins_sound.at("fire"), false);
|
||||
}
|
||||
|
||||
void SoundBoardPinController::write_pin(uint8_t pin, bool value) const
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
|
||||
#include "output/SoundBoardPinController.h"
|
||||
|
||||
#include "output/OutputPinController.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace flippR_driver
|
||||
@@ -24,13 +22,12 @@ public:
|
||||
SoundBoardPinController(std::map<std::string, uint8_t> pins_sound, std::shared_ptr<std::mutex> output_item_mutex);
|
||||
~SoundBoardPinController() override = default;
|
||||
|
||||
|
||||
void activate(const items::detail::Sound &sound);
|
||||
void deactivate(const items::detail::Sound &sound);
|
||||
void activate(const items::detail::Sound &sound) override;
|
||||
void deactivate(const items::detail::Sound &sound) override;
|
||||
|
||||
private:
|
||||
void write_sound_address(uint8_t address) const;
|
||||
void fire_sound(bool fire) const;
|
||||
void fire_sound() const;
|
||||
|
||||
void write_pin(uint8_t pin, bool value) const;
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
|
||||
using namespace flippR_driver::output;
|
||||
|
||||
items::detail::DriverBoardItem::DriverBoardItem(std::shared_ptr<OutputPinController> pin_controller, const uint8_t address) :
|
||||
pin_controller(std::move(pin_controller)), address(address)
|
||||
items::detail::DriverBoardItem::DriverBoardItem(const uint8_t address) :
|
||||
address(address)
|
||||
{}
|
||||
|
||||
uint8_t items::detail::DriverBoardItem::get_address() const
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
|
||||
#include "output/items/DriverBoardItem.h"
|
||||
|
||||
#include "output/OutputPinController.h"
|
||||
|
||||
#include <memory>
|
||||
namespace flippR_driver
|
||||
{
|
||||
@@ -22,7 +20,7 @@ namespace detail
|
||||
class DriverBoardItem : public output::items::DriverBoardItem
|
||||
{
|
||||
public:
|
||||
DriverBoardItem(std::shared_ptr<OutputPinController> pin_controller, const uint8_t address);
|
||||
DriverBoardItem(const uint8_t address);
|
||||
|
||||
~DriverBoardItem() override = default;
|
||||
|
||||
@@ -30,8 +28,6 @@ public:
|
||||
|
||||
protected:
|
||||
const uint8_t address;
|
||||
|
||||
const std::shared_ptr<OutputPinController> pin_controller;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace items
|
||||
namespace detail
|
||||
{
|
||||
|
||||
class Item : public items::Item
|
||||
class Item : public virtual items::Item
|
||||
{
|
||||
public:
|
||||
Item(std::string name);
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace detail
|
||||
{
|
||||
|
||||
Lamp::Lamp(std::shared_ptr<DriverBoardPinController> pin_controller, uint8_t address, std::string name) :
|
||||
detail::Item(std::move(name)), DriverBoardItem(std::move(pin_controller), address), activated(false)
|
||||
detail::Item(std::move(name)), DriverBoardItem(address), pin_controller(std::move(pin_controller), activated(false)
|
||||
{
|
||||
CLOG(INFO, OUTPUT_LOGGER) << "Created lamp " << name << " with address " << address;
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ public:
|
||||
bool is_activated() override;
|
||||
|
||||
private:
|
||||
const std::shared_ptr<DriverBoardPinController> pin_controller;
|
||||
bool activated;
|
||||
};
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace detail
|
||||
{
|
||||
|
||||
Solenoid::Solenoid(std::shared_ptr<DriverBoardPinController> pin_controller, uint8_t address, std::string name, std::chrono::milliseconds deactivation_time)
|
||||
: detail::Item(std::move(name)), DriverBoardItem(std::move(pin_controller), address), deactivation_time(deactivation_time)
|
||||
: detail::Item(std::move(name)), DriverBoardItem(address), pin_controller(std::move(pin_controller)), deactivation_time(deactivation_time)
|
||||
{
|
||||
CLOG(INFO, OUTPUT_LOGGER) << "Created solenoid " << name << " with address " << address;
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ private:
|
||||
virtual void triggerTask();
|
||||
|
||||
private:
|
||||
const std::shared_ptr<DriverBoardPinController> pin_controller;
|
||||
const std::chrono::milliseconds deactivation_time;
|
||||
|
||||
std::future<void> trigger_task;
|
||||
|
||||
@@ -21,8 +21,7 @@ namespace detail
|
||||
{
|
||||
|
||||
Sound::Sound(std::shared_ptr<SoundBoardPinController> pin_controller, uint8_t address, std::string name, std::chrono::milliseconds deactivation_time, u_int id)
|
||||
:
|
||||
pin_controller(std::move(pin_controller)), detail::Item(std::move(name)), DriverBoardItem(pin_controller, address), deactivation_time(deactivation_time), id(id)
|
||||
: detail::Item(std::move(name)), DriverBoardItem(address), pin_controller(std::move(pin_controller)), deactivation_time(deactivation_time), id(id)
|
||||
{
|
||||
CLOG(INFO, OUTPUT_LOGGER) << "Created sound " << id << " with name " << name << " and address " << address;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user