C

Qt Quick Ultralite Automotive Cluster Demo

cmake_minimum_required (VERSION 3.21.1)

project(automotive VERSION 0.0.1 LANGUAGES C CXX ASM)
if (NOT TARGET Qul::Core)
    find_package(Qul)
    get_target_property(includes Qul::Core INTERFACE_INCLUDE_DIRECTORIES)
endif()

include(src/3rdparty/etl/CMakeLists.txt)

option(ENABLE_CANBUS "Enable CAN Bus" OFF)
message(STATUS "Enable CAN Bus: ${ENABLE_CANBUS}")

if(ENABLE_CANBUS AND NOT QUL_RH850_CANBUS_ENABLED)
    message(STATUS "ENABLE_CANBUS option is ON. Pass -DQUL_RH850_CANBUS_ENABLED Cache entry to enable interrupt vectors for CAN")
endif()

set(UNIT_SYSTEM "metric" CACHE STRING "Automotive Demo Unit System")
if (NOT DEMO_REGION)
    if (UNIT_SYSTEM STREQUAL "imperial")
        set(DEMO_REGION "usa")
    else()
        set(DEMO_REGION "de")
    endif()
else()
    set(DEMO_REGION ${DEMO_REGION})
endif()
message(STATUS "DEMO_REGION: ${DEMO_REGION}")

qul_add_target(automotive
    src/platform/${QUL_OS_LOWERCASE}/main.cpp
    src/simulationcontroller.cpp
    src/simulation/states.cpp
    src/simulation/drivetrain.cpp
    src/simulation/speedlimits.cpp
    src/simulation/drivestates.cpp
    src/simulation/lights.cpp
)

if(QUL_BUILD_QMLPROJECT_DEMOS)

if(QUL_PLATFORM MATCHES "^tviic2d6m")
        qul_add_target(automotive_qmlproject
            QML_PROJECT
            qmlproject/automotive_tviic2d6m.qmlproject
            SELECTORS ${UNIT_SYSTEM} ${DEMO_REGION}
        )
    else()
        qul_add_target(automotive_qmlproject
            QML_PROJECT
            qmlproject/automotive.qmlproject
            SELECTORS ${UNIT_SYSTEM} ${DEMO_REGION}
        )
    endif()

endif()

set_property(TARGET automotive APPEND PROPERTY QUL_FONT_FILES
    ${CMAKE_CURRENT_SOURCE_DIR}/fonts/Sarabun-Regular.ttf
    ${CMAKE_CURRENT_SOURCE_DIR}/fonts/Sarabun-Bold.ttf
)

if (QUL_OS MATCHES "FreeRTOS")
    # Use heap_5 policy and custom FreeRTOSConfig.h
    set_property(TARGET automotive PROPERTY QUL_FREERTOS_HEAP_POLICY "heap_5")
    target_include_directories(automotive PRIVATE ${QUL_PLATFORM_TARGET_DIR})
endif()

if (ENABLE_CANBUS)
    add_subdirectory(src/canbus)
    target_compile_definitions(automotive PUBLIC ENABLE_CANBUS)
endif()

add_subdirectory(src/hmi_input)
qul_target_generate_interfaces(automotive
    ${CMAKE_CURRENT_SOURCE_DIR}/src/hmi_input/hmi_input.h
    ${CMAKE_CURRENT_SOURCE_DIR}/src/hmi_input/hmi_input_event.h
    ${CMAKE_CURRENT_SOURCE_DIR}/src/simulationcontroller.h)
target_include_directories(automotive PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)

set_source_files_properties(
    images/needle-standard-sport.png
    images/highlight-big-sport.png
    images/highlight-normal.png
    images/needle-normal.png
    PROPERTIES QUL_RESOURCE_OPTIMIZE_FOR_ROTATION ON)

set_source_files_properties(
      images/albums/ak.png
      images/albums/thievery-corp.png
      images/albums/phazz.png
      images/albums/tycho.png
      images/albums/juno.png
      images/gauge-gauge-frame-sport-center.png
      PROPERTIES
      QUL_RESOURCE_IMAGE_PIXEL_FORMAT AutomaticCompressedLossless)

if(QUL_PLATFORM MATCHES "^tviic2d6m")
    # Reduce VRAM usage by leaving some images that don't get scaled in flash
    set_source_files_properties(
          images/photos/beatriz.png
          images/photos/aryn.png
          images/photos/hirini.png
          images/photos/caspar.png
          images/photos/joslin.png
          images/albums/ak.png
          images/albums/thievery-corp.png
          images/albums/phazz.png
          images/albums/tycho.png
          images/albums/juno.png
          PROPERTIES
          QUL_RESOURCE_CACHE_POLICY "NoCaching")
endif()

