Skip to content

Commit

Permalink
#5 Repaired clock code sorta
Browse files Browse the repository at this point in the history
at least to the point that the build doesn't break anymore, but it neither works nor is being used yet
  • Loading branch information
wraybowling committed Aug 25, 2020
1 parent c956aba commit 63f32a4
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 65 deletions.
21 changes: 0 additions & 21 deletions old_src/weight.cpp

This file was deleted.

3 changes: 3 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ upload_flags =
usbtiny
upload_command = avrdude $UPLOAD_FLAGS -U flash:w:$SOURCE:i

[env:native]
platform = native

[env:USBtiny ISP]
upload_protocol = usbtiny

Expand Down
39 changes: 17 additions & 22 deletions src/clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,21 @@
* when the new frame is lower than the previous, then we have a new pulse
*/

#include "pins.h"
#include "clock.h"

Clock::Clock(void) {
predictor.Init();
}

void Clock::clockIn(int sync_voltage) {
sync_debounce = sync_debounce << 1 + sync_voltage > 900;
syncCounter++;
sync_debounce = (sync_debounce << 1) + (sync_voltage > 900);
sync_counter++;
if (sync_debounce == 1) {
const uint32_t NEW_PERIOD = millis() - millis_prev_sync;
sync_period = predictor.Predict(NEW_PERIOD);
syncCounter = 0;
sync_counter = 0;
}
}

bool Clock::clockOut() {
const int MULTIPLIER_STEP = (getMux(clock_div_knob) * 10 + 512) / 1023 - 5;
const int MULTIPLIER = abs(MULTIPLIER_STEP) == 5
bool Clock::clockOut(int division_voltage) {
const int MULTIPLIER_STEP = (division_voltage * 10 + 512) / 1023 - 5;
const unsigned int MULTIPLIER = abs(MULTIPLIER_STEP) == 5
? 24
: 1 << abs(MULTIPLIER_STEP);

Expand All @@ -49,24 +44,24 @@ bool Clock::clockOut() {
// actually just skip

// if (something) {
// this.clock_skips++;
// if (this.clock_skips >= MULTIPLIER)
// {
// this.clock_skips = 0;
// }
clock_skips++;
if (clock_skips >= MULTIPLIER)
{
clock_skips = 0;
}
// }
} else { // divide period (faster)
const NEXT_MODULO =
//const NEXT_MODULO =
//prev_modulo

//millis_next_clock_on = now + periodPrediction / multiplier;
// millis_next_clock_on = now + periodPrediction / multiplier;
}
millis_next_clock_off = millis_next_clock_on + 25;
// millis_next_clock_off = millis_next_clock_on + 25;
return false;
}

void Clock::reTrigger()
{
this.skips = 0;
void Clock::reTrigger() {
clock_skips = 0;
}


Expand Down
13 changes: 11 additions & 2 deletions src/clock.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef CLOCK_H
#define CLOCK_H

#include <Arduino.h>
#include "peaks_pattern_predictor.h"

Expand All @@ -9,6 +12,7 @@ class Clock {
uint32_t sync_period;
uint32_t sync_counter;
uint32_t prev_modulo;
uint32_t next_modulo;
uint32_t clock_skips;
uint8_t clock_counter;
// uint32_t clock_slip;
Expand All @@ -19,8 +23,13 @@ class Clock {
uint32_t millis_next_clock_off;

public:
Clock() {
predictor.Init();
}
void clockIn(int sync_voltage);
bool clockOut();
bool clockOut(int division_voltage);
void reTrigger();
// void doTimeStuff();
};
};

#endif
9 changes: 5 additions & 4 deletions src/led.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
* light up when you press that button
*/

#ifndef TRIGERPLUS_LED_H_
#define TRIGERPLUS_LED_H_
#endif
#ifndef TRIPLUSGER_LED_H_
#define TRIPLUSGER_LED_H_

#include <Arduino.h>
#include "pins.h"
Expand All @@ -29,4 +28,6 @@ void lights(byte grw, byte orange)
shiftOut(led_data, led_clock, LSBFIRST, grw);
shiftOut(led_data, led_clock, LSBFIRST, orange);
digitalWrite(led_latch, HIGH);
}
}

#endif
5 changes: 3 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "multiplexer.h"
#include "led.h"
#include "grid.h"
#include "clock.h"

void setup()
{
Expand Down Expand Up @@ -59,7 +60,7 @@ short pwm = 0;
void loop()
{
// local vars
int this_clock_in = getMux(clock_div_cv);
int this_clock_in = getTrigerMux(clock_div_cv);
bool this_left = digitalRead(left_button);

unsigned long time = millis();
Expand Down Expand Up @@ -110,7 +111,7 @@ void loop()
(pwm % 40) == 0,
1
};
short viz = step / (24 * 4);
short viz = (step / 24) % 4;
byte state = 0
+ tracker[viz] * (viz == 0 ? 1 : brightness[2])
+ B1000 * brightness[leftGrid.get_weight(step+0, 1)]
Expand Down
8 changes: 5 additions & 3 deletions src/multiplexer.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma once

/**
* multiplexed analog signals
* all are read on A6 via the getMux() function
Expand All @@ -11,7 +13,7 @@
#define record_button B110 // 6
#define record_button_master B111 // 7

int getMux(char channels)
int getTrigerMux(char channels)
{
digitalWrite(mux_select_0, bitRead(channels, 0));
digitalWrite(mux_select_1, bitRead(channels, 1));
Expand All @@ -21,10 +23,10 @@ int getMux(char channels)

bool getHostMode()
{
int mode = getMux(host_vs_slave);
int mode = getTrigerMux(host_vs_slave);
if (mode > 900)
return 1; //host
if (mode > 0)
return 0; //slave
return 1; //normal
}
}
17 changes: 6 additions & 11 deletions src/peaks_pattern_predictor.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,15 @@ class PatternPredictor
public:
PatternPredictor() {}

void Init()
{
void Init() {
last_prediction_ = 0;
history_pointer_ = 0;
// std::fill(&history_[0], &history_[history_size], 0);
// for (int i = 0; i < history_size; i++)
// {
// history_[i] = 0;
// }
history_ = {0};
for (unsigned int i = 0; i < history_size; i++) {
history_[i] = 0;
}
}

uint32_t Predict(uint32_t value)
{
uint32_t Predict(uint32_t value) {
// Record the incoming value.
history_[history_pointer_] = value;

Expand Down Expand Up @@ -94,7 +89,7 @@ class PatternPredictor
uint32_t history_pointer_;
uint32_t last_prediction_;

DISALLOW_COPY_AND_ASSIGN(PatternPredictor);
// DISALLOW_COPY_AND_ASSIGN(PatternPredictor);
};

#endif // PATTERN_PREDICTOR_H
5 changes: 5 additions & 0 deletions src/pins.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef TRIPLUSGER_PINS_H_
#define TRIPLUSGER_PINS_H_

/**
* ATMEGA328 AU pin configuration & assignment
*
Expand Down Expand Up @@ -44,3 +47,5 @@
#define top_button 0 //30 (pd0)
#define left_button 1 //31 (pd1)
#define right_button 2 //32 (pd2)

#endif

0 comments on commit 63f32a4

Please sign in to comment.