Compare commits

...

2 Commits

11 changed files with 180 additions and 31 deletions

View File

@ -1,4 +1,8 @@
#include "Arduino.h"
#include "SPI.h"
#include "SegmentDisplay.h"
#include "SegmentDisplayChars.h"
void SegmentDisplay::begin()

View File

@ -2,9 +2,6 @@
#define SegmentDisplay_h
#include "Arduino.h"
#include "SPI.h"
#include "SegmentDisplayChars.h"
/**
* Drives up to 8 digits using two 8-bit shift registers.
@ -19,7 +16,7 @@
**/
// Comment to use shiftOut. Set clockPin and dataPin instead.
#define SDSupportSPI
//#define SDSupportSPI
class SegmentDisplay
@ -51,8 +48,8 @@ class SegmentDisplay
#endif
protected:
void writeDigit(byte value, byte digitMask);
void writeDisplay(byte characterMask, byte digitMask);
inline void writeDigit(unsigned char value, unsigned char digitMask);
inline void writeDisplay(unsigned char characterMask, unsigned char digitMask);
private:
int digits = 6;

View File

@ -13,7 +13,7 @@
#define SegmentG 64 // Middle
const byte SDNumberSegments[10] PROGMEM =
const unsigned char SDNumberSegments[10] PROGMEM =
{
/**
* _
@ -98,7 +98,7 @@ const byte SDNumberSegments[10] PROGMEM =
const byte SDCharacterSegments[26] PROGMEM =
const unsigned char SDCharacterSegments[26] PROGMEM =
{
/**
* _
@ -166,11 +166,11 @@ const byte SDCharacterSegments[26] PROGMEM =
/**
*
* |
* |
* |
* |
*
**/
SegmentE | SegmentF,
SegmentB | SegmentC,
/**
*
@ -182,11 +182,11 @@ const byte SDCharacterSegments[26] PROGMEM =
/**
*
* |_|
* |_
* |
*
**/
SegmentE | SegmentF | SegmentG,
SegmentB | SegmentD | SegmentE | SegmentF | SegmentG,
/**
*
@ -196,14 +196,6 @@ const byte SDCharacterSegments[26] PROGMEM =
**/
SegmentD | SegmentE | SegmentF,
/**
* _
*
* | |
*
**/
SegmentA | SegmentC | SegmentE,
/**
*
* _
@ -212,6 +204,14 @@ const byte SDCharacterSegments[26] PROGMEM =
**/
SegmentC | SegmentE | SegmentG,
/**
* _
* | |
* | |
*
**/
SegmentA | SegmentB | SegmentC | SegmentE | SegmentF,
/**
* _
* | |
@ -268,6 +268,14 @@ const byte SDCharacterSegments[26] PROGMEM =
**/
SegmentB | SegmentC | SegmentD | SegmentE | SegmentF,
/**
*
* | |
* |_|
*
**/
SegmentB | SegmentC | SegmentD | SegmentE | SegmentF,
/**
*
*
@ -278,19 +286,11 @@ const byte SDCharacterSegments[26] PROGMEM =
/**
*
* |_|
* | |
* _
*
**/
SegmentB | SegmentD | SegmentF,
/**
*
* _|
* |
*
**/
SegmentB | SegmentC | SegmentG,
SegmentB | SegmentC | SegmentE | SegmentF | SegmentG,
/**
*

2
test/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
runner
runner.cpp

View File

@ -0,0 +1,62 @@
#include <cxxtest/TestSuite.h>
#include "Mock.h"
#include "lib/SegmentDisplay.h"
class SegmentDisplayTestSuite : public CxxTest::TestSuite
{
public:
void testBeginEnd(void)
{
SegmentDisplay* display = new SegmentDisplay();
display->begin();
display->end();
}
/*
void testWriteNumberFull(void)
{
SegmentDisplay* display = new SegmentDisplay();
display->begin();
display->setDigits(8);
display->writeNumber(12345678);
display->end();
// TODO test writing the full 8-digit numbers
}
void testWriteTextFull(void)
{
// TODO test writing full length text
TS_WARN("Not implemented");
}
void testWriteNumberPartial(void)
{
// TODO test writing a partial 5-digit numbers
TS_WARN("Not implemented");
}
void testWriteTextPartial(void)
{
// TODO test writing partial text
TS_WARN("Not implemented");
}
void testWriteNumberOverflow(void)
{
// TODO test writing a number larger than 8 digits
TS_WARN("Not implemented");
}
void testWriteTextOverflow(void)
{
// TODO test writing text which is too long
TS_WARN("Not implemented");
}
*/
};

31
test/mock/Arduino.h Normal file
View File

@ -0,0 +1,31 @@
// Contains the bare minimum to get the test suite up and running
#ifndef ArduinoMock_h
#define ArduinoMock_h
#include <stdint.h>
#define HIGH 0x1
#define LOW 0x0
#define INPUT 0x0
#define OUTPUT 0x1
#define LSBFIRST 0
#define MSBFIRST 1
#define PIN_SPI_SS (17)
#define PIN_SPI_MOSI (16)
#define PIN_SPI_MISO (14)
#define PIN_SPI_SCK (15)
static const uint8_t SS = PIN_SPI_SS;
static const uint8_t MOSI = PIN_SPI_MOSI;
static const uint8_t MISO = PIN_SPI_MISO;
static const uint8_t SCK = PIN_SPI_SCK;
void digitalWrite(uint32_t dwPin, uint32_t dwVal);
void pinMode(uint32_t dwPin, uint32_t dwMode);
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
#endif

19
test/mock/Mock.cpp Normal file
View File

@ -0,0 +1,19 @@
// Provides implementations for the mock headers that write out to a vector.
// Access this vector using Mock.h.
#include "Arduino.h"
#include "Mock.h"
void digitalWrite(uint32_t dwPin, uint32_t dwVal)
{
}
void pinMode(uint32_t dwPin, uint32_t dwMode)
{
}
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val)
{
}

4
test/mock/Mock.h Normal file
View File

@ -0,0 +1,4 @@
#ifndef Mock_h
#define Mock_h
#endif

1
test/mock/SPI.h Normal file
View File

@ -0,0 +1 @@
// Contains the bare minimum to get the test suite up and running

7
test/mock/avr/pgmspace.h Normal file
View File

@ -0,0 +1,7 @@
// Contains the bare minimum to get the test suite up and running
#ifndef pgmspacemock_h
#define pgmspacemock_h
#define PROGMEM __attribute__(())
#endif

22
test/runner.sh Normal file
View File

@ -0,0 +1,22 @@
#!/bin/sh
# Note:
# This works perfectly on Windows 10 Anniversary Edition using Ubuntu on Windows,
# just apt-get install g++!
CXXTest="../../CxxTest"
CXXTestGen="$CXXTest/bin/cxxtestgen"
$CXXTestGen --error-printer -o runner.cpp SegmentDisplayTestSuite.h
if [ $? -ne 0 ]; then
echo "Generating unit test runner failed, aborting"
exit $?
fi
g++ -o runner -I$CXXTest -I ../ -Imock -std=c++11 mock/Mock.cpp ../lib/*.cpp runner.cpp
if [ $? -ne 0 ]; then
echo "Compiling unit test runner failed, aborting"
exit $?
fi
./runner