diff --git a/.gitmodules b/.gitmodules index 2024270..9043cd9 100644 --- a/.gitmodules +++ b/.gitmodules @@ -160,9 +160,4 @@ [submodule ".\\avnet_rsl10_2devices\\HardwareDefinitions"] path = .\\avnet_rsl10_2devices\\HardwareDefinitions url = https://github.com/Azure-Sphere-DevX/AzureSphereDevX.HardwareDefinitions.git -[submodule "avnet_lightranger5/AzureSphereDevX"] - path = avnet_lightranger5/AzureSphereDevX - url = https://github.com/Azure-Sphere-DevX/AzureSphereDevX.git -[submodule "avnet_lightranger5/HardwareDefinitions"] - path = avnet_lightranger5/HardwareDefinitions - url = https://github.com/Azure-Sphere-DevX/AzureSphereDevX.HardwareDefinitions.git + diff --git a/avnet_lightranger5/.vscode/launch.json b/avnet_lightranger5/.vscode/launch.json deleted file mode 100644 index fcace73..0000000 --- a/avnet_lightranger5/.vscode/launch.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Launch for Azure Sphere High-Level Applications (gdb)", - "type": "azurespheredbg", - "request": "launch", - "args": [], - "stopAtEntry": false, - "cwd": "${workspaceFolder}", - "environment": [], - "externalConsole": true, - "partnerComponents": [ "f6768b9a-e086-4f5a-8219-5ffe9684b001" ], - "MIMode": "gdb", - "setupCommands": [ - { - "description": "Enable pretty-printing for gdb", - "text": "-enable-pretty-printing", - "ignoreFailures": true - } - ] - } - ] -} \ No newline at end of file diff --git a/avnet_lightranger5/.vscode/settings.json b/avnet_lightranger5/.vscode/settings.json deleted file mode 100644 index 94d6c8e..0000000 --- a/avnet_lightranger5/.vscode/settings.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "cmake.generator": "Ninja", - "cmake.buildDirectory": "${workspaceRoot}/out/ARM-${buildType}", - "cmake.buildToolArgs": [ "-v" ], - "cmake.configureSettings": { - "CMAKE_TOOLCHAIN_FILE": "${command:azuresphere.AzureSphereSdkDir}/CMakeFiles/AzureSphereToolchain.cmake", - "AZURE_SPHERE_TARGET_API_SET": "latest-lts" - }, - "cmake.configureOnOpen": true, - "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools", - "files.associations": { - "dx_avnet_iot_connect.h": "c", - "dx_json_serializer.h": "c" - } -} \ No newline at end of file diff --git a/avnet_lightranger5/AzureSphereDevX b/avnet_lightranger5/AzureSphereDevX deleted file mode 160000 index 32fb212..0000000 --- a/avnet_lightranger5/AzureSphereDevX +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 32fb212aa73d764f2602e2e2624929972af6c003 diff --git a/avnet_lightranger5/CMakeLists.txt b/avnet_lightranger5/CMakeLists.txt deleted file mode 100644 index 9659192..0000000 --- a/avnet_lightranger5/CMakeLists.txt +++ /dev/null @@ -1,64 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. - -cmake_minimum_required (VERSION 3.10) - -project (avnet_lightranger5_TMF8801_HLApp-V1 C) - -# Check if there is a global azsphere_board.cmake file -get_filename_component(PARENT_DIR ${PROJECT_SOURCE_DIR} DIRECTORY) - -if (EXISTS "${PARENT_DIR}/azsphere_board.global.txt") - include("${PARENT_DIR}/azsphere_board.global.txt") -else() - include(azsphere_board.txt) -endif() - -if (EXISTS "${PARENT_DIR}/tools/cmake/azsphere_config.cmake") - include(../tools/cmake/azsphere_config.cmake) - auto_generate_azsphere_config() -else() - - # For information on setting tools revision and target api set see - # https://docs.microsoft.com/en-us/azure-sphere/app-development/using-cmake-functions - - azsphere_configure_tools(TOOLS_REVISION "21.07") - azsphere_configure_api(TARGET_API_SET "12") - -endif() - -add_subdirectory("AzureSphereDevX" out) - -# Create executable -add_executable (${PROJECT_NAME} main.c) -target_link_libraries (${PROJECT_NAME} applibs pthread gcc_s c azure_sphere_devx) -target_include_directories(${PROJECT_NAME} PUBLIC AzureSphereDevX/include ) - - -set(BOARD_COUNTER 0) - -if(AVNET) - MATH(EXPR BOARD_COUNTER "${BOARD_COUNTER}+1") - add_definitions( -DOEM_AVNET=TRUE ) - azsphere_target_hardware_definition(${PROJECT_NAME} TARGET_DIRECTORY "HardwareDefinitions/avnet_mt3620_sk" TARGET_DEFINITION "sample_appliance.json") - message(STATUS "Azure Sphere board selected: AVNET REV 1") -endif(AVNET) - -if(AVNET_REV_2) - MATH(EXPR BOARD_COUNTER "${BOARD_COUNTER}+1") - add_definitions( -DOEM_AVNET=TRUE ) - azsphere_target_hardware_definition(${PROJECT_NAME} TARGET_DIRECTORY "HardwareDefinitions/avnet_mt3620_sk_rev2" TARGET_DEFINITION "sample_appliance.json") - message(STATUS "Azure Sphere board selected: AVNET REV 2") -endif(AVNET_REV_2) - - -if(BOARD_COUNTER EQUAL 0) - message(FATAL_ERROR "No Azure Sphere boards selected. Ensure one board set") -endif() - -if(BOARD_COUNTER GREATER 1) - message(FATAL_ERROR "Multiple (${BOARD_COUNTER}) Azure Sphere boards selected. Ensure only one board set") -endif() - - -azsphere_target_add_image_package(${PROJECT_NAME}) \ No newline at end of file diff --git a/avnet_lightranger5/CMakeSettings.json b/avnet_lightranger5/CMakeSettings.json deleted file mode 100644 index 004e70d..0000000 --- a/avnet_lightranger5/CMakeSettings.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "environments": [ - { - "environment": "AzureSphere" - } - ], - "configurations": [ - { - "name": "ARM-Debug", - "generator": "Ninja", - "configurationType": "Debug", - "inheritEnvironments": [ - "AzureSphere" - ], - "buildRoot": "${projectDir}\\out\\${name}", - "installRoot": "${projectDir}\\out\\${name}", - "cmakeToolchain": "${env.AzureSphereDefaultSDKDir}CMakeFiles\\AzureSphereToolchain.cmake", - "buildCommandArgs": "-v", - "ctestCommandArgs": "", - "variables": [ - { - "name": "AZURE_SPHERE_TARGET_API_SET", - "value": "latest-lts" - } - ] - }, - { - "name": "ARM-Release", - "generator": "Ninja", - "configurationType": "Release", - "inheritEnvironments": [ - "AzureSphere" - ], - "buildRoot": "${projectDir}\\out\\${name}", - "installRoot": "${projectDir}\\out\\${name}", - "cmakeToolchain": "${env.AzureSphereDefaultSDKDir}CMakeFiles\\AzureSphereToolchain.cmake", - "buildCommandArgs": "-v", - "ctestCommandArgs": "", - "variables": [ - { - "name": "AZURE_SPHERE_TARGET_API_SET", - "value": "latest-lts" - } - ] - } - ] -} diff --git a/avnet_lightranger5/README.md b/avnet_lightranger5/README.md deleted file mode 100644 index c95b1c3..0000000 --- a/avnet_lightranger5/README.md +++ /dev/null @@ -1,17 +0,0 @@ -# Azure IoT Starter Project (empty) - -This is an empty (starter) project that can be used for new Azure Sphere applications based on the DevX library. The project connects to an Azure IoTHub, -IoTCentral, or Avnet's IoTConnect and nothing more. Use the other examples in this folder to help you see how to build out the project to meet your requirements. Search the project for "TODO" to see where to add definitions, declarations and code. -## Config app_manifest.json sample - -1. Set ID Scope -1. Set Allowed connections -1. Set DeviceAuthentication - -For more information refer to: - -1. [Adding the Azure Sphere DevX library](https://github.com/gloveboxes/AzureSphereDevX/wiki/Adding-the-DevX-Library) -1. [Azure Messaging](https://github.com/gloveboxes/AzureSphereDevX/wiki/IoT-Hub-Sending-messages) -1. [Device Twins](https://github.com/gloveboxes/AzureSphereDevX/wiki/IoT-Hub-Device-Twins) -1. [Direct Methods](https://github.com/gloveboxes/AzureSphereDevX/wiki/IoT-Hub-Direct-Methods) -1. [GPIO](https://github.com/gloveboxes/AzureSphereDevX/wiki/Working-with-GPIO) diff --git a/avnet_lightranger5/app_exit_codes.h b/avnet_lightranger5/app_exit_codes.h deleted file mode 100644 index f9b6a1c..0000000 --- a/avnet_lightranger5/app_exit_codes.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -/* Copyright (c) Microsoft Corporation. All rights reserved. - Licensed under the MIT License. */ - -/// -/// Exit codes for this application. Application exit codes -/// must be between 1 and 149, where 0 is reserved for successful -// termination. dx_exit_codes.h owns/defines exit codes 0 and -/// 150 - 254. -/// -typedef enum { - APP_ExitCode_Telemetry_Buffer_Too_Small = 1 -} App_Exit_Code; \ No newline at end of file diff --git a/avnet_lightranger5/app_manifest.json b/avnet_lightranger5/app_manifest.json deleted file mode 100644 index c119d6b..0000000 --- a/avnet_lightranger5/app_manifest.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "SchemaVersion": 1, - "Name": "avnet_lightranger5_TMF8801_HLApp-V1", - "ComponentId": "b8f5931e-173a-40f5-a4f8-3d98240f53ec", - "EntryPoint": "/bin/app", - "CmdArgs": [ "--ScopeID", "0ne00000000" ], - "Capabilities": { - "Gpio": [], - "Pwm": [ "$SAMPLE_LED_PWM_CONTROLLER" ], - "AllowedConnections": [ "global.azure-devices-provisioning.net", - "YOUR_IOT_HUB-HOSTNAME.azure-devices.net"], - "DeviceAuthentication": "00000000-0000-0000-0000-000000000000", - "AllowedApplicationConnections": [ "f6768b9a-e086-4f5a-8219-5ffe9684b001" ] - }, - "ApplicationType": "Default" -} diff --git a/avnet_lightranger5/applibs_versions.h b/avnet_lightranger5/applibs_versions.h deleted file mode 100644 index 22f5880..0000000 --- a/avnet_lightranger5/applibs_versions.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -/// -/// This identifier should be defined before including any of the networking-related header files. -/// It indicates which version of the Wi-Fi data structures the application uses. -/// -#define NETWORKING_STRUCTS_VERSION 1 - -/// -/// This identifier must be defined before including any of the Wi-Fi related header files. -/// It indicates which version of the Wi-Fi data structures the application uses. -/// -#define WIFICONFIG_STRUCTS_VERSION 1 - -/// -/// This identifier must be defined before including any of the UART-related header files. -/// It indicates which version of the UART data structures the application uses. -/// -#define UART_STRUCTS_VERSION 1 - -/// -/// This identifier must be defined before including any of the SPI-related header files. -/// It indicates which version of the SPI data structures the application uses. -/// -#define SPI_STRUCTS_VERSION 1 \ No newline at end of file diff --git a/avnet_lightranger5/azsphere_board.txt b/avnet_lightranger5/azsphere_board.txt deleted file mode 100644 index 011bb0e..0000000 --- a/avnet_lightranger5/azsphere_board.txt +++ /dev/null @@ -1,7 +0,0 @@ -# Select your developer board by removing the # tag from the beginning of the line -# If you are NOT using the AVNET Revision 1 board be sure to comment out the AVNET board - -# set(AVNET TRUE "AVNET Azure Sphere Starter Kit Revision 1") -set(AVNET_REV_2 TRUE "AVNET Azure Sphere Starter Kit Revision 2") -# set(SEEED_STUDIO_RDB TRUE "Seeed Studio Azure Sphere MT3620 Development Kit (aka Reference Design Board or RDB)") -# set(SEEED_STUDIO_MINI TRUE "Seeed Studio Azure Sphere MT3620 Mini Dev Board") \ No newline at end of file diff --git a/avnet_lightranger5/launch.vs.json b/avnet_lightranger5/launch.vs.json deleted file mode 100644 index 09ab6f1..0000000 --- a/avnet_lightranger5/launch.vs.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "version": "0.2.1", - "defaults": {}, - "configurations": [ - { - "type": "azurespheredbg", - "name": "GDB Debugger (HLCore)", - "project": "CMakeLists.txt", - "inheritEnvironments": [ - "AzureSphere" - ], - "customLauncher": "AzureSphereLaunchOptions", - "workingDirectory": "${workspaceRoot}", - "applicationPath": "${debugInfo.target}", - "imagePath": "${debugInfo.targetImage}", - "targetCore": "HLCore", - "targetApiSet": "${env.AzureSphereTargetApiSet}", - "partnerComponents": [ "f6768b9a-e086-4f5a-8219-5ffe9684b001" ] - } - ] -} diff --git a/avnet_lightranger5/lightranger5_click.h b/avnet_lightranger5/lightranger5_click.h deleted file mode 100644 index 03748d1..0000000 --- a/avnet_lightranger5/lightranger5_click.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -/* Copyright (c) Avnet Incorporated. All rights reserved. - Licensed under the MIT License. */ - -#define JSON_STRING_MAX_SIZE 100 - -// Define the different messages IDs we can send to real time applications -// If this enum is changed, it also needs to be changed for the high level application -typedef enum -{ - IC_LIGHTRANGER5_CLICK_UNKNOWN, - IC_LIGHTRANGER5_CLICK_HEARTBEAT, - IC_LIGHTRANGER5_CLICK_READ_SENSOR_RESPOND_WITH_TELEMETRY, - IC_LIGHTRANGER5_CLICK_SET_AUTO_TELEMETRY_RATE, - IC_LIGHTRANGER5_CLICK_READ_SENSOR -} INTER_CORE_CMD_LIGHTRANGER5_CLICK; -typedef uint8_t cmdType; - -// Define the expected data structure. -typedef struct __attribute__((packed)) -{ - uint8_t cmd; - uint32_t telemtrySendRate; - //////////////////////////////////////////////////////////////////////////////////////// - // Don't change the declarations above or the generic RTApp implementation will break // - //////////////////////////////////////////////////////////////////////////////////////// -} IC_COMMAND_BLOCK_LIGHTRANGER5_CLICK_HL_TO_RT; - -typedef struct __attribute__((packed)) -{ - uint8_t cmd; - uint32_t telemtrySendRate; - char telemetryJSON[JSON_STRING_MAX_SIZE]; - //////////////////////////////////////////////////////////////////////////////////////// - // Don't change the declarations above or the generic RTApp implementation will break // - //////////////////////////////////////////////////////////////////////////////////////// - int range_mm; -} IC_COMMAND_BLOCK_LIGHTRANGER5_CLICK_RT_TO_HL; diff --git a/avnet_lightranger5/main.c b/avnet_lightranger5/main.c deleted file mode 100644 index ab2da75..0000000 --- a/avnet_lightranger5/main.c +++ /dev/null @@ -1,342 +0,0 @@ -/* Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. - * - * This example is built on the Azure Sphere DevX library. - * 1. DevX is an Open Source community-maintained implementation of the Azure Sphere SDK samples. - * 2. DevX is a modular library that simplifies common development scenarios. - * - You can focus on your solution, not the plumbing. - * 3. DevX documentation is maintained at https://github.com/gloveboxes/AzureSphereDevX/wiki - * 4. The DevX library is not a substitute for understanding the Azure Sphere SDK Samples. - * - https://github.com/Azure/azure-sphere-samples - * - * DEVELOPER BOARD SELECTION - * - * The following developer boards are supported. - * - * 1. AVNET Azure Sphere Starter Kit. - * 2. AVNET Azure Sphere Starter Kit Revision 2. - * 3. Seeed Studio Azure Sphere MT3620 Development Kit aka Reference Design Board or rdb. - * 4. Seeed Studio Seeed Studio MT3620 Mini Dev Board. - * - * ENABLE YOUR DEVELOPER BOARD - * - * Each Azure Sphere developer board manufacturer maps pins differently. You need to select the - * configuration that matches your board. - * - * Follow these steps: - * - * 1. Open CMakeLists.txt. - * 2. Uncomment the set command that matches your developer board. - * 3. Click File, then Save to auto-generate the CMake Cache. - * - * How to use this sample - * - * Developers can use this sample as a starting point for their DevX based Azure Sphere - * application. It will connect to an Azure IoTHub, IOTCentral or Avnet's IoTConnect. - * - * There are sections marked with "TODO" that the developer can review for hints on where - * to add code, or to enable code that may be needed for general support, such as sending - * telemetry. - * - ************************************************************************************************/ -#include "main.h" - -static int closeRange = DEFAULT_CLOSE_RANGE; -static int mediumRange = DEFAULT_MEDIUM_RANGE; -static int farRange = DEFAULT_FAR_RANGE; - -static int lastRangeMeasurement = -1; - -/**************************************************************************************** - * Implementation - ****************************************************************************************/ -//static DX_DECLARE_DEVICE_TWIN_HANDLER(dt_set_sensor_polling_period_ms); - -static DX_DEVICE_TWIN_HANDLER(dt_red_led_set_limit, deviceTwinBinding) -{ - // validate data is sensible range before applying. - if (deviceTwinBinding->twinType == DX_DEVICE_TWIN_INT && - *(int *)deviceTwinBinding->propertyValue >= MIN_CLOSE_RANGE && - *(int *)deviceTwinBinding->propertyValue < mediumRange) { - - closeRange = *(int *)deviceTwinBinding->propertyValue; - - dx_deviceTwinAckDesiredValue(deviceTwinBinding, deviceTwinBinding->propertyValue, - DX_DEVICE_TWIN_RESPONSE_COMPLETED); - - } else { - dx_deviceTwinAckDesiredValue(deviceTwinBinding, deviceTwinBinding->propertyValue, - DX_DEVICE_TWIN_RESPONSE_ERROR); - } -} -DX_DEVICE_TWIN_HANDLER_END - -static DX_DEVICE_TWIN_HANDLER(dt_blue_led_set_limit, deviceTwinBinding) -{ - // validate data is sensible range before applying - if (deviceTwinBinding->twinType == DX_DEVICE_TWIN_INT && - *(int *)deviceTwinBinding->propertyValue >=closeRange && - *(int *)deviceTwinBinding->propertyValue < farRange) { - - mediumRange = *(int *)deviceTwinBinding->propertyValue; - - dx_deviceTwinAckDesiredValue(deviceTwinBinding, deviceTwinBinding->propertyValue, - DX_DEVICE_TWIN_RESPONSE_COMPLETED); - - } else { - dx_deviceTwinAckDesiredValue(deviceTwinBinding, deviceTwinBinding->propertyValue, - DX_DEVICE_TWIN_RESPONSE_ERROR); - } -} -DX_DEVICE_TWIN_HANDLER_END - -static DX_DEVICE_TWIN_HANDLER(dt_green_led_set_limit, deviceTwinBinding) -{ - // validate data is sensible range before applying - if (deviceTwinBinding->twinType == DX_DEVICE_TWIN_INT && - *(int *)deviceTwinBinding->propertyValue > mediumRange && - *(int *)deviceTwinBinding->propertyValue < FAR_RANGE_MAX) { - - farRange = *(int *)deviceTwinBinding->propertyValue; - - dx_deviceTwinAckDesiredValue(deviceTwinBinding, deviceTwinBinding->propertyValue, - DX_DEVICE_TWIN_RESPONSE_COMPLETED); - - } else { - dx_deviceTwinAckDesiredValue(deviceTwinBinding, deviceTwinBinding->propertyValue, - DX_DEVICE_TWIN_RESPONSE_ERROR); - } -} -DX_DEVICE_TWIN_HANDLER_END - -static DX_DEVICE_TWIN_HANDLER(dt_set_sensor_polling_period_ms, deviceTwinBinding) -{ - - // validate data is sensible range before applying. - if (deviceTwinBinding->twinType == DX_DEVICE_TWIN_INT && - *(int *)deviceTwinBinding->propertyValue >= MIN_POLL_TIME_MS && - *(int *)deviceTwinBinding->propertyValue <= MAX_POLL_TIME_MS) { - - // Break the ms value int seconds and ms for the timespec struct - int seconds = (int)(*(int *)deviceTwinBinding->propertyValue/1000); - int ms = (long)(*(int *)deviceTwinBinding->propertyValue) - (seconds * 1000); - - dx_timerChange(&readSensorTimer, &(struct timespec){seconds, ms * ONE_MS}); - - dx_deviceTwinAckDesiredValue(deviceTwinBinding, deviceTwinBinding->propertyValue, - DX_DEVICE_TWIN_RESPONSE_COMPLETED); - - } else { - dx_deviceTwinAckDesiredValue(deviceTwinBinding, deviceTwinBinding->propertyValue, - DX_DEVICE_TWIN_RESPONSE_ERROR); - } -} -DX_DEVICE_TWIN_HANDLER_END - -static DX_DEVICE_TWIN_HANDLER(dt_set_telemetemetry_period_seconds, deviceTwinBinding) -{ - - // validate data is sensible range before applying. - if (deviceTwinBinding->twinType == DX_DEVICE_TWIN_INT && - *(int *)deviceTwinBinding->propertyValue >= MIN_TELEMETRY_TX_PERIOD && - *(int *)deviceTwinBinding->propertyValue <= MAX_TELEMETRY_TX_PERIOD) { - - dx_timerChange(&sendTelemetryTimer, &(struct timespec){ *(int *)deviceTwinBinding->propertyValue, 0}); - - dx_deviceTwinAckDesiredValue(deviceTwinBinding, deviceTwinBinding->propertyValue, - DX_DEVICE_TWIN_RESPONSE_COMPLETED); - - } else { - dx_deviceTwinAckDesiredValue(deviceTwinBinding, deviceTwinBinding->propertyValue, - DX_DEVICE_TWIN_RESPONSE_ERROR); - } -} -DX_DEVICE_TWIN_HANDLER_END - - -// Using the rangeStatus value, turn on/off the range indication LEDs -static void setPwmStatusLed(RGB_Status rangeStatus, int range) -{ - static RGB_Status lastRangeStatus = RGB_INVALID; - static int lastRange = -1; - uint32_t dutyCycle = 100; - - // Nothing to see here folks, move along . . . - if((lastRangeStatus == rangeStatus) && (lastRange == range)){ - return; - } - - // Update the local static variables - lastRangeStatus = rangeStatus; - lastRange = range; - - // Turn off all the LED's then set the LED corresponding to the range status - // Turn off RGBLED - 100% duty cycle is off - dx_pwmSetDutyCycle(&pwm_red_led, 1000, 100); - dx_pwmSetDutyCycle(&pwm_green_led, 1000, 100); - dx_pwmSetDutyCycle(&pwm_blue_led, 1000, 100); - - switch (rangeStatus) - { - case RGB_OUT_OF_RANGE: - break; // Leave the LEDs off - case RGB_CLOSE: // Red LED - dutyCycle = (uint32_t)((float)(range-0)/(float)(closeRange-0)*100); - dx_pwmSetDutyCycle(&pwm_red_led, 1000, dutyCycle); - break; - case RGB_MEDIUM: // Blue LED - dutyCycle = (uint32_t)(((float)(range-closeRange)/(float)(mediumRange - closeRange))*100); - dx_pwmSetDutyCycle(&pwm_blue_led, 1000, dutyCycle); - break; - case RGB_FAR: // Green LED - dutyCycle = (uint32_t)(((float)(range-mediumRange)/(float)(farRange - mediumRange))*100); - dx_pwmSetDutyCycle(&pwm_green_led, 1000, dutyCycle); - break; - case RGB_INVALID: - default: - break; - } -} - -/// -/// receive_msg_handler() -/// This handler is called when the high level application receives a raw data read response from the -/// Thermo CLICK real time application. -/// -static void receive_msg_handler(void *data_block, ssize_t message_length) -{ - - // Cast the data block so we can index into the data - IC_COMMAND_BLOCK_LIGHTRANGER5_CLICK_RT_TO_HL *messageData = (IC_COMMAND_BLOCK_LIGHTRANGER5_CLICK_RT_TO_HL*) data_block; - - switch (messageData->cmd) { - case IC_LIGHTRANGER5_CLICK_READ_SENSOR: - - if(messageData->range_mm == -1){ - setPwmStatusLed(RGB_OUT_OF_RANGE, messageData->range_mm); - } - else{ - if(messageData->range_mm <= closeRange){ - setPwmStatusLed(RGB_CLOSE, messageData->range_mm); - } - else if (messageData->range_mm <= mediumRange){ - setPwmStatusLed(RGB_MEDIUM, messageData->range_mm); - } - else if (messageData->range_mm <= farRange){ - setPwmStatusLed(RGB_FAR, messageData->range_mm); - } - else{ - setPwmStatusLed(RGB_OUT_OF_RANGE, messageData->range_mm); - } - } - - // Capture the last measurement in the global variable - lastRangeMeasurement = messageData->range_mm; - - break; - // Handle the other cases by doing nothing - case IC_LIGHTRANGER5_CLICK_HEARTBEAT: - case IC_LIGHTRANGER5_CLICK_READ_SENSOR_RESPOND_WITH_TELEMETRY: - case IC_LIGHTRANGER5_CLICK_SET_AUTO_TELEMETRY_RATE: - case IC_LIGHTRANGER5_CLICK_UNKNOWN: - default: - break; - } -} - -/// -/// Periodic timer to read the TMF8801 sensor -/// -static DX_TIMER_HANDLER(ReadSensorHandler) -{ - //Code to read the sensor data in your application - // reset inter-core block - memset(&ic_tx_block, 0x00, sizeof(IC_COMMAND_BLOCK_LIGHTRANGER5_CLICK_HL_TO_RT)); - - // Send read sensor message to realtime core app one - ic_tx_block.cmd = IC_LIGHTRANGER5_CLICK_READ_SENSOR; - dx_intercorePublish(&intercore_lightranger5_click_binding, &ic_tx_block, - sizeof(IC_COMMAND_BLOCK_LIGHTRANGER5_CLICK_HL_TO_RT)); -} -DX_TIMER_HANDLER_END - -/// -/// Periodic timer to read the TMF8801 sensor -/// -static DX_TIMER_HANDLER(SendTelemetryHandler) -{ - - snprintf(msgBuffer, sizeof(msgBuffer), "{\"rangeData\":%d}", lastRangeMeasurement); - Log_Debug("%s\n", msgBuffer); - - if(dx_isAzureConnected()){ - dx_azurePublish(msgBuffer, strlen(msgBuffer), messageProperties, NELEMS(messageProperties), &contentProperties); - } -} -DX_TIMER_HANDLER_END - -/// -/// Initialize peripherals, device twins, direct methods, timer_bindings. -/// -static void InitPeripheralsAndHandlers(void) -{ -#ifdef USE_AVNET_IOTCONNECT - dx_avnetConnect(&dx_config, NETWORK_INTERFACE); -#else - // TODO, to connect this application to Azure, remove the comment - // specifier below and update the app_manifest.json file with the details - // for your Azure resources and Azure Sphere tenant. - //dx_azureConnect(&dx_config, NETWORK_INTERFACE, IOT_PLUG_AND_PLAY_MODEL_ID); -#endif - - dx_gpioSetOpen(gpio_bindings, NELEMS(gpio_bindings)); - dx_timerSetStart(timer_bindings, NELEMS(timer_bindings)); - dx_deviceTwinSubscribe(device_twin_bindings, NELEMS(device_twin_bindings)); - dx_directMethodSubscribe(direct_method_bindings, NELEMS(direct_method_bindings)); - dx_intercoreConnect(&intercore_lightranger5_click_binding); - dx_pwmSetOpen(pwm_bindings, NELEMS(pwm_bindings)); - - // Turn off RGBLED - 100% duty cycle is off - dx_pwmSetDutyCycle(&pwm_red_led, 1000, 100); - dx_pwmSetDutyCycle(&pwm_green_led, 1000, 100); - dx_pwmSetDutyCycle(&pwm_blue_led, 1000, 100); - - Log_Debug("Lightranger5 Demo Starting . . . \n"); -} - -/// -/// Close peripherals and handlers. -/// -static void ClosePeripheralsAndHandlers(void) -{ - dx_timerSetStop(timer_bindings, NELEMS(timer_bindings)); - dx_pwmSetClose(pwm_bindings, NELEMS(pwm_bindings)); - dx_deviceTwinUnsubscribe(); - dx_directMethodUnsubscribe(); - dx_gpioSetClose(gpio_bindings, NELEMS(gpio_bindings)); - dx_timerEventLoopStop(); -} - -int main(int argc, char *argv[]) -{ - dx_registerTerminationHandler(); - - if (!dx_configParseCmdLineArguments(argc, argv, &dx_config)) { - return dx_getTerminationExitCode(); - } - - InitPeripheralsAndHandlers(); - - // Main loop - while (!dx_isTerminationRequired()) { - int result = EventLoop_Run(dx_timerGetEventLoop(), -1, true); - // Continue if interrupted by signal, e.g. due to breakpoint being set. - if (result == -1 && errno != EINTR) { - dx_terminate(DX_ExitCode_Main_EventLoopFail); - } - } - - ClosePeripheralsAndHandlers(); - Log_Debug("Application exiting.\n"); - return dx_getTerminationExitCode(); -} \ No newline at end of file diff --git a/avnet_lightranger5/main.h b/avnet_lightranger5/main.h deleted file mode 100644 index 2c375f4..0000000 --- a/avnet_lightranger5/main.h +++ /dev/null @@ -1,161 +0,0 @@ - -#include "hw/sample_appliance.h" // Hardware definition -#include "app_exit_codes.h" -#include "dx_azure_iot.h" -#include "dx_config.h" -#include "dx_json_serializer.h" -#include "dx_terminate.h" -#include "dx_timer.h" -#include "dx_utilities.h" -#include "dx_direct_methods.h" -#include "dx_version.h" -#include "dx_config.h" -#include "dx_gpio.h" -#include "dx_pwm.h" -#include -#include -#include "dx_intercore.h" -#include "lightranger5_click.h" -#include "dx_uart.h" - -// Use main.h to define all your application definitions, message properties/contentProperties, -// bindings and binding sets. - -// https://docs.microsoft.com/en-us/azure/iot-pnp/overview-iot-plug-and-play -#define IOT_PLUG_AND_PLAY_MODEL_ID "dtmi:amsTmf8801Workshop:SphereTMF8801_5eg;1" - -// Details on how to connect your application using an ethernet adaptor -// https://docs.microsoft.com/en-us/azure-sphere/network/connect-ethernet -#define NETWORK_INTERFACE "wlan0" - -#define SAMPLE_VERSION_NUMBER "1.0" -#define ONE_MS 1000000 -#define ONE_HUNDRED_MS 100000000 - -#define DEFAULT_SENSOR_POLL_PERIOD_SECONDS 0 -#define DEFAULT_SENSOR_POLL_PERIOD_MS (ONE_MS * 50) - -#define DEFAULT_SEND_TELEMETRY_PERIOD_SECONDS 5 - -#define MIN_POLL_TIME_MS 20 -#define MAX_POLL_TIME_MS 60*1000 // 1 Minute - -#define MIN_TELEMETRY_TX_PERIOD 1 -#define MAX_TELEMETRY_TX_PERIOD (60*60) // 1 Hour - -#define DEFAULT_CLOSE_RANGE 100 -#define DEFAULT_MEDIUM_RANGE 200 -#define DEFAULT_FAR_RANGE 300 - -#define MIN_CLOSE_RANGE 30 -#define FAR_RANGE_MAX 500 - -DX_USER_CONFIG dx_config; - -/**************************************************************************************** - * Avnet IoTConnect Support - ****************************************************************************************/ -// TODO: If the application will connect to Avnet's IoTConnect platform enable the -// #define below -//#define USE_AVNET_IOTCONNECT - -/**************************************************************************************** - * Application defines - ****************************************************************************************/ -typedef enum { - RGB_INVALID = 0, - RGB_OUT_OF_RANGE, - RGB_CLOSE, - RGB_MEDIUM, - RGB_FAR -} RGB_Status; - -/**************************************************************************************** - * Forward declarations - ****************************************************************************************/ -static void receive_msg_handler(void *data_block, ssize_t message_length); -static DX_DECLARE_TIMER_HANDLER(ReadSensorHandler); -static DX_DECLARE_TIMER_HANDLER(SendTelemetryHandler); -static DX_DECLARE_DEVICE_TWIN_HANDLER(dt_red_led_set_limit); -static DX_DECLARE_DEVICE_TWIN_HANDLER(dt_blue_led_set_limit); -static DX_DECLARE_DEVICE_TWIN_HANDLER(dt_green_led_set_limit); -static DX_DECLARE_DEVICE_TWIN_HANDLER(dt_set_sensor_polling_period_ms); -static DX_DECLARE_DEVICE_TWIN_HANDLER(dt_set_telemetemetry_period_seconds); - -IC_COMMAND_BLOCK_LIGHTRANGER5_CLICK_HL_TO_RT ic_tx_block; -IC_COMMAND_BLOCK_LIGHTRANGER5_CLICK_RT_TO_HL ic_rx_block; - -/**************************************************************************************** - * Telemetry message buffer property sets - ****************************************************************************************/ - -// Number of bytes to allocate for the JSON telemetry message for IoT Hub/Central -#define JSON_MESSAGE_BYTES 32 -static char msgBuffer[JSON_MESSAGE_BYTES] = {0}; - -static DX_MESSAGE_PROPERTY *messageProperties[] = {&(DX_MESSAGE_PROPERTY){.key = "appid", .value = "TMF8801"}, - &(DX_MESSAGE_PROPERTY){.key = "type", .value = "telemetry"}, - &(DX_MESSAGE_PROPERTY){.key = "schema", .value = "1"}}; - -static DX_MESSAGE_CONTENT_PROPERTIES contentProperties = {.contentEncoding = "utf-8", .contentType = "application/json"}; - -/**************************************************************************************** - * Bindings - ****************************************************************************************/ -DX_INTERCORE_BINDING intercore_lightranger5_click_binding = { - .sockFd = -1, - .nonblocking_io = true, - .rtAppComponentId = "f6768b9a-e086-4f5a-8219-5ffe9684b001", - .interCoreCallback = receive_msg_handler, - .intercore_recv_block = &ic_rx_block, - .intercore_recv_block_length = sizeof(IC_COMMAND_BLOCK_LIGHTRANGER5_CLICK_RT_TO_HL)}; - -static DX_TIMER_BINDING readSensorTimer = { - .repeat = &(struct timespec){DEFAULT_SENSOR_POLL_PERIOD_SECONDS, DEFAULT_SENSOR_POLL_PERIOD_MS}, - .name = "readSensorTimer", .handler = ReadSensorHandler}; - -static DX_TIMER_BINDING sendTelemetryTimer = { - .repeat = &(struct timespec){DEFAULT_SEND_TELEMETRY_PERIOD_SECONDS, 0}, - .name = "sendTelemetryTimer", .handler = SendTelemetryHandler}; - -static DX_PWM_CONTROLLER pwm_led_controller = {.controllerId = SAMPLE_LED_PWM_CONTROLLER, - .name = "PWM Click Controller"}; - -static DX_PWM_BINDING pwm_red_led = { - .pwmController = &pwm_led_controller, .channelId = 0, .name = "red_led"}; -static DX_PWM_BINDING pwm_green_led = { - .pwmController = &pwm_led_controller, .channelId = 1, .name = "green led"}; -static DX_PWM_BINDING pwm_blue_led = { - .pwmController = &pwm_led_controller, .channelId = 2, .name = "blue led"}; - -static DX_DEVICE_TWIN_BINDING dt_red_limit = {.propertyName = "redLimit_mm", - .twinType = DX_DEVICE_TWIN_INT, - .handler = dt_red_led_set_limit}; - -static DX_DEVICE_TWIN_BINDING dt_green_limit = {.propertyName = "greenLimit_mm", - .twinType = DX_DEVICE_TWIN_INT, - .handler = dt_green_led_set_limit}; - -static DX_DEVICE_TWIN_BINDING dt_blue_limit = {.propertyName = "blueLimit_mm", - .twinType = DX_DEVICE_TWIN_INT, - .handler = dt_blue_led_set_limit}; - -static DX_DEVICE_TWIN_BINDING dt_desired_sample_rate_ms = {.propertyName = "sensorPollPeriod_ms", - .twinType = DX_DEVICE_TWIN_INT, - .handler = dt_set_sensor_polling_period_ms}; - -static DX_DEVICE_TWIN_BINDING dt_telemetry_tx_period_s = {.propertyName = "setTelemetrySendPeriod_seconds", - .twinType = DX_DEVICE_TWIN_INT, - .handler = dt_set_telemetemetry_period_seconds}; - - -/**************************************************************************************** - * Binding sets - ****************************************************************************************/ -DX_DEVICE_TWIN_BINDING *device_twin_bindings[] = {&dt_red_limit, &dt_green_limit, &dt_blue_limit, - &dt_desired_sample_rate_ms, - &dt_telemetry_tx_period_s}; -DX_DIRECT_METHOD_BINDING *direct_method_bindings[] = {}; -DX_GPIO_BINDING *gpio_bindings[] = {}; -DX_TIMER_BINDING *timer_bindings[] = {&readSensorTimer, &sendTelemetryTimer}; -static DX_PWM_BINDING *pwm_bindings[] = {&pwm_red_led, &pwm_green_led, &pwm_blue_led};