blk_box_tc/main/steps/step6.hpp
2024-08-07 18:15:31 -05:00

57 lines
1.4 KiB
C++

#ifndef STEP_6_HPP
#define STEP_6_HPP
#include "wires_puzzle.h"
#include "drivers/wires.h"
#include "drivers/bottom_half.h"
static const char *STEP6_TAG = "step6";
static uint8_t cut_wires = 0;
void step6(void) {
get_cut_wires();
clear_all_pressed_released();
WireColor wires[NUM_WIRES];
load_wires_from_sd_card(wires);
bool solution[NUM_WIRES] = {0};
solve_wires(wires, solution);
while (1) {
uint8_t new_cut_wires = get_cut_wires();
uint8_t just_cut_wires = new_cut_wires & ~cut_wires;
cut_wires |= new_cut_wires;
for (int i = 0; i < NUM_WIRES; i++) {
if (just_cut_wires & (1<<i)) {
if (solution[i]) {
play_raw(MOUNT_POINT "/correct.pcm");
} else {
strike("Cut wrong wire");
}
}
}
if (get_touch_pressed()) {
bool correct = true;
for (int i = 0; i < NUM_WIRES; i++) {
bool wire_cut = (cut_wires & (1<<i)) != 0;
if (solution[i] && !wire_cut) {
correct = false;
}
}
if (correct) {
return;
} else {
strike("Not all wires are cut!");
}
}
vTaskDelay(pdMS_TO_TICKS(10));
}
}
#endif /* STEP_6_HPP */