52 lines
910 B
Arduino
52 lines
910 B
Arduino
|
|
||
|
#include "commands.hpp"
|
||
|
#include "tone.hpp"
|
||
|
#include "serial.hpp"
|
||
|
#include "tones.hpp"
|
||
|
#include "dac.hpp"
|
||
|
#include "timing.hpp"
|
||
|
#include "util.hpp"
|
||
|
#include "scheduler.hpp"
|
||
|
|
||
|
unsigned long int micros_at = 0;
|
||
|
|
||
|
inline unsigned long micros_diff() {
|
||
|
unsigned long now = micros();
|
||
|
unsigned long diff = now - micros_at;
|
||
|
micros_at = now;
|
||
|
return diff;
|
||
|
}
|
||
|
|
||
|
void setup() {
|
||
|
dac::init();
|
||
|
serial::init();
|
||
|
scheduler::do_next();
|
||
|
}
|
||
|
|
||
|
void loop() {
|
||
|
if(Serial.available() && Serial.read() == ':') {
|
||
|
commands::process();
|
||
|
}
|
||
|
|
||
|
if(scheduler::running && timing::at >= scheduler::timestamp) {
|
||
|
scheduler::do_next();
|
||
|
}
|
||
|
|
||
|
timing::update();
|
||
|
|
||
|
float value = 0;
|
||
|
uint32_t passed = ((uint64_t)timing::diff << (20)) / 1000000L;
|
||
|
|
||
|
for(int i = 0; i < tones::active; i++) {
|
||
|
Tone& t = tones::all[i];
|
||
|
if(!t.active()) {
|
||
|
continue;
|
||
|
}
|
||
|
t.update(passed);
|
||
|
value += t.get();
|
||
|
}
|
||
|
|
||
|
dac::set(value);
|
||
|
}
|
||
|
|