##
# @file    main.py
# @brief   CAN DEMO
# @author  Ryan Davison-Pearce
# @date    Dec 2019
# @copyright Ryan Davison-Pearce
#


from PY_VTS.mgr.GV import CONST,GV
from PY_VTS.mgr.CAN import *
from PY_VTS.mgr.screens import *

import gui
import gnss
import vbox

from screen_WHEEL import ScreenWHEEL
from screen_INFO import Screen_INFO

def main():

    GV.load_images(["Reset","GNSS","SD"])    # TODO pass what images to load
    GV.load_fonts()

    if GV.font_addr < GV.image_bank.end:
        print ('RAM_G FULL! images: 0 - 0x{:08X} fonts: 0x{:08X} - 1MB'.format(
            GV.image_bank.end, GV.font_addr))
        print ('           over by: 0x{:08X} bytes'.format(GV.image_bank.end - GV.font_addr))
    else:
        print ('RAM_G GOOD images: 0 - 0x{:08X} fonts: 0x{:08X} - 1MB'.format(
            GV.image_bank.end, GV.font_addr))

    mgr_files = Mgr_Files()

    mgr_can = MgrCAN(bus1=True, bus1_t=True, bus0=True, bus0_t=True)
    # MgrCAN.add_signel("Angle Sensor 0", "signal", 129, 3, 23, 16, order="big", scale=-1, msg_size=4) # MX5 NC
    MgrCAN.add_signel("Angle Sensor 0", "signal", 0x09, 3,  0, 16, scale=0.1, type="s")
    MgrCAN.add_signel("Angle Sensor 1", "signal", 0x09, 3, 16, 16,  type="s")
    MgrCAN.add_signel("Angle Sensor 2", "signal", 0x09, 3, 32, 16, scale=0.1, type="s")
    MgrCAN.add_signel("Angle Sensor 3", "signal", 0x09, 3, 48, 16, type="s")

    MgrCAN.add_signel("Angle Info", "signal", 0x578, 3, 0, 64, order = "big")

    mgr_screens = Mgr_Screens()
    mgr_screens.Add_Screen(Screen_INFO(),"Info")
    mgr_screens.Add_Screen(ScreenWHEEL(),"Wheel",start=True)

    while (gnss.init_status() > 0):
        pass
    vbox.init(vbox.VBOX_SRC_GNSS_BASIC)



if __name__ == "__main__":
    main()
