|
1 | 1 | import os
|
| 2 | +import threading |
2 | 3 | from time import sleep
|
| 4 | +from time import time |
3 | 5 |
|
4 | 6 | import dotenv
|
5 | 7 | from blossom_interface import BlossomInterface
|
|
8 | 10 |
|
9 | 11 | if __name__ == '__main__':
|
10 | 12 | dotenv.load_dotenv()
|
11 |
| - bl = BlossomInterface(False, os.getenv("SERVER_IP"), os.getenv("SERVER_PORT")) |
| 13 | + # Initialize blossom interface |
| 14 | + # Multi-blossom setup will only work with network interface |
| 15 | + bl = BlossomInterface(True, os.getenv("SERVER_IP"), os.getenv("SERVER_PORT")) |
12 | 16 |
|
13 | 17 | # Control blossom with bl object
|
14 | 18 | bl.reset()
|
|
27 | 31 | bl.do_sequence(idle_sequences[0], 0, 0)
|
28 | 32 | random.shuffle(idle_sequences)
|
29 | 33 | bl.do_sequence(idle_sequences[0], 0, 1)
|
30 |
| - input() |
| 34 | + |
| 35 | + # You might want to control blossom without use sleep() that blocks main program. In that case, use threading. |
| 36 | + # In most cases, sleep() is used for playing several sequences in a row. Because bl.do_sequence() will interrupt |
| 37 | + # current sequence. |
| 38 | + # You can use threading with sleep to do this. |
| 39 | + # Or if your sequence is not dynamic, you can use blossom_sequence_comb.py to combine sequences to be a new |
| 40 | + # sequence. |
| 41 | + |
| 42 | + # Example: |
| 43 | + class MyBlossomInterface: |
| 44 | + def __init__(self, bli): |
| 45 | + self.bli = bli |
| 46 | + |
| 47 | + def do_idle_sequences(self, delay_time, blossom_id, total_rounds): |
| 48 | + my_idle_sequences = ["breathing/exhale", "breathing/inhale", "fear/fear_startled", "happy/happy_lookingup", |
| 49 | + "sad/sad_downcast"] |
| 50 | + sleep(delay_time) |
| 51 | + for i in range(total_rounds): |
| 52 | + random.shuffle(my_idle_sequences) |
| 53 | + print(f"Sequence: {my_idle_sequences[0]}, Blossom ID: {0}") |
| 54 | + self.bli.do_sequence(my_idle_sequences[0], 0, 0) |
| 55 | + random.shuffle(my_idle_sequences) |
| 56 | + print(f"Sequence: {my_idle_sequences[0]}, Blossom ID: {1}") |
| 57 | + self.bli.do_sequence(my_idle_sequences[0], 0, 1) |
| 58 | + sleep(3) |
| 59 | + |
| 60 | + # import threading |
| 61 | + my_bl = MyBlossomInterface(bl) |
| 62 | + bl_thread_target = my_bl.do_idle_sequences |
| 63 | + bl_thread_kwargs = {"delay_time": 0, "blossom_id": 0, "total_rounds": 3} |
| 64 | + bl_thread = threading.Thread(target=bl_thread_target, kwargs=bl_thread_kwargs) |
| 65 | + bl_thread.start() |
| 66 | + # Doing something else |
0 commit comments