Visual Mystery Systems
import managers.jobManager as jobManager
import menu.menu_creator as menu
import threading
import os
import time

os.system("vcgencmd display_power 0")
os.system("clear")

t1 = threading.Thread(target=jobManager.schedule_jobs)
t2 = threading.Thread(target=menu.create)

t1.start()
t2.start()

ciego/ciego.py
byerlikaya/ciego
import RPi.GPIO as GPIO
import system.system_gpio as system_gpio
import time


GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(system_gpio.RELAY, GPIO.OUT)
GPIO.output(system_gpio.RELAY, GPIO.HIGH)


def open():
     GPIO.output(system_gpio.RELAY, GPIO.LOW)
     time.sleep(0.5)


def close():
    GPIO.output(system_gpio.RELAY, GPIO.HIGH)
    time.sleep(0.5)
ciego/hardware/displayRelay.py
byerlikaya/ciego
import time
from RPLCD.i2c import CharLCD
lcd = CharLCD(i2c_expander='PCF8574', address=0x27, port=1,
              cols=20, rows=4, dotsize=8,
              charmap='A02',
              auto_linebreaks=True,
              backlight_enabled=True)


def text_cursor(messeage, cursor_pos):
    lcd.cursor_pos = (0, cursor_pos)
    lcd.write_string(messeage[0:40])
    time.sleep(0.02)


def text_with_play_icon(messages):
    play = (0b10000,
            0b11000,
            0b11100,
            0b11110,
            0b11100,
            0b11000,
            0b10000,
            0b00000)
    lcd.create_char(0, play)
    index = 0
    for message in messages:
        lcd.cursor_pos = (message[0], 0)
        if index == 1:
            lcd.write_string(("\x00" + message[1])[0:40])
        else:
            lcd.write_string(message[1][0:40])
        index+=1

    time.sleep(0.02)


def text(messages):
    for message in messages:
        lcd.cursor_pos = (message[0], 0)
        lcd.write_string(message[1][0:40])
    time.sleep(0.02)


def clear():
    lcd.clear()

ciego/hardware/lcdDriver.py
byerlikaya/ciego
class language:
    startup_1="Click"
    startup_2="'OK' to install."
    language_1="Language"
    video_1="Choose Video"
    motion_sensor="Motion Sensor"
    yes="Yes"
    no="No"
    loop="Loop Setting"
    start_time="Start Time"
    end_time="End Time"
    play_type="Play Nonstop"
    play_type_1="Every {} minutes"
    save="Save changes?"
    reset="Reset all settings?"
    system_option_1="System Startup"
    system_start_time="Sysem Open Time"
    system_end_time="System Close Time"

ciego/languages/language_en.py
byerlikaya/ciego
class language:
    startup_1="Kurulum icin"
    startup_2="'OK' basiniz."
    language_1="Dil Secimi"
    video_1="Video Secimi"
    motion_sensor="Hareket Sensoru"
    yes="Evet"
    no="Hayir"
    loop="Dongu Ayari"
    start_time="Baslangic Saati"
    end_time="Bitis Saati"
    play_type="Araliksiz Oynat"
    play_type_1="{} dakikada bir"
    save="Kaydedilsin mi?"
    reset="Kurulum silinsin mi?"
    system_option_1="Sistem Baslangici"
    system_start_time="Sistem Acilis Saati"
    system_end_time="Sistem Kapanis Saati"

ciego/languages/language_tr.py
byerlikaya/ciego
import os
import datetime
import system.system_constans as system_constans
import shutil


class setup:
    def __init__(self, video, video_path, loop, motion_sensor):
        self.video = video
        self.video_path = video_path
        self.loop = loop
        self.motion_sensor = motion_sensor

# usb belleği sisteme dahil ediyor.


def usb_prepare():
    #print("----------------- " + system_constans.system_label + " " + system_constans.system_version + " -----------------")
    os.system("sudo umount {}".format(system_constans.dir_path))
    # os.system("lsblk")
    os.system("sudo mount /dev/sda {}".format(system_constans.dir_path))
    os.system("sudo mount /dev/sda1 {}".format(system_constans.dir_path))
    os.system("sudo mount /dev/sdb1 {}".format(system_constans.dir_path))
    os.system("sudo mount /dev/sdc1 {}".format(system_constans.dir_path))
    os.system("sudo mount /dev/sdd1 {}".format(system_constans.dir_path))
    os.system("sudo mount /dev/sde1 {}".format(system_constans.dir_path))
    os.system("sudo mount /dev/sdf1 {}".format(system_constans.dir_path))
    os.system("sudo mount /dev/sdg1 {}".format(system_constans.dir_path))
    os.system("sudo mount /dev/sdh1 {}".format(system_constans.dir_path))
    os.system("clear")
    # os.system("lsblk")
    #os.system("ls /mnt")

# kurulum dosyalarını kaydediyor.
def save_setting(self):

    directory_control()

    # seçilen video ya ait ayarları dosyaya yazdırıyoruz.
    file = open(system_constans.dir_path_video +
                "/video"+str(self.video+1)+".txt", "w+")

    video_name = self.video_path.replace(system_constans.dir_path, "")

    file.write(str(self.video)+"\n")  # 0
    file.write(video_name+"\n")  # 1

    shutil.copyfile(self.video_path,
                    "{}/{}".format(system_constans.dir_path_video, video_name))

    if self.loop.start_hour == 0 and self.loop.start_minute == 0:
        self.loop.start_hour = 0
        self.loop.start_minute = 0

    file.write(str(self.loop.start_hour)+"\n")  # 2
    file.write(str(self.loop.start_minute)+"\n")  # 3

    if self.loop.end_hour == 0 and self.loop.end_minute == 0:
        self.loop.end_hour = 0
        self.loop.end_minute = 0

    file.write(str(self.loop.end_hour)+"\n")  # 4
    file.write(str(self.loop.end_minute)+"\n")  # 5

    file.write(str(self.loop.minute)+"\n")  # 6

    file.write(str(self.motion_sensor)+"\n")  # 7
    file.close()
    print("Setting file saved.")
    save_job_restart(1)

# usb sürücüdeki video dosyalarının tam yolunu getirir.


def get_video_list_with_usb():
    video_list = []

    for path in os.listdir(system_constans.dir_path):
        file = os.path.join(system_constans.dir_path, path)
        if os.path.isfile(file):
            filename, file_extension = os.path.splitext(file)
            if file_extension != ".txt":
                video_list.append(file)

    return video_list


def get_video_list_with_local():
    video_list = []

    for path in os.listdir(system_constans.dir_path_video):
        file = os.path.join(system_constans.dir_path_video, path)
        if os.path.isfile(file):
            filename, file_extension = os.path.splitext(file)
            if file_extension != ".txt":
                video_list.append(file)

    return video_list

# usb sürücüdeki kurulum dosyalarının tam yolunu getirir.


def get_option_files():
    option_file_list = []

    directory_control()

    for path in os.listdir(system_constans.dir_path_video):
        file = os.path.join(system_constans.dir_path_video, path)
        if os.path.isfile(file):
            if path.startswith("video"):
                option_file_list.append(file)

    return option_file_list


def directory_control():
    # eğer usb bellek içerisinde ayar klasörü yok ise oluşturuyoruz.
    if os.path.exists(system_constans.dir_path_video) == False:
        os.mkdir(system_constans.dir_path_video)

    if os.path.exists(system_constans.dir_path_system_options_local) == False:
        os.mkdir(system_constans.dir_path_system_options_local)

    if os.path.exists(system_constans.dir_path_job_restart) == False:
        os.mkdir(system_constans.dir_path_job_restart)


def options_file_control():
    directory_control()

    if os.path.isfile("{}/options.txt".format(system_constans.dir_path_system_options_local)) == False:
        return False
    return True


def save_options(option):
    file = open(
        "{}/options.txt".format(system_constans.dir_path_system_options_local), "w+")

    file.write(option.language + "\n")

    file.write(str(option.start_hour) + "\n")
    file.write(str(option.start_minute) + "\n")

    file.write(str(option.end_hour) + "\n")
    file.write(str(option.end_minute) + "\n")

    file.close()
    print("Options file saved.")

def save_job_restart(status):
    directory_control()
    file = open("{}/job.txt".format(system_constans.dir_path_job_restart),"w+")
    file.write(str(status))
    file.close()
    print("Job restart status changed.")

def get_job_restart_status():
    file = open("{}/job.txt".format(system_constans.dir_path_job_restart))
    status=[]

    for f in file:
        status.append(f)
    
    file.close()

    return status

def get_system_options(option):
    options_file_control()
    file = open(
        "{}/options.txt".format(system_constans.dir_path_system_options_local))

    optionList = []

    for f in file:
        optionList.append(f)

    option.language = optionList[0]
    option.start_hour = optionList[1]
    option.start_minute = optionList[2]
    option.end_hour = optionList[3]
    option.end_minute = optionList[4]

    file.close()

    return option


def reset(reset):
    if reset:
        os.system("sudo rm -rf {}".format(system_constans.dir_path_video))
        print("Settings are reseted.")
        save_job_restart(1)
    else:
        pass


class job:
    video_path = ""
    start_time = datetime.time(0, 0, 0)
    end_time = datetime.time(0, 0, 0)
    repeat_minute = 0
    motion_sensor = False


def get_jobs():
    configs = []

    for option_file in get_option_files():
        config_infos = []
        file = open(option_file)
        for line in file:
            config_infos.append(line)
        file.close()
        configs.append(config_infos)

    job_list = []

    for config in configs:
        j = job()
        j.video_path = "{}/{}".format(system_constans.dir_path_video,
                                      config[1].strip())
        j.start_time = datetime.time(int(config[2]), int(config[3]), 0)
        j.end_time = datetime.time(int(config[4]), int(config[5]), 0)
        j.repeat_minute = int(config[6])
        j.motion_sensor = config[7].strip()
        job_list.append(j)

    return job_list

ciego/managers/fileManager.py
byerlikaya/ciego
#import os
import schedule
import time
import datetime
import managers.fileManager as fileManager
import managers.videoManager as videoManager

scheduler1 = schedule.Scheduler()
scheduler2 = schedule.Scheduler()


def schedule_jobs():

    scheduler1.clear()
    scheduler2.clear()

    # print("-----------------------------------------------")
    # os.system("sudo date")

    for jb in fileManager.get_jobs():
        # print("-----------------------------------------------")
        # print("video path : " + jb.video_path)
        # print("start time : " + jb.start_time.strftime("%H:%M"))
        # print("end time : " + jb.end_time.strftime("%H:%M"))
        # print("repeat minute : " + str(jb.repeat_minute))
        # print("motion sensor : " + jb.motion_sensor)

        # print(datetime.datetime.now().time())

        nowTime = datetime.datetime.now().time()

        now = datetime.datetime.now()
        delta = datetime.timedelta(seconds=2)
        now_Time = (datetime.datetime.combine(
            datetime.date(1, 1, 1), now.time()) + delta).time()

        if jb.start_time == jb.end_time:
            if jb.start_time >= nowTime and jb.end_time >= nowTime:
                scheduler1.every().day.at(now_Time.strftime("%H:%M:%S")).do(setup_job, sjb=jb)
            else:
                scheduler1.every().day.at(jb.start_time.strftime("%H:%M")).do(setup_job, sjb=jb)
        else:
            if jb.start_time <= nowTime and nowTime <= jb.end_time:
                scheduler1.every().day.at(now_Time.strftime("%H:%M:%S")).do(setup_job, sjb=jb)
            else:
                scheduler1.every().day.at(jb.start_time.strftime("%H:%M")).do(setup_job, sjb=jb)

    while True:
        scheduler1.run_pending()
        scheduler2.run_pending()
        if job_restart_control() == True:
            job_restart()
            break
        time.sleep(1)

    time.sleep(1)
    schedule_jobs()


def setup_job(sjb):
    if sjb.repeat_minute == 0:
        # bitiş saatine kadar sürekli oynat
        if sjb.motion_sensor == False:
            scheduler2.every().second.until(sjb.end_time.strftime(
                "%H:%M")).do(video_job, video_path=sjb.video_path)
        else:
            scheduler2.every().second.until(sjb.end_time.strftime("%H:%M")).do(
                video_job_motion_sensor, video_path=sjb.video_path)
    else:
        # bitiş saatine kadar her x dakikada bir oynat
        if sjb.motion_sensor == False:
            scheduler2.every(sjb.repeat_minute).minutes.until(
                sjb.end_time.strftime("%H:%M")).do(video_job, video_path=sjb.video_path)
        else:
            scheduler2.every(sjb.repeat_minute).minutes.until(sjb.end_time.strftime(
                "%H:%M")).do(video_job_motion_sensor, video_path=sjb.video_path)
    # return scheduler1.cancel_job(scheduler1)


def video_job(video_path):
    # print("-----------------------------------------------")
    # print(video_path + " is playing")
    # print(str(datetime.datetime.now()))
    videoManager.start_video(video_path)


def video_job_motion_sensor(video_path):
    # print("-----------------------------------------------")
    # print(video_path + " is playing (motion_sensor)")
    # print(str(datetime.datetime.now()))
    videoManager.start_video(video_path)


def cancel_all_jobs():
    schedule.clear()
    scheduler1.clear()
    scheduler2.clear()


def job_restart_control():
    status = fileManager.get_job_restart_status()
    time.sleep(1)
    if len(status) > 0:
        if status[0] == "1":
            return True
        return False
    return False


def job_restart():
    fileManager.save_job_restart(0)
    print("Jobs restart")

ciego/managers/jobManager.py
byerlikaya/ciego
import time
import vlc
import os
import hardware.displayRelay as display_relay

def start_video(video_path):  

    playing = set([1, 2, 3, 4])

    vlc_instance = vlc.Instance()

    player = vlc_instance.media_player_new()

    media = vlc_instance.media_new(video_path)

    player.set_media(media)

    player.audio_set_volume(100)    
    os.system("vcgencmd display_power 1")    
    os.system("clear")  

    display_relay.open()      
    time.sleep(2)
    player.play()
    os.system("clear") 
    time.sleep(2)
    os.system("clear") 

    while True:
        state = player.get_state()

        if state.value not in playing:
            os.system("clear")
            os.system("vcgencmd display_power 0") 
            
            display_relay.close()

            player.stop()                      
            break
        time.sleep(2)

    player.release()

    #print("Video Sonlandi..")

ciego/managers/videoManager.py
byerlikaya/ciego
import RPi.GPIO as GPIO
import time
import managers.fileManager as fileManager
import menu.menu_step as menu_step
import system.system_gpio as system_gpio
import system.system_constans as system_constans
import hardware.lcdDriver as lcdDriver
import os
#import datetime

# usb sisteme dahil ediliyor ve içeriği listeleniyor.
fileManager.usb_prepare()

GPIO.setmode(GPIO.BCM)

GPIO.setup(system_gpio.BTN_OK, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(system_gpio.BTN_YES, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(system_gpio.BTN_NO, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(system_gpio.BTN_BACK, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(system_gpio.BTN_RESET, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)


# okunuyor ve dosya yolu listesi alınıyor.
video_list = fileManager.get_video_list_with_usb()

if len(video_list) == 0:
    video_list = fileManager.get_video_list_with_local()


class loop:
    step = 1
    start_hour = 0
    start_minute = 0
    end_hour = 0
    end_minute = 0
    minute = 0


loop = loop()

option = menu_step.option()


def create():
    if fileManager.options_file_control():
        savedOption = fileManager.get_system_options(option)
        option.language = savedOption.language.replace("\n", "")
        option.start_hour = int(savedOption.start_hour)
        option.start_minute = int(savedOption.start_minute)
        option.end_hour = int(savedOption.end_hour)
        option.end_minute = int(savedOption.end_minute)
        create_menu(system_constans.menu_step_startup,
                    0, False, False, False, 1)
    else:
        create_menu(system_constans.menu_step_system,
                    0, False, False, False, 1)


def create_menu(step, video_index, motion_sensor, save, reset, time_step):
    lcdDriver.clear()
    while True:
        os.system("clear") 
        menu_step.label_info()
        menu_step.time_info()
        # Başlangıç
        if step == system_constans.menu_step_startup:
            menu_step.step_startup(option)
        # Video Seçimi
        elif step == system_constans.menu_step_video:
            if len(video_list) > 0:
                contents = fileManager.get_jobs()
                video_setup = False
                for content in contents:
                    cvideo = content.video_path.replace(system_constans.dir_path,"").replace(system_constans.dir_path_video,"").replace("//","/")
                    vvideo = video_list[video_index].replace(system_constans.dir_path,"").replace(system_constans.dir_path_video,"")
                    if cvideo == vvideo:
                        video_setup = True
                menu_step.step_video(option, str(
                    video_list[video_index]), video_index+1, len(video_list), video_setup)
            else:
                step = 100000
        # Hareket Sensörü
        elif step == system_constans.menu_step_motion_sensor:
            menu_step.step_motion_sensor(motion_sensor)
        # Döngü Ayarı
        elif step == system_constans.menu_step_loop:
            menu_step.step_loop(option, loop, time_step)
        # Kaydet
        elif step == system_constans.menu_step_save_option:
            menu_step.step_save_option(option, save)
        # Sistem
        elif step == system_constans.menu_step_system:
            menu_step.step_system(option, time_step)
        # Reset
        elif step == system_constans.menu_step_reset:
            menu_step.step_reset(option, reset)
        else:
            if save == True:
                fm = fileManager.setup(
                    video_index, video_list[video_index], loop, motion_sensor)
                fileManager.save_setting(fm)
            create()

        button_ok_click(step, video_index, motion_sensor,
                        save,  reset, time_step)

        button_yes_click(step, video_index,  motion_sensor,
                         save,  reset, time_step)

        button_no_click(step, video_index,   motion_sensor,
                        save,  reset, time_step)

        button_back_click(step, video_index, motion_sensor,
                          save,  reset, time_step)

        button_reset_click(reset)


def button_ok_click(step, video_index, motion_sensor, save,  reset, time_step):
    if GPIO.input(system_gpio.BTN_OK) == GPIO.HIGH:
        time.sleep(0.1)
        if step == system_constans.menu_step_system:
            if option.step == 0:
                # fileManager.save_options(option)
                option.step += 1
                create_menu(step, video_index, motion_sensor,
                            save,  reset, time_step)
            elif option.step <= 2 and time_step == 1:
                time_step += 1
                create_menu(step, video_index, motion_sensor,
                            save,  reset, time_step)
            elif option.step < 2 and time_step == 2:
                time_step = 1
                option.step += 1
                create_menu(step, video_index, motion_sensor,
                            save,  reset, time_step)
            else:
                fileManager.save_options(option)
                time_step = 1
                option.step = 0
                create()
        elif step == system_constans.menu_step_reset:
            fileManager.reset(reset)
            create()
        else:
            if step != system_constans.menu_step_loop:
                step += 1
            elif step == system_constans.menu_step_loop and (loop.step == 1 or loop.step == 2) and time_step == 2:
                loop.step += 1
                time_step = 1
            elif step == system_constans.menu_step_loop and (loop.step == 1 or loop.step == 2) and time_step == 1:
                time_step += 1
            else:
                loop.step = 1
                time_step = 1
                step += 1
            create_menu(step, video_index, motion_sensor,
                        save,  reset, time_step)


def button_back_click(step, video_index, motion_sensor, save,  reset, time_step):
    if GPIO.input(system_gpio.BTN_BACK) == GPIO.HIGH:
        if step == system_constans.menu_step_system:
            if option.step == 0:
                pass
            elif (option.step == 1 or option.step == 2) and time_step == 1:
                option.step -= 1
            elif (option.step == 1 or option.step == 2) and time_step == 2:
                time_step -= 1
            create_menu(step, video_index, motion_sensor,
                        save,  reset, time_step)
        else:
            time.sleep(0.1)
            if step != system_constans.menu_step_loop:
                step -= 1
            elif step == system_constans.menu_step_loop and loop.step > 1:
                loop.step -= 1
            elif step == system_constans.menu_step_loop and time_step > 1:
                time_step -= 1
            else:
                loop.step = 1
                step -= 1
            create_menu(step, video_index, motion_sensor,
                        save,  reset, time_step)


def button_yes_click(step, video_index, motion_sensor, save,  reset, time_step):
    if GPIO.input(system_gpio.BTN_YES) == GPIO.HIGH:
        time.sleep(0.1)
        # her basımda sonraki videoya geçiş sağlanıyor.
        if step == system_constans.menu_step_video:
            video_index += 1
            if video_index < len(video_list):
                time.sleep(0.5)
                create_menu(step, video_index, motion_sensor,
                            save,  reset, time_step)
            else:
                video_index -= 1
        # hareket sensörü aktif ediliyor
        elif step == system_constans.menu_step_motion_sensor:
            create_menu(step, video_index, True, save,
                        reset, time_step)
        # döngü ayarında saat seçimi yaptırılıyor
        elif step == system_constans.menu_step_loop:
            # başlangıç saati artırılıyor
            if loop.step == 1 and time_step == 1:
                if loop.start_hour <= 22:
                    loop.start_hour += 1
                else:
                    loop.start_hour = 0
            # başlangıç dakikası artırılıyor.
            elif loop.step == 1 and time_step == 2:
                if loop.start_minute <= 58:
                    loop.start_minute += 1
                else:
                    loop.start_minute = 0
            # bitiş saati artırılıyor.
            elif loop.step == 2 and time_step == 1:
                if loop.end_hour <= 22:
                    loop.end_hour += 1
                else:
                    loop.end_hour = 0
            # bitiş dakikası artırılıyor.
            elif loop.step == 2 and time_step == 2:
                if loop.end_minute <= 58:
                    loop.end_minute += 1
                else:
                    loop.end_minute = 0
            elif loop.step == 3:
                if loop.minute <= 55:
                    loop.minute += 1
                else:
                    loop.minute = 0
            create_menu(step, video_index, motion_sensor,
                        save,  reset, time_step)
        # kaydedilsin evet
        elif step == system_constans.menu_step_save_option:
            create_menu(step, video_index,   motion_sensor,
                        True,  reset, time_step)
        # dil seçimi yaptırılıyor.
        elif step == system_constans.menu_step_system:
            if option.step == 0:
                if option.language_step == 1:
                    option.language_step = 0
            elif option.step == 1:
                # başlangıç saati artırılıyor
                if time_step == 1:
                    if option.start_hour <= 22:
                        option.start_hour += 1
                    else:
                        option.start_hour = 0
                # başlangıç dakikası artırılıyor.
                elif time_step == 2:
                    if option.start_minute <= 58:
                        option.start_minute += 1
                    else:
                        option.start_minute = 0
            elif option.step == 2:
                # bitiş saati artırılıyor.
                if time_step == 1:
                    if option.end_hour <= 22:
                        option.end_hour += 1
                    else:
                        option.end_hour = 0
                # bitiş dakikası artırılıyor.
                elif time_step == 2:
                    if option.end_minute <= 58:
                        option.end_minute += 1
                    else:
                        option.end_minute = 0

            create_menu(step, video_index, motion_sensor,
                        save,  reset, time_step)
        # sistem reset
        elif step == system_constans.menu_step_reset:
            create_menu(step, video_index, motion_sensor,
                        save,  True, time_step)


def button_no_click(step, video_index,  motion_sensor, save,  reset, time_step):
    if GPIO.input(system_gpio.BTN_NO) == GPIO.HIGH:
        time.sleep(0.1)
        # her basımda önceki videoya geçiş sağlanıyor.
        if step == system_constans.menu_step_video:
            video_index -= 1
            if video_index >= 0:
                time.sleep(0.5)
                create_menu(step, video_index,   motion_sensor,
                            save,  reset, time_step)
            else:
                video_index += 1
        # hareket sensörü pasif ediliyor
        elif step == system_constans.menu_step_motion_sensor:
            create_menu(step, video_index, False, save,  reset, time_step)
        # döngü ayarında dakika seçimi yaptırılıyor
        elif step == system_constans.menu_step_loop:
            # başlangıç saati azaltılıyor
            if loop.step == 1 and time_step == 1:
                if loop.start_hour > 1:
                    loop.start_hour -= 1
                elif loop.start_hour == 0:
                    loop.start_hour = 23
                else:
                    loop.start_hour = 0
            # başlangıç dakikası azaltılıyor.
            elif loop.step == 1 and time_step == 2:
                if loop.start_minute > 0:
                    loop.start_minute -= 1
                elif loop.start_minute == 0:
                    loop.start_minute = 59
                else:
                    loop.start_minute = 0
            # bitiş saati azaltılıyor.
            elif loop.step == 2 and time_step == 1:
                if loop.end_hour > 1:
                    loop.end_hour -= 1
                elif loop.end_hour == 0:
                    loop.end_hour = 23
                else:
                    loop.end_hour = 0
            # bitiş dakikası artırılıyor.
            elif loop.step == 2 and time_step == 2:
                if loop.end_minute > 0:
                    loop.end_minute -= 1
                elif loop.end_minute == 0:
                    loop.end_minute = 59
                else:
                    loop.end_minute = 0
            elif loop.step == 3:
                if loop.minute > 1:
                    loop.minute -= 1
                else:
                    loop.minute = 0
            create_menu(step, video_index, motion_sensor,
                        save,  reset, time_step)
        # kaydedilsin hayır
        elif step == system_constans.menu_step_save_option:
            create_menu(step, video_index, motion_sensor,
                        False,  reset, time_step)
        # dil seçimi yaptırılıyor.
        elif step == system_constans.menu_step_system:
            if option.step == 0:
                if option.language_step == 0:
                    option.language_step = 1
            elif option.step == 1:
                # başlangıç saati azaltılıyor
                if time_step == 1:
                    if option.start_hour > 1:
                        option.start_hour -= 1
                    elif option.start_hour == 0:
                        option.start_hour = 23
                    else:
                        loop.start_hour = 0
               # başlangıç dakikası azaltılıyor.
                elif time_step == 2:
                    if option.start_minute > 0:
                        option.start_minute -= 1
                    elif option.start_minute == 0:
                        option.start_minute = 59
                    else:
                        option.start_minute = 0
            elif option.step == 2:
                # bitiş saati azaltılıyor.
                if option.step == 2 and time_step == 1:
                    if option.end_hour > 1:
                        option.end_hour -= 1
                    elif option.end_hour == 0:
                        option.end_hour = 23
                    else:
                        loop.end_hour = 0
                # bitiş dakikası artırılıyor.
                elif option.step == 2 and time_step == 2:
                    if option.end_minute > 0:
                        option.end_minute -= 1
                    elif option.end_minute == 0:
                        option.end_minute = 59
                    else:
                        option.end_minute = 0

            create_menu(step, video_index, motion_sensor,
                        save,  reset, time_step)
        # sistem reset
        elif step == system_constans.menu_step_reset:
            create_menu(step, video_index, motion_sensor,
                        save,  False, time_step)


def button_reset_click(reset):
    if GPIO.input(system_gpio.BTN_RESET) == GPIO.HIGH:
        time.sleep(0.1)
        create_menu(system_constans.menu_step_reset,
                    0, False, False,  reset, 1)

ciego/menu/menu_creator.py
byerlikaya/ciego
import datetime
import hardware.lcdDriver as lcdDriver
import system.system_constans as system_constans
import time


# lcd ekranı karşılama mesajı yazdırılıyor 3sn bekletiliyor ve kurulum aşaması aktif ediliyor.
messages = [
    (1, " ***** " + system_constans.system_label + " *****"),
    (2, " ***** " + system_constans.system_version + " *****")
]

lcdDriver.text(messages)
time.sleep(2)


class option:
    def __init__(self):
        self.step = 0
        self.language_step = 0
        self.language = "tr"
        self.start_hour = 0
        self.start_minute = 0
        self.end_hour = 0
        self.end_minute = 0


def setup_language(self):
    if self.language == "tr":
        import languages.language_tr as lan
        return lan.language()
    elif self.language == "en":
        import languages.language_en as lan
        return lan.language()


def label_info():
    lcdDriver.text_cursor(system_constans.system_label, 0)


def time_info():
    lcdDriver.text_cursor(
        datetime.datetime.now().time().strftime("%H:%M:%S"), 12)


def step_startup(option):
    l = setup_language(option)
    messages = [
        (1, l.startup_1),
        (2, l.startup_2)
    ]
    lcdDriver.text(messages)


def step_system(option, time_step):
    messages = []

    if option.step == 0:
        if option.language_step == 0:
            option.language = "tr"
            messages.append((2, ">TR< - EN"))
        elif option.language_step == 1:
            option.language = "en"
            messages.append((2, "TR - >EN<"))
        l = setup_language(option)
        messages.append((1, l.language_1))
    elif option.step == 1:
        messages.clear()
        l = setup_language(option)
        if len(str(option.start_hour)) == 1:
            option_start_hour = "0" + str(option.start_hour)
        else:
            option_start_hour = str(option.start_hour)

        if len(str(option.start_minute)) == 1:
            option_start_minute = "0" + str(option.start_minute)
        else:
            option_start_minute = str(option.start_minute)

        messages.append((1, l.system_option_1))

        messages.append((2, l.system_start_time))
        if time_step == 1:
            messages.append(
                (3, ">" + option_start_hour + "<:" + option_start_minute))
        elif time_step == 2:
            messages.append(
                (3, option_start_hour + ":>" + option_start_minute + "<"))
    elif option.step == 2:
        messages.clear()
        l = setup_language(option)

        if len(str(option.end_hour)) == 1:
            option_end_hour = "0" + str(option.end_hour)
        else:
            option_end_hour = str(option.end_hour)

        if len(str(option.end_minute)) == 1:
            option_end_minute = "0" + str(option.end_minute)
        else:
            option_end_minute = str(option.end_minute)

        messages.append((1, l.system_option_1))

        messages.append((2, l.system_end_time + ": "))
        if time_step == 1:
            messages.append(
                (3, ">" + option_end_hour + "<:" + option_end_minute))
        elif time_step == 2:
            messages.append(
                (3, option_end_hour + ":>" + option_end_minute + "<"))

    lcdDriver.text(messages)


def step_video(option, video_name, video_index, video_count, video_setup):
    l = setup_language(option)

    video_name = video_name.replace("{}/".format(system_constans.dir_path),"")
    video_name = video_name.replace("{}/".format(system_constans.dir_path_video), "")

    messages = [
        (1, "{} ({}/{})".format(l.video_1, video_index, video_count)),
        (2, video_name)
    ]
    if video_setup == True:
        lcdDriver.text_with_play_icon(messages)
    else:
        lcdDriver.text(messages)


def step_reset(option, reset):
    l = setup_language(option)
    messages = [
        (1, l.reset)
    ]
    if reset == True:
        messages.append((2, ">" + l.yes + "< - " + l.no))
    else:
        messages.append((2, l.yes + " - >" + l.no + "<"))
    lcdDriver.text(messages)


def step_motion_sensor(option, motion_sensor):
    l = setup_language(option)
    messages = [
        (1, l.motion_sensor)
    ]
    if motion_sensor == True:
        messages.append((2, ">" + l.yes + "< - " + l.no))
    else:
        messages.append((2, l.yes + " - >" + l.no + "<"))
    lcdDriver.text(messages)


def step_loop(option, loop, time_step):
    l = setup_language(option)
    messages = []
    if len(str(loop.start_hour)) == 1:
        loop_start_hour = "0" + str(loop.start_hour)
    else:
        loop_start_hour = str(loop.start_hour)

    if len(str(loop.start_minute)) == 1:
        loop_start_minute = "0" + str(loop.start_minute)
    else:
        loop_start_minute = str(loop.start_minute)

    if len(str(loop.end_hour)) == 1:
        loop_end_hour = "0" + str(loop.end_hour)
    else:
        loop_end_hour = str(loop.end_hour)

    if len(str(loop.end_minute)) == 1:
        loop_end_minute = "0" + str(loop.end_minute)
    else:
        loop_end_minute = str(loop.end_minute)

    if len(str(loop.minute)) == 1:
        minute = "0" + str(loop.minute)
    else:
        minute = str(loop.minute)

    messages.append((1, l.loop))
    if loop.step == 1:
        messages.append((2, l.start_time))
        if time_step == 1:
            messages.append(
                (3, ">" + loop_start_hour + "<:" + loop_start_minute))
        elif time_step == 2:
            messages.append(
                (3, loop_start_hour + ":>" + loop_start_minute + "<"))
    elif loop.step == 2:
        messages.append((2, l.end_time + ": "))
        if time_step == 1:
            messages.append((3, ">" + loop_end_hour + "<:" + loop_end_minute))
        elif time_step == 2:
            messages.append((3, loop_end_hour + ":>" + loop_end_minute + "<"))
    elif loop.step == 3:
        if loop.minute == 0:
            messages.append((2, l.play_type))
        else:
            messages.append((2, l.play_type_1.format(minute)))
    lcdDriver.text(messages)


def step_save_option(option, save):
    l = setup_language(option)
    messages = [
        (1, l.save)
    ]
    if save == True:
        messages.append((2, ">" + l.yes + "< - " + l.no))
    else:
        messages.append((2, l.yes + " - >" + l.no + "<"))
    lcdDriver.text(messages)

ciego/menu/menu_step.py
byerlikaya/ciego
menu_step_reset=-1
menu_step_system=0
menu_step_startup=1
menu_step_video=2
menu_step_motion_sensor=-300
menu_step_loop=3
menu_step_save_option=4

system_label="CIEGO"
system_version="V.1.0"

dir_path = "/mnt"
# dir_path_ciego ="{}/ciego".format(dir_path)
# dir_path_system_options="{}/system_options".format(dir_path)

dir_path_local = "/home/ciego"
#dir_path_ciego_local ="{}/ciego".format(dir_path_local)
dir_path_system_options_local="{}/system_options".format(dir_path_local)
dir_path_video = "{}/video".format(dir_path_local)
dir_path_job_restart = "{}/job".format(dir_path_local)
ciego/system/system_constans.py
byerlikaya/ciego
#BUTTONS -----------------------------------------------

BTN_OK = 19
BTN_YES =5
BTN_NO = 6
BTN_BACK= 13
BTN_RESET=26

#-------------------------------------------------------

RELAY=27
ciego/system/system_gpio.py
byerlikaya/ciego