From 0916a874fdbdd6a8af8feafc6a3e25ff7e026a3b Mon Sep 17 00:00:00 2001 From: Nathan van Ofwegen Date: Sun, 5 Sep 2021 21:59:58 +0200 Subject: [PATCH] mvp --- .editorconfig | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ animation.h | 24 +++++++++++++++++++++ dnddice.ino | 57 ++++++++++++++++++++++++++++--------------------- 3 files changed, 116 insertions(+), 24 deletions(-) create mode 100644 .editorconfig create mode 100644 animation.h diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..1639887 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,59 @@ +[*] +cpp_indent_braces=false +cpp_indent_multi_line_relative_to=innermost_parenthesis +cpp_indent_within_parentheses=indent +cpp_indent_preserve_within_parentheses=false +cpp_indent_case_labels=false +cpp_indent_case_contents=true +cpp_indent_case_contents_when_block=false +cpp_indent_lambda_braces_when_parameter=true +cpp_indent_goto_labels=one_left +cpp_indent_preprocessor=leftmost_column +cpp_indent_access_specifiers=false +cpp_indent_namespace_contents=true +cpp_indent_preserve_comments=false +cpp_new_line_before_open_brace_namespace=ignore +cpp_new_line_before_open_brace_type=ignore +cpp_new_line_before_open_brace_function=ignore +cpp_new_line_before_open_brace_block=ignore +cpp_new_line_before_open_brace_lambda=ignore +cpp_new_line_scope_braces_on_separate_lines=false +cpp_new_line_close_brace_same_line_empty_type=false +cpp_new_line_close_brace_same_line_empty_function=false +cpp_new_line_before_catch=true +cpp_new_line_before_else=true +cpp_new_line_before_while_in_do_while=false +cpp_space_before_function_open_parenthesis=remove +cpp_space_within_parameter_list_parentheses=false +cpp_space_between_empty_parameter_list_parentheses=false +cpp_space_after_keywords_in_control_flow_statements=true +cpp_space_within_control_flow_statement_parentheses=false +cpp_space_before_lambda_open_parenthesis=false +cpp_space_within_cast_parentheses=false +cpp_space_after_cast_close_parenthesis=false +cpp_space_within_expression_parentheses=false +cpp_space_before_block_open_brace=true +cpp_space_between_empty_braces=false +cpp_space_before_initializer_list_open_brace=false +cpp_space_within_initializer_list_braces=true +cpp_space_preserve_in_initializer_list=true +cpp_space_before_open_square_bracket=false +cpp_space_within_square_brackets=false +cpp_space_before_empty_square_brackets=false +cpp_space_between_empty_square_brackets=false +cpp_space_group_square_brackets=true +cpp_space_within_lambda_brackets=false +cpp_space_between_empty_lambda_brackets=false +cpp_space_before_comma=false +cpp_space_after_comma=true +cpp_space_remove_around_member_operators=true +cpp_space_before_inheritance_colon=true +cpp_space_before_constructor_colon=true +cpp_space_remove_before_semicolon=true +cpp_space_after_semicolon=false +cpp_space_remove_around_unary_operator=true +cpp_space_around_binary_operator=insert +cpp_space_around_assignment_operator=insert +cpp_space_pointer_reference_alignment=left +cpp_space_around_ternary_operator=insert +cpp_wrap_preserve_blocks=one_liners diff --git a/animation.h b/animation.h new file mode 100644 index 0000000..f2e2d60 --- /dev/null +++ b/animation.h @@ -0,0 +1,24 @@ +static const unsigned char PROGMEM imd2[] = { + 0x00, 0x00, 0x00, 0x00, 0x00 + , 0x00, 0x00, 0x00, 0x00, 0x00 + , 0x00, 0x00, 0x00, 0x00, 0x00 + , 0x00, 0x0f, 0xff, 0xf0, 0x00 + , 0x00, 0xe0, 0x00, 0x07, 0x00 + , 0x07, 0x00, 0x00, 0x00, 0xe0 + , 0x0c, 0x00, 0x00, 0x00, 0x30 + , 0x30, 0x00, 0x00, 0x00, 0x0c + , 0x20, 0x00, 0x00, 0x00, 0x04 + , 0x20, 0x00, 0x00, 0x00, 0x04 + , 0x20, 0x00, 0x00, 0x00, 0x04 + , 0x30, 0x00, 0x00, 0x00, 0x0c + , 0x38, 0x00, 0x00, 0x00, 0x1c + , 0x36, 0x00, 0x00, 0x00, 0x6c + , 0x31, 0xc0, 0x00, 0x03, 0x8c + , 0x1d, 0xff, 0xc3, 0xfd, 0x38 + , 0x07, 0x86, 0x18, 0x61, 0xe0 + , 0x01, 0xf6, 0x18, 0x6f, 0x80 + , 0x00, 0x1f, 0xff, 0xf8, 0x00 + , 0x00, 0x00, 0x00, 0x00, 0x00 + , 0x00, 0x00, 0x00, 0x00, 0x00 + , 0x00, 0x00, 0x00, 0x00, 0x00 +}; \ No newline at end of file diff --git a/dnddice.ino b/dnddice.ino index 9b0f488..b98da9b 100644 --- a/dnddice.ino +++ b/dnddice.ino @@ -1,6 +1,7 @@ #include #include "esp_adc_cal.h" #include "Button2.h" +#include "animation.h" #include "dndlogo.h" #define ADC_EN 14 //ADC_EN is the ADC detection enable port @@ -13,8 +14,9 @@ Button2 btn1(BUTTON_1); Button2 btn2(BUTTON_2); // MENU -byte menuItems[] = {20, 12, 10, 8, 6, 4, 3, 2}; +byte menuItems[] = { 20, 12, 10, 8, 6, 4, 3, 2 }; byte menuPosition = 0; +int menuHeight = 20; int num_items = sizeof(menuItems) / sizeof(byte); String temp; @@ -51,8 +53,7 @@ void showVoltage() uint16_t v = analogRead(ADC_PIN); float battery_voltage = ((float)v / 4095.0) * 2.0 * 3.3 * (vref / 1000.0); String voltage = "Voltage :" + String(battery_voltage) + "V"; - Serial.println(voltage); - //tft.fillScreen(TFT_BLACK); + tft.fillScreen(TFT_BLACK); tft.setTextDatum(BL_DATUM); tft.drawString(voltage, tft.width() / 1.5, tft.height()); } @@ -60,11 +61,19 @@ void showVoltage() void throwDice() { + tft.fillScreen(TFT_BLACK); + drawMenu(); + randomSeed(analogRead(1)); int dice = menuItems[menuPosition]; int number = random(dice) + 1; - tft.setTextPadding(tft.width()); - tft.setTextDatum(BL_DATUM); - tft.drawString(String(number), tft.width() / 1.5, tft.height()); + tft.setTextColor(TFT_WHITE, TFT_BLACK); + tft.setTextSize(6); + tft.setTextDatum(MC_DATUM); + tft.setTextPadding(tft.height()); + tft.drawString(String(number), tft.width() / 2, (tft.height() / 2) + (menuHeight / 2)); + espDelay(1000); + tft.fillScreen(TFT_BLACK); + drawMenu(); } void drawMenu() @@ -72,13 +81,13 @@ void drawMenu() tft.fillScreen(TFT_BLACK); tft.setTextColor(TFT_WHITE, TFT_BLACK); tft.setTextSize(2); - tft.drawRect(0, 20, TFT_HEIGHT, 1, TFT_WHITE); + tft.drawRect(0, menuHeight, TFT_HEIGHT, 1, TFT_WHITE); int boxWidth = round(tft.width() / num_items); for (int i = 1; i <= num_items; i++) { - tft.drawFastVLine(i * boxWidth, 0, 20, TFT_WHITE); + tft.drawFastVLine(i * boxWidth, 0, menuHeight, TFT_WHITE); tft.setTextColor(TFT_WHITE, TFT_BLACK); tft.setTextSize(2); tft.setTextDatum(MC_DATUM); @@ -95,8 +104,8 @@ void drawSelectedMenu() { int boxWidth = round(tft.width() / num_items); - tft.drawRect(menuPosition * boxWidth, 0, boxWidth, 20, TFT_WHITE); - tft.fillRect(menuPosition * boxWidth, 0, boxWidth, 20, TFT_WHITE); + tft.drawRect(menuPosition * boxWidth, 0, boxWidth, menuHeight, TFT_WHITE); + tft.fillRect(menuPosition * boxWidth, 0, boxWidth, menuHeight, TFT_WHITE); tft.setTextColor(TFT_BLACK, TFT_WHITE); tft.setTextDatum(MC_DATUM); @@ -140,21 +149,21 @@ void button_init() // clearScreen(); // drawMenu(); // }); - btn1.setPressedHandler([](Button2 &b) - { - throwDice(); - espDelay(1000); - }); + btn1.setPressedHandler([](Button2& b) + { + throwDice(); + espDelay(1000); + }); - btn2.setPressedHandler([](Button2 &b) - { - menuPosition++; - menuPosition = menuPosition++ % num_items; - drawMenu(); - drawSelectedDice(); - espDelay(1000); - clearScreen(); - }); + btn2.setPressedHandler([](Button2& b) + { + menuPosition++; + menuPosition = menuPosition++ % num_items; + drawMenu(); + // drawSelectedDice(); + // espDelay(1000); + clearScreen(); + }); } void button_loop()