namespace cleanup

This commit is contained in:
Kevin Matz 2021-01-08 14:01:51 -05:00
parent f1fe989d9a
commit eef99b8c51
2 changed files with 32 additions and 15 deletions

View File

@ -25,17 +25,24 @@
#include "universe.h"
namespace DMX {
/*
accept new data from receiver
using std::copy;
/**
*/
void Universe::set(std::vector<uint8_t> vect) {
// full length universe is 513, including start code
// truncate larger data and pad shorter data with 0
vect.resize(513, 0);
switch (vect.front()) // start code
{
Universe::Universe() {
null_start_data_.fill(0);
}
/**
accept new data from receiver
@param vector<uint8_t> varaibly sized data, beginning with a start code.
*/
void Universe::set(vector<uint8_t> vect) {
switch (vect.front()) { // start code
case E111_NULL_START:
std::copy(vect.begin(), vect.end(), null_start_data_.begin());
vect.resize(null_start_data_.size(), 0); // pad shorter, truncate larger
copy(vect.begin(), vect.end(), null_start_data_.begin());
for (const auto &cb : callbacks_)
cb(this);
break;
@ -44,8 +51,10 @@ void Universe::set(std::vector<uint8_t> vect) {
}
}
/*
/**
register a data consumer callback function
@param const DataHandlerFunction something that knows what to do with DMX
*/
void Universe::onData(const DataHandlerFunction callback)
{

View File

@ -23,12 +23,18 @@
*/
#pragma once
#include <stdint.h>
#include <cstdint>
#include <functional>
#include <vector>
namespace DMX {
using std::uint8_t;
using std::uint16_t;
using std::array;
using std::function;
using std::vector;
// Table D1 - Reserved START Codes
static const uint8_t E111_NULL_START = 0;
static const uint8_t E111_ASC_TEXT_ASCII = 23;
@ -40,10 +46,10 @@ static const uint8_t E111_ASC_SIP = 207;
// register type for data users to subscribe callbacks
class Universe; // forward declare the Univserse class
typedef std::function<void(Universe *)> DataHandlerFunction;
typedef function<void(Universe *)> DataHandlerFunction;
// convience declare the type of null_start_data_
typedef std::array<uint8_t, 513> null_start_data_t;
typedef array<uint8_t, 513> null_start_data_t;
/*
The Universe class
@ -54,14 +60,16 @@ typedef std::array<uint8_t, 513> null_start_data_t;
*/
class Universe {
public:
Universe ();
null_start_data_t * data() { return &null_start_data_; }
void onData (const DataHandlerFunction callback);
void set (std::vector<uint8_t>);
void set (vector<uint8_t>);
uint8_t slot (uint16_t address) { return null_start_data_[address]; }
private:
null_start_data_t null_start_data_;
std::vector<DataHandlerFunction> callbacks_;
vector<DataHandlerFunction> callbacks_;
};
} // DMX