-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathVoltageControlledEuclideanSequencerTest.cpp
103 lines (86 loc) · 2.04 KB
/
VoltageControlledEuclideanSequencerTest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
g++ -I../RebelTechnology/Libraries/wiring -I../RebelTechnology/Libraries/avrsim -I/opt/local/include -L/opt/local/lib -o VoltageControlledEuclideanSequencerTest -lboost_unit_test_framework VoltageControlledEuclideanSequencerTest.cpp ../RebelTechnology/Libraries/avrsim/avr/io.c ../RebelTechnology/Libraries/wiring/serial.c ../RebelTechnology/Libraries/avrsim/avr/interrupt.c && ./VoltageControlledEuclideanSequencerTest
*/
// #define mcu atmega168
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE Test
#include <boost/test/unit_test.hpp>
#include "VoltageControlledEuclideanSequencer.cpp"
struct PinFixture {
PinFixture() {
setup();
PIND |= _BV(PORTD2);
PIND |= _BV(PORTD3);
PIND |= _BV(PORTD4);
PIND |= _BV(PORTD5);
PIND |= _BV(PORTD6);
PIND |= _BV(PORTD7);
}
};
void setCountMode(){
PIND &= ~_BV(PORTD6);
}
void setDelayMode(){
PIND |= _BV(PORTD6);
}
void setReset(bool high = true){
if(high)
PIND &= ~_BV(PORTD2);
else
PIND |= _BV(PORTD2);
}
void setClock(bool high = true){
if(high)
PIND &= ~_BV(PORTD3);
else
PIND |= _BV(PORTD3);
INT1_vect();
}
void toggleClock(int times = 1){
for(int i=0; i<times; ++i){
PIND ^= _BV(PORTD3);
INT1_vect();
}
}
void pulseClock(int times = 1){
for(int i=0; i<times; ++i){
PIND &= ~_BV(PORTD3); // clock high
INT1_vect();
PIND |= _BV(PORTD3); // clock low
INT1_vect();
}
}
void setDivide(float value){
adc_values[0] = ADC_VALUE_RANGE-1-value*1023*4;
}
void setDelay(float value){
adc_values[1] = ADC_VALUE_RANGE-1-value*1023*4;
}
bool divideIsHigh(){
return !(PORTB & _BV(PORTB0));
}
bool delayIsHigh(){
return !(PORTB & _BV(PORTB1));
}
bool combinedIsHigh(){
return !(PORTB & _BV(PORTB2));
}
struct DefaultFixture {
PinFixture pins;
DefaultFixture(){
loop();
setDivide(0.0);
setDelay(0.0);
loop();
}
};
BOOST_AUTO_TEST_CASE(universeInOrder)
{
BOOST_CHECK(2+2 == 4);
}
BOOST_AUTO_TEST_CASE(testDefaults){
PinFixture fixture;
loop();
BOOST_CHECK(!resetIsHigh());
BOOST_CHECK(!clockIsHigh());
}