Compare commits

...

2 Commits

7 changed files with 141 additions and 7 deletions

View File

@ -2,6 +2,7 @@
import logging import logging
import valconomy import valconomy
from valconomy import ValorantPlayerInfo, RiotPlayerInfo
def main(): def main():
logging.basicConfig( logging.basicConfig(
@ -11,8 +12,12 @@ def main():
try: try:
h.menu(None, False) h.menu(None, False)
h.none() h.none()
h.queue_start(RiotPlayerInfo.dummy(
valorant=ValorantPlayerInfo()))
h.menu(None, True) h.menu(None, True)
h.idle(None) h.idle(None)
h.queue_start(RiotPlayerInfo.dummy(
valorant=ValorantPlayerInfo(queue_type='unrated', is_party_owner=True)))
h.service() h.service()
finally: finally:

View File

@ -48,6 +48,10 @@ class RiotPlayerInfo:
valorant: ValorantPlayerInfo = None valorant: ValorantPlayerInfo = None
@classmethod
def dummy(cls, **kwargs):
return cls('00000000-0000-0000-0000-000000000000', 'Player', 'gamer', 'dnd', **kwargs)
def full_name(self) -> str: def full_name(self) -> str:
return f'{self.name}#{self.tag}' return f'{self.name}#{self.tag}'
@ -305,6 +309,10 @@ class HIDValconomyHandler(ValconomyHandler):
def idle(self, info: RiotPlayerInfo): def idle(self, info: RiotPlayerInfo):
self._enq(2) self._enq(2)
def queue_start(self, info: RiotPlayerInfo):
ms_not_comp = info.valorant.is_party_owner and info.valorant.queue_type == 'unrated'
self._enq(3, 1 if ms_not_comp else 0, fmt='B')
class GameState(Enum): class GameState(Enum):
NONE = 0 NONE = 0
MENU = 1 MENU = 1

View File

@ -14,6 +14,7 @@ static lv_style_t s_hero, s_subtitle;
static lv_obj_t *o_container = NULL; static lv_obj_t *o_container = NULL;
static lv_anim_timeline_t *at_active = NULL; static lv_anim_timeline_t *at_active = NULL;
static lv_anim_timeline_t *at_active_rep = NULL;
static lv_obj_t *o_active = NULL; static lv_obj_t *o_active = NULL;
static bool state_ready = true; static bool state_ready = true;
@ -38,8 +39,8 @@ static const void* imgfont_get_path(
static void b_cfg_cb(lv_event_t *e) { static void b_cfg_cb(lv_event_t *e) {
lv_obj_t *box = lv_msgbox_create(NULL); lv_obj_t *box = lv_msgbox_create(NULL);
lv_msgbox_add_title(box, "Hello"); lv_msgbox_add_title(box, "Settings");
lv_msgbox_add_text(box, "test message"); lv_msgbox_add_text(box, "Sorry, there aren't any right now.");
lv_msgbox_add_close_button(box); lv_msgbox_add_close_button(box);
} }
@ -51,6 +52,10 @@ static void setup_next_state() {
lv_anim_timeline_delete(at_active); lv_anim_timeline_delete(at_active);
at_active = NULL; at_active = NULL;
} }
if (at_active_rep) {
lv_anim_timeline_delete(at_active_rep);
at_active_rep = NULL;
}
if (o_active) { if (o_active) {
lv_obj_delete(o_active); lv_obj_delete(o_active);
o_active = NULL; o_active = NULL;
@ -63,6 +68,8 @@ static void setup_next_state() {
lv_obj_set_size(o_active, lv_pct(100), lv_pct(100)); lv_obj_set_size(o_active, lv_pct(100), lv_pct(100));
at_active = lv_anim_timeline_create(); at_active = lv_anim_timeline_create();
at_active_rep = lv_anim_timeline_create();
lv_anim_timeline_set_repeat_count(at_active_rep, LV_ANIM_REPEAT_INFINITE);
} }
bool val_ui_state_ready() { bool val_ui_state_ready() {
@ -70,6 +77,7 @@ bool val_ui_state_ready() {
} }
static void anim_state_ready_cb(lv_anim_t *anim) { static void anim_state_ready_cb(lv_anim_t *anim) {
lv_anim_timeline_start(at_active_rep);
state_ready = true; state_ready = true;
} }
static void anim_x_cb(void *var, int32_t v) { static void anim_x_cb(void *var, int32_t v) {
@ -81,10 +89,10 @@ static void anim_y_cb(void *var, int32_t v) {
static void anim_opa_cb(void *var, int32_t v) { static void anim_opa_cb(void *var, int32_t v) {
lv_obj_set_style_opa(var, v, 0); lv_obj_set_style_opa(var, v, 0);
} }
static void anim_val_time_text(lv_anim_t *anim) { static void anim_val_time_text(lv_anim_t *anim) {
lv_label_set_text_static(anim->var, M_VAL_TIME); lv_label_set_text_static(anim->var, M_VAL_TIME);
} }
void val_ui_none() { void val_ui_none() {
setup_next_state(); setup_next_state();
@ -194,6 +202,32 @@ void val_ui_menu(bool was_idle) {
lv_anim_timeline_add(at_active, 0, &a_title); lv_anim_timeline_add(at_active, 0, &a_title);
lv_anim_timeline_add(at_active, 0, &a_sub); lv_anim_timeline_add(at_active, 0, &a_sub);
// Repeating loop swing back and forth
lv_anim_t a_title_swing;
lv_anim_init(&a_title_swing);
lv_anim_set_early_apply(&a_title_swing, false);
lv_anim_set_var(&a_title_swing, l_main);
lv_anim_set_exec_cb(&a_title_swing, anim_x_cb);
// Left
lv_anim_set_path_cb(&a_title_swing, lv_anim_path_ease_out);
lv_anim_set_values(&a_title_swing, 0, -10);
lv_anim_set_duration(&a_title_swing, 500);
lv_anim_timeline_add(at_active_rep, 0, &a_title_swing);
// Left to right
lv_anim_set_path_cb(&a_title_swing, lv_anim_path_ease_in_out);
lv_anim_set_values(&a_title_swing, -10, 10);
lv_anim_set_duration(&a_title_swing, 1000);
lv_anim_timeline_add(at_active_rep, 500, &a_title_swing);
// Right to centre
lv_anim_set_path_cb(&a_title_swing, lv_anim_path_ease_in);
lv_anim_set_values(&a_title_swing, 10, 0);
lv_anim_set_duration(&a_title_swing, 500);
lv_anim_timeline_add(at_active_rep, 1500, &a_title_swing);
lv_anim_timeline_start(at_active); lv_anim_timeline_start(at_active);
} }
@ -234,12 +268,91 @@ void val_ui_idle() {
lv_anim_timeline_start(at_active); lv_anim_timeline_start(at_active);
} }
static void anim_text_color_mix_hero_sub(void *var, int32_t v) {
lv_obj_set_style_text_color(
var, lv_color_mix(color_text_hero, color_text_subtitle, v), 0);
}
void val_ui_queue_start(bool ms_not_comp) {
setup_next_state();
// Widgets
lv_obj_t *l_main = lv_label_create(o_active);
lv_obj_add_style(l_main, &s_hero, 0);
lv_obj_center(l_main);
lv_label_set_text_static(l_main, "SEARCHING...");
lv_obj_t *l_subtitle = lv_label_create(o_active);
lv_obj_add_style(l_subtitle, &s_subtitle, 0);
lv_obj_center(l_subtitle);
lv_label_set_text_static(l_subtitle, ms_not_comp ? "UHHH SHOULD THAT BE COMP?" : "I HOPE IT'S NOT SPLIT...");
lv_obj_t *spinner = lv_spinner_create(o_active);
lv_obj_set_size(spinner, 100, 100);
lv_obj_center(spinner);
lv_obj_set_style_arc_color(spinner, color_text_hero, LV_PART_INDICATOR);
lv_spinner_set_anim_params(spinner, 1500, 200);
lv_obj_update_layout(o_active);
const int32_t offset = -60;
lv_obj_set_y(l_main, offset);
lv_obj_set_y(
l_subtitle,
offset + (lv_obj_get_height(l_main) + lv_obj_get_height(l_subtitle)) / 2 + 5);
lv_obj_set_y(
spinner,
lv_obj_get_height(o_container) / 4);
// offset + (lv_obj_get_height(l_main)/2) + lv_obj_get_height(l_subtitle) + (lv_obj_get_height(spinner)/2) + 15);
// Animations
lv_anim_t a_title;
lv_anim_init(&a_title);
lv_anim_set_var(&a_title, l_main);
lv_anim_set_values(
&a_title,
-(lv_obj_get_width(o_container) - lv_obj_get_width(l_main)) / 2, 0);
lv_anim_set_exec_cb(&a_title, anim_x_cb);
lv_anim_set_path_cb(&a_title, lv_anim_path_ease_out);
lv_anim_set_duration(&a_title, 750);
lv_anim_t a_sub;
lv_anim_init(&a_sub);
lv_anim_set_var(&a_sub, l_subtitle);
lv_anim_set_values(
&a_sub,
(lv_obj_get_width(o_container) - lv_obj_get_width(l_subtitle)) / 2, 0);
lv_anim_set_exec_cb(&a_sub, anim_x_cb);
lv_anim_set_path_cb(&a_sub, lv_anim_path_ease_out);
lv_anim_set_completed_cb(&a_sub, anim_state_ready_cb);
lv_anim_set_duration(&a_sub, 750);
lv_anim_timeline_add(at_active, 0, &a_title);
lv_anim_timeline_add(at_active, 0, &a_sub);
if (ms_not_comp) {
lv_anim_t a_warn;
lv_anim_init(&a_warn);
lv_anim_set_early_apply(&a_warn, false);
lv_anim_set_var(&a_warn, l_subtitle);
lv_anim_set_path_cb(&a_warn, lv_anim_path_linear);
lv_anim_set_duration(&a_warn, 1000);
lv_anim_set_exec_cb(&a_warn, anim_text_color_mix_hero_sub);
lv_anim_set_values(&a_warn, 0, 255);
lv_anim_timeline_add(at_active_rep, 0, &a_warn);
lv_anim_set_values(&a_warn, 255, 0);
lv_anim_timeline_add(at_active_rep, 1000, &a_warn);
}
lv_anim_timeline_start(at_active);
}
void val_lvgl_ui(lv_display_t *disp) { void val_lvgl_ui(lv_display_t *disp) {
color_primary = lv_color_hex(0xff4655); color_primary = lv_color_hex(0xff4655);
color_secondary = lv_color_hex(0xf7518f); color_secondary = lv_color_hex(0xf7518f);
color_text_hero = lv_palette_lighten(LV_PALETTE_GREY, 2); color_text_hero = lv_palette_lighten(LV_PALETTE_GREY, 2);
color_text_subtitle = lv_palette_darken(LV_PALETTE_GREY, 2); color_text_subtitle = lv_palette_darken(LV_PALETTE_GREY, 1);
// init default theme // init default theme
lv_theme_default_init( lv_theme_default_init(

View File

@ -15,5 +15,6 @@ bool val_ui_state_ready();
void val_ui_none(); void val_ui_none();
void val_ui_menu(bool was_idle); void val_ui_menu(bool was_idle);
void val_ui_idle(); void val_ui_idle();
void val_ui_queue_start(bool ms_not_comp);
void val_lvgl_ui(lv_display_t *disp); void val_lvgl_ui(lv_display_t *disp);

View File

@ -101,7 +101,7 @@ void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_
ESP_LOGE(TAG, "Failed to grab LVGL lock"); ESP_LOGE(TAG, "Failed to grab LVGL lock");
return; return;
} }
if (buf[0] > ST_IDLE) { if (buf[0] > ST_QUEUE_START) {
ESP_LOGW(TAG, "Unknown state %hhu", buf[0]); ESP_LOGW(TAG, "Unknown state %hhu", buf[0]);
goto ret; goto ret;
} }
@ -123,6 +123,13 @@ void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_
case ST_IDLE: case ST_IDLE:
val_ui_idle(); val_ui_idle();
break; break;
case ST_QUEUE_START:
if (bufsize < 2) {
ESP_LOGE(TAG, "Invalid ST_QUEUE_START command");
goto ret;
}
val_ui_queue_start((bool)buf[1]);
break;
} }
ret: ret:

View File

@ -8,7 +8,8 @@
typedef enum val_state { typedef enum val_state {
ST_NONE = 0, ST_NONE = 0,
ST_MENU, ST_MENU,
ST_IDLE ST_IDLE,
ST_QUEUE_START,
} val_state_t; } val_state_t;
void val_usb_init(void); void val_usb_init(void);

View File

@ -21,7 +21,6 @@ CONFIG_ESP_WIFI_DPP_SUPPORT=y
CONFIG_FREERTOS_HZ=1000 CONFIG_FREERTOS_HZ=1000
CONFIG_TINYUSB_DEBUG_LEVEL=0 CONFIG_TINYUSB_DEBUG_LEVEL=0
CONFIG_TINYUSB_HID_COUNT=1 CONFIG_TINYUSB_HID_COUNT=1
CONFIG_LV_DEF_REFR_PERIOD=24
CONFIG_LV_USE_LOG=y CONFIG_LV_USE_LOG=y
CONFIG_LV_LOG_PRINTF=y CONFIG_LV_LOG_PRINTF=y
CONFIG_LV_FONT_MONTSERRAT_24=y CONFIG_LV_FONT_MONTSERRAT_24=y