Added libheptaled

This commit is contained in:
Sebastian 2014-11-19 18:49:34 +01:00
parent b2da04a840
commit 5229158dd9
6 changed files with 113 additions and 0 deletions

1
libheptaled/.clang Normal file
View File

@ -0,0 +1 @@
--std=c++11

27
libheptaled/Makefile Normal file
View File

@ -0,0 +1,27 @@
OBJDIR = bin
CXX = clang++
CXXFLAGS = --std=c++11
LDFLAGS =
$(OBJDIR)/display.o : common.h digit.h display.h display.cpp
all : start $(OBJDIR)/display.o
@echo ":: Done !"
start :
@echo " LibHeptaled"
@echo "============="
@echo ":: Building using $(CXX)"
$(OBJDIR)/%.o : %.cpp Makefile
mkdir -p $$(dirname $@)
$(CXX) $(CXXFLAGS) -c $< -o $@
$(OBJDIR)/$(TARGET) : $(OBJDIR)/$(TARGET).o
$(CXX) $+ $(LDFLAGS) -o $@
clean :
@rm -rf $(OBJDIR)

12
libheptaled/common.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef COMMON_H
#define COMMON_H COMMON_H
#include <vector>
namespace HeptaLed {
typedef std::vector<uint8_t> ByteBuffer;
}
#endif

19
libheptaled/digit.h Normal file
View File

@ -0,0 +1,19 @@
#ifndef DIGIT_H
#define DIGIT_H DIGIT_H
#include <string>
#include "common.h"
namespace HeptaLed {
class Digit {
public:
virtual void render(std::string::const_iterator stringIt, ByteBuffer::iterator const& bufferIt) = 0;
};
}
#endif

26
libheptaled/display.cpp Normal file
View File

@ -0,0 +1,26 @@
#include "display.h"
namespace HeptaLed {
Display& Display::add(std::shared_ptr<Digit> digit) {
digits.push_back(digit);
return *this;
}
ByteBuffer Display::render(std::string const& s) {
ByteBuffer buffer(digits.size());
std::string::const_iterator stringIt = s.begin();
ByteBuffer::iterator byteIt = buffer.begin();
for(DigitVector::iterator it = digits.begin(); it != digits.end(); ++it) {
(*it)->render(stringIt,byteIt);
++byteIt;
}
return buffer;
}
}

28
libheptaled/display.h Normal file
View File

@ -0,0 +1,28 @@
#ifndef DISPLAY_H
#define DISPLAY_H DISPLAY_H
#include <vector>
#include <memory>
#include <string>
#include <stdint.h>
#include "common.h"
#include "digit.h"
namespace HeptaLed {
typedef std::vector<std::shared_ptr<Digit>> DigitVector;
class Display {
public:
Display& add(std::shared_ptr<Digit> digit);
ByteBuffer render(std::string const& s);
private:
DigitVector digits;
};
}
#endif