diff --git a/.gitignore b/.gitignore index a1363379944a5745ceb49c0e493d80eb9335c79a..f08278d85a0ff60e89c0d831ebbe8cec793e81fc 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -*.pdf +*.pdf \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..26d33521af10bcc7fd8cea344038eaaeb78d0ef5 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/Final Project.iml b/.idea/Final Project.iml new file mode 100644 index 0000000000000000000000000000000000000000..e4149dd68905b6dbb59dc88ce9f92b8afdb5059d --- /dev/null +++ b/.idea/Final Project.iml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="PYTHON_MODULE" version="4"> + <component name="NewModuleRootManager"> + <content url="file://$MODULE_DIR$"> + <excludeFolder url="file://$MODULE_DIR$/venv" /> + </content> + <orderEntry type="jdk" jdkName="Python 3.10 (Final Project)" jdkType="Python SDK" /> + <orderEntry type="sourceFolder" forTests="false" /> + </component> +</module> \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000000000000000000000000000000000000..105ce2da2d6447d11dfe32bfb846c3d5b199fc99 --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ +<component name="InspectionProjectProfileManager"> + <settings> + <option name="USE_PROJECT_PROFILE" value="false" /> + <version value="1.0" /> + </settings> +</component> \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000000000000000000000000000000000000..92f766b99c1856f25842cf3e58c5437d6cdffb19 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (Final Project)" project-jdk-type="Python SDK" /> +</project> \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000000000000000000000000000000000..d4560ab8286fbef0fd832ea8ff6e39579bd71df8 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectModuleManager"> + <modules> + <module fileurl="file://$PROJECT_DIR$/.idea/Final Project.iml" filepath="$PROJECT_DIR$/.idea/Final Project.iml" /> + </modules> + </component> +</project> \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000000000000000000000000000000000000..94a25f7f4cb416c083d265558da75d457237d671 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="$PROJECT_DIR$" vcs="Git" /> + </component> +</project> \ No newline at end of file diff --git a/alarm.py b/alarm.py index eb5024514cfab21af29f731b868142bfd693c6f0..49034feef78d40512348fa59b512c7745ff25b69 100644 --- a/alarm.py +++ b/alarm.py @@ -1,5 +1,32 @@ -# Code adapted from https://raspberrydiy.com/raspberry-pi-alarm-clock/ -import vlc -from time import sleep - - +# # Code adapted from https://raspberrydiy.com/raspberry-pi-alarm-clock/ +# import vlc +# from time import sleep +# # from dataclasses import dataclass, field +# +# # @dataclass +# # class AlarmClock: +# +# # sound: str +# +# +# # Constants +# VLC_INSTANCE = vlc.Instance("--input-repeat=999") +# PLAYER = VLC_INSTANCE.media_player_new() +# SONG = VLC_INSTANCE.media_new("/home/pi/Music/song.mp3") +# VOLUME = 100 +# +# PLAYER.set_media(SONG) +# PLAYER.audio_set_volume(VOLUME) +# +# def play_alarm(volume: int = VOLUME): +# PLAYER.set_media(SONG) +# PLAYER.audio_set_volume(volume) +# +# def stop_alarm(): +# pass +# +# def snooze_alarm(snooze_time: int = 60): +# pass +# +# +# diff --git a/simple_alarm_clock.py b/simple_alarm_clock.py new file mode 100644 index 0000000000000000000000000000000000000000..306dde8135b5a7369248ce6433d5bac85432e040 --- /dev/null +++ b/simple_alarm_clock.py @@ -0,0 +1,84 @@ +from dataclasses import dataclass +from enum import Enum, auto +from datetime import time, datetime +from typing import Optional, Any +from time import sleep +import vlc + +# Simple Alarm Clock has 5 functionalities: +# 1. Set Alarm Time - Set the time for the alarm to sound, does NOT make the alarm active +# 2. Start Alarm - Make the alarm active, which will run the timer until it reaches the specified time +# 3. Sound Alarm - Play the sound for the alarm +# 4. Snooze Alarm - Stop the alarm sound and wait for some time to play the alarm again +# 5. Stop Alarm - If the alarm is active or is playing, stop the alarm (deactivate state) + +DEFAULT_VOLUME = 50 + + +class AlarmState(Enum): + SET = auto(), + STARTED = auto(), + PLAYING = auto(), + SNOOZED = auto(), + DEACTIVATED = auto(), + + +@dataclass +class AlarmClock: + player: Optional + wake_time: time + current_state: AlarmState = AlarmState.DEACTIVATED + + def set_alarm(self, wake_time: time) -> time: + print(f"SETTING ALARM to: {wake_time}") + self.current_state = AlarmState.SET + self.wake_time = wake_time + return self.wake_time + + def start_alarm(self, check_frequency: int = 1) -> bool: + print(f"STARTING ALARM") + self.current_state = AlarmState.STARTED + now = datetime.now().time() + if now >= self.wake_time: + return False + sleep_time_amount = check_frequency if check_frequency > 1 else 1 + while now < self.wake_time: + # Sleep for some time + sleep(sleep_time_amount) + now = datetime.now().time() + self.sound_alarm() + return True + + def sound_alarm(self, sound: Optional = None, volume: int = DEFAULT_VOLUME): + print(f"SOUNDING ALARM") + self.current_state = AlarmState.PLAYING + if sound is not None: + self.player.set_media(sound) + self.player.audio_set_volume(volume) + self.player.play() + + def snooze_alarm(self, snooze_time: int = 60): + print(f"SNOOZING ALARM") + self.current_state = AlarmState.SNOOZED + self.player.pause() + # Maybe make this async later + sleep(snooze_time) + self.player.play() + if self.current_state is AlarmState.SNOOZED: + self.sound_alarm() + + def stop_alarm(self, deactivate: bool = True): + print(f"STOPPING ALARM") + if self.current_state is AlarmState.PLAYING: + self.player.stop() + self.current_state = AlarmState.DEACTIVATED if deactivate else AlarmState.SET + + +def simple_alarm_mode(): + alarm_clock = AlarmClock(math, ALARM_TIME) + + +ALARM_TIME = time(7, 0, 0) + +if __name__ == '__main__': + simple_alarm_mode() \ No newline at end of file diff --git a/vlc_mock.py b/vlc_mock.py new file mode 100644 index 0000000000000000000000000000000000000000..7cd0ee40a6f58724c429cd006f4a20d33e3cec8a --- /dev/null +++ b/vlc_mock.py @@ -0,0 +1,2 @@ +class VlcTestInstance: + pass \ No newline at end of file