qul_add_resource(automotive
    FILES
        images/fuel.png
        images/highlight-big-sport.png
        images/high-beams.png
        images/beam.png
        images/white-line-left.png
        images/sport.png
        images/battery.png
        images/pseudo-mask-vertical.png
        images/bg-mask.png
        images/white-line-right.png
        images/setup.png
        images/play.png
        images/ready.png
        images/top-line.png
        images/gauge-gauge-frame.png
        images/oil-temp.png
        images/needle-normal.png
        images/airbag.png
        images/turn_right.png
        images/needle-standard-sport.png
        images/leaf.png
        images/gauge-gauge-frame-sport-side.png
        images/red-border-right.png
        images/gauge-gauge-frame-sport-center.png
        images/highlight-normal.png
        images/navi.png
        images/gauge-normal.png
        images/phone.png
        images/red-border-left.png
        images/clock.png
        images/car-highlights.png
        images/assets-phone-list-pseudo-mask.png
        images/road.png
        images/highlight-standard-sport.png
        images/parked.png
        images/speed-limit-warning.png
        images/turn_left.png
        images/photos/beatriz.png
        images/photos/aryn.png
        images/photos/hirini.png
        images/photos/caspar.png
        images/photos/joslin.png
        images/albums/ak.png
        images/albums/thievery-corp.png
        images/albums/phazz.png
        images/albums/tycho.png
        images/albums/juno.png
)

qul_target_qml_sources(automotive
    automotive.qml
    PerformanceMetrics.qml
    PerformanceMetricItem.qml
    NormalMode.qml
    NormalModeContentItem.qml
    SportMode.qml
    MediaPlayer.qml
    Phone.qml
    CarStatus.qml
    LaneAssist.qml
    LaneAssistWhiteLine.qml
    Navi.qml
    Menu.qml
    BaseGauge.qml
    Gauge.qml
    MiddleGauge.qml
    SportGauge.qml
    TempGauge.qml
    GuideArrow.qml
    GuideArrowItem.qml
    SpeedWarningIndicator.qml
    LinearGauge.qml
    TellTales.qml
    TellTalesIndicator.qml
    DriveModeSelector.qml
)

qul_add_qml_module(automotive_module
    URI Automotive
    QML_FILES
        imports/Automotive/NormalModeModel.qml
        imports/Automotive/SportModeModel.qml
        imports/Automotive/MainModel.qml
        imports/Automotive/PhoneModel.qml
        imports/Automotive/MediaPlayerModel.qml
        imports/Automotive/Style.qml
        imports/Automotive/TellTalesModel.qml
        imports/Automotive/SettingsMenuModel.qml
        imports/Automotive/MathAPI.qml
        imports/Automotive/NaviModel.qml
        +${UNIT_SYSTEM}/Units.qml
        +${UNIT_SYSTEM}/SpeedLimitValues.qml
        +${UNIT_SYSTEM}/SpeedLimitImage.qml
        region/+${DEMO_REGION}/Region.qml
    SOURCES
        src/connectivityservice.cpp
    HEADERS
        src/connectivityservice.h
    OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/modules # avoid Automotive/ and automotive in the same dir
)

qul_add_resource(automotive_module
    FILES
        images/arrow-0.png
        images/arrow-45.png
        images/arrow-90.png
        images/arrow-round.png
        images/speed-limit-warnings/55mph.png
        images/speed-limit-warnings/70.png
        images/speed-limit-warnings/50.png
        images/speed-limit-warnings/140.png
        images/speed-limit-warnings/90.png
        images/speed-limit-warnings/30.png
        images/speed-limit-warnings/20mph.png
        images/speed-limit-warnings/45mph.png
        images/speed-limit-warnings/35mph.png
        images/speed-limit-warnings/85mph.png
)

target_include_directories(automotive_module PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)

target_link_libraries(automotive PRIVATE automotive_etl automotive_module)
app_target_setup_os(automotive)

if(QUL_BUILD_QMLPROJECT_DEMOS)
    target_include_directories(automotive_qmlproject PRIVATE
        ${CMAKE_CURRENT_SOURCE_DIR}/src
    )

    target_sources(automotive_qmlproject PRIVATE
        src/platform/${QUL_OS_LOWERCASE}/main.cpp
        src/simulationcontroller.cpp
        src/simulation/states.cpp
        src/simulation/drivetrain.cpp
        src/simulation/speedlimits.cpp
        src/simulation/drivestates.cpp
        src/simulation/lights.cpp
    )

    if (QUL_OS MATCHES "FreeRTOS")
        # Use heap_5 policy and custom FreeRTOSConfig.h
        set_property(TARGET automotive_qmlproject PROPERTY QUL_FREERTOS_HEAP_POLICY "heap_5")
        target_include_directories(automotive_qmlproject PRIVATE ${QUL_PLATFORM_TARGET_DIR})
    endif()

    if (ENABLE_CANBUS)
       target_compile_definitions(automotive_qmlproject PUBLIC ENABLE_CANBUS)
    endif()

    target_sources(automotive_qmlproject PRIVATE src/connectivityservice.cpp)

    target_link_libraries(automotive_qmlproject PRIVATE automotive_etl)
    app_target_setup_os(automotive_qmlproject)
endif()