Skip to content

Commit

Permalink
PolyDiv: allow all steps=0; hide inactive steps
Browse files Browse the repository at this point in the history
  • Loading branch information
djphazer committed Jan 8, 2024
1 parent 41f93ce commit f1eac89
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions software/o_c_REV/HEM_PolyDiv.ino
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,25 @@ public:
uint8_t steps[NUM_STEPS];

bool Poke() {
// reset case
if (step_index < 0) {
++step_index;
return true;
}
// reset case
if (step_index < 0) {
step_index = 0;
return steps[step_index] > 0;
}

// quota achieved, advance to next enabled step
if (++clock_count >= steps[step_index]) {
clock_count = 0;
do { // lol this will get stuck if anything goes wrong...
++step_index %= NUM_STEPS;
} while (steps[step_index] == 0);
return true;
}
return false;
// quota achieved, advance to next enabled step
if (++clock_count >= steps[step_index]) {
clock_count = 0;

int i = 0;
do {
++step_index %= NUM_STEPS;
++i;
} while (steps[step_index] == 0 && i < NUM_STEPS);

return steps[step_index] > 0;
}
return false;
}
void Reset() {
step_index = -1;
Expand Down Expand Up @@ -139,15 +143,15 @@ public:
const int s = cursor % NUM_STEPS;
const int div = div_seq[ch].steps[s] + direction;
//if (div < 0) div = MAX_DIV;
div_seq[ch].steps[s] = constrain(div, (cursor == STEP1A || cursor == STEP1B) ? 1 : 0, MAX_DIV);
div_seq[ch].steps[s] = constrain(div, 0, MAX_DIV);
}

uint64_t OnDataRequest() {
uint64_t data = 0;
const size_t b = 6; // bitsize
ForEachChannel(ch) {
for (size_t i = 0; i < NUM_STEPS; i++) {
const uint8_t val = div_seq[ch].steps[i] + (i == 0 ? -1 : 0);
const uint8_t val = div_seq[ch].steps[i];
Pack(data, PackLocation {ch*NUM_STEPS*b + i*b, b}, val);
}
}
Expand All @@ -158,7 +162,7 @@ public:
const size_t b = 6; // bitsize
ForEachChannel(ch) {
for (size_t i = 0; i < NUM_STEPS; i++) {
div_seq[ch].steps[i] = Unpack(data, PackLocation {ch*NUM_STEPS*b + i*b, b}) + (i == 0 ? 1 : 0);
div_seq[ch].steps[i] = Unpack(data, PackLocation {ch*NUM_STEPS*b + i*b, b});
div_seq[ch].steps[i] = constrain(div_seq[ch].steps[i], 0, MAX_DIV);
}
// step 1 cannot be zero
Expand Down Expand Up @@ -189,6 +193,8 @@ private:
// divisions
ForEachChannel(ch) {
for(int i = 0; i < NUM_STEPS; i++) {
if (div_seq[ch].steps[i] == 0 && cursor != i + ch*NUM_STEPS) continue;

gfxPrint(1 + 31*ch, 15 + (i*10), div_seq[ch].steps[i]);
DrawSlider(14 + 31*ch, 15 + (i*10), 14, div_seq[ch].steps[i], MAX_DIV, cursor == i+ch*NUM_STEPS);

Expand Down

0 comments on commit f1eac89

Please sign in to comment.