Skip to content

Commit 15a7937

Browse files
authored
Merge pull request #600 from jw098/home-to-date
Home to date time
2 parents a38c640 + f296498 commit 15a7937

File tree

6 files changed

+388
-102
lines changed

6 files changed

+388
-102
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,8 @@ file(GLOB MAIN_SOURCES
957957
Source/NintendoSwitch/Inference/NintendoSwitch_DateReader.h
958958
Source/NintendoSwitch/Inference/NintendoSwitch_DetectHome.cpp
959959
Source/NintendoSwitch/Inference/NintendoSwitch_DetectHome.h
960+
Source/NintendoSwitch/Inference/NintendoSwitch_SelectedSettingDetector.cpp
961+
Source/NintendoSwitch/Inference/NintendoSwitch_SelectedSettingDetector.h
960962
Source/NintendoSwitch/NintendoSwitch_ConsoleHandle.cpp
961963
Source/NintendoSwitch/NintendoSwitch_ConsoleHandle.h
962964
Source/NintendoSwitch/NintendoSwitch_MultiSwitchProgram.cpp

SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
#include "PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_PokemonSwapMenu.h"
123123
#include "CommonTools/Images/ImageFilter.h"
124124
#include "NintendoSwitch/Options/NintendoSwitch_ModelType.h"
125-
125+
#include "NintendoSwitch/Programs/NintendoSwitch_Navigation.h"
126126

127127
#include <QPixmap>
128128
#include <QVideoFrame>
@@ -316,11 +316,18 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
316316
ProControllerContext context(scope, console.pro_controller());
317317
VideoOverlaySet overlays(overlay);
318318

319+
320+
#if 1
321+
home_to_date_time(console, context, false);
322+
#endif
323+
324+
#if 0
319325
// std::terminate();
320326
ImageRGB32 image("20250503-121259857603.png");
321327

322328
image = filter_rgb32_brightness(image, COLOR_RED, false, 0x00ffff01, 0, 200);
323329
image.save("temp.png");
330+
#endif
324331

325332

326333
#if 0
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/* Detect Home
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
8+
#include "CommonTools/Images/SolidColorTest.h"
9+
#include "NintendoSwitch_SelectedSettingDetector.h"
10+
11+
#include <iostream>
12+
using std::cout;
13+
using std::endl;
14+
15+
namespace PokemonAutomation{
16+
namespace NintendoSwitch{
17+
18+
SelectedSettingWatcher::~SelectedSettingWatcher() = default;
19+
20+
SelectedSettingWatcher::SelectedSettingWatcher(ImageFloatBox selected_box, ImageFloatBox not_selected_box1, ImageFloatBox not_selected_box2)
21+
: VisualInferenceCallback("SelectedSettingWatcher")
22+
, m_selected_box(selected_box)
23+
, m_not_selected_box1(not_selected_box1)
24+
, m_not_selected_box2(not_selected_box2)
25+
{}
26+
27+
void SelectedSettingWatcher::make_overlays(VideoOverlaySet& items) const{
28+
items.add(COLOR_RED, m_selected_box);
29+
items.add(COLOR_BLUE, m_not_selected_box1);
30+
items.add(COLOR_BLUE, m_not_selected_box2);
31+
}
32+
33+
bool is_white_theme(const ImageViewRGB32& screen){
34+
ImageFloatBox window_top(0.60, 0.02, 0.35, 0.05);
35+
ImageStats stats_window_top = image_stats(extract_box_reference(screen, window_top));
36+
bool white_theme = stats_window_top.average.sum() > 600;
37+
return white_theme;
38+
}
39+
40+
bool SelectedSettingWatcher::process_frame(const ImageViewRGB32& screen, WallClock timestamp){
41+
42+
ImageStats stats_unselected_box1 = image_stats(extract_box_reference(screen, m_not_selected_box1));
43+
double unselected1_average_sum = stats_unselected_box1.average.sum();
44+
cout << "unselected_average_sum1: " << std::to_string(unselected1_average_sum) << endl;
45+
46+
ImageStats stats_unselected_box2 = image_stats(extract_box_reference(screen, m_not_selected_box2));
47+
double unselected2_average_sum = stats_unselected_box2.average.sum();
48+
cout << "unselected_average_sum2: " << std::to_string(unselected2_average_sum) << endl;
49+
50+
double average_sum_unselected_diff = std::abs(unselected1_average_sum - unselected2_average_sum);
51+
52+
ImageStats stats_selected_box = image_stats(extract_box_reference(screen, m_selected_box));
53+
double selected_average_sum = stats_selected_box.average.sum();
54+
cout << "selected_average_sum: " << std::to_string(selected_average_sum) << endl;
55+
56+
bool is_selected = false;
57+
if (is_white_theme(screen)){ // light mode
58+
// unselected should be brighter than selected
59+
is_selected = selected_average_sum < std::min(unselected1_average_sum, unselected2_average_sum) - average_sum_unselected_diff - 20 ;
60+
}else{ // dark mode
61+
// selected should be brighter than unselected
62+
is_selected = selected_average_sum > std::max(unselected1_average_sum, unselected2_average_sum) + average_sum_unselected_diff + 20;
63+
}
64+
65+
return is_selected;
66+
}
67+
68+
69+
70+
71+
72+
73+
}
74+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* Selected Setting Detector
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_NintendoSwitch_SelectedSettingDetector_H
8+
#define PokemonAutomation_NintendoSwitch_SelectedSettingDetector_H
9+
10+
#include "Common/Cpp/Color.h"
11+
#include "CommonFramework/ImageTools/ImageBoxes.h"
12+
#include "CommonTools/InferenceCallbacks/VisualInferenceCallback.h"
13+
#include "CommonTools/VisualDetector.h"
14+
15+
namespace PokemonAutomation{
16+
namespace NintendoSwitch{
17+
18+
19+
class SelectedSettingWatcher : public VisualInferenceCallback{
20+
public:
21+
SelectedSettingWatcher(ImageFloatBox selected_box, ImageFloatBox not_selected_box1, ImageFloatBox not_selected_box2);
22+
virtual ~SelectedSettingWatcher();
23+
24+
virtual void make_overlays(VideoOverlaySet& items) const override;
25+
26+
// return true if the area within the selected_box is highlighted, compared with the area within unselected_box
27+
// This compares the brightness of the selected_box with the unselected_box.
28+
// selected_box: the box where we expect the screen should be highlighted
29+
// not_selected_box 1 and 2: the boxes where we expect the screen should NOT be highlighted. These acts as the control, for comparison.
30+
// the average sum of selected_box should be greater than the absolute difference of average sum between unselected_box 1 and 2.
31+
virtual bool process_frame(const ImageViewRGB32& screen, WallClock timestamp) override;
32+
33+
34+
protected:
35+
ImageFloatBox m_selected_box;
36+
ImageFloatBox m_not_selected_box1;
37+
ImageFloatBox m_not_selected_box2;
38+
};
39+
40+
41+
}
42+
}
43+
#endif
44+

0 commit comments

Comments
 (0)