Compare commits
2 Commits
3806fd7ee8
...
42aa5fa315
| Author | SHA1 | Date | |
|---|---|---|---|
| 42aa5fa315 | |||
| ab7148be42 |
@ -1,5 +1,6 @@
|
||||
#include "all.h"
|
||||
|
||||
static const char *TAG = "driver_all";
|
||||
static void init_i2c();
|
||||
|
||||
void init_drivers() {
|
||||
@ -9,6 +10,8 @@ void init_drivers() {
|
||||
// init the bottom half so that we can get user input.
|
||||
init_bottom_half();
|
||||
init_sd();
|
||||
init_speaker();
|
||||
|
||||
}
|
||||
|
||||
/// @brief Initializes I2C_NUM_0.
|
||||
@ -21,6 +24,8 @@ void init_drivers() {
|
||||
/// - The PERH port
|
||||
/// - The Capacitive Touch Panel
|
||||
static void init_i2c() {
|
||||
ESP_LOGI(TAG, "Initializing i2c...");
|
||||
|
||||
i2c_config_t conf = {
|
||||
.mode = I2C_MODE_MASTER,
|
||||
.sda_io_num = GPIO_NUM_5,
|
||||
@ -37,4 +42,6 @@ static void init_i2c() {
|
||||
|
||||
ESP_ERROR_CHECK(i2c_param_config(I2C_NUM_0, &conf));
|
||||
ESP_ERROR_CHECK(i2c_driver_install(I2C_NUM_0, conf.mode, 0, 0, 0));
|
||||
|
||||
ESP_LOGI(TAG, "i2c initialized!");
|
||||
}
|
||||
@ -36,6 +36,8 @@ static void receive_touch();
|
||||
// }
|
||||
|
||||
void init_bottom_half() {
|
||||
ESP_LOGI(TAG, "Initializing bottom half...");
|
||||
|
||||
ESP_ERROR_CHECK(gpio_set_direction(BOTTOM_PIN_INTERUPT, GPIO_MODE_INPUT));
|
||||
ESP_ERROR_CHECK(gpio_set_pull_mode(BOTTOM_PIN_INTERUPT, GPIO_PULLUP_ONLY));
|
||||
|
||||
@ -52,6 +54,8 @@ void init_bottom_half() {
|
||||
receive_touch();
|
||||
|
||||
xTaskCreate(poll_bottom_task, "poll_bottom", 4096, NULL, 10, NULL);
|
||||
|
||||
ESP_LOGI(TAG, "Bottom half initialized!");
|
||||
}
|
||||
|
||||
static uint8_t receive_delta(void) {
|
||||
@ -173,10 +177,10 @@ static bool _take_key(KeypadKey* kp, uint16_t* keypad_bitfield) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool get_pressed_keypad(KeypadKey* kp) {
|
||||
bool get_keypad_pressed(KeypadKey* kp) {
|
||||
return _take_key(kp, &keypad_pressed);
|
||||
}
|
||||
bool get_released_keypad(KeypadKey* kp) {
|
||||
bool get_keypad_released(KeypadKey* kp) {
|
||||
return _take_key(kp, &keypad_released);
|
||||
}
|
||||
|
||||
@ -254,23 +258,23 @@ static bool _take_switch(SwitchKey* switch_, uint8_t* switch_bitfield) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool get_pressed_button(ButtonKey* button) {
|
||||
bool get_button_pressed(ButtonKey* button) {
|
||||
return _take_button(button, &button_pressed);
|
||||
}
|
||||
bool get_released_button(ButtonKey* button) {
|
||||
bool get_button_released(ButtonKey* button) {
|
||||
return _take_button(button, &button_released);
|
||||
}
|
||||
uint8_t get_button_state() {
|
||||
return button_state;
|
||||
}
|
||||
|
||||
bool get_flipped_up_switch(SwitchKey* switch_) {
|
||||
bool get_switch_flipped_up(SwitchKey* switch_) {
|
||||
return _take_switch(switch_, &switch_flipped_up);
|
||||
}
|
||||
bool get_flipped_down_switch(SwitchKey* switch_) {
|
||||
bool get_switch_flipped_down(SwitchKey* switch_) {
|
||||
return _take_switch(switch_, &switch_flipped_down);
|
||||
}
|
||||
bool get_flipped_switch(SwitchKey* switch_) {
|
||||
bool get_switch_flipped(SwitchKey* switch_) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int bit_selector = (1 << i);
|
||||
if (
|
||||
|
||||
@ -62,11 +62,11 @@ void clear_all_pressed_released();
|
||||
/// @brief Gets the key that was just pressed (if any)
|
||||
/// @param kp an OUT variable for the key that was pressed (if any)
|
||||
/// @return true if there was a key that was just pressed
|
||||
bool get_pressed_keypad(KeypadKey* kp);
|
||||
bool get_keypad_pressed(KeypadKey* kp);
|
||||
/// @brief Gets the key that was just released (if any)
|
||||
/// @param kp an OUT variable for the key that was released (if any)
|
||||
/// @return true if there was a key that was just released
|
||||
bool get_released_keypad(KeypadKey* kp);
|
||||
bool get_keypad_released(KeypadKey* kp);
|
||||
/// @brief Converts a `KeypadKey` to a char
|
||||
/// @param kp The value to convert
|
||||
/// @return The char representing the key
|
||||
@ -74,15 +74,14 @@ char char_of_keypad_key(KeypadKey kp);
|
||||
// TODO: add a get_keypad state?
|
||||
|
||||
|
||||
// TODO: rename these to get_button_pressed.
|
||||
/// @brief Gets the button that was just pressed (if any)
|
||||
/// @param button an OUT variable for the button that was pressed (if any)
|
||||
/// @return true if there was a button that was just pressed
|
||||
bool get_pressed_button(ButtonKey* button);
|
||||
bool get_button_pressed(ButtonKey* button);
|
||||
/// @brief Gets the button that was just released (if any)
|
||||
/// @param button an OUT variable for the button that was released (if any)
|
||||
/// @return true if there was a button that was just released
|
||||
bool get_released_button(ButtonKey* button);
|
||||
bool get_button_released(ButtonKey* button);
|
||||
/// @brief Gets the raw state of the buttons b1-b4 as bitflags.
|
||||
/// B1 is MSB and B4 is LSB.
|
||||
/// @return Bitflags for b1-b4.
|
||||
@ -91,15 +90,15 @@ uint8_t get_button_state();
|
||||
/// @brief Gets the switch that was just flipped up (if any)
|
||||
/// @param switch_ an OUT variable for the switch that was flipped up (if any)
|
||||
/// @return true if there was a switch that was just flipped up
|
||||
bool get_flipped_up_switch(SwitchKey* switch_);
|
||||
bool get_switch_flipped_up(SwitchKey* switch_);
|
||||
/// @brief Gets the switch that was just flipped down (if any)
|
||||
/// @param switch_ an OUT variable for the switch that was flipped down (if any)
|
||||
/// @return true if there was a switch that was just flipped down
|
||||
bool get_flipped_down_switch(SwitchKey* switch_);
|
||||
bool get_switch_flipped_down(SwitchKey* switch_);
|
||||
/// @brief Gets the switch that was just flipped (if any)
|
||||
/// @param switch_ an OUT variable for the switch that was flipped (if any)
|
||||
/// @return true if there was a switch that was just flipped
|
||||
bool get_flipped_switch(SwitchKey* switch_);
|
||||
bool get_switch_flipped(SwitchKey* switch_);
|
||||
/// @brief Gets the raw state of the switches s1-s4 as bitflags.
|
||||
/// S1 is MSB and S4 is LSB.
|
||||
/// @return Bitflags for s1-s4.
|
||||
|
||||
@ -8,7 +8,7 @@ i2c_lcd_pcf8574_handle_t lcd;
|
||||
static const char *TAG = "char_lcd";
|
||||
|
||||
void init_lcd() {
|
||||
ESP_LOGI(TAG, "Initializing LCD");
|
||||
ESP_LOGI(TAG, "Initializing LCD...");
|
||||
|
||||
lcd_init(&lcd, LCD_ADDR, CHAR_LCD_I2C_NUM);
|
||||
lcd_begin(&lcd, LCD_COLS, LCD_ROWS);
|
||||
|
||||
@ -8,7 +8,7 @@ static const char* mount_point = MOUNT_POINT;
|
||||
static const char* TAG = "sd";
|
||||
|
||||
bool init_sd() {
|
||||
ESP_LOGI(TAG, "Initializing SD card");
|
||||
ESP_LOGI(TAG, "Initializing SD card...");
|
||||
|
||||
esp_err_t ret;
|
||||
|
||||
@ -40,6 +40,8 @@ bool init_sd() {
|
||||
.flags = 0
|
||||
// .flags = SDMMC_SLOT_FLAG_INTERNAL_PULLUP
|
||||
};
|
||||
|
||||
try_mount:
|
||||
ESP_LOGI(TAG, "Mounting filesystem");
|
||||
ret = esp_vfs_fat_sdmmc_mount(mount_point, &host, &slot_config, &mount_config, &card);
|
||||
|
||||
@ -47,15 +49,28 @@ bool init_sd() {
|
||||
ESP_LOGI(TAG, "Filesystem mounted");
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Failed to mount sd card: %s.", esp_err_to_name(ret));
|
||||
|
||||
lcd_print(0, 0, "SD Mount Failed!");
|
||||
lcd_print(0, 1, esp_err_to_name(ret));
|
||||
lcd_print(0, 2, "Press Green to retry");
|
||||
|
||||
lcd_print(0, 0, "SD: ");
|
||||
lcd_print(4, 0, esp_err_to_name(ret));
|
||||
lcd_print(0, 1, "Press Green to retry");
|
||||
lcd_print(0, 2, "Press Yellow to skip");
|
||||
lcd_print(0, 3, "Press Red to format");
|
||||
|
||||
// TODO: impl buttons
|
||||
ButtonKey button;
|
||||
while (!( get_button_pressed(&button) && (button == ButtonKey::button_green || button == ButtonKey::button_red || button == ButtonKey::button_yellow) )) vTaskDelay(pdMS_TO_TICKS(10));
|
||||
|
||||
return false;
|
||||
lcd_clear();
|
||||
|
||||
if (button == ButtonKey::button_green) {
|
||||
goto try_mount;
|
||||
}
|
||||
if (button == ButtonKey::button_yellow) {
|
||||
return false;
|
||||
}
|
||||
if (button == ButtonKey::button_red) {
|
||||
mount_config.format_if_mount_failed = true;
|
||||
goto try_mount;
|
||||
}
|
||||
}
|
||||
|
||||
// Card has been initialized, print its properties
|
||||
|
||||
@ -2,135 +2,137 @@
|
||||
|
||||
i2s_chan_handle_t tx_chan;
|
||||
|
||||
static const char *TAG = "speaker_driver";
|
||||
static const char *TAG = "speaker";
|
||||
|
||||
esp_err_t play_raw_stop_queue(const char *fp, QueueHandle_t stop_handle) {
|
||||
FILE *fh = fopen(fp, "rb");
|
||||
if (fh == NULL)
|
||||
{
|
||||
ESP_LOGE(TAG, "Failed to open file");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
FILE *fh = fopen(fp, "rb");
|
||||
if (fh == NULL) {
|
||||
ESP_LOGE(TAG, "Failed to open file");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
// create a writer buffer
|
||||
uint8_t *read_buf = (uint8_t*) calloc(AUDIO_BUFFER, sizeof(uint8_t));
|
||||
uint16_t *write_buf = (uint16_t*) calloc(AUDIO_BUFFER, sizeof(uint16_t));
|
||||
size_t bytes_read = 0;
|
||||
size_t bytes_written = 0;
|
||||
// create a writer buffer
|
||||
uint8_t *read_buf = (uint8_t*) calloc(AUDIO_BUFFER, sizeof(uint8_t));
|
||||
uint16_t *write_buf = (uint16_t*) calloc(AUDIO_BUFFER, sizeof(uint16_t));
|
||||
size_t bytes_read = 0;
|
||||
size_t bytes_written = 0;
|
||||
|
||||
esp_err_t channel_enable_result = i2s_channel_enable(tx_chan);
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT(channel_enable_result);
|
||||
if (channel_enable_result != ESP_OK) {
|
||||
return channel_enable_result;
|
||||
}
|
||||
esp_err_t channel_enable_result = i2s_channel_enable(tx_chan);
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT(channel_enable_result);
|
||||
if (channel_enable_result != ESP_OK) {
|
||||
return channel_enable_result;
|
||||
}
|
||||
|
||||
bytes_read = fread(read_buf, sizeof(uint8_t), AUDIO_BUFFER, fh);
|
||||
for (int i = 0; i < bytes_read; i++) {
|
||||
write_buf[i] = read_buf[i] << 4;
|
||||
}
|
||||
bytes_read = fread(read_buf, sizeof(uint8_t), AUDIO_BUFFER, fh);
|
||||
for (int i = 0; i < bytes_read; i++) {
|
||||
write_buf[i] = read_buf[i] << 4;
|
||||
}
|
||||
|
||||
// i2s_channel_enable(tx_handle);
|
||||
// i2s_channel_enable(tx_handle);
|
||||
|
||||
while (bytes_read > 0) {
|
||||
// write the buffer to the i2s
|
||||
// ESP_LOGI(TAG, "Writing: ");
|
||||
// for (int i = 0; i < words_read; i++) {
|
||||
// int16_t val = buf[i];
|
||||
// printf("%s0x%04X ", (val < 0 ? "-" : "+"), (val < 0 ? -val : val));
|
||||
// }>
|
||||
i2s_channel_write(tx_chan, write_buf, bytes_read * sizeof(int16_t), &bytes_written, portMAX_DELAY);
|
||||
bytes_read = fread(read_buf, sizeof(uint8_t), AUDIO_BUFFER, fh);
|
||||
for (int i = 0; i < bytes_read; i++) {
|
||||
write_buf[i] = read_buf[i] << 4;
|
||||
}
|
||||
uint8_t recv = 0;
|
||||
if (xQueueReceive(stop_handle, &recv, 0)) {
|
||||
break;
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
}
|
||||
while (bytes_read > 0) {
|
||||
// write the buffer to the i2s
|
||||
// ESP_LOGI(TAG, "Writing: ");
|
||||
// for (int i = 0; i < words_read; i++) {
|
||||
// int16_t val = buf[i];
|
||||
// printf("%s0x%04X ", (val < 0 ? "-" : "+"), (val < 0 ? -val : val));
|
||||
// }>
|
||||
i2s_channel_write(tx_chan, write_buf, bytes_read * sizeof(int16_t), &bytes_written, portMAX_DELAY);
|
||||
bytes_read = fread(read_buf, sizeof(uint8_t), AUDIO_BUFFER, fh);
|
||||
for (int i = 0; i < bytes_read; i++) {
|
||||
write_buf[i] = read_buf[i] << 4;
|
||||
}
|
||||
uint8_t recv = 0;
|
||||
if (xQueueReceive(stop_handle, &recv, 0)) {
|
||||
break;
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
}
|
||||
|
||||
i2s_channel_disable(tx_chan);
|
||||
free(read_buf);
|
||||
free(write_buf);
|
||||
fclose(fh);
|
||||
i2s_channel_disable(tx_chan);
|
||||
free(read_buf);
|
||||
free(write_buf);
|
||||
fclose(fh);
|
||||
|
||||
return ESP_OK;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t play_raw(const char *fp) {
|
||||
FILE *fh = fopen(fp, "rb");
|
||||
if (fh == NULL)
|
||||
{
|
||||
ESP_LOGE(TAG, "Failed to open file");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
FILE *fh = fopen(fp, "rb");
|
||||
if (fh == NULL)
|
||||
ESP_LOGE(TAG, "Failed to open file");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
// create a writer buffer
|
||||
uint8_t *read_buf = (uint8_t*) calloc(AUDIO_BUFFER, sizeof(uint8_t));
|
||||
uint16_t *write_buf = (uint16_t*) calloc(AUDIO_BUFFER, sizeof(uint16_t));
|
||||
size_t bytes_read = 0;
|
||||
size_t bytes_written = 0;
|
||||
// create a writer buffer
|
||||
uint8_t *read_buf = (uint8_t*) calloc(AUDIO_BUFFER, sizeof(uint8_t));
|
||||
uint16_t *write_buf = (uint16_t*) calloc(AUDIO_BUFFER, sizeof(uint16_t));
|
||||
size_t bytes_read = 0;
|
||||
size_t bytes_written = 0;
|
||||
|
||||
esp_err_t channel_enable_result = i2s_channel_enable(tx_chan);
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT(channel_enable_result);
|
||||
if (channel_enable_result != ESP_OK) {
|
||||
return channel_enable_result;
|
||||
}
|
||||
esp_err_t channel_enable_result = i2s_channel_enable(tx_chan);
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT(channel_enable_result);
|
||||
if (channel_enable_result != ESP_OK) {
|
||||
return channel_enable_result;
|
||||
}
|
||||
|
||||
bytes_read = fread(read_buf, sizeof(uint8_t), AUDIO_BUFFER, fh);
|
||||
for (int i = 0; i < bytes_read; i++) {
|
||||
write_buf[i] = read_buf[i] << 4;
|
||||
}
|
||||
bytes_read = fread(read_buf, sizeof(uint8_t), AUDIO_BUFFER, fh);
|
||||
for (int i = 0; i < bytes_read; i++) {
|
||||
write_buf[i] = read_buf[i] << 4;
|
||||
}
|
||||
|
||||
// i2s_channel_enable(tx_handle);
|
||||
// i2s_channel_enable(tx_handle);
|
||||
|
||||
while (bytes_read > 0) {
|
||||
// write the buffer to the i2s
|
||||
// ESP_LOGI(TAG, "Writing: ");
|
||||
// for (int i = 0; i < words_read; i++) {
|
||||
// int16_t val = buf[i];
|
||||
// printf("%s0x%04X ", (val < 0 ? "-" : "+"), (val < 0 ? -val : val));
|
||||
// }>
|
||||
i2s_channel_write(tx_chan, write_buf, bytes_read * sizeof(int16_t), &bytes_written, portMAX_DELAY);
|
||||
bytes_read = fread(read_buf, sizeof(uint8_t), AUDIO_BUFFER, fh);
|
||||
for (int i = 0; i < bytes_read; i++) {
|
||||
write_buf[i] = read_buf[i] << 4;
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
}
|
||||
while (bytes_read > 0) {
|
||||
// write the buffer to the i2s
|
||||
// ESP_LOGI(TAG, "Writing: ");
|
||||
// for (int i = 0; i < words_read; i++) {
|
||||
// int16_t val = buf[i];
|
||||
// printf("%s0x%04X ", (val < 0 ? "-" : "+"), (val < 0 ? -val : val));
|
||||
// }>
|
||||
i2s_channel_write(tx_chan, write_buf, bytes_read * sizeof(int16_t), &bytes_written, portMAX_DELAY);
|
||||
bytes_read = fread(read_buf, sizeof(uint8_t), AUDIO_BUFFER, fh);
|
||||
for (int i = 0; i < bytes_read; i++) {
|
||||
write_buf[i] = read_buf[i] << 4;
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
}
|
||||
|
||||
i2s_channel_disable(tx_chan);
|
||||
free(read_buf);
|
||||
free(write_buf);
|
||||
fclose(fh);
|
||||
i2s_channel_disable(tx_chan);
|
||||
free(read_buf);
|
||||
free(write_buf);
|
||||
fclose(fh);
|
||||
|
||||
return ESP_OK;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void init_speaker(void) {
|
||||
i2s_chan_config_t tx_chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(I2S_NUM_AUTO, I2S_ROLE_MASTER);
|
||||
ESP_ERROR_CHECK(i2s_new_channel(&tx_chan_cfg, &tx_chan, NULL));
|
||||
ESP_LOGI(TAG, "Initializing speaker...");
|
||||
|
||||
i2s_std_config_t tx_std_cfg = {
|
||||
.clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(SAMPLE_RATE),
|
||||
.slot_cfg = I2S_STD_MSB_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_MONO),
|
||||
.gpio_cfg = {
|
||||
.mclk = I2S_GPIO_UNUSED,
|
||||
.bclk = SPEAKER_PIN_BCLK,
|
||||
.ws = SPEAKER_PIN_WS,
|
||||
.dout = SPEAKER_PIN_DOUT,
|
||||
.din = GPIO_NUM_NC,
|
||||
.invert_flags = {
|
||||
.mclk_inv = false,
|
||||
.bclk_inv = false,
|
||||
.ws_inv = false,
|
||||
},
|
||||
},
|
||||
};
|
||||
ESP_ERROR_CHECK(i2s_channel_init_std_mode(tx_chan, &tx_std_cfg));
|
||||
i2s_chan_config_t tx_chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(I2S_NUM_AUTO, I2S_ROLE_MASTER);
|
||||
ESP_ERROR_CHECK(i2s_new_channel(&tx_chan_cfg, &tx_chan, NULL));
|
||||
|
||||
i2s_std_config_t tx_std_cfg = {
|
||||
.clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(SAMPLE_RATE),
|
||||
.slot_cfg = I2S_STD_MSB_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_MONO),
|
||||
.gpio_cfg = {
|
||||
.mclk = I2S_GPIO_UNUSED,
|
||||
.bclk = SPEAKER_PIN_BCLK,
|
||||
.ws = SPEAKER_PIN_WS,
|
||||
.dout = SPEAKER_PIN_DOUT,
|
||||
.din = GPIO_NUM_NC,
|
||||
.invert_flags = {
|
||||
.mclk_inv = false,
|
||||
.bclk_inv = false,
|
||||
.ws_inv = false,
|
||||
},
|
||||
},
|
||||
};
|
||||
ESP_ERROR_CHECK(i2s_channel_init_std_mode(tx_chan, &tx_std_cfg));
|
||||
|
||||
ESP_LOGI(TAG, "Speaker initialized!");
|
||||
}
|
||||
|
||||
void play_example() {
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT(play_raw("/sdcard/o.pcm"));
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT(play_raw("/sdcard/o.pcm"));
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@ void do_star_codes(StarCodeHandler* star_codes, int star_codes_len) {
|
||||
char current[STRING_MAX_LEN+1] = {0};
|
||||
|
||||
while (1) {
|
||||
while (get_pressed_keypad(&key)) {
|
||||
while (get_keypad_pressed(&key)) {
|
||||
if (key == KeypadKey::star) {
|
||||
current[0] = '*';
|
||||
for (int i = 1; i < STRING_MAX_LEN; i++) {
|
||||
|
||||
@ -25,13 +25,10 @@ extern "C" void app_main(void) {
|
||||
|
||||
init_drivers();
|
||||
init_tft();
|
||||
init_speaker();
|
||||
init_sseg();
|
||||
init_game_module_timer();
|
||||
init_leds();
|
||||
init_wires();
|
||||
init_bottom_half();
|
||||
|
||||
init_power_board();
|
||||
|
||||
clean_bomb();
|
||||
|
||||
@ -42,7 +42,7 @@ void setup_wires(void) {
|
||||
ButtonKey button;
|
||||
|
||||
while (1) {
|
||||
while (get_pressed_keypad(&key)) {
|
||||
while (get_keypad_pressed(&key)) {
|
||||
if (key == KeypadKey::k1) {
|
||||
generate_new_wires(wires);
|
||||
save_wires_to_sd_card(wires);
|
||||
@ -53,7 +53,7 @@ void setup_wires(void) {
|
||||
}
|
||||
}
|
||||
|
||||
while (get_pressed_button(&button)) {
|
||||
while (get_button_pressed(&button)) {
|
||||
if (button == ButtonKey::b1) {
|
||||
// left
|
||||
editing_idx = editing_idx - 1;
|
||||
|
||||
@ -26,7 +26,7 @@ static void battery_stats(void) {
|
||||
xReturned = xTaskCreate(bat_monitor_task, "bat_monitor", 4096, NULL, 5, &xHandle);
|
||||
|
||||
KeypadKey k;
|
||||
while (!get_pressed_keypad(&k) || k != KeypadKey::pound) vTaskDelay(pdMS_TO_TICKS(10));
|
||||
while (!get_keypad_pressed(&k) || k != KeypadKey::pound) vTaskDelay(pdMS_TO_TICKS(10));
|
||||
|
||||
if (xReturned == pdPASS) {
|
||||
vTaskDelete(xHandle);
|
||||
@ -176,7 +176,7 @@ static void set_game_time(void) {
|
||||
KeypadKey key;
|
||||
ButtonKey button;
|
||||
while (1) {
|
||||
while (get_pressed_keypad(&key)) {
|
||||
while (get_keypad_pressed(&key)) {
|
||||
if (key == KeypadKey::star) {
|
||||
digits[0] = 0;
|
||||
digits[1] = 0;
|
||||
@ -244,7 +244,7 @@ static void set_game_time(void) {
|
||||
_update_display(digits, cursor_pos);
|
||||
}
|
||||
|
||||
while (get_pressed_button(&button)) {
|
||||
while (get_button_pressed(&button)) {
|
||||
if (button == ButtonKey::b1) {
|
||||
cursor_pos = MAX(0, cursor_pos-1);
|
||||
} else if (button == ButtonKey::b2) {
|
||||
@ -279,22 +279,22 @@ static void debug_switches(void) {
|
||||
ButtonKey button;
|
||||
SwitchKey switch_;
|
||||
while (1) {
|
||||
if (get_pressed_button(&button)) {
|
||||
if (get_button_pressed(&button)) {
|
||||
sprintf(buf, "Button Pressed: %d ", button);
|
||||
lcd_print(0, 3, buf);
|
||||
ESP_LOGI(TAG, "%s", buf);
|
||||
}
|
||||
if (get_released_button(&button)) {
|
||||
if (get_button_released(&button)) {
|
||||
sprintf(buf, "Button Released: %d", button);
|
||||
lcd_print(0, 3, buf);
|
||||
ESP_LOGI(TAG, "%s", buf);
|
||||
}
|
||||
if (get_flipped_down_switch(&switch_)) {
|
||||
if (get_switch_flipped_down(&switch_)) {
|
||||
sprintf(buf, "Switch Down: %d ", switch_);
|
||||
lcd_print(0, 3, buf);
|
||||
ESP_LOGI(TAG, "%s", buf);
|
||||
}
|
||||
if (get_flipped_up_switch(&switch_)) {
|
||||
if (get_switch_flipped_up(&switch_)) {
|
||||
sprintf(buf, "Switch Up: %d ", switch_);
|
||||
lcd_print(0, 3, buf);
|
||||
ESP_LOGI(TAG, "%s", buf);
|
||||
@ -338,7 +338,7 @@ static void debug_switches(void) {
|
||||
}
|
||||
|
||||
|
||||
if (get_pressed_keypad(&key) && key == KeypadKey::pound) {
|
||||
if (get_keypad_pressed(&key) && key == KeypadKey::pound) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -229,7 +229,7 @@ static bool play_part(uint32_t time) {
|
||||
SwitchKey switch_;
|
||||
|
||||
while (times < 15) {
|
||||
while (get_pressed_button(&button)) {
|
||||
while (get_button_pressed(&button)) {
|
||||
start_module_timer();
|
||||
if ((int)(button) == correct) {
|
||||
times++;
|
||||
@ -240,7 +240,7 @@ static bool play_part(uint32_t time) {
|
||||
strike("Incorrect action");
|
||||
}
|
||||
}
|
||||
while (get_flipped_switch(&switch_)) {
|
||||
while (get_switch_flipped(&switch_)) {
|
||||
start_module_timer();
|
||||
if (switch_leds[(int)(switch_)] + 4 == correct) {
|
||||
times++;
|
||||
@ -269,7 +269,7 @@ static bool play_part(uint32_t time) {
|
||||
}
|
||||
|
||||
void step1(void) {
|
||||
while (get_flipped_switch(nullptr));
|
||||
while (get_switch_flipped(nullptr));
|
||||
|
||||
init_step();
|
||||
while (!play_part(40*1000));
|
||||
|
||||
@ -95,7 +95,7 @@ void step2(void) {
|
||||
while(solved_times < NUM_SOLVES) {
|
||||
// for every bit in the answer-
|
||||
set_module_sseg_raw(display_map);
|
||||
if (get_pressed_keypad(&key)) {
|
||||
if (get_keypad_pressed(&key)) {
|
||||
lcd_clear();
|
||||
char c = char_of_keypad_key(key);
|
||||
// ESP_LOGI(TAG, "Pressed: %c", c);
|
||||
|
||||
@ -78,7 +78,7 @@ void step3(void) {
|
||||
while (times < TIMES_TO_COMPLETE) {
|
||||
tone = tone_dist(gen);
|
||||
// tone = 2;
|
||||
while (get_pressed_button(nullptr)) vTaskDelay(pdMS_TO_TICKS(10));
|
||||
while (get_button_pressed(nullptr)) vTaskDelay(pdMS_TO_TICKS(10));
|
||||
|
||||
play_raw(MOUNT_POINT "/que.pcm");
|
||||
play_raw(TONE_FILES[tone]);
|
||||
@ -193,7 +193,7 @@ static void debug_actual_values(uint8_t buttons, uint8_t switch_) {
|
||||
static void wait_for_timer(void) {
|
||||
KeypadKey key;
|
||||
while (get_module_time() > 0) {
|
||||
if (get_pressed_keypad(&key) && key == KeypadKey::kd) {
|
||||
if (get_keypad_pressed(&key) && key == KeypadKey::kd) {
|
||||
set_module_time(0);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -206,7 +206,7 @@ bool play_game(int time, int required_score) {
|
||||
show_board();
|
||||
|
||||
ButtonKey button;
|
||||
while (get_pressed_button(&button));
|
||||
while (get_button_pressed(&button));
|
||||
// SwitchKey switch_;
|
||||
|
||||
const TickType_t first_repeat_time = pdMS_TO_TICKS(700);
|
||||
@ -215,7 +215,7 @@ bool play_game(int time, int required_score) {
|
||||
TickType_t last_repeat = 0;
|
||||
|
||||
while(game) {
|
||||
while (get_pressed_button(&button)) {
|
||||
while (get_button_pressed(&button)) {
|
||||
switch (button) {
|
||||
case ButtonKey::b1:
|
||||
move_left();
|
||||
@ -240,7 +240,7 @@ bool play_game(int time, int required_score) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
while (get_released_button(&button)) {
|
||||
while (get_button_released(&button)) {
|
||||
if (button == ButtonKey::b3) {
|
||||
down_held = 0;
|
||||
}
|
||||
@ -269,7 +269,7 @@ bool play_game(int time, int required_score) {
|
||||
strike("Out of time");
|
||||
return false;
|
||||
}
|
||||
// if (get_flipped_switch(&switch_)) {
|
||||
// if (get_switch_flipped(&switch_)) {
|
||||
// printf("%d\n", piece);
|
||||
// for (int i = 0; i < sizeof(piece_nodes)/sizeof(piece_nodes[0]); i++) {
|
||||
// int* p = piece_nodes[i];
|
||||
@ -295,9 +295,9 @@ static void complete(void) {
|
||||
xSemaphoreGive(xGuiSemaphore);
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(500));
|
||||
while (get_pressed_button(nullptr));
|
||||
while (get_button_pressed(nullptr));
|
||||
while (1) {
|
||||
if (get_pressed_button(nullptr)) break;
|
||||
if (get_button_pressed(nullptr)) break;
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
}
|
||||
if (xSemaphoreTake(xGuiSemaphore, portMAX_DELAY) == pdTRUE) {
|
||||
@ -313,9 +313,9 @@ static void fail(void) {
|
||||
xSemaphoreGive(xGuiSemaphore);
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(500));
|
||||
while (get_pressed_button(nullptr));
|
||||
while (get_button_pressed(nullptr));
|
||||
while (1) {
|
||||
if (get_pressed_button(nullptr)) break;
|
||||
if (get_button_pressed(nullptr)) break;
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
}
|
||||
if (xSemaphoreTake(xGuiSemaphore, portMAX_DELAY) == pdTRUE) {
|
||||
|
||||
@ -248,7 +248,7 @@ void step5(void) {
|
||||
// wait for submit
|
||||
KeypadKey key;
|
||||
while (1) {
|
||||
if (get_module_time() <= 0 || (get_pressed_keypad(&key) && (char_of_keypad_key(key) == '#'))) {
|
||||
if (get_module_time() <= 0 || (get_keypad_pressed(&key) && (char_of_keypad_key(key) == '#'))) {
|
||||
solved_correctly = submit_0(green_indicators);
|
||||
break;
|
||||
}
|
||||
@ -278,7 +278,7 @@ void step5(void) {
|
||||
|
||||
KeypadKey key;
|
||||
while (1) {
|
||||
if (get_pressed_keypad(&key)) {
|
||||
if (get_keypad_pressed(&key)) {
|
||||
char keypad_char = char_of_keypad_key(key);
|
||||
if (keypad_char == '#') {
|
||||
solved_correctly = submit_1(indicators_num, pressed_keys, starting_switch_state);
|
||||
@ -329,7 +329,7 @@ void step5(void) {
|
||||
ButtonKey button;
|
||||
|
||||
while (1) {
|
||||
if (get_pressed_button(&button)) {
|
||||
if (get_button_pressed(&button)) {
|
||||
uint8_t button_state = get_button_state();
|
||||
|
||||
if ((button_state & 0b1) == 0b1) {
|
||||
@ -355,7 +355,7 @@ void step5(void) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (get_pressed_keypad(&key)) {
|
||||
if (get_keypad_pressed(&key)) {
|
||||
char keypad_char = char_of_keypad_key(key);
|
||||
if (keypad_char == '#') {
|
||||
solved_correctly = submit_2(lit_leds, green_button_pressed, blue_button_pressed, fingerprint_sensor_pressed, keypad_string);
|
||||
@ -398,7 +398,7 @@ void step5(void) {
|
||||
|
||||
ButtonKey button;
|
||||
while (1) {
|
||||
if (get_pressed_button(&button)) {
|
||||
if (get_button_pressed(&button)) {
|
||||
buttons_pressed++;
|
||||
uint8_t button_state = get_button_state();
|
||||
|
||||
@ -466,7 +466,7 @@ void step5(void) {
|
||||
uint8_t starting_switch_state = get_switch_state();
|
||||
|
||||
while (1) {
|
||||
if (get_pressed_button(&button)) {
|
||||
if (get_button_pressed(&button)) {
|
||||
uint8_t button_state = get_button_state();
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
@ -481,7 +481,7 @@ void step5(void) {
|
||||
}
|
||||
ESP_ERROR_CHECK(led_strip_refresh(leds));
|
||||
}
|
||||
if (get_module_time() <= 0 || (get_pressed_keypad(&key) && (char_of_keypad_key(key) == '#'))) {
|
||||
if (get_module_time() <= 0 || (get_keypad_pressed(&key) && (char_of_keypad_key(key) == '#'))) {
|
||||
solved_correctly = submit_4(button_colors, switch_colors, starting_switch_state);
|
||||
break;
|
||||
}
|
||||
@ -514,7 +514,7 @@ void step5(void) {
|
||||
KeypadKey key;
|
||||
|
||||
while (1) {
|
||||
if (get_pressed_button(&button)) {
|
||||
if (get_button_pressed(&button)) {
|
||||
uint8_t button_state = get_button_state();
|
||||
bool failed = false;
|
||||
|
||||
@ -532,7 +532,7 @@ void step5(void) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (get_module_time() <= 0 || (get_pressed_keypad(&key) && (char_of_keypad_key(key) == '#'))) {
|
||||
if (get_module_time() <= 0 || (get_keypad_pressed(&key) && (char_of_keypad_key(key) == '#'))) {
|
||||
ESP_LOGI(TAG, "Keypad Char: %c, time: %lu", char_of_keypad_key(key), get_module_time());
|
||||
solved_correctly = submit_5(indicator_numbers, buttons_pressed);
|
||||
break;
|
||||
@ -580,7 +580,7 @@ void step5(void) {
|
||||
|
||||
std::uniform_int_distribution<> led_turn_on_dist(0, 3);
|
||||
while (1) {
|
||||
if (get_pressed_button(&button)) {
|
||||
if (get_button_pressed(&button)) {
|
||||
uint8_t button_state = get_button_state();
|
||||
bool failed = false;
|
||||
|
||||
@ -623,7 +623,7 @@ void step5(void) {
|
||||
|
||||
lastCycleTime = xTaskGetTickCount();
|
||||
}
|
||||
if (get_module_time() <= 0 || (get_pressed_keypad(&key) && (char_of_keypad_key(key) == '#'))) {
|
||||
if (get_module_time() <= 0 || (get_keypad_pressed(&key) && (char_of_keypad_key(key) == '#'))) {
|
||||
solved_correctly = submit_6(buttons_cycling, button_turned_on, led_off);
|
||||
break;
|
||||
}
|
||||
@ -747,7 +747,7 @@ void step5(void) {
|
||||
KeypadKey key;
|
||||
|
||||
while (1) {
|
||||
if (get_pressed_keypad(&key)) {
|
||||
if (get_keypad_pressed(&key)) {
|
||||
if (key == KeypadKey::star) {
|
||||
// clear
|
||||
entered_string = "";
|
||||
@ -828,7 +828,7 @@ void step5(void) {
|
||||
|
||||
KeypadKey key;
|
||||
while (1) {
|
||||
if (get_pressed_keypad(&key)) {
|
||||
if (get_keypad_pressed(&key)) {
|
||||
bool failed = false;
|
||||
|
||||
if (key == KeypadKey::star) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user