Skip to content

Commit cb11285

Browse files
author
Gin
committed
add calorie watcher
1 parent e8b7349 commit cb11285

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

SerialPrograms/Source/PokemonLZA/Inference/PokemonLZA_HyperspaceCalorieDetector.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,34 @@ bool HyperspaceCalorieDetector::detect(const ImageViewRGB32& screen){
5454
}
5555

5656

57+
HyperspaceCalorieLimitWatcher::HyperspaceCalorieLimitWatcher(Logger& logger, uint16_t calorie_limit)
58+
: HyperspaceCalorieDetector(logger), VisualInferenceCallback("HyperspaceCalorieLimitWatcher")
59+
, m_calorie_limit(calorie_limit)
60+
{}
61+
62+
bool HyperspaceCalorieLimitWatcher::process_frame(const ImageViewRGB32& frame, WallClock timestamp){
63+
bool detected = detect(frame);
64+
if (!detected){
65+
m_start_of_detection = WallClock::min();
66+
return false;
67+
}
68+
const uint16_t calorie = calorie_number();
69+
if (calorie > m_calorie_limit){
70+
m_start_of_detection = WallClock::min();
71+
return false;
72+
}
73+
74+
if (m_start_of_detection == WallClock::min()){
75+
m_start_of_detection = timestamp;
76+
}
77+
78+
if (timestamp - m_start_of_detection >= Milliseconds(300) && calorie <= m_calorie_limit){
79+
return true;
80+
}
81+
82+
return false;
83+
}
84+
5785

5886

5987
}

SerialPrograms/Source/PokemonLZA/Inference/PokemonLZA_HyperspaceCalorieDetector.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ class HyperspaceCalorieDetector : public StaticScreenDetector{
3838
uint16_t m_calorie_number = 0;
3939
};
4040

41+
class HyperspaceCalorieLimitWatcher : public HyperspaceCalorieDetector, public VisualInferenceCallback{
42+
public:
43+
HyperspaceCalorieLimitWatcher(Logger& logger, uint16_t calorie_limit);
44+
45+
virtual bool process_frame(const ImageViewRGB32& frame, WallClock timestamp) override;
46+
47+
private:
48+
uint16_t m_calorie_limit;
49+
WallClock m_start_of_detection = WallClock::min();
50+
};
51+
4152

4253

4354

0 commit comments

Comments
 (0)