|
5 | 5 | */ |
6 | 6 |
|
7 | 7 | #include "NintendoSwitch_TurboMacro.h" |
8 | | - |
| 8 | +#include "CommonTools/Async/InferenceRoutines.h" |
| 9 | +#include "PokemonLA/Inference/Sounds/PokemonLA_ShinySoundDetector.h" |
| 10 | +#include "PokemonLZA/Options/PokemonLZA_ShinyDetectedAction.h" |
| 11 | +#include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h" |
9 | 12 | //#include <iostream> |
10 | 13 | //using std::cout; |
11 | 14 | //using std::endl; |
@@ -40,22 +43,70 @@ TurboMacro::TurboMacro() |
40 | 43 | ControllerClass::NintendoSwitch_RightJoycon, |
41 | 44 | } |
42 | 45 | ) |
| 46 | + , RUN_UNTIL_CALLBACK( |
| 47 | + "Trigger to stop program:", |
| 48 | + { |
| 49 | + {RunUntilCallback::NONE, "none", "None"}, |
| 50 | + {RunUntilCallback::LZA_SHINY_SOUND, "lza-shiny-sound", "LZA: Shiny Sound Detected"}, |
| 51 | + }, |
| 52 | + LockMode::LOCK_WHILE_RUNNING, |
| 53 | + RunUntilCallback::NONE |
| 54 | + ) |
43 | 55 | { |
44 | 56 | PA_ADD_OPTION(LOOP); |
| 57 | + PA_ADD_OPTION(RUN_UNTIL_CALLBACK); |
45 | 58 | PA_ADD_OPTION(TABLE); |
46 | 59 | } |
47 | 60 |
|
48 | 61 |
|
49 | 62 | void TurboMacro::program(SingleSwitchProgramEnvironment& env, CancellableScope& scope){ |
| 63 | + switch (RUN_UNTIL_CALLBACK){ |
| 64 | + case RunUntilCallback::NONE: |
| 65 | + run_table(env, scope); |
| 66 | + break; |
| 67 | + case RunUntilCallback::LZA_SHINY_SOUND: |
| 68 | + run_table_stop_when_lza_shiny_sound(env, scope); |
| 69 | + break; |
| 70 | + default: |
| 71 | + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "TurboMacro::program(): Unknown RunUntilCallback"); |
| 72 | + |
| 73 | + } |
| 74 | +} |
50 | 75 |
|
51 | | - // Connect the controller. |
52 | | - //pbf_press_button(context, BUTTON_LCLICK, 40ms, 40ms); |
53 | 76 |
|
| 77 | +void TurboMacro::run_table(SingleSwitchProgramEnvironment& env, CancellableScope& scope){ |
54 | 78 | for (uint32_t c = 0; c < LOOP; c++){ |
55 | 79 | TABLE.run(scope, env.console.controller()); |
56 | 80 | } |
57 | 81 | } |
58 | 82 |
|
| 83 | +void TurboMacro::run_table_stop_when_lza_shiny_sound(SingleSwitchProgramEnvironment& env, CancellableScope& scope){ |
| 84 | + PokemonLZA::ShinySoundDetectedActionOption shiny_detected_option("Shiny Detected", "", "1000 ms", PokemonLZA::ShinySoundDetectedAction::NOTIFY_ON_FIRST_ONLY); |
| 85 | + PokemonLZA::ShinySoundHandler shiny_sound_handler(shiny_detected_option); |
| 86 | + PokemonLA::ShinySoundDetector shiny_detector(env.console, [&](float error_coefficient) -> bool { |
| 87 | + // Warning: This callback will be run from a different thread than this function. |
| 88 | + // env.console.overlay().add_log("Shiny Sound Detected!", COLOR_YELLOW); |
| 89 | + return shiny_sound_handler.on_shiny_sound( |
| 90 | + env, env.console, |
| 91 | + 0, |
| 92 | + error_coefficient |
| 93 | + ); |
| 94 | + }); |
| 95 | + |
| 96 | + ProControllerContext context(scope, env.console.controller<ProController>()); |
| 97 | + |
| 98 | + int ret = run_until( |
| 99 | + env.console, scope, |
| 100 | + [&](CancellableScope& scope){ |
| 101 | + run_table(env, scope); |
| 102 | + }, |
| 103 | + {shiny_detector} |
| 104 | + ); |
| 105 | + |
| 106 | + if (ret == 0){ |
| 107 | + go_home(env.console, context); |
| 108 | + } |
| 109 | +} |
59 | 110 |
|
60 | 111 | } |
61 | 112 | } |
0 commit comments