step 3
This commit is contained in:
parent
fe9a4df7a9
commit
b6eac70c2c
@ -142,8 +142,8 @@ bool get_flipped_switch(SwitchKey* switch_) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t get_switch_state(uint8_t* switch_flags) {
|
uint8_t get_switch_state() {
|
||||||
return (uint8_t)(button_state && 0xF);
|
return (uint8_t)(~button_state & 0xF);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool get_touch_state(void) {
|
bool get_touch_state(void) {
|
||||||
|
|||||||
@ -59,7 +59,7 @@ uint8_t get_button_state();
|
|||||||
bool get_flipped_up_switch(SwitchKey* switch_);
|
bool get_flipped_up_switch(SwitchKey* switch_);
|
||||||
bool get_flipped_down_switch(SwitchKey* switch_);
|
bool get_flipped_down_switch(SwitchKey* switch_);
|
||||||
bool get_flipped_switch(SwitchKey* switch_);
|
bool get_flipped_switch(SwitchKey* switch_);
|
||||||
uint8_t get_switch_state(uint8_t* switch_flags);
|
uint8_t get_switch_state();
|
||||||
|
|
||||||
bool get_touch_state(void);
|
bool get_touch_state(void);
|
||||||
bool get_touch_pressed(void);
|
bool get_touch_pressed(void);
|
||||||
|
|||||||
@ -3,7 +3,9 @@ set(SOURCES
|
|||||||
"step0.cpp"
|
"step0.cpp"
|
||||||
"step1.cpp"
|
"step1.cpp"
|
||||||
"step2.cpp"
|
"step2.cpp"
|
||||||
|
"step3.cpp"
|
||||||
"step4.cpp"
|
"step4.cpp"
|
||||||
|
"step5.cpp"
|
||||||
"step6.cpp"
|
"step6.cpp"
|
||||||
"wires_puzzle.cpp"
|
"wires_puzzle.cpp"
|
||||||
"tetris.c"
|
"tetris.c"
|
||||||
|
|||||||
339
main/steps/step3.cpp
Normal file
339
main/steps/step3.cpp
Normal file
@ -0,0 +1,339 @@
|
|||||||
|
#include "step3.h"
|
||||||
|
|
||||||
|
static const char *TAG = "step3";
|
||||||
|
|
||||||
|
static std::random_device rd;
|
||||||
|
static std::mt19937 gen(rd());
|
||||||
|
static std::uniform_int_distribution<> puzzle_dist(0, 7);
|
||||||
|
static std::uniform_int_distribution<> led_picker_dist(0, 20);
|
||||||
|
static std::uniform_int_distribution<> led_color_dist(0, 5);
|
||||||
|
|
||||||
|
static const int INDICATOR_RED[6] = {30, 0, 0, 25, 15, 10};
|
||||||
|
static const int INDICATOR_GREEN[6] = {0, 0, 30, 5, 0, 10};
|
||||||
|
static const int INDICATOR_BLUE[6] = {0, 30, 0, 0, 15, 10};
|
||||||
|
|
||||||
|
void step3(void) {
|
||||||
|
int solved_puzzles = 0;
|
||||||
|
while (solved_puzzles < 3) {
|
||||||
|
|
||||||
|
// int puzzle = puzzle_dist(gen);
|
||||||
|
int puzzle = 2;
|
||||||
|
switch (puzzle) {
|
||||||
|
case 0: {
|
||||||
|
lcd_print(&lcd, "Clear");
|
||||||
|
set_module_time(10000);
|
||||||
|
start_module_timer();
|
||||||
|
|
||||||
|
std::uniform_int_distribution<> green_indicators_dist(2, 15);
|
||||||
|
|
||||||
|
// create all green indicators
|
||||||
|
uint8_t green_indicators = green_indicators_dist(gen);
|
||||||
|
std::set<int> indicators;
|
||||||
|
|
||||||
|
// ESP_LOGI(TAG, "green indicators: %i", green_indicators);
|
||||||
|
|
||||||
|
while (indicators.size() < green_indicators) {
|
||||||
|
int led = led_picker_dist(gen);
|
||||||
|
indicators.insert(led);
|
||||||
|
// ESP_LOGI(TAG, "added green led at %i", led);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (std::set<int>::iterator it = indicators.begin(); it != indicators.end(); it++) {
|
||||||
|
ESP_ERROR_CHECK(led_strip_set_pixel(leds, *it, 0, 10, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
// add non-green indicators
|
||||||
|
const int NON_GREEN_INDICATOR_RED[3] = {30, 0, 15};
|
||||||
|
const int NON_GREEN_INDICATOR_BLUE[3] = {0, 30, 15};
|
||||||
|
std::uniform_int_distribution<> non_green_indicator_color_dist(0, 2);
|
||||||
|
|
||||||
|
std::uniform_int_distribution<> remaining_indicators_dist(0, 20 - green_indicators);
|
||||||
|
int non_green_indicators = remaining_indicators_dist(gen);
|
||||||
|
std::set<int> remaining_indicators;
|
||||||
|
|
||||||
|
// ESP_LOGI(TAG, "non-green indicators: %i", non_green_indicators);
|
||||||
|
|
||||||
|
while (remaining_indicators.size() < non_green_indicators) {
|
||||||
|
int led_attempt = led_picker_dist(gen);
|
||||||
|
if (indicators.find(led_attempt) == indicators.end()) {
|
||||||
|
remaining_indicators.insert(led_attempt);
|
||||||
|
// ESP_LOGI(TAG, "added non-green led at %i", led_attempt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (std::set<int>::iterator it = remaining_indicators.begin(); it != remaining_indicators.end(); it++) {
|
||||||
|
int color = non_green_indicator_color_dist(gen);
|
||||||
|
ESP_ERROR_CHECK(led_strip_set_pixel(leds, *it, NON_GREEN_INDICATOR_RED[color], 0, NON_GREEN_INDICATOR_BLUE[color]));
|
||||||
|
}
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK(led_strip_refresh(leds));
|
||||||
|
|
||||||
|
// wait for time
|
||||||
|
while (1) {
|
||||||
|
if (get_module_time() <= 0) {
|
||||||
|
uint8_t state = get_switch_state();
|
||||||
|
uint8_t flipped_state = 0;
|
||||||
|
flipped_state |= (state & 0x01) << 3;
|
||||||
|
flipped_state |= (state & 0x02) << 1;
|
||||||
|
flipped_state |= (state & 0x04) >> 1;
|
||||||
|
flipped_state |= (state & 0x08) >> 3;
|
||||||
|
|
||||||
|
if (flipped_state == green_indicators) {
|
||||||
|
solved_puzzles++;
|
||||||
|
} else {
|
||||||
|
strike("Incorrect switch combination! (step 3, puzzle 0)");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(10));
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 1: {
|
||||||
|
lcd_print(&lcd, "Blank");
|
||||||
|
set_module_time(10000);
|
||||||
|
start_module_timer();
|
||||||
|
|
||||||
|
std::uniform_int_distribution<> on_indicators_dist(16, 21);
|
||||||
|
|
||||||
|
uint8_t indicators_num = on_indicators_dist(gen);
|
||||||
|
std::set<int> indicators;
|
||||||
|
|
||||||
|
while (indicators.size() < indicators_num) {
|
||||||
|
indicators.insert(led_picker_dist(gen));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (std::set<int>::iterator it = indicators.begin(); it != indicators.end(); it++) {
|
||||||
|
int color = led_color_dist(gen);
|
||||||
|
ESP_ERROR_CHECK(led_strip_set_pixel(leds, *it, INDICATOR_RED[color], INDICATOR_GREEN[color], INDICATOR_BLUE[color]));
|
||||||
|
}
|
||||||
|
ESP_ERROR_CHECK(led_strip_refresh(leds));
|
||||||
|
// ESP_LOGI(TAG, "puzzle 1 LEDs set (%i leds)", indicators_num);
|
||||||
|
|
||||||
|
if (indicators_num < 18) {
|
||||||
|
while (1) {
|
||||||
|
if (get_module_time() <= 0) {
|
||||||
|
if (get_switch_state() == 0b1111) {
|
||||||
|
solved_puzzles++;
|
||||||
|
// ESP_LOGI(TAG, "puzzle 1 solved (switches)!");
|
||||||
|
} else {
|
||||||
|
strike("Switch state was changed! (step 3, puzzle 1)");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(10));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
uint8_t starting_switch_state = get_switch_state();
|
||||||
|
KeypadKey key;
|
||||||
|
std::string pressed_keys;
|
||||||
|
while (1) {
|
||||||
|
if (get_pressed_keypad(&key)) {
|
||||||
|
pressed_keys += char_of_keypad_key(key);
|
||||||
|
// ESP_LOGI(TAG, "key %c pressed", char_of_keypad_key(key));
|
||||||
|
}
|
||||||
|
if (get_module_time() <= 0) {
|
||||||
|
if (starting_switch_state == get_switch_state()) {
|
||||||
|
if (pressed_keys == "ADCB") {
|
||||||
|
solved_puzzles++;
|
||||||
|
// ESP_LOGI(TAG, "puzzle 1 solved (keypad)!");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
strike("Switch state was changed! (step 3, puzzle 1)");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(10));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 2: {
|
||||||
|
set_module_time(10000);
|
||||||
|
start_module_timer();
|
||||||
|
|
||||||
|
std::uniform_int_distribution<> lit_led_dist(0, 1);
|
||||||
|
bool rfid_lit = lit_led_dist(gen);
|
||||||
|
// ESP_LOGI(TAG, "rfid lit: %i", rfid_lit);
|
||||||
|
bool lcd_lit = lit_led_dist(gen);
|
||||||
|
bool speaker_lit = lit_led_dist(gen);
|
||||||
|
bool keypad_lit = lit_led_dist(gen);
|
||||||
|
bool tft_lit = lit_led_dist(gen);
|
||||||
|
|
||||||
|
Led rfid_led = rfid;
|
||||||
|
Led lcd_led = char_lcd;
|
||||||
|
Led speaker_led = speaker;
|
||||||
|
Led keypad_led = keypad;
|
||||||
|
Led tft_led = tft;
|
||||||
|
|
||||||
|
if (rfid_lit) {
|
||||||
|
int color = led_color_dist(gen);
|
||||||
|
ESP_ERROR_CHECK(led_strip_set_pixel(leds, rfid_led, INDICATOR_RED[color], INDICATOR_GREEN[color], INDICATOR_BLUE[color]));
|
||||||
|
}
|
||||||
|
if (lcd_lit) {
|
||||||
|
int color = led_color_dist(gen);
|
||||||
|
ESP_ERROR_CHECK(led_strip_set_pixel(leds, lcd_led, INDICATOR_RED[color], INDICATOR_GREEN[color], INDICATOR_BLUE[color]));
|
||||||
|
}
|
||||||
|
if (speaker_lit) {
|
||||||
|
int color = led_color_dist(gen);
|
||||||
|
ESP_ERROR_CHECK(led_strip_set_pixel(leds, speaker_led, INDICATOR_RED[color], INDICATOR_GREEN[color], INDICATOR_BLUE[color]));
|
||||||
|
}
|
||||||
|
if (keypad_lit) {
|
||||||
|
int color = led_color_dist(gen);
|
||||||
|
ESP_ERROR_CHECK(led_strip_set_pixel(leds, keypad_led, INDICATOR_RED[color], INDICATOR_GREEN[color], INDICATOR_BLUE[color]));
|
||||||
|
}
|
||||||
|
if (tft_lit) {
|
||||||
|
int color = led_color_dist(gen);
|
||||||
|
ESP_ERROR_CHECK(led_strip_set_pixel(leds, tft_led, INDICATOR_RED[color], INDICATOR_GREEN[color], INDICATOR_BLUE[color]));
|
||||||
|
}
|
||||||
|
ESP_ERROR_CHECK(led_strip_refresh(leds));
|
||||||
|
|
||||||
|
int green_button_pressed = 0;
|
||||||
|
// ESP_LOGI(TAG, "green pressed: %i", green_button_pressed);
|
||||||
|
int blue_button_pressed = 0;
|
||||||
|
int fingerprint_sensor_pressed = 0;
|
||||||
|
std::string keypad_string;
|
||||||
|
|
||||||
|
ButtonKey button;
|
||||||
|
KeypadKey key;
|
||||||
|
SwitchKey switch1 = s1;
|
||||||
|
SwitchKey switch2 = s2;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
if (get_pressed_button(&button)) {
|
||||||
|
uint8_t button_state = get_button_state();
|
||||||
|
// ESP_LOGI(TAG, "Button pressed! (%i)", button_state());
|
||||||
|
|
||||||
|
if ((button_state & 0b1) == 0b1) {
|
||||||
|
green_button_pressed++;
|
||||||
|
if ((green_button_pressed > 1) || !rfid_lit) {
|
||||||
|
strike("Green button pressed too many times! (step 3, puzzle 2)");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((button_state & 0b1000) == 0b1000) {
|
||||||
|
blue_button_pressed++;
|
||||||
|
if ((blue_button_pressed > 1) || !lcd_lit) {
|
||||||
|
strike("Blue button pressed too many times! (step 3, puzzle 2)");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (get_touch_pressed()) {
|
||||||
|
fingerprint_sensor_pressed++;
|
||||||
|
if ((fingerprint_sensor_pressed > 2) || !speaker_lit) {
|
||||||
|
strike("Fingerprint sensor pressed too many times! (step 3, puzzle 2)");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (get_pressed_keypad(&key)) {
|
||||||
|
bool wrong = false;
|
||||||
|
keypad_string += char_of_keypad_key(key);
|
||||||
|
switch (keypad_string.length()) {
|
||||||
|
case 1: {
|
||||||
|
if (keypad_string != "1") {
|
||||||
|
strike("1 was not pressed on Keypad! (step 3, puzzle 2)");
|
||||||
|
wrong = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 2: {
|
||||||
|
if (keypad_string != "12") {
|
||||||
|
strike("12 was not pressed on Keypad! (step 3, puzzle 2)");
|
||||||
|
wrong = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
strike("keypad length was more than 2! (step 3, puzzle 2)");
|
||||||
|
wrong = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (wrong) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (get_flipped_up_switch(&switch1) || get_flipped_up_switch(&switch2)) {
|
||||||
|
if (!tft_lit) {
|
||||||
|
strike("Switch 1 or 2 were flipped up! (step 3, puzzle 2)");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (get_module_time() <= 0) {
|
||||||
|
bool rfid_correct = !(rfid_lit && (green_button_pressed != 1));
|
||||||
|
bool lcd_correct = !(lcd_lit && (blue_button_pressed != 1));
|
||||||
|
bool speaker_correct = !(speaker_lit && (fingerprint_sensor_pressed != 2));
|
||||||
|
bool keypad_correct = !(keypad_lit && (keypad_string != "12"));
|
||||||
|
bool tft_correct = !(tft_lit && ((get_switch_state() & 0b11) != 0b11));
|
||||||
|
|
||||||
|
if (rfid_correct && lcd_correct && speaker_correct && keypad_correct && tft_correct) {
|
||||||
|
solved_puzzles++;
|
||||||
|
} else {
|
||||||
|
strike("Final state was not correct! (step 3, puzzle 2)");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(10));
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 3: {
|
||||||
|
lcd_print(&lcd, "Nothing");
|
||||||
|
set_module_time(10000);
|
||||||
|
start_module_timer();
|
||||||
|
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 4: {
|
||||||
|
lcd_print(&lcd, "Blink");
|
||||||
|
set_module_time(10000);
|
||||||
|
start_module_timer();
|
||||||
|
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 5: {
|
||||||
|
lcd_print(&lcd, "Ummm");
|
||||||
|
set_module_time(10000);
|
||||||
|
start_module_timer();
|
||||||
|
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 6: {
|
||||||
|
lcd_print(&lcd, "Plank");
|
||||||
|
set_module_time(10000);
|
||||||
|
start_module_timer();
|
||||||
|
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 7: {
|
||||||
|
lcd_print(&lcd, "What");
|
||||||
|
set_module_time(10000);
|
||||||
|
start_module_timer();
|
||||||
|
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 8: {
|
||||||
|
lcd_print(&lcd, "Plink");
|
||||||
|
set_module_time(10000);
|
||||||
|
start_module_timer();
|
||||||
|
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
clean_bomb();
|
||||||
|
}
|
||||||
|
}
|
||||||
18
main/steps/step3.h
Normal file
18
main/steps/step3.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#ifndef STEP_3_H
|
||||||
|
#define STEP_3_H
|
||||||
|
|
||||||
|
#include "../drivers/bottom_half.h"
|
||||||
|
#include "../drivers/game_timer.h"
|
||||||
|
#include "../drivers/char_lcd.h"
|
||||||
|
#include "../drivers/leds.h"
|
||||||
|
#include "../drivers/wires.h"
|
||||||
|
#include "../helper.h"
|
||||||
|
#include <random>
|
||||||
|
#include <iostream>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
|
static const char *STEP3_TAG = "step3";
|
||||||
|
|
||||||
|
void step3(void);
|
||||||
|
|
||||||
|
#endif /* STEP_3_H */
|
||||||
@ -1,51 +0,0 @@
|
|||||||
#ifndef STEP_3_HPP
|
|
||||||
#define STEP_3_HPP
|
|
||||||
|
|
||||||
#include <random>
|
|
||||||
#include "../drivers/bottom_half.h"
|
|
||||||
#include <iostream>
|
|
||||||
#include "../drivers/game_timer.h"
|
|
||||||
#include <set>
|
|
||||||
|
|
||||||
static const char *STEP3_TAG = "step3";
|
|
||||||
|
|
||||||
std::random_device rd;
|
|
||||||
std::mt19937 gen(rd());
|
|
||||||
std::uniform_int_distribution<> puzzle_dist(0, 7);
|
|
||||||
std::uniform_int_distribution<> puzzle_zero_dist(0, 15);
|
|
||||||
std::uniform_int_distribution<> led_dist(0, 20);
|
|
||||||
|
|
||||||
void step3(void) {
|
|
||||||
set_module_time(3000);
|
|
||||||
|
|
||||||
// int puzzle = puzzle_dist(gen);
|
|
||||||
int puzzle = 0;
|
|
||||||
switch (puzzle) {
|
|
||||||
case 0:
|
|
||||||
lcd_print(&lcd, "Clear");
|
|
||||||
|
|
||||||
int green_indicators = puzzle_zero_dist(gen);
|
|
||||||
std::set<int> indicators;
|
|
||||||
|
|
||||||
while (indicators.size() < green_indicators) {
|
|
||||||
indicators.insert(led_dist(gen));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (std::set<int>::iterator it = indicators.begin(); it != indicators.end(); it++) {
|
|
||||||
ESP_ERROR_CHECK(led_strip_set_pixel(leds, *it, 0, 60, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
if (get_module_time() <= 0) {
|
|
||||||
ESP_LOGI(STEP3_TAG, "switch state: %i", get_switch_state(0));
|
|
||||||
// get_switch_state();
|
|
||||||
}
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(10));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* STEP_3_HPP */
|
|
||||||
@ -1,16 +1,12 @@
|
|||||||
#ifndef STEP_5_HPP
|
#include "step5.h"
|
||||||
#define STEP_5_HPP
|
|
||||||
|
|
||||||
#include "../drivers/bottom_half.h"
|
static const char *TAG = "step5";
|
||||||
#include <iostream>
|
|
||||||
#include <random>
|
|
||||||
|
|
||||||
static const char *STEP5_TAG = "step5";
|
static Led speaker_led = speaker;
|
||||||
|
// one: 0b00000110
|
||||||
Led speaker_led = speaker;
|
// seven: 0b00000111
|
||||||
|
static const uint8_t SSEG_NUMS[8] = {0b00111111, 0b01011011, 0b01001111, 0b01100110, 0b01101101, 0b01111101, 0b01111111, 0b01101111};
|
||||||
const uint8_t SSEG_NUMS[10] = {0b00111111, 0b00000110, 0b01011011, 0b01001111, 0b01100110, 0b01101101, 0b01111101, 0b00000111, 0b01111111, 0b01101111};
|
static const uint8_t SSEG_MAPS[5][4] = {
|
||||||
const uint8_t SSEG_MAPS[5][4] = {
|
|
||||||
{0b0101101, 0b1111010, 0b1000010, 0b1010100},
|
{0b0101101, 0b1111010, 0b1000010, 0b1010100},
|
||||||
{0b01000101, 0b00100100, 0b00110110, 0b01111011},
|
{0b01000101, 0b00100100, 0b00110110, 0b01111011},
|
||||||
{0b00101010, 0b00000010, 0b00010111, 0b00111100},
|
{0b00101010, 0b00000010, 0b00010111, 0b00111100},
|
||||||
@ -18,25 +14,36 @@ const uint8_t SSEG_MAPS[5][4] = {
|
|||||||
{0b01000111, 0b00011001, 0b01111000, 0b00111110}
|
{0b01000111, 0b00011001, 0b01111000, 0b00111110}
|
||||||
};
|
};
|
||||||
|
|
||||||
const int INDICATOR_RED[5] = {60, 0, 0, 35, 20};
|
static const int INDICATOR_RED[5] = {30, 0, 0, 25, 10};
|
||||||
const int INDICATOR_GREEN[5] = {0, 0, 60, 25, 20};
|
static const int INDICATOR_GREEN[5] = {0, 0, 30, 5, 10};
|
||||||
const int INDICATOR_BLUE[5] = {0, 60, 0, 0, 20};
|
static const int INDICATOR_BLUE[5] = {0, 30, 0, 0, 10};
|
||||||
|
|
||||||
// random number generators
|
// random number generators
|
||||||
std::random_device rd;
|
static std::random_device rd;
|
||||||
std::mt19937 gen(rd());
|
static std::mt19937 gen(rd());
|
||||||
std::uniform_int_distribution<> answer_dist(0, 9);
|
static std::uniform_int_distribution<> answer_dist(0, 7);
|
||||||
std::uniform_int_distribution<> map_dist(0, 4);
|
static std::uniform_int_distribution<> map_dist(0, 4);
|
||||||
std::uniform_int_distribution<> display_dist(0, 3);
|
static std::uniform_int_distribution<> display_dist(0, 3);
|
||||||
std::uniform_int_distribution<> random_segment_dist(0, 127);
|
static std::uniform_int_distribution<> random_segment_dist(0, 127);
|
||||||
|
|
||||||
int answer = 0;
|
static int answer = 0;
|
||||||
uint8_t answer_sseg = SSEG_NUMS[0];
|
static uint8_t answer_sseg = SSEG_NUMS[0];
|
||||||
char answer_char = '0';
|
static char answer_char = '0';
|
||||||
uint8_t display_map[4] = {0b00000000, 0b00000000, 0b00000000, 0b00000000};
|
static uint8_t display_map[4] = {0b00000000, 0b00000000, 0b00000000, 0b00000000};
|
||||||
int chosen_map = 0;
|
static int chosen_map = 0;
|
||||||
|
|
||||||
void new_puzzle(void) {
|
std::map<int, int> number_map = {
|
||||||
|
{0, 0},
|
||||||
|
{1, 2},
|
||||||
|
{2, 3},
|
||||||
|
{3, 4},
|
||||||
|
{4, 5},
|
||||||
|
{5, 6},
|
||||||
|
{6, 8},
|
||||||
|
{7, 9},
|
||||||
|
};
|
||||||
|
|
||||||
|
static void new_puzzle(void) {
|
||||||
// scramble lights
|
// scramble lights
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
led_strip_set_pixel(leds, speaker_led, INDICATOR_RED[map_dist(gen)], INDICATOR_GREEN[map_dist(gen)], INDICATOR_BLUE[map_dist(gen)]);
|
led_strip_set_pixel(leds, speaker_led, INDICATOR_RED[map_dist(gen)], INDICATOR_GREEN[map_dist(gen)], INDICATOR_BLUE[map_dist(gen)]);
|
||||||
@ -52,14 +59,16 @@ void new_puzzle(void) {
|
|||||||
|
|
||||||
answer = answer_dist(gen);
|
answer = answer_dist(gen);
|
||||||
answer_sseg = SSEG_NUMS[answer];
|
answer_sseg = SSEG_NUMS[answer];
|
||||||
|
// convert answer to number value to account for missing 1 and 7
|
||||||
|
answer = number_map[answer];
|
||||||
answer_char = '0' + answer;
|
answer_char = '0' + answer;
|
||||||
// ESP_LOGI(STEP5_TAG, "Answer: %i", answer);
|
// ESP_LOGI(TAG, "Answer: %i", answer);
|
||||||
|
|
||||||
chosen_map = map_dist(gen);
|
chosen_map = map_dist(gen);
|
||||||
for (int i = 0; i < 4; ++i) {
|
for (int i = 0; i < 4; ++i) {
|
||||||
display_map[i] = SSEG_MAPS[chosen_map][i];
|
display_map[i] = SSEG_MAPS[chosen_map][i];
|
||||||
}
|
}
|
||||||
// ESP_LOGI(STEP5_TAG, "Chosen Map: %i", chosen_map);
|
// ESP_LOGI(TAG, "Chosen Map: %i", chosen_map);
|
||||||
|
|
||||||
ESP_ERROR_CHECK(led_strip_set_pixel(leds, speaker_led, INDICATOR_RED[chosen_map], INDICATOR_GREEN[chosen_map], INDICATOR_BLUE[chosen_map]));
|
ESP_ERROR_CHECK(led_strip_set_pixel(leds, speaker_led, INDICATOR_RED[chosen_map], INDICATOR_GREEN[chosen_map], INDICATOR_BLUE[chosen_map]));
|
||||||
ESP_ERROR_CHECK(led_strip_refresh(leds));
|
ESP_ERROR_CHECK(led_strip_refresh(leds));
|
||||||
@ -70,7 +79,7 @@ void new_puzzle(void) {
|
|||||||
// choose display and flip bit
|
// choose display and flip bit
|
||||||
int display = display_dist(gen);
|
int display = display_dist(gen);
|
||||||
display_map[display] ^= (1 << i);
|
display_map[display] ^= (1 << i);
|
||||||
// ESP_LOGI(STEP5_TAG, "Flipping bit %i on display %i", i, display);
|
// ESP_LOGI(TAG, "Flipping bit %i on display %i", i, display);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -85,7 +94,7 @@ void step5(void) {
|
|||||||
set_module_sseg_raw(display_map);
|
set_module_sseg_raw(display_map);
|
||||||
if (get_pressed_keypad(&key)) {
|
if (get_pressed_keypad(&key)) {
|
||||||
char c = char_of_keypad_key(key);
|
char c = char_of_keypad_key(key);
|
||||||
// ESP_LOGI(STEP0_TAG, "Pressed: %c", c);
|
// ESP_LOGI(TAG, "Pressed: %c", c);
|
||||||
if (c == answer_char) {
|
if (c == answer_char) {
|
||||||
solved_times++;
|
solved_times++;
|
||||||
if (solved_times < 3) {
|
if (solved_times < 3) {
|
||||||
@ -102,5 +111,3 @@ void step5(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* STEP_5_HPP */
|
|
||||||
14
main/steps/step5.h
Normal file
14
main/steps/step5.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#ifndef STEP_5_H
|
||||||
|
#define STEP_5_H
|
||||||
|
|
||||||
|
#include "../drivers/bottom_half.h"
|
||||||
|
#include "../drivers/wires.h"
|
||||||
|
#include "../drivers/game_timer.h"
|
||||||
|
#include "../drivers/leds.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include <random>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
void step5(void);
|
||||||
|
|
||||||
|
#endif /* STEP_5_H */
|
||||||
16
sdkconfig
16
sdkconfig
@ -1,6 +1,6 @@
|
|||||||
#
|
#
|
||||||
# Automatically generated file. DO NOT EDIT.
|
# Automatically generated file. DO NOT EDIT.
|
||||||
# Espressif IoT Development Framework (ESP-IDF) 5.2.1 Project Configuration
|
# Espressif IoT Development Framework (ESP-IDF) 5.2.2 Project Configuration
|
||||||
#
|
#
|
||||||
CONFIG_SOC_MPU_MIN_REGION_SIZE=0x20000000
|
CONFIG_SOC_MPU_MIN_REGION_SIZE=0x20000000
|
||||||
CONFIG_SOC_MPU_REGIONS_MAX_NUM=8
|
CONFIG_SOC_MPU_REGIONS_MAX_NUM=8
|
||||||
@ -331,6 +331,7 @@ CONFIG_SOC_WIFI_WAPI_SUPPORT=y
|
|||||||
CONFIG_SOC_WIFI_CSI_SUPPORT=y
|
CONFIG_SOC_WIFI_CSI_SUPPORT=y
|
||||||
CONFIG_SOC_WIFI_MESH_SUPPORT=y
|
CONFIG_SOC_WIFI_MESH_SUPPORT=y
|
||||||
CONFIG_SOC_WIFI_SUPPORT_VARIABLE_BEACON_WINDOW=y
|
CONFIG_SOC_WIFI_SUPPORT_VARIABLE_BEACON_WINDOW=y
|
||||||
|
CONFIG_SOC_WIFI_PHY_NEEDS_USB_WORKAROUND=y
|
||||||
CONFIG_SOC_BLE_SUPPORTED=y
|
CONFIG_SOC_BLE_SUPPORTED=y
|
||||||
CONFIG_SOC_BLE_MESH_SUPPORTED=y
|
CONFIG_SOC_BLE_MESH_SUPPORTED=y
|
||||||
CONFIG_SOC_BLE_50_SUPPORTED=y
|
CONFIG_SOC_BLE_50_SUPPORTED=y
|
||||||
@ -435,6 +436,7 @@ CONFIG_ESP_ROM_HAS_RETARGETABLE_LOCKING=y
|
|||||||
CONFIG_ESP_ROM_USB_OTG_NUM=3
|
CONFIG_ESP_ROM_USB_OTG_NUM=3
|
||||||
CONFIG_ESP_ROM_USB_SERIAL_DEVICE_NUM=4
|
CONFIG_ESP_ROM_USB_SERIAL_DEVICE_NUM=4
|
||||||
CONFIG_ESP_ROM_HAS_ERASE_0_REGION_BUG=y
|
CONFIG_ESP_ROM_HAS_ERASE_0_REGION_BUG=y
|
||||||
|
CONFIG_ESP_ROM_HAS_ENCRYPTED_WRITES_USING_LEGACY_DRV=y
|
||||||
CONFIG_ESP_ROM_GET_CLK_FREQ=y
|
CONFIG_ESP_ROM_GET_CLK_FREQ=y
|
||||||
CONFIG_ESP_ROM_HAS_HAL_WDT=y
|
CONFIG_ESP_ROM_HAS_HAL_WDT=y
|
||||||
CONFIG_ESP_ROM_NEEDS_SWSETUP_WORKAROUND=y
|
CONFIG_ESP_ROM_NEEDS_SWSETUP_WORKAROUND=y
|
||||||
@ -557,6 +559,7 @@ CONFIG_APPTRACE_LOCK_ENABLE=y
|
|||||||
# Bluetooth
|
# Bluetooth
|
||||||
#
|
#
|
||||||
# CONFIG_BT_ENABLED is not set
|
# CONFIG_BT_ENABLED is not set
|
||||||
|
CONFIG_BT_ALARM_MAX_NUM=50
|
||||||
# end of Bluetooth
|
# end of Bluetooth
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -744,7 +747,10 @@ CONFIG_ESP_EVENT_POST_FROM_IRAM_ISR=y
|
|||||||
#
|
#
|
||||||
# GDB Stub
|
# GDB Stub
|
||||||
#
|
#
|
||||||
|
CONFIG_ESP_GDBSTUB_ENABLED=y
|
||||||
# CONFIG_ESP_SYSTEM_GDBSTUB_RUNTIME is not set
|
# CONFIG_ESP_SYSTEM_GDBSTUB_RUNTIME is not set
|
||||||
|
CONFIG_ESP_GDBSTUB_SUPPORT_TASKS=y
|
||||||
|
CONFIG_ESP_GDBSTUB_MAX_TASKS=32
|
||||||
# end of GDB Stub
|
# end of GDB Stub
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -909,6 +915,7 @@ CONFIG_ESP_PHY_RF_CAL_PARTIAL=y
|
|||||||
# CONFIG_ESP_PHY_RF_CAL_NONE is not set
|
# CONFIG_ESP_PHY_RF_CAL_NONE is not set
|
||||||
# CONFIG_ESP_PHY_RF_CAL_FULL is not set
|
# CONFIG_ESP_PHY_RF_CAL_FULL is not set
|
||||||
CONFIG_ESP_PHY_CALIBRATION_MODE=0
|
CONFIG_ESP_PHY_CALIBRATION_MODE=0
|
||||||
|
# CONFIG_ESP_PHY_PLL_TRACK_DEBUG is not set
|
||||||
# end of PHY
|
# end of PHY
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -1206,6 +1213,7 @@ CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE=0
|
|||||||
CONFIG_FREERTOS_TASK_NOTIFICATION_ARRAY_ENTRIES=1
|
CONFIG_FREERTOS_TASK_NOTIFICATION_ARRAY_ENTRIES=1
|
||||||
# CONFIG_FREERTOS_USE_TRACE_FACILITY is not set
|
# CONFIG_FREERTOS_USE_TRACE_FACILITY is not set
|
||||||
# CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS is not set
|
# CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS is not set
|
||||||
|
# CONFIG_FREERTOS_USE_APPLICATION_TASK_TAG is not set
|
||||||
# end of Kernel
|
# end of Kernel
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -1493,7 +1501,9 @@ CONFIG_MBEDTLS_CMAC_C=y
|
|||||||
CONFIG_MBEDTLS_HARDWARE_AES=y
|
CONFIG_MBEDTLS_HARDWARE_AES=y
|
||||||
CONFIG_MBEDTLS_AES_USE_INTERRUPT=y
|
CONFIG_MBEDTLS_AES_USE_INTERRUPT=y
|
||||||
CONFIG_MBEDTLS_AES_INTERRUPT_LEVEL=0
|
CONFIG_MBEDTLS_AES_INTERRUPT_LEVEL=0
|
||||||
|
# CONFIG_MBEDTLS_GCM_SUPPORT_NON_AES_CIPHER is not set
|
||||||
CONFIG_MBEDTLS_HARDWARE_MPI=y
|
CONFIG_MBEDTLS_HARDWARE_MPI=y
|
||||||
|
# CONFIG_MBEDTLS_LARGE_KEY_SOFTWARE_MPI is not set
|
||||||
CONFIG_MBEDTLS_MPI_USE_INTERRUPT=y
|
CONFIG_MBEDTLS_MPI_USE_INTERRUPT=y
|
||||||
CONFIG_MBEDTLS_MPI_INTERRUPT_LEVEL=0
|
CONFIG_MBEDTLS_MPI_INTERRUPT_LEVEL=0
|
||||||
CONFIG_MBEDTLS_HARDWARE_SHA=y
|
CONFIG_MBEDTLS_HARDWARE_SHA=y
|
||||||
@ -1580,7 +1590,7 @@ CONFIG_MBEDTLS_ECP_FIXED_POINT_OPTIM=y
|
|||||||
# CONFIG_MBEDTLS_CHACHA20_C is not set
|
# CONFIG_MBEDTLS_CHACHA20_C is not set
|
||||||
# CONFIG_MBEDTLS_HKDF_C is not set
|
# CONFIG_MBEDTLS_HKDF_C is not set
|
||||||
# CONFIG_MBEDTLS_THREADING_C is not set
|
# CONFIG_MBEDTLS_THREADING_C is not set
|
||||||
# CONFIG_MBEDTLS_LARGE_KEY_SOFTWARE_MPI is not set
|
CONFIG_MBEDTLS_ERROR_STRINGS=y
|
||||||
# end of mbedTLS
|
# end of mbedTLS
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -2225,6 +2235,8 @@ CONFIG_ESP32_APPTRACE_LOCK_ENABLE=y
|
|||||||
# CONFIG_EVENT_LOOP_PROFILING is not set
|
# CONFIG_EVENT_LOOP_PROFILING is not set
|
||||||
CONFIG_POST_EVENTS_FROM_ISR=y
|
CONFIG_POST_EVENTS_FROM_ISR=y
|
||||||
CONFIG_POST_EVENTS_FROM_IRAM_ISR=y
|
CONFIG_POST_EVENTS_FROM_IRAM_ISR=y
|
||||||
|
CONFIG_GDBSTUB_SUPPORT_TASKS=y
|
||||||
|
CONFIG_GDBSTUB_MAX_TASKS=32
|
||||||
# CONFIG_OTA_ALLOW_HTTP is not set
|
# CONFIG_OTA_ALLOW_HTTP is not set
|
||||||
# CONFIG_ESP_SYSTEM_PD_FLASH is not set
|
# CONFIG_ESP_SYSTEM_PD_FLASH is not set
|
||||||
CONFIG_ESP32S3_DEEP_SLEEP_WAKEUP_DELAY=2000
|
CONFIG_ESP32S3_DEEP_SLEEP_WAKEUP_DELAY=2000
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user