-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
163 lines (122 loc) · 4.74 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Run the augmented reality garden
**Note**: Make sure your do the video mapping configuration with the configure_video_mapping.py file
Usage:
main.py <config-file-path>
Options:
-h --help Show this screen.
<config-file-path> Path to the config file. Use the config.ini.example for help
"""
import os
import random
import sys
from time import sleep
from typing import Callable, List
from docopt import docopt
from datas.repositories.PlayerRepository import PlayerRepository
from motion_detection.motion_detection import MotionDetection
from py_video_mapping import *
from scenario import Scenario
from speech_to_text.plant_intent_recognizer.detect_intent import Intent
from speech_to_text.voice_controller import VoiceController, register_function_for_intent, \
register_function_for_active, register_function_for_sleep
from utils.config_reader import ConfigReader
from ffpyplayer.player import MediaPlayer
FOLDER_ABSOLUTE_PATH = os.path.normpath(os.path.dirname(os.path.abspath(__file__)))
MOTION_DETECTION_SONG_PATH = os.path.join(FOLDER_ABSOLUTE_PATH, "ressources", "sounds", "son_de_la_foret.mp3")
CORRECT_SOUND = os.path.join(FOLDER_ABSOLUTE_PATH, "ressources", "sounds", "mario_yippee.wav")
INCOMPREHENSION_SOUND = os.path.join(FOLDER_ABSOLUTE_PATH, "ressources", "sounds", "mario_oof.wav")
KARAOKE_TIME = 1 # Time in seconds to lock the karaoke
NEXT_STEPS: List[Callable[[], None]] = [] # Global var to know what the next function should be
args = docopt(__doc__)
config_file_path = args["<config-file-path>"]
config_reader = ConfigReader(config_file_path)
py_video_mapping = PyVideoMapping(PyVideoMapping.get_all_screens()[-1], config_reader=config_reader)
scenario = Scenario(py_video_mapping)
@register_function_for_active
@register_function_for_intent(intent=Intent.SALUTATION)
def display_main_menu():
scenario.display_main_menu()
@register_function_for_intent(intent=Intent.FIN)
def force_sleep_mode():
vc.set_mode_sleep()
def display_karaoke():
scenario.display_karaoke()
sleep(KARAOKE_TIME)
@register_function_for_intent(intent=Intent.HELP)
def display_help():
scenario.display_command_list()
@register_function_for_intent(intent=Intent.PLANTER_UN_BULBE)
def start_planting_bulbe():
global NEXT_STEPS
NEXT_STEPS = [
scenario.display_action_creuser,
scenario.display_action_placer_bulbe,
scenario.display_action_reboucher_trou,
scenario.display_action_arroser,
scenario.display_karaoke,
]
player_repo.action_new_plant() # Reward in advance
play_next_step()
@register_function_for_intent(intent=Intent.SUIVRE_ETAT_PLANTE)
def suivre_etat_plante():
scenario.display_sub_menu1()
@register_function_for_intent(intent=Intent.AFFICHER_NIVEAU)
def afficher_niveau():
scenario.display_gardener_progression(player_repo)
@register_function_for_intent(intent=Intent.AFFICHER_ETAT_PLANTE)
def plant_state():
scenario.display_plant_state(player_repo.garden.compute_flower_rank(), player_repo.garden)
@register_function_for_intent(intent=Intent.AFFICHER_PROGRES_PLANTE)
def plant_progress():
scenario.display_plant_progression(player_repo)
@register_function_for_intent(intent=Intent.ENTRETENIR_PLANTE)
def entretenir_plante():
# Dirt should be mixed every week
# For demo purposes we use random
if random.random() < 0.66:
scenario.display_action_arroser()
player_repo.action_water()
else:
scenario.display_action_biner()
player_repo.action_hoe()
global NEXT_STEPS
NEXT_STEPS = [display_karaoke]
@register_function_for_intent(intent=Intent.UNKNOWN_INTENT)
def incomprehension_feedback():
song = MediaPlayer(INCOMPREHENSION_SOUND)
scenario.display_incomprehension_feedback()
@register_function_for_intent(intent=Intent.POSITIF)
def play_next_step():
if NEXT_STEPS:
f = NEXT_STEPS.pop(0) # Call the first function and remove it from the FIFO
scenario.display_good_feedback()
song = MediaPlayer(CORRECT_SOUND)
sleep(1)
f()
else:
print("Trying to call a next step but there is none", file=sys.stderr, flush=True)
@register_function_for_sleep
def on_sleep():
scenario.blackout()
md.start()
@register_function_for_active
def stop_motion_detection():
md.stop()
def on_motion_detection():
scenario.display_wake_up_word()
song = MediaPlayer(MOTION_DETECTION_SONG_PATH)
if not vc.active:
scenario.blackout()
player_repo = PlayerRepository(config_reader=config_reader)
md = MotionDetection(config_reader, on_motion_detection)
vc = VoiceController(config_reader)
vc.start()
sleep(2)
scenario.display_good_feedback()
MediaPlayer(CORRECT_SOUND)
sleep(2)
on_sleep()
print("ALL GOOD")