RootScreen:
    HomeScreen:
    ReadoutScreen:
    ReadData:
    ProgramTemp:
    Program:
    Credits:
    Modify:

<QuitPU>:
    title: "BiogasControllerApp"
    font_size: 50
    size_hint: 0.5, 0.4
    auto_dismiss: False
    GridLayout:
        cols:1
        Label:
            text: "Are you sure you want to leave?"
            font_size: 20
        GridLayout:
            cols:2
            Button:
                text: "Yes"
                font_size: 15
                on_release:
                    root.quitapp()
                    app.stop()
            Button:
                text: "No"
                font_size: 15
                on_press:
                    root.dismiss()

<NoConnection>:
    title: "WARNING!"
    font_size: 50
    size_hint: 0.5, 0.4
    auto_dismiss: False
    GridLayout:
        cols:1
        Label:
            text: "Unable to open Serial Port"
            font_size: 20
        GridLayout:
            cols:2
            Button:
                text: "Details"
                on_release:
                    root.details()
            Button:
                text:"Ok"
                on_release:
                    root.dismiss()

<ConnectionFail>:
    title: "WARNING!"
    font_size: 50
    size_hint: 0.7, 0.6
    auto_dismiss: False
    GridLayout:
        cols:1
        Label:
            text: "Unable to communicate"
            font_size: 20
        Label:
            text: "Possible ways to resolve this problem:\n- Try again\n- Restart the PIC16F877 or reset the program\n- Check the cable / connect one"
            font_size: 14
        Button:
            text:"Ok"
            on_release:
                root.dismiss()

<DetailInfo>:
    on_open: self.update_details = root.infos()
    title: "DETAILS"
    font_size: 50
    size_hint: 1, 0.7
    auto_dismiss: False
    GridLayout:
        cols:1
        Label:
            text: "Unable to open Serial Port"
            font_size: 20
        Label:
            id: errormessage
            text: root.infos()
            font_size: 13
        Label:
            text: root.error_tips()
            font_size: 13
        Button:
            text:"Ok"
            on_release:
                root.dismiss()

<Modeswitch>:
    title: "NOTICE!"
    font_size: 50
    size_hint: 0.5, 0.4
    auto_dismiss: False
    GridLayout:
        cols:1
        Label:
            text: "Mode Switched!"
            font_size: 30
        Button:
            text:"Ok"
            on_release:
                root.dismiss()

<SaveConf>:
    title: "NOTICE!"
    font_size: 50
    size_hint: 0.5, 0.4
    auto_dismiss: False
    GridLayout:
        cols:1
        Label:
            text: "SAVED!"
            font_size: 30
        Button:
            text:"Ok"
            on_release:
                root.dismiss()

<Connecting_PU>:
    title: "NOTICE!"
    font_size: 50
    size_hint: 0.5, 0.4
    auto_dismiss: False
    GridLayout:
        cols:1
        Label:
            text: "Establishing connection with PIC16F877"
            font_size: 18
        Label:
            text: "This Process may take a while..."
            font_size: 15
        Button:
            text:"Ok"
            on_release:
                root.dismiss()

<MissingFieldsError>:
    title: "WARNING!"
    font_size: 50
    size_hint: 0.5, 0.4
    auto_dismiss: False
    GridLayout:
        cols:1
        Label:
            text: "Missing Information!"
            font_size: 18
        Label:
            text: "Check your entry"
            font_size: 15
        Button:
            text:"Ok"
            on_release:
                root.dismiss()

<Disconnecting_PU>:
    title: "NOTICE!"
    font_size: 50
    size_hint: 0.5, 0.4
    auto_dismiss: False
    GridLayout:
        cols:1
        Label:
            text: "Connection with PIC16F877 terminated"
            font_size: 18
        Label:
            text: "The connection to the Microcontroller\nhas been terminated successfully"
            font_size: 15
        Button:
            text:"Ok"
            on_release:
                root.dismiss()

######################################
# SCREENS
######################################
<HomeScreen>:
    name: "HomeS"
    canvas.before:
        Color:
            rgba: (50,50,50,0.2)
        Rectangle:
            size: self.size
            pos: self.pos
    GridLayout:
        cols:1
        Label:
            text: "BiogasanlageControllerApp"
            font_size: 50
            color: (0, 113, 0, 1)
            bold:True
            italic:True
        FloatLayout:
            GridLayout:
                cols: 2
                size_hint: 0.8, 0.8
                pos_hint: {"x": 0.1, "y": 0.1}
                Button:
                    text: "Start"
                    background_color: (255, 0, 0, 0.6)
                    font_size: 30
                    on_release:
                        root.tryconnection()
                Button:
                    text: "Quit"
                    background_color: (255, 0, 0, 0.6)
                    font_size: 30
                    on_release:
                        root.exitapp()
            Label:
                text: root.reset()
                id: app_version
                font_size: 13
                pos_hint: {"y": -0.45, "x":0.05}
            Button:
                text: "Settings"
                font_size: 13
                size_hint: 0.07, 0.06
                pos_hint: {"x":0.01, "y":0.01}
                background_color: (50, 0, 0, 0.2)
                on_release:
                    app.root.current = "Settings"
                    root.manager.transition.direction = "down"

<ReadoutScreen>:
    on_pre_enter: self.reset_screen = root.resscreen()
    name: "Readout"
    canvas.before:
        Color:
            rgba: (50,50,50,0.2)
        Rectangle:
            size: self.size
            pos: self.pos
    GridLayout:
    FloatLayout:
        Label:
            pos_hint: {"y":0.4}
            text: "READOUT"
            font_size: 40
            color: (0, 113, 0, 1)
            bold: True
        GridLayout:
            cols:4
            size_hint: 0.8, 0.3
            pos_hint: {"x":0.1, "y":0.4}
            Label:
                text: "SENSOR 1: "
                font_size: 20
            Label:
                id: sonde1
                text: ""
            Label:
                text: "SENSOR 2: "
                font_size: 20
            Label:
                id: sonde2
                text: ""
            Label:
                text: "SENSOR 3: "
                font_size: 20
            Label:
                id: sonde3
                text: ""
            Label:
                text: "SENSOR 4: "
                font_size: 20
            Label:
                id: sonde4
                text: ""
        Button:
            text: "Start communication"
            size_hint: 0.2, 0.1
            pos_hint: {"x": 0.5, "y": 0.05}
            background_color: (255, 0, 0, 0.6)
            on_release:
                root.start_com()
        Button:
            text: "End communication"
            size_hint: 0.2, 0.1
            pos_hint: {"x": 0.7, "y": 0.05}
            background_color: (255, 0, 0, 0.6)
            on_release:
                root.end_com()
        Button:
            text: "Back"
            size_hint: 0.3, 0.1
            pos_hint: {"x":0.05, "y":0.05}
            background_color: (255, 0, 0, 0.6)
            on_release:
                root.leave_screen()
                app.root.current = "HomeS"
                root.manager.transition.direction = "left"
        ToggleButton:
            id: mode_sel
            size_hint: 0.15, 0.1
            pos_hint: {"x":0.1, "y":0.2}
            text: "Normal Mode" if self.state == "normal" else "Fast Mode"
            on_text: root.switch_mode(mode_sel.text)
            background_color: (255,0,0,0.6) if self.state == "normal" else (0,0,255,0.6)
        Button:
            text: "Read Data"
            size_hint: 0.15, 0.1
            pos_hint: {"x":0.3, "y":0.2}
            background_color: (255, 0, 0, 0.6)
            on_release:
                root.leave_screen()
                app.root.current = "RD"
                root.manager.transition.direction = "down"
        Button:
            text: "Temperature"
            size_hint: 0.15, 0.1
            pos_hint: {"x":0.5, "y":0.2}
            background_color: (255, 0, 0, 0.6)
            on_release:
                root.leave_screen()
                app.root.current = "PT"
                root.manager.transition.direction = "down"
        Button:
            text: "Change all Data"
            size_hint: 0.15, 0.1
            pos_hint: {"x":0.7, "y":0.2}
            background_color: (255, 0, 0, 0.6)
            on_release:
                root.leave_screen()
                app.root.current = "PR"
                root.manager.transition.direction = "down"
        Label:
            id: frequency
            text: "Frequency will appear here"
            font_size: 10
            pos_hint: {"x":0.4, "y": 0.3}

<ReadData>:
    name: "RD"
    canvas.before:
        Color:
            rgba: (50,50,50,0.2)
        Rectangle:
            size: self.size
            pos: self.pos
    GridLayout:
    FloatLayout:
        Label:
            text: "Read Data"
            font_size: 40
            color: (0, 113, 0, 1)
            bold: True
            pos_hint: {"y":0.4}
        Button:
            text: "Start Readout"
            size_hint: 0.2, 0.1
            pos_hint: {"x":0.4, "y":0.1}
            on_release:
                root.read_data()
        Button:
            text: "Back"
            size_hint: 0.2, 0.1
            pos_hint: {"x":0.1, "y":0.1}
            background_color: (255, 0, 0, 0.6)
            on_release:
                app.root.current = "Readout"
                root.manager.transition.direction = "up"
        GridLayout:
            cols:4
            size_hint: 0.8, 0.4
            pos_hint: {"x":0.1, "y":0.3}
            Label:
                text: "Sonde 1"
                font_size: 20
            Label:
                id: inf_sonde1
                text: ""
            Label:
                text: "Sonde 2"
                font_size: 20
            Label:
                id: inf_sonde2
                text: ""
            Label:
                text: "Sonde 3"
                font_size: 20
            Label:
                id: inf_sonde3
                text: ""
            Label:
                text: "Sonde 4"
                font_size: 20
            Label:
                id: inf_sonde4
                text: ""

<ProgramTemp>:
    on_pre_enter: self.check_config = root.read_config()
    name: "PT"
    canvas.before:
        Color:
            rgba: (50,50,50,0.2)
        Rectangle:
            size: self.size
            pos: self.pos
    FloatLayout:
        Label:
            text: "Change Temperature"
            pos_hint: {"y":0.4}
            font_size: 40
            color: (0, 113, 0, 1)
            bold: True
        GridLayout:
            size_hint: 0.8, 0.4
            pos_hint: {"x": 0.1, "y":0.3}
            cols:2
            Label:
                text: "Temperature Sensor 1: "
            TextInput:
                id: temp_s1
                multiline: False
                input_filter: "float"
            Label:
                text: "Temperature Sensor 2: "
            TextInput:
                id: temp_s2
                multiline: False
                input_filter: "float"
            Label:
                text: "Temperature Sensor 3: "
            TextInput:
                id: temp_s3
                multiline: False
                input_filter: "float"
            Label:
                text: "Temperature Sensor 4: "
            TextInput:
                id: temp_s4
                multiline: False
                input_filter: "float"
        Button:
            text: "Back"
            size_hint: 0.1, 0.1
            pos_hint: {"x":0.1, "y":0.1}
            background_color: (255, 0, 0, 0.6)
            on_release:
                app.root.current = "Readout"
                root.manager.transition.direction = "up"
        ToggleButton:
            id: prsel
            size_hint: 0.2, 0.1
            pos_hint: {"x":0.35, "y": 0.1}
            text: "Full\nreprogramming" if self.state == "normal" else "Partial\nreprogramming"
            on_release: root.change_mode()
            background_color: (255,0,0,0.6) if self.state == "normal" else (0,0,255,0.6)
        Button:
            text: "Save"
            size_hint: 0.2, 0.1
            pos_hint: {"x":0.6, "y":0.1}
            background_color: (255, 0, 0, 0.6)
            on_release:
                root.send_data()

<Program>:
    name: "PR"
    on_pre_enter: self.check_config = root.read_config()
    canvas.before:
        Color:
            rgba: (50,50,50,0.2)
        Rectangle:
            size: self.size
            pos: self.pos
    FloatLayout:
        Label:
            text: "Change all Data"
            font_size: 40
            color: (0, 113, 0, 1)
            bold: True
            pos_hint: {"y":0.4}
        GridLayout:
            size_hint: 0.8, 0.5
            pos_hint: {"x":0.1, "y":0.2}
            cols: 4
            Label:
                text: "Sensor 1, a:"
            TextInput:
                id: s1_a
                multiline: False
                input_filter: "float"
            Label:
                text: "Sensor 1, b:"
            TextInput:
                id: s1_b
                multiline: False
                input_filter: "float"
            Label:
                text: "Sensor 1, c:"
            TextInput:
                id: s1_c
                multiline: False
                input_filter: "float"
            Label:
                text: "Sensor 1, Temp:"
            TextInput:
                id: s1_t
                multiline: False
                input_filter: "float"
            Label:
                text: "Sensor 2, a:"
            TextInput:
                id: s2_a
                multiline: False
                input_filter: "float"
            Label:
                text: "Sensor 2, b:"
            TextInput:
                id: s2_b
                multiline: False
                input_filter: "float"
            Label:
                text: "Sensor 2, c:"
            TextInput:
                id: s2_c
                multiline: False
                input_filter: "float"
            Label:
                text: "Sensor 2, Temp:"
            TextInput:
                id: s2_t
                multiline: False
                input_filter: "float"
            Label:
                text: "Sensor 3, a:"
            TextInput:
                id: s3_a
                multiline: False
                input_filter: "float"
            Label:
                text: "Sensor 3, b:"
            TextInput:
                id: s3_b
                multiline: False
                input_filter: "float"
            Label:
                text: "Sensor 3, c:"
            TextInput:
                id: s3_c
                multiline: False
                input_filter: "float"
            Label:
                text: "Sensor 3, Temp:"
            TextInput:
                id: s3_t
                multiline: False
                input_filter: "float"
            Label:
                text: "Sensor 4, a:"
            TextInput:
                id: s4_a
                multiline: False
                input_filter: "float"
            Label:
                text: "Sensor 4, b:"
            TextInput:
                id: s4_b
                multiline: False
                input_filter: "float"
            Label:
                text: "Sensor 4, c:"
            TextInput:
                id: s4_c
                multiline: False
                input_filter: "float"
            Label:
                text: "Sensor 4, Temp:"
            TextInput:
                id: s4_t
                multiline: False
                input_filter: "float"
        Button:
            text: "Back"
            size_hint: 0.1, 0.1
            pos_hint: {"x":0.1, "y":0.1}
            background_color: (255, 0, 0, 0.6)
            on_release:
                app.root.current = "Readout"
                root.manager.transition.direction = "up"
        ToggleButton:
            id: prsel
            size_hint: 0.2, 0.1
            pos_hint: {"x":0.35, "y": 0.1}
            text: "Full\nreprogramming" if self.state == "normal" else "Partial\nreprogramming"
            on_release: root.change_mode()
            background_color: (255,0,0,0.6) if self.state == "normal" else (0,0,255,0.6)
        Button:
            text: "Save"
            size_hint: 0.2, 0.1
            pos_hint: {"x":0.6, "y":0.1}
            background_color: (255, 0, 0, 0.6)
            on_release:
                root.send_data()


<Credits>:
    name: "Credits"
    canvas.before:
        Color:
            rgba: (50,50,50,0.2)
        Rectangle:
            size: self.size
            pos: self.pos
    FloatLayout:
        Button:
            text: "back"
            size_hint: 0.4, 0.2
            pos_hint: {"x":0.3, "y":0.1}
            on_release:
                app.root.current = "Settings"
                root.manager.transition.direction = "right"
        GridLayout:
            cols:1
            pos_hint:{"x":0.05, "y":0.35}
            size_hint: 0.9, 0.5
            Label:
                text: "This is a rework of the BiogasControllerApp V1, that was originally programmed by S. Reichmuth."
            Label:
                text: "Written by:                   Janis Hutz\nDesigned by:                Janis Hutz\nDesign language:         Kivy"

<Modify>:
    on_pre_enter: self.config = root.read_config()
    name: "Settings"
    canvas.before:
        Color:
            rgba: (50,50,50,0.2)
        Rectangle:
            size: self.size
            pos: self.pos
    GridLayout:
        cols: 1
        Label:
            text: "Settings"
            font_size: 40
            color: (0, 113, 0, 1)
            bold: True
        FloatLayout:
            GridLayout:
                pos_hint: {"x":0.05, "y":0.05}
                size_hint: 0.9, 0.9
                cols: 4
                Button:
                    text: "Back"
                    background_color: (255,0,0,0.6)
                    on_release:
                        app.root.current = "HomeS"
                        root.manager.transition.direction = "up"
                Button:
                    text: "Report a\nBug"
                    background_color: (255,0,0,0.6)
                    on_release:
                        root.issue_reporting()
                ToggleButton:
                    id: prsel
                    text: "Full\nreprogramming" if self.state == "normal" else "Partial\nreprogramming"
                    on_release: root.change_programming()
                    background_color: (255,0,0,0.6) if self.state == "normal" else (0,0,255,0.6)
                Button:
                    text: "Credits"
                    background_color: (255,0,0,0.6)
                    on_release:
                        app.root.current = "Credits"
                        root.manager.transition.direction = "left"
