[{"element_type":"image_url","content":"https://hackster.imgix.net/uploads/attachments/1623069/image_h1qXicdZFB.png?auto=compress%2Cformat\u0026w=740\u0026h=555\u0026fit=max","metadata":{"alt":"Test2","caption":""}},{"element_type":"image_url","content":"https://hackster.imgix.net/uploads/attachments/1623070/image_kWIJSbWcq7.png?auto=compress%2Cformat\u0026w=740\u0026h=555\u0026fit=max","metadata":{"alt":"Test1","caption":""}},{"element_type":"product","content":"https://www.adafruit.com/product/63","metadata":{}},{"element_type":"product","content":"https://www.adafruit.com/product/824","metadata":{}},{"element_type":"product","content":"https://www.adafruit.com/product/155","metadata":{}},{"element_type":"embed","content":"https://www.youtube.com/watch?v=TTemPlQt_nI"},{"element_type":"text","content":"\n  \n        \u003cp\u003eMake a robot that reacts to gestures by waving its arms in a cheer!\u003c/p\u003e\n\u003ch2 id=\"toc-introduction-0\" class=\"hckui__typography__h3 title-with-anchor\"\u003e\u003cstrong\u003eIntroduction:\u003c/strong\u003e\u003c/h2\u003e\n\u003cp class=\"hckui__typography__bodyL\"\u003eIn this project, we aim to create an interactive paper robot using Hexabitz modules. The robot will be equipped with a servo motor and a motion sensor, enabling it to move its arms and wave in response to any movement detected by the sensor. By combining the versatility of Hexabitz with the simplicity of paper, we hope to create a fun and engaging DIY project that showcases the potential of modular robotics. Whether you're a beginner or an experienced maker, this project is sure to provide a rewarding challenge and a unique addition to your robotics collection. So let's get started and bring this interactive paper robot to life!\u003c/p\u003e\n\u003ch2 class=\"hckui__typography__bodyL\"\u003e\u003cstrong\u003eTools:\u003c/strong\u003e\u003c/h2\u003e\n\u003cp class=\"hckui__typography__bodyL\"\u003eThe DIY interactive paper robot with Hexabitz is a project aimed at designing a paper robot for children using servo motors and motion sensors. The robot is capable of moving its arms and waving whenever any movement is detected in front of the sensor.\u003c/p\u003e\n\u003cp class=\"hckui__typography__bodyL\"\u003eThis project combines creativity, engineering, and technology to create an interactive and engaging experience for children. By using simple materials like paper and basic electronic components, we can build a fun and educational toy that encourages children to explore the world of robotics.\u003c/p\u003e\n\u003cp class=\"hckui__typography__bodyL\"\u003eThe main components used in this project are servo motor, which allow the robot's arms to move in different directions, and a motion sensor that detects any movement in its vicinity.\u003c/p\u003e\n\u003cp class=\"hckui__typography__bodyL\"\u003eThe DIY interactive paper robot not only introduces children to basic robotics concepts but also encourages them to think creatively and problem-solve. They can customize their robots by decorating them with colors, patterns, or even adding additional features like LED lights or sound effects.\u003c/p\u003e\n\u003cp class=\"hckui__typography__bodyL\"\u003eThrough this project, children will learn about basic electronics, coding, and how different components work together to create a functional robot. It provides an opportunity for hands-on learning and fosters curiosity and imagination.\u003c/p\u003e\n\u003ch2 class=\"hckui__typography__bodyL\"\u003e\u003cstrong\u003eHow I build it 🛠️\u003c/strong\u003e\u003c/h2\u003e\n\u003ch3 id=\"toc-step-1--plan-the-array-and-assemble-the-hardware-3\" class=\"hckui__typography__h3 title-with-anchor\"\u003e\u003cstrong\u003eStep 1: Plan the array and assemble the hardware\u003c/strong\u003e\u003c/h3\u003e\n\u003cp class=\"hckui__typography__bodyL\"\u003e\u003cspan\u003eWe prepare the project components and plan our array design by aligning modules side-by-side.\u003c/span\u003e\u003c/p\u003e\n\u003cp class=\"hckui__typography__bodyL\"\u003e\u003cspan\u003eCheerBot Template: If you need to print CheerBot templates, you can download them here: \u003c/span\u003e\u003ca class=\"hckui__typography__linkBlue\" href=\"https://www.okdo.com/p/okdo-microbit-build-a-paper-robot-kit\"\u003ehttps://www.okdo.com/p/okdo-microbit-build-a-paper-robot-kit\u003c/a\u003e\u003c/p\u003e\n\u003ch3 id=\"toc-step-2--writing-codes-with-stm32cubeide-software-4\" class=\"hckui__typography__h3 title-with-anchor\"\u003e\u003cstrong\u003eStep 2: Writing codes with STM32CubeIDE software\u003c/strong\u003e\u003c/h3\u003e\n\u003cp class=\"hckui__typography__bodyL\"\u003e\u003cstrong\u003eH0AR9x Firmware H0AR9.h code:\u003c/strong\u003e\u003c/p\u003e\n\u003cp class=\"hckui__typography__bodyL\"\u003eFirst, reduce the number of ports in the.h file. This can be achieved by replacing the original number of ports with one less, and commenting out the last port along with its related USART port and UART Init prototype. For example, if the original number of ports is 6, it should be reduced to 5 by commenting out (//#define _P6), (//#define _Usart6 1), and (//extern void MX_USART6_UART_Init(void);).\u003c/p\u003e\n\u003cp class=\"hckui__typography__bodyL\"\u003e\u003cstrong\u003eH0AR9x Firmware H0AR9.c code:\u003c/strong\u003e\u003c/p\u003e\n\u003cp class=\"hckui__typography__bodyL\"\u003eSecond, comment the MX_USART6_UART_Init() port inside the Module_Peripheral_Init() function in the.c file, also commenting this port inside GetPort function.\u003c/p\u003e\n\u003cp class=\"hckui__typography__bodyL\"\u003e\u003cstrong\u003eH0AR9x Firmware H0AR9_gpio.c code:\u003c/strong\u003e\u003c/p\u003e\n\u003cp class=\"hckui__typography__bodyL\"\u003eThird, add the instructions for configuring the pin you are going to use in H0AR9_gpio.c file.\u003c/p\u003e\n\u003cpre class=\"hljs nix\"\u003e\u003ccode\u003e\u003cspan\u003eGPIO_InitStruct.\u003cspan class=\"hljs-attr\"\u003ePin\u003c/span\u003e = GPIO_PIN_8;\u003c/span\u003e\u003cbr\u003e\u003cspan\u003eGPIO_InitStruct.\u003cspan class=\"hljs-attr\"\u003eMode\u003c/span\u003e = GPIO_MODE_OUTPUT_PP;\u003c/span\u003e\u003cbr\u003e\u003cspan\u003eGPIO_InitStruct.\u003cspan class=\"hljs-attr\"\u003ePull\u003c/span\u003e = GPIO_NOPULL;\u003c/span\u003e\u003cbr\u003e\u003cspan\u003eGPIO_InitStruct.\u003cspan class=\"hljs-attr\"\u003eSpeed\u003c/span\u003e = GPIO_SPEED_FREQ_HIGH;\u003c/span\u003e\u003cbr\u003e\u003cspan\u003eHAL_GPIO_Init(GPIOB,\u0026amp;GPIO_InitStruct);\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\n\u003cp class=\"hckui__typography__bodyL\"\u003e\u003cstrong\u003eH0AR9x Firmware main.c code:\u003c/strong\u003e\u003c/p\u003e\n\u003cp class=\"hckui__typography__bodyL\"\u003eFirst, we define the motion variable:\u003c/p\u003e\n\u003cpre class=\"hljs abnf\"\u003e\u003ccode\u003e\u003cspan\u003euint16_t prox\u003cspan class=\"hljs-comment\"\u003e;\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\n\u003cp class=\"hckui__typography__bodyL\"\u003eand then defined the other variable used in the code.\u003c/p\u003e\n\u003cpre class=\"hljs abnf\"\u003e\u003ccode\u003e\u003cspan\u003eint q\u003cspan class=\"hljs-comment\"\u003e;\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\n\u003cp class=\"hckui__typography__bodyL\"\u003e\u003cspan\u003eAnd in the repeated closed loop, we made sure that MCU periodically checks the \u003c/span\u003e\u003ccode\u003eprox\u003c/code\u003e\u003cspan\u003e value of the sensor using the API from module factsheet.\u003c/span\u003e\u003c/p\u003e\n\u003cpre class=\"hljs lisp\"\u003e\u003ccode\u003e\u003cspan\u003eSampleDistance(\u003cspan class=\"hljs-name\"\u003e\u0026amp;prox\u003c/span\u003e)\u003cspan class=\"hljs-comment\"\u003e;\u003c/span\u003e\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\n\u003cp class=\"hckui__typography__bodyL\"\u003eAnd if the motion achieves the required condition (i.e. if we wave in front of the PIR motion sensor), the servo motor is turned on at certain angles to move the robot's arms.\u003c/p\u003e\n\u003cpre class=\"hljs apache\"\u003e\u003ccode\u003e\u003cspan\u003e\u003cspan class=\"hljs-attribute\"\u003eif\u003c/span\u003e (q \u0026gt; \u003cspan class=\"hljs-number\"\u003e15\u003c/span\u003e)\u003c/span\u003e\u003cbr\u003e\u003cspan\u003e\t\tHAL_GPIO_WritePin(GPIOB, GPIO_PIN_\u003cspan class=\"hljs-number\"\u003e8\u003c/span\u003e, GPIO_PIN_SET);\u003c/span\u003e\u003cbr\u003e\u003cspan\u003e\t\tDelay_ms(\u003cspan class=\"hljs-number\"\u003e1\u003c/span\u003e.\u003cspan class=\"hljs-number\"\u003e5\u003c/span\u003e);\u003c/span\u003e\u003cbr\u003e\u003cspan\u003e\t\tHAL_GPIO_WritePin(GPIOB, GPIO_PIN_\u003cspan class=\"hljs-number\"\u003e8\u003c/span\u003e, GPIO_PIN_RESET);\u003c/span\u003e\u003cbr\u003e\u003cspan\u003e\t\tDelay_ms(\u003cspan class=\"hljs-number\"\u003e20\u003c/span\u003e);\u003c/span\u003e\u003cbr\u003e\u003cspan\u003e                HAL_GPIO_WritePin(GPIOB, GPIO_PIN_\u003cspan class=\"hljs-number\"\u003e8\u003c/span\u003e, GPIO_PIN_SET);\u003c/span\u003e\u003cbr\u003e\u003cspan\u003e                Delay_ms(\u003cspan class=\"hljs-number\"\u003e0\u003c/span\u003e.\u003cspan class=\"hljs-number\"\u003e5\u003c/span\u003e);\u003c/span\u003e\u003cbr\u003e\u003cspan\u003e\t\tHAL_GPIO_WritePin(GPIOB, GPIO_PIN_\u003cspan class=\"hljs-number\"\u003e8\u003c/span\u003e, GPIO_PIN_RESET);\u003c/span\u003e\u003cbr\u003e\u003cspan\u003e\t\tDelay_ms(\u003cspan class=\"hljs-number\"\u003e10\u003c/span\u003e);\u003c/span\u003e\u003cbr\u003e\u003cspan\u003e                HAL_GPIO_WritePin(GPIOB, GPIO_PIN_\u003cspan class=\"hljs-number\"\u003e8\u003c/span\u003e, GPIO_PIN_SET);\u003c/span\u003e\u003cbr\u003e\u003cspan\u003e                Delay_ms(\u003cspan class=\"hljs-number\"\u003e2\u003c/span\u003e.\u003cspan class=\"hljs-number\"\u003e5\u003c/span\u003e);\u003c/span\u003e\u003cbr\u003e\u003cspan\u003e\t\tHAL_GPIO_WritePin(GPIOB, GPIO_PIN_\u003cspan class=\"hljs-number\"\u003e8\u003c/span\u003e, GPIO_PIN_RESET);\u003c/span\u003e\u003cbr\u003e\u003cspan\u003e\t\tDelay_ms(\u003cspan class=\"hljs-number\"\u003e50\u003c/span\u003e);\u003c/span\u003e\u003c/code\u003e\u003c/pre\u003e\n\u003cul class=\"hckui__typography__bodyL\"\u003e\n\u003cli\u003e\n\u003cspan\u003eCheck out this project for : \u003c/span\u003e\u003ca class=\"hckui__typography__linkBlue\" href=\"https://www.hackster.io/aula-jazmati/controlling-a-servo-motor-with-raspberry-pi-and-python-gui-ad71a2\"\u003eHow is a Servo Controlled.\u003c/a\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp class=\"hckui__typography__bodyL\"\u003eNote: For this project, make sure you're using the standard 180° servo.\u003c/p\u003e\n\u003ch3 id=\"toc-step-3--test-the-system----5\" class=\"hckui__typography__h3 title-with-anchor\"\u003e\u003cstrong\u003eStep 3: Test the System 🤖👋😊\u003c/strong\u003e\u003c/h3\u003e\n\u003cp class=\"hckui__typography__bodyL\"\u003eIn conclusion, the DIY interactive paper robot with Hexabitz is an exciting project that combines art, technology, and education. It offers an engaging way for children to learn about robotics while having fun building their own unique robots. Let's dive into this project and unleash our creativity!\u003c/p\u003e\n\u003cp\u003e\u003ca href=\"https://www.youtube.com/watch?v=TTemPlQt_nI\"\u003ehttps://www.youtube.com/watch?v=QbJlmUX6kw4\u003c/a\u003e\u003c/p\u003e\n\u003cp\u003e\u003ca href=\"https://www.youtube.com/watch?v=TTemPlQt_nI\"\u003ehttps://www.youtube.com/watch?v=TTemPlQt_nI\u003c/a\u003e\u003c/p\u003e\n\u003ch3 id=\"toc-references-6\" class=\"hckui__typography__h3 title-with-anchor\"\u003e\u003cstrong\u003eReferences:\u003c/strong\u003e\u003c/h3\u003e\n\u003cul class=\"hckui__typography__bodyL\"\u003e\n\u003cli\u003e\u003ca href=\"https://www.hackster.io/aula-jazmati/make-diy-interactive-paper-robot-with-hexabitz-a015bd\"\u003ehttps://www.hackster.io/aula-jazmati/make-diy-interactive-paper-robot-with-hexabitz-a015bd\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca class=\"hckui__typography__linkBlue\" href=\"https://www.okdo.com/wp-content/uploads/2023/01/Full_Booklet_v1.pdf\"\u003ehttps://www.okdo.com/wp-content/uploads/2023/01/Full_Booklet_v1.pdf\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca class=\"hckui__typography__linkBlue\" href=\"https://www.instructables.com/Make-a-Ticklish-Robot/\"\u003ehttps://www.instructables.com/Make-a-Ticklish-Robot/\u003c/a\u003e\u003c/li\u003e\n\u003c/ul\u003e\n      \n","metadata":{}},{"element_type":"image_url","content":"https://hackster.imgix.net/uploads/attachments/1622947/image_ZsPX7JhEOn.png?auto=compress%2Cformat\u0026w=740\u0026h=555\u0026fit=max","metadata":{"alt":"How","caption":""}},{"element_type":"image_url","content":"https://hackster.imgix.net/uploads/attachments/1623062/image_UEYri629AQ.png?auto=compress%2Cformat\u0026w=740\u0026h=555\u0026fit=max","metadata":{"alt":"Inside","caption":""}},{"element_type":"image_url","content":"https://hackster.imgix.net/uploads/attachments/1623061/image_0gM5W4NMI4.png?auto=compress%2Cformat\u0026w=740\u0026h=555\u0026fit=max","metadata":{"alt":"The","caption":""}},{"element_type":"image_url","content":"https://hackster.imgix.net/uploads/attachments/1622317/image_i4actXMbEs.png?auto=compress%2Cformat\u0026w=740\u0026h=555\u0026fit=max","metadata":{"alt":"CheerBot","caption":""}},{"element_type":"image_url","content":"https://hackster.imgix.net/uploads/attachments/1623059/image_8uGVndi54q.png?auto=compress%2Cformat\u0026w=740\u0026h=555\u0026fit=max","metadata":{"alt":"The","caption":""}},{"element_type":"image_url","content":"https://hackster.imgix.net/uploads/attachments/1623245/image_M8zk6Z8xyf.png?auto=compress%2Cformat\u0026w=740\u0026h=555\u0026fit=max","metadata":{"alt":"PIR","caption":""}},{"element_type":"code","content":"/*H0AR9x-main code\n BitzOS (BOS) V0.2.9 - Copyright (C) 2017-2023 Hexabitz\n All rights reserved\n\n File Name     : main.c\n Description   : Main program body.\n */\n/* Includes ------------------------------------------------------------------*/\n#include \"BOS.h\"\nuint16_t prox;\nint q;\n\n\n/* Private function prototypes -----------------------------------------------*/\n// char *user_data = \"The application is running\\r\\n\"; //demo data for transmission-\n/* Main function ------------------------------------------------------------*/\n\nint main(void){\n\n\tModule_Init();\t\t//Initialize Module \u0026  BitzOS\n\n\t//MX_USART5_UART_Init();\n\t\t//Don't place your code here.\n\tfor(;;){}\n}\n\n/*---float H0AR9_temperature;\nfloat H0AR9_humidity;--------------------------------------------------------*/\n\n/* User Task */\nvoid UserTask(void *argument){\n\n\twhile(1){\n\tSampleDistance(\u0026prox);\n\t\tq  =prox;\n\t\tif (q \u003e 15)\n\t\tHAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_SET);\n\t\tDelay_ms(1.5);\n\t\tHAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_RESET);\n\t\tDelay_ms(20);\n    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_SET);\n    Delay_ms(0.5);\n\t\tHAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_RESET);\n\t\tDelay_ms(10);\n    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_SET);\n    Delay_ms(2.5);\n\t\tHAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_RESET);\n\t\tDelay_ms(50);\n\n\t}\n}\n\n\n\n/*-----------------------------------------------------------*/","metadata":{"language":"cpp","linenums":false}},{"element_type":"code","content":"/*H0AR9x.h\n BitzOS (BOS) V0.2.9 - Copyright (C) 2017-2023 Hexabitz\n All rights reserved\n \n File Name     : H0AR9.h\n Description   : Header file for module H0AR9.\n \t \t \t \t (Description_of_module)\n\n(Description of Special module peripheral configuration):\n\u003e\u003e\n\u003e\u003e\n\u003e\u003e\n\n */\n\n/* Define to prevent recursive inclusion -------------------------------------*/\n#ifndef H0AR9_H\n#define H0AR9_H\n\n/* Includes ------------------------------------------------------------------*/\n#include \"BOS.h\"\n#include \"H0AR9_MemoryMap.h\"\n#include \"H0AR9_uart.h\"\n#include \"H0AR9_gpio.h\"\n#include \"H0AR9_dma.h\"\n#include \"H0AR9_inputs.h\"\n#include \"H0AR9_eeprom.h\"\n#include \"H0AR9_i2c.h\"\n/* Exported definitions -------------------------------------------------------*/\n\n#define\tmodulePN\t\t_H0AR9\n\n\n/* Port-related definitions */\n#define\tNumOfPorts\t\t\t6\n\n#define P_PROG \t\t\t\tP2\t\t\t\t\t\t/* ST factory bootloader UART */\n\n/* Define available ports */\n#define _P1 \n#define _P2 \n#define _P3 \n#define _P4\n#define _P5\n//#define _P6\n\n/* Define available USARTs */\n#define _Usart1 1\n#define _Usart2 1\n#define _Usart3 1\n#define _Usart4 1\n#define _Usart5 1\n//#define _Usart6\t1\n\n\n/* Port-UART mapping */\n\n#define P1uart \u0026huart4\n#define P2uart \u0026huart2\n#define P3uart \u0026huart3\n#define P4uart \u0026huart1\n#define P5uart \u0026huart5\n//#define P6uart \u0026huart6\n\n\n/* Port Definitions */\n#define\tUSART1_TX_PIN\t\tGPIO_PIN_9\n#define\tUSART1_RX_PIN\t\tGPIO_PIN_10\n#define\tUSART1_TX_PORT\t\tGPIOA\n#define\tUSART1_RX_PORT\t\tGPIOA\n#define\tUSART1_AF\t\t\tGPIO_AF1_USART1\n\n#define\tUSART2_TX_PIN\t\tGPIO_PIN_2\n#define\tUSART2_RX_PIN\t\tGPIO_PIN_3\n#define\tUSART2_TX_PORT\t\tGPIOA\n#define\tUSART2_RX_PORT\t\tGPIOA\n#define\tUSART2_AF\t\t\tGPIO_AF1_USART2\n\n#define\tUSART3_TX_PIN\t\tGPIO_PIN_10\n#define\tUSART3_RX_PIN\t\tGPIO_PIN_11\n#define\tUSART3_TX_PORT\t\tGPIOB\n#define\tUSART3_RX_PORT\t\tGPIOB\n#define\tUSART3_AF\t\t\tGPIO_AF4_USART3\n\n#define\tUSART4_TX_PIN\t\tGPIO_PIN_0\n#define\tUSART4_RX_PIN\t\tGPIO_PIN_1\n#define\tUSART4_TX_PORT\t\tGPIOA\n#define\tUSART4_RX_PORT\t\tGPIOA\n#define\tUSART4_AF\t\t\tGPIO_AF4_USART4\n\n#define\tUSART5_TX_PIN\t\tGPIO_PIN_3\n#define\tUSART5_RX_PIN\t\tGPIO_PIN_2\n#define\tUSART5_TX_PORT\t\tGPIOD\n#define\tUSART5_RX_PORT\t\tGPIOD\n#define\tUSART5_AF\t\t\tGPIO_AF3_USART5\n\n#define\tUSART6_TX_PIN\t\tGPIO_PIN_8\n#define\tUSART6_RX_PIN\t\tGPIO_PIN_9\n#define\tUSART6_TX_PORT\t\tGPIOB\n#define\tUSART6_RX_PORT\t\tGPIOB\n#define\tUSART6_AF\t\t\tGPIO_AF8_USART6\n\n/* Module-specific Definitions */\n\n#define NUM_MODULE_PARAMS\t\t\t\t\t\t7\n#define STOP_MEASUREMENT_RANGING      0\n#define START_MEASUREMENT_RANGING     1\n/* Module EEPROM Variables */\n\n// Module Addressing Space 500 - 599\n#define _EE_MODULE\t\t\t\t\t\t\t500\t\t\n\n/* Module_Status Type Definition */\ntypedef enum\n{\n  H0AR9_OK = 0,\n  H0AR9_ERR_UnknownMessage,\n  H0AR9_ERR_RGB,\n  H0AR9_ERR_PROXIMITY,\n  H0AR9_ERR_TEMPRATURE,\n  H0AR9_ERR_HUMIDITY,\n  H0AR9_ERR_PIR,\n  H0AR9_ERR_BUSY,\n  H0AR9_ERR_TIMEOUT,\n  H0AR9_ERR_IO,\n  H0AR9_ERR_TERMINATED,\n  H0AR9_ERR_WrongParams,\n  H0AR9_ERROR = 25\n} Module_Status;\n\n/* Indicator LED */\n#define _IND_LED_PORT\t\t\tGPIOB\n#define _IND_LED_PIN\t\t\tGPIO_PIN_14\n\n/* Export UART variables */\nextern UART_HandleTypeDef huart1;\nextern UART_HandleTypeDef huart2;\nextern UART_HandleTypeDef huart3;\nextern UART_HandleTypeDef huart4;\nextern UART_HandleTypeDef huart5;\nextern UART_HandleTypeDef huart6;\n\n/* Define UART Init prototypes */\nextern void MX_USART1_UART_Init(void);\nextern void MX_USART2_UART_Init(void);\nextern void MX_USART3_UART_Init(void);\nextern void MX_USART4_UART_Init(void);\nextern void MX_USART5_UART_Init(void);\n//extern void MX_USART6_UART_Init(void);\nextern void SystemClock_Config(void);\nextern void ExecuteMonitor(void);\n\n\n/* -----------------------------------------------------------------------\n |\t\t\t\t\t\t\t\t  APIs\t\t\t\t\t\t\t          |  \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t \t|\n/* -----------------------------------------------------------------------\n */\nuint16_t Read_Word(uint8_t reg);\nvoid Error_Handler(void);\nvoid initialValue(void);\nvoid APDS9950_init(void);\nvoid WriteRegData(uint8_t reg, uint8_t data);\nvoid stopStreamMems(void);\nvoid SamplePIR(bool *pir);\nvoid SampleColor(uint16_t *Red, uint16_t *Green, uint16_t *Blue);\nvoid SampleDistance(uint16_t *Proximity);\nvoid SampleTemperature(float *temperature);\nvoid SampleHumidity(float *humidity);\nvoid SampleColorBuf(float *buffer);\nvoid SampleDistanceBuff(float *buffer);\nvoid SampleTemperatureBuf(float *buffer);\nvoid SampleHumidityBuf(float *buffer);\nvoid SamplePIRBuf(float *buffer);\nvoid SampleColorToPort(uint8_t port,uint8_t module);\nvoid SampleDistanceToPort(uint8_t port,uint8_t module);\nvoid SampleTemperatureToPort(uint8_t port,uint8_t module);\nvoid SampleHumidityToPort(uint8_t port,uint8_t module);\nvoid SamplePIRToPort(uint8_t port,uint8_t module);\nvoid SampleColorToString(char *cstring, size_t maxLen);\nvoid SampleDistanceToString(char *cstring, size_t maxLen);\nvoid SampleTemperatureToString(char *cstring, size_t maxLen);\nvoid SampleHumidityToString(char *cstring, size_t maxLen);\nvoid SamplePIRToString(char *cstring, size_t maxLen);\nModule_Status StreamColorToBuffer(float *buffer, uint32_t period, uint32_t timeout);\nModule_Status StreamDistanceToBuffer(float *buffer, uint32_t period, uint32_t timeout);\nModule_Status StreamTemperatureToBuffer(float *buffer, uint32_t period, uint32_t timeout);\nModule_Status StreamHumidityToBuffer(float *buffer, uint32_t period, uint32_t timeout);\nModule_Status StreamPIRToBuffer(float *buffer, uint32_t period, uint32_t timeout);\nModule_Status StreamColorToPort(uint8_t port, uint8_t module, uint32_t period, uint32_t timeout);\nModule_Status StreamDistanceToPort(uint8_t port, uint8_t module, uint32_t period, uint32_t timeout);\nModule_Status StreamTemperatureToPort(uint8_t port, uint8_t module, uint32_t period, uint32_t timeout);\nModule_Status StreamHumidityToPort(uint8_t port, uint8_t module, uint32_t period, uint32_t timeout);\nModule_Status StreamPIRToPort(uint8_t port, uint8_t module, uint32_t period, uint32_t timeout);\nModule_Status StreamColorToCLI(uint32_t period, uint32_t timeout);\nModule_Status StreamDistanceToCLI(uint32_t period, uint32_t timeout);\nModule_Status StreamTemperatureToCLI(uint32_t period, uint32_t timeout);\nModule_Status StreamHumidityToCLI(uint32_t period, uint32_t timeout);\nModule_Status StreamPIRToCLI(uint32_t period, uint32_t timeout);\nvoid SetupPortForRemoteBootloaderUpdate(uint8_t port);\nvoid remoteBootloaderUpdate(uint8_t src,uint8_t dst,uint8_t inport,uint8_t outport);\n\n/* -----------------------------------------------------------------------\n |\t\t\t\t\t\t\t\tCommands\t\t\t\t\t\t\t      |\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t \t|\n/* -----------------------------------------------------------------------\n */\n\n\n#endif /* H0AR9_H */\n\n/************************ (C) COPYRIGHT HEXABITZ *****END OF FILE****/","metadata":{"language":"cpp","linenums":false}},{"element_type":"code","content":"/* H0AR9x.c\n BitzOS (BOS) V0.2.9 - Copyright (C) 2017-2023 Hexabitz\n All rights reserved\n\n File Name     : H0AR9.c\n Description   : Source code for module H0AR9.\n \t \t \t \t (Description_of_module)\n\n(Description of Special module peripheral configuration):\n\u003e\u003e\n\u003e\u003e\n\u003e\u003e\n\n */\n\n/* Includes ------------------------------------------------------------------*/\n#include \"BOS.h\"\n#include \"stdio.h\"\n#include \"stdlib.h\"\n#include \"string.h\"\n#include \"H0AR9_inputs.h\"\n/* Define UART variables */\nUART_HandleTypeDef huart1;\nUART_HandleTypeDef huart2;\nUART_HandleTypeDef huart3;\nUART_HandleTypeDef huart4;\nUART_HandleTypeDef huart5;\nUART_HandleTypeDef huart6;\n\n/* Exported variables */\nextern FLASH_ProcessTypeDef pFlash;\nextern uint8_t numOfRecordedSnippets;\nextern I2C_HandleTypeDef hi2c2;\n\n/* Module exported parameters ------------------------------------------------*/\nuint8_t H0AR9_PIR;\nuint16_t H0AR9_RGBred;\nuint16_t H0AR9_RGBgreen;\nuint16_t H0AR9_RGBblue;\nuint16_t H0AR9_proximity;\nfloat H0AR9_temperature;\nfloat H0AR9_humidity;\nmodule_param_t modParam[NUM_MODULE_PARAMS] = {{.paramPtr=\u0026H0AR9_RGBred, .paramFormat=FMT_UINT16, .paramName=\"RGBred\"},\n{.paramPtr=\u0026H0AR9_RGBgreen, .paramFormat=FMT_UINT16, .paramName=\"RGBgreen\"},\n{.paramPtr=\u0026H0AR9_RGBblue,  .paramFormat=FMT_UINT16, .paramName=\"RGBblue\"},\n{.paramPtr=\u0026H0AR9_proximity, .paramFormat=FMT_UINT16, .paramName=\"proximity\"},\n{.paramPtr=\u0026H0AR9_temperature, .paramFormat=FMT_FLOAT, .paramName=\"temperature\"},\n{.paramPtr=\u0026H0AR9_humidity, .paramFormat=FMT_FLOAT, .paramName=\"humidity\"},\n{.paramPtr=\u0026H0AR9_PIR, .paramFormat=FMT_UINT8, .paramName=\"PIR\"},\n};\n\n\n\n\n#define MIN_MEMS_PERIOD_MS\t\t\t\t100\n#define MAX_MEMS_TIMEOUT_MS\t\t\t\t0xFFFFFFFF\nfloat H0AR9_temperature;\n\n\n/* Private variables ---------------------------------------------------------*/\ntypedef void (*SampleMemsToPort)(uint8_t, uint8_t);\ntypedef void (*SampleMemsToString)(char *, size_t);\ntypedef void (*SampleMemsToBuffer)(float *buffer);\n//temprature and humidity sensor addresses\nstatic const uint8_t tempHumAdd = (0x40)\u003c\u003c1; // Use 7-bit address\nstatic const uint8_t tempReg = 0x00;\nstatic const uint8_t humidityReg = 0x01;\n\n/*Define private variables*/\nstatic bool stopStream = false;\nextern I2C_HandleTypeDef hi2c2;\n\nuint8_t buf[10];\nuint8_t CONTROL, Enable, ATIME, WTIME, PPULSE;\nuint8_t redReg, greenReg, blueReg, distanceReg;\nuint16_t RED_data, GREEN_data, BLUE_data, Prox_data;\nuint16_t val;\nuint8_t pir;\nuint8_t CONTROL, Enable, ATIME, WTIME, PPULSE;\nuint16_t Red __attribute__((section(\".mySection\")));\nuint16_t Green __attribute__((section(\".mySection\")));\nuint16_t Blue __attribute__((section(\".mySection\")));\nuint16_t distance1 __attribute__((section(\".mySection\")));\nfloat temp __attribute__((section(\".mySection\")));\nfloat hum __attribute__((section(\".mySection\")));\nuint8_t Sample __attribute__((section(\".mySection\")));\n/* Private function prototypes -----------------------------------------------*/\nstatic Module_Status StreamMemsToBuf( float *buffer, uint32_t period, uint32_t timeout, SampleMemsToBuffer function);\nstatic Module_Status StreamMemsToPort(uint8_t port, uint8_t module, uint32_t period, uint32_t timeout, SampleMemsToPort function);\nstatic Module_Status StreamMemsToCLI(uint32_t period, uint32_t timeout, SampleMemsToString function);\nstatic Module_Status PollingSleepCLISafe(uint32_t period);\nvoid FLASH_Page_Eras(uint32_t Addr );\nvoid ExecuteMonitor(void);\n\n/* Create CLI commands --------------------------------------------------------*/\nstatic portBASE_TYPE SampleSensorCommand(int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString);\nstatic portBASE_TYPE StreamSensorCommand(int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString);\nstatic portBASE_TYPE StopStreamCommand(int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString);\n\n/* CLI command structure : sample */\nconst CLI_Command_Definition_t SampleCommandDefinition = {\n\t(const int8_t *) \"sample\",\n\t(const int8_t *) \"sample:\\r\\n Syntax: sample [color]/[distance]/[temp]/[humidity]/[pir].\\r\\n\\r\\n\",\n\tSampleSensorCommand,\n\t1\n};\n/* CLI command structure : stream */\nconst CLI_Command_Definition_t StreamCommandDefinition = {\n\t(const int8_t *) \"stream\",\n\t(const int8_t *) \"stream:\\r\\n Syntax: stream [color]/[distance]/[temp]/[humidity]/[pir] (period in ms) (time in ms) [port] [module].\\r\\n\\r\\n\",\n\tStreamSensorCommand,\n\t-1\n};\n/* CLI command structure : stop */\nconst CLI_Command_Definition_t StopCommandDefinition = {\n\t(const int8_t *) \"stop\",\n\t(const int8_t *) \"stop:\\r\\n Syntax: stop\\r\\n \\\n\\tStop the current streaming of MEMS values. r\\n\\r\\n\",\n\tStopStreamCommand,\n\t0\n};\n\n/*-----------------------------------------------------------*/\n\n/* -----------------------------------------------------------------------\n |\t\t\t\t\t\t\t\t\t\t\t\t Private Functions\t \t\t\t\t\t\t\t\t\t\t\t\t\t\t|\n ----------------------------------------------------------------------- \n */\n\n/**\n * @brief  System Clock Configuration\n *         The system Clock is configured as follow : \n *            System Clock source            = PLL (HSE)\n *            SYSCLK(Hz)                     = 48000000\n *            HCLK(Hz)                       = 48000000\n *            AHB Prescaler                  = 1\n *            APB1 Prescaler                 = 1\n *            HSE Frequency(Hz)              = 8000000\n *            PREDIV                         = 1\n *            PLLMUL                         = 6\n *            Flash Latency(WS)              = 1\n * @param  None\n * @retval None\n */\nvoid SystemClock_Config(void){\n\t  RCC_OscInitTypeDef RCC_OscInitStruct = {0};\n\t  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};\n\t  RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};\n\n\t  /** Configure the main internal regulator output voltage\n\t  */\n\t  HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);\n\t  /** Initializes the RCC Oscillators according to the specified parameters\n\t  * in the RCC_OscInitTypeDef structure.\n\t  */\n\t  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE;\n\t  RCC_OscInitStruct.HSEState = RCC_HSE_ON;\n\t  RCC_OscInitStruct.LSIState = RCC_LSI_ON;\n\t  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;\n\t  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;\n\t  RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV1;\n\t  RCC_OscInitStruct.PLL.PLLN = 12;\n\t  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;\n\t  RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;\n\t  RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;\n      HAL_RCC_OscConfig(\u0026RCC_OscInitStruct);\n\n\t  /** Initializes the CPU, AHB and APB buses clocks\n\t  */\n\t  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK\n\t                              |RCC_CLOCKTYPE_PCLK1;\n\t  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;\n\t  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;\n\t  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;\n\n\t  HAL_RCC_ClockConfig(\u0026RCC_ClkInitStruct, FLASH_LATENCY_2);\n\n\t  /** Initializes the peripherals clocks\n\t  */\n\t  PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC|RCC_PERIPHCLK_USART2;\n\t  PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;\n\t  PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;\n\t  HAL_RCCEx_PeriphCLKConfig(\u0026PeriphClkInit);\n\t  PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_I2C2;\n\t  PeriphClkInit.I2c2ClockSelection = RCC_I2C2CLKSOURCE_PCLK1;\n\t  HAL_RCCEx_PeriphCLKConfig(\u0026PeriphClkInit);\n\t  HAL_NVIC_SetPriority(SysTick_IRQn,0,0);\n\t\n}\n\n/*-----------------------------------------------------------*/\n\n\n/* --- Save array topology and Command Snippets in Flash RO --- \n */\nuint8_t SaveToRO(void){\n\tBOS_Status result =BOS_OK;\n\tHAL_StatusTypeDef FlashStatus =HAL_OK;\n\tuint16_t add =8;\n    uint16_t temp =0;\n\tuint8_t snipBuffer[sizeof(snippet_t) + 1] ={0};\n\t\n\tHAL_FLASH_Unlock();\n\t\n\t/* Erase RO area */\n\tFLASH_PageErase(FLASH_BANK_1,RO_START_ADDRESS);\n\tFlashStatus =FLASH_WaitForLastOperation((uint32_t ) HAL_FLASH_TIMEOUT_VALUE);\n\tFLASH_PageErase(FLASH_BANK_1,RO_MID_ADDRESS);\n\t//TOBECHECKED\n\tFlashStatus =FLASH_WaitForLastOperation((uint32_t ) HAL_FLASH_TIMEOUT_VALUE);\n\tif(FlashStatus != HAL_OK){\n\t\treturn pFlash.ErrorCode;\n\t}\n\telse{\n\t\t/* Operation is completed, disable the PER Bit */\n\t\tCLEAR_BIT(FLASH-\u003eCR,FLASH_CR_PER);\n\t}\n\t\n\t/* Save number of modules and myID */\n\tif(myID){\n\t\ttemp =(uint16_t )(N \u003c\u003c 8) + myID;\n\t\t//HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD,RO_START_ADDRESS,temp);\n\t\tHAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD,RO_START_ADDRESS,temp);\n\t\t//TOBECHECKED\n\t\tFlashStatus =FLASH_WaitForLastOperation((uint32_t ) HAL_FLASH_TIMEOUT_VALUE);\n\t\tif(FlashStatus != HAL_OK){\n\t\t\treturn pFlash.ErrorCode;\n\t\t}\n\t\telse{\n\t\t\t/* If the program operation is completed, disable the PG Bit */\n\t\t\tCLEAR_BIT(FLASH-\u003eCR,FLASH_CR_PG);\n\t\t}\n\t\t\n\t\t/* Save topology */\n\t\tfor(uint8_t i =1; i \u003c= N; i++){\n\t\t\tfor(uint8_t j =0; j \u003c= MaxNumOfPorts; j++){\n\t\t\t\tif(array[i - 1][0]){\n          \tHAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD,RO_START_ADDRESS + add,array[i - 1][j]);\n\t\t\t\t //HALFWORD \t//TOBECHECKED\n\n\t\t\t\t\tFlashStatus =FLASH_WaitForLastOperation((uint32_t ) HAL_FLASH_TIMEOUT_VALUE);\n\t\t\t\t\tif(FlashStatus != HAL_OK){\n\t\t\t\t\t\treturn pFlash.ErrorCode;\n\t\t\t\t\t}\n\t\t\t\t\telse{\n\t\t\t\t\t\t/* If the program operation is completed, disable the PG Bit */\n\t\t\t\t\t\tCLEAR_BIT(FLASH-\u003eCR,FLASH_CR_PG);\n\t\t\t\t\t\tadd +=8;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n\t// Save Command Snippets\n\tint currentAdd = RO_MID_ADDRESS;\n\tfor(uint8_t s =0; s \u003c numOfRecordedSnippets; s++){\n\t\tif(snippets[s].cond.conditionType){\n\t\t\tsnipBuffer[0] =0xFE;\t\t// A marker to separate Snippets\n\t\t\tmemcpy((uint32_t* )\u0026snipBuffer[1],(uint8_t* )\u0026snippets[s],sizeof(snippet_t));\n\t\t\t// Copy the snippet struct buffer (20 x numOfRecordedSnippets). Note this is assuming sizeof(snippet_t) is even.\n\t\t\tfor(uint8_t j =0; j \u003c (sizeof(snippet_t)/4); j++){\n\t\t\t\tHAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD,currentAdd,*(uint64_t* )\u0026snipBuffer[j*8]);\n\t\t\t\t//HALFWORD\n\t\t\t\t//TOBECHECKED\n\t\t\t\tFlashStatus =FLASH_WaitForLastOperation((uint32_t ) HAL_FLASH_TIMEOUT_VALUE);\n\t\t\t\tif(FlashStatus != HAL_OK){\n\t\t\t\t\treturn pFlash.ErrorCode;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\t/* If the program operation is completed, disable the PG Bit */\n\t\t\t\t\tCLEAR_BIT(FLASH-\u003eCR,FLASH_CR_PG);\n\t\t\t\t\tcurrentAdd +=8;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Copy the snippet commands buffer. Always an even number. Note the string termination char might be skipped\n\t\t\tfor(uint8_t j =0; j \u003c ((strlen(snippets[s].cmd) + 1)/4); j++){\n\t\t\t\tHAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD,currentAdd,*(uint64_t* )(snippets[s].cmd + j*4 ));\n\t\t\t\t//HALFWORD\n\t\t\t\t//TOBECHECKED\n\t\t\t\tFlashStatus =FLASH_WaitForLastOperation((uint32_t ) HAL_FLASH_TIMEOUT_VALUE);\n\t\t\t\tif(FlashStatus != HAL_OK){\n\t\t\t\t\treturn pFlash.ErrorCode;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\t/* If the program operation is completed, disable the PG Bit */\n\t\t\t\t\tCLEAR_BIT(FLASH-\u003eCR,FLASH_CR_PG);\n\t\t\t\t\tcurrentAdd +=8;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n\tHAL_FLASH_Lock();\n\t\n\treturn result;\n}\n\n/* --- Clear array topology in SRAM and Flash RO --- \n */\nuint8_t ClearROtopology(void){\n\t// Clear the array \n\tmemset(array,0,sizeof(array));\n\tN =1;\n\tmyID =0;\n\t\n\treturn SaveToRO();\n}\n/*-----------------------------------------------------------*/\n\n/* --- Trigger ST factory bootloader update for a remote module.\n */\nvoid remoteBootloaderUpdate(uint8_t src,uint8_t dst,uint8_t inport,uint8_t outport){\n\n\tuint8_t myOutport =0, lastModule =0;\n\tint8_t *pcOutputString;\n\n\t/* 1. Get route to destination module */\n\tmyOutport =FindRoute(myID,dst);\n\tif(outport \u0026\u0026 dst == myID){ /* This is a 'via port' update and I'm the last module */\n\t\tmyOutport =outport;\n\t\tlastModule =myID;\n\t}\n\telse if(outport == 0){ /* This is a remote update */\n\t\tif(NumberOfHops(dst)== 1)\n\t\tlastModule = myID;\n\t\telse\n\t\tlastModule = route[NumberOfHops(dst)-1]; /* previous module = route[Number of hops - 1] */\n\t}\n\n\t/* 2. If this is the source of the message, show status on the CLI */\n\tif(src == myID){\n\t\t/* Obtain the address of the output buffer.  Note there is no mutual\n\t\t exclusion on this buffer as it is assumed only one command console\n\t\t interface will be used at any one time. */\n\t\tpcOutputString =FreeRTOS_CLIGetOutputBuffer();\n\n\t\tif(outport == 0)\t\t// This is a remote module update\n\t\t\tsprintf((char* )pcOutputString,pcRemoteBootloaderUpdateMessage,dst);\n\t\telse\n\t\t\t// This is a 'via port' remote update\n\t\t\tsprintf((char* )pcOutputString,pcRemoteBootloaderUpdateViaPortMessage,dst,outport);\n\n\t\tstrcat((char* )pcOutputString,pcRemoteBootloaderUpdateWarningMessage);\n\t\twritePxITMutex(inport,(char* )pcOutputString,strlen((char* )pcOutputString),cmd50ms);\n\t\tDelay_ms(100);\n\t}\n\n\t/* 3. Setup my inport and outport for bootloader update */\n\tSetupPortForRemoteBootloaderUpdate(inport);\n\tSetupPortForRemoteBootloaderUpdate(myOutport);\n\n\n\t/* 5. Build a DMA stream between my inport and outport */\n\tStartScastDMAStream(inport,myID,myOutport,myID,BIDIRECTIONAL,0xFFFFFFFF,0xFFFFFFFF,false);\n}\n\n/*-----------------------------------------------------------*/\n\n/* --- Setup a port for remote ST factory bootloader update:\n - Set baudrate to 57600\n - Enable even parity\n - Set datasize to 9 bits\n */\nvoid SetupPortForRemoteBootloaderUpdate(uint8_t port){\n\tUART_HandleTypeDef *huart =GetUart(port);\n\n\thuart-\u003eInit.BaudRate =57600;\n\thuart-\u003eInit.Parity = UART_PARITY_EVEN;\n\thuart-\u003eInit.WordLength = UART_WORDLENGTH_9B;\n\tHAL_UART_Init(huart);\n\n\t/* The CLI port RXNE interrupt might be disabled so enable here again to be sure */\n\t__HAL_UART_ENABLE_IT(huart,UART_IT_RXNE);\n}\n\n/* --- H0AR9 module initialization.\n */\nvoid Module_Peripheral_Init(void){\n\n\t/* Array ports */\n\tMX_USART1_UART_Init();\n\tMX_USART2_UART_Init();\n\tMX_USART3_UART_Init();\n\tMX_USART4_UART_Init();\n\tMX_USART5_UART_Init();\n\t//MX_USART6_UART_Init();\n\t/* initialize GPIO for module */\n\t  SENSORS_GPIO_Init();\n\t  /* initialize I2C for module */\n\t  MX_I2C_Init();\n\t  /* initialize color\u0026proximity sensor */\n\t  APDS9950_init();\n\n\t/* Create module special task (if needed) */\n}\n\n/*-----------------------------------------------------------*/\n/* --- H0AR9 message processing task.\n */\nModule_Status Module_MessagingTask(uint16_t code, uint8_t port, uint8_t src, uint8_t dst, uint8_t shift)\n{\n\tModule_Status result = H0AR9_OK;\n\tuint32_t period = 0, timeout = 0;\n\n\tswitch (code)\n\t{\n\t\tcase CODE_H0AR9_SAMPLE_COLOR:\n\t\t{\n\t\t\tSampleColorToPort(cMessage[port-1][1+shift] ,cMessage[port-1][shift]);\n\t\t\tbreak;\n\t\t}\n\t\tcase CODE_H0AR9_SAMPLE_DISTANCE:\n\t\t{\n\t\t\tSampleDistanceToPort(cMessage[port-1][1+shift] ,cMessage[port-1][shift]);\n\t\t\tbreak;\n\t\t}\n\t\tcase CODE_H0AR9_SAMPLE_TEMP:\n\t\t{\n\t\t\tSampleTemperatureToPort(cMessage[port-1][1+shift] ,cMessage[port-1][shift]);\n\t\t\tbreak;\n\t\t}\n\t\tcase CODE_H0AR9_SAMPLE_HUMIDITY:\n\t\t{\n\t\t\tSampleHumidityToPort(cMessage[port-1][1+shift] ,cMessage[port-1][shift]);\n\t\t\tbreak;\n\t\t}\n\t\tcase CODE_H0AR9_SAMPLE_PIR:\n\t\t{\n\t\t\tSamplePIRToPort(cMessage[port-1][1+shift] ,cMessage[port-1][shift]);\n\t\t\tbreak;\n\t\t}\n\n\t\tcase CODE_H0AR9_STREAM_COLOR:\n\t\t{\n\t\t\tperiod = ((uint32_t) cMessage[port - 1][2 + shift] ) + ((uint32_t) cMessage[port - 1][3 + shift] \u003c\u003c 8) + ((uint32_t) cMessage[port - 1][4 + shift] \u003c\u003c 16) + ((uint32_t)cMessage[port - 1][5 + shift] \u003c\u003c 24);\n\t\t\ttimeout = ((uint32_t) cMessage[port - 1][6 + shift] ) + ((uint32_t) cMessage[port - 1][7 + shift] \u003c\u003c 8) + ((uint32_t) cMessage[port - 1][8 + shift] \u003c\u003c 16) + ((uint32_t)cMessage[port - 1][9 + shift] \u003c\u003c 24);\n\t\t\tStreamColorToPort(cMessage[port-1][1+shift] ,cMessage[port-1][shift], period, timeout);\n\t\t\tbreak;\n\t\t}\n\n\t\tcase CODE_H0AR9_STREAM_DISTANCE:\n\t\t{\n\t\t\tperiod = ((uint32_t) cMessage[port - 1][2 + shift] ) + ((uint32_t) cMessage[port - 1][3 + shift] \u003c\u003c 8) + ((uint32_t) cMessage[port - 1][4 + shift] \u003c\u003c 16) + ((uint32_t)cMessage[port - 1][5 + shift] \u003c\u003c24);\n\t\t\ttimeout = ((uint32_t) cMessage[port - 1][6 + shift] ) + ((uint32_t) cMessage[port - 1][7 + shift] \u003c\u003c 8) + ((uint32_t) cMessage[port - 1][8 + shift] \u003c\u003c 16) + ((uint32_t)cMessage[port - 1][9 + shift]\u003c\u003c24);\n\t\t\tStreamDistanceToPort(cMessage[port-1][1+shift] ,cMessage[port-1][shift], period, timeout);\n\t\t\tbreak;\n\t\t}\n\t\tcase CODE_H0AR9_STREAM_TEMP:\n\t\t{\n\t\t\tperiod = ((uint32_t) cMessage[port - 1][2 + shift] ) + ((uint32_t) cMessage[port - 1][3 + shift] \u003c\u003c 8) + ((uint32_t) cMessage[port - 1][4 + shift] \u003c\u003c 16) + ((uint32_t)cMessage[port - 1][5 + shift]\u003c\u003c24);\n\t\t\ttimeout = ((uint32_t) cMessage[port - 1][6 + shift] ) + ((uint32_t) cMessage[port - 1][7 + shift] \u003c\u003c 8) + ((uint32_t) cMessage[port - 1][8 + shift] \u003c\u003c 16) + ((uint32_t)cMessage[port - 1][9 + shift]\u003c\u003c24);\n\t\t\tStreamTemperatureToPort(cMessage[port-1][1+shift] ,cMessage[port-1][shift], period, timeout);\n\t\t\tbreak;\n\t\t}\n\t\tcase CODE_H0AR9_STREAM_HUMIDITY:\n\t\t{\n\t\t\tperiod = ((uint32_t) cMessage[port - 1][2 + shift] ) + ((uint32_t) cMessage[port - 1][3 + shift] \u003c\u003c 8) + ((uint32_t) cMessage[port - 1][4 + shift] \u003c\u003c 16) + ((uint32_t)cMessage[port - 1][5 + shift]\u003c\u003c24);\n\t\t\ttimeout = ((uint32_t) cMessage[port - 1][6 + shift] ) + ((uint32_t) cMessage[port - 1][7 + shift] \u003c\u003c 8) + ((uint32_t) cMessage[port - 1][8 + shift] \u003c\u003c 16) + ((uint32_t)cMessage[port - 1][9 + shift]\u003c\u003c24);\n\t\t\tStreamHumidityToPort(cMessage[port-1][1+shift] ,cMessage[port-1][shift], period, timeout);\n\t\t\tbreak;\n\t\t}\n\t\tcase CODE_H0AR9_STREAM_PIR:\n\t\t{\n\t\t\tperiod = ((uint32_t) cMessage[port - 1][2 + shift] ) + ((uint32_t) cMessage[port - 1][3 + shift] \u003c\u003c 8) + ((uint32_t) cMessage[port - 1][4 + shift] \u003c\u003c 16) + ((uint32_t)cMessage[port - 1][5 + shift] \u003c\u003c24);\n\t\t\ttimeout = ((uint32_t) cMessage[port - 1][6 + shift] ) + ((uint32_t) cMessage[port - 1][7 + shift] \u003c\u003c 8) + ((uint32_t) cMessage[port - 1][8 + shift] \u003c\u003c 16) + ((uint32_t)cMessage[port - 1][9 + shift] \u003c\u003c24);\n\t\t\tStreamPIRToPort(cMessage[port-1][1+shift] ,cMessage[port-1][shift], period, timeout);\n\t\t\tbreak;\n\t\t}\n\t\tcase CODE_H0AR9_STREAM_STOP:\n\t\t{\n\t\t\tstopStreamMems();\n\t\t\tresult = H0AR9_OK;\n\t\t\tbreak;\n\t\t}\n\n\t\tdefault:\n\t\t\tresult = H0AR9_ERR_UnknownMessage;\n\t\t\tbreak;\n\t}\n\n\treturn result;\n}\n\n/* --- Get the port for a given UART. \n */\nuint8_t GetPort(UART_HandleTypeDef *huart){\n\n\tif(huart-\u003eInstance == USART4)\n\t\treturn P1;\n\telse if(huart-\u003eInstance == USART2)\n\t\treturn P2;\n\telse if(huart-\u003eInstance == USART3)\n\t\treturn P3;\n\telse if(huart-\u003eInstance == USART1)\n\t\treturn P4;\n\telse if(huart-\u003eInstance == USART5)\n\t\treturn P5;\n\t//else if(huart-\u003eInstance == USART6)\n\t\t//return P6;\n\t\n\treturn 0;\n}\n/*------------------------------------------------------------*/\n//initialize APDS9950 sensor\nvoid APDS9950_init(void)\n{\n//registers addresses\n\tCONTROL = 0x0F;\n\tEnable = 0x00;\n\tATIME  = 0x01;\n\tWTIME  = 0x03;\n\tPPULSE = 0x0E;\n\tredReg = 0x16;\n\tgreenReg = 0x18;\n    blueReg = 0x1A;\n    distanceReg = 0x1C;\n\n    WriteRegData (Enable,0x00);\n    WriteRegData (ATIME,0x00);\n    WriteRegData (WTIME,0xff);\n    WriteRegData (PPULSE,0x01);\n    WriteRegData (CONTROL, 0x20);\n    WriteRegData (Enable, 0x0F);\n}\n\n/*-----------------------------------------------------------*/\nvoid initialValue(void)\n{\n\tRed=0;\n\tGreen=0;\n\tBlue=0;\n\tdistance1=0;\n\ttemp=0;\n\thum=0;\n\tSample=0;\n}\n/*-----------------------------------------------------------*/\n\n\n/* --- Register this module CLI Commands\n */\nvoid RegisterModuleCLICommands(void){\n\tFreeRTOS_CLIRegisterCommand( \u0026SampleCommandDefinition );\n\tFreeRTOS_CLIRegisterCommand( \u0026StreamCommandDefinition );\n\tFreeRTOS_CLIRegisterCommand( \u0026StopCommandDefinition);\n\n}\n\n/*-----------------------------------------------------------*/\n\n\n/* Module special task function (if needed) */\n//void Module_Special_Task(void *argument){\n//\n//\t/* Infinite loop */\n//\tuint8_t cases; // Test variable.\n//\tfor(;;){\n//\t\t/*  */\n//\t\tswitch(cases){\n//\n//\n//\t\t\tdefault:\n//\t\t\t\tosDelay(10);\n//\t\t\t\tbreak;\n//\t\t}\n//\n//\t\ttaskYIELD();\n//\t}\n//\n//}\n\n\n/*-----------------------------------------------------------*/\n\n\n\n\n/*-----------------------------------------------------------*/\nstatic Module_Status StreamMemsToPort(uint8_t port, uint8_t module, uint32_t period, uint32_t timeout, SampleMemsToPort function)\n{\n\tModule_Status status = H0AR9_OK;\n\n\n\tif (period \u003c MIN_MEMS_PERIOD_MS)\n\t\treturn H0AR9_ERR_WrongParams;\n\tif (port == 0)\n\t\treturn H0AR9_ERR_WrongParams;\n\tif (port == PcPort) // Check if CLI is not enabled at that port!\n\t\treturn H0AR9_ERR_BUSY;\n\n\tif (period \u003e timeout)\n\t\ttimeout = period;\n\n\tlong numTimes = timeout / period;\n\tstopStream = false;\n\n\twhile ((numTimes-- \u003e 0) || (timeout \u003e= MAX_MEMS_TIMEOUT_MS)) {\n\t\tfunction(port, module);\n\n\t\tvTaskDelay(pdMS_TO_TICKS(period));\n\t\tif (stopStream) {\n\t\t\tstatus = H0AR9_ERR_TERMINATED;\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn status;\n}\n/*-----------------------------------------------------------*/\n\nstatic Module_Status StreamMemsToBuf( float *buffer, uint32_t period, uint32_t timeout, SampleMemsToBuffer function)\n\n{\n\tModule_Status status = H0AR9_OK;\n\n\tif (period \u003c MIN_MEMS_PERIOD_MS)\n\t\treturn H0AR9_ERR_WrongParams;\n\n\t// TODO: Check if CLI is enable or not\n\n\tif (period \u003e timeout)\n\t\ttimeout = period;\n\n\tlong numTimes = timeout / period;\n\tstopStream = false;\n\n\twhile ((numTimes-- \u003e 0) || (timeout \u003e= MAX_MEMS_TIMEOUT_MS)) {\n\t\tfunction(buffer);\n\n\t\tvTaskDelay(pdMS_TO_TICKS(period));\n\t\tif (stopStream) {\n\t\t\tstatus = H0AR9_ERR_TERMINATED;\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn status;\n}\n/*-----------------------------------------------------------*/\n\nstatic Module_Status StreamMemsToCLI(uint32_t period, uint32_t timeout, SampleMemsToString function)\n{\n\tModule_Status status = H0AR9_OK;\n\tint8_t *pcOutputString = NULL;\n\n\tif (period \u003c MIN_MEMS_PERIOD_MS)\n\t\treturn H0AR9_ERR_WrongParams;\n\n\t// TODO: Check if CLI is enable or not\n\n\tif (period \u003e timeout)\n\t\ttimeout = period;\n\n\tlong numTimes = timeout / period;\n\tstopStream = false;\n\n\twhile ((numTimes-- \u003e 0) || (timeout \u003e= MAX_MEMS_TIMEOUT_MS)) {\n\t\tpcOutputString = FreeRTOS_CLIGetOutputBuffer();\n\t\tfunction((char *)pcOutputString, 100);\n\n\n\t\twritePxMutex(PcPort, (char *)pcOutputString, strlen((char *)pcOutputString), cmd500ms, HAL_MAX_DELAY);\n\t\tif (PollingSleepCLISafe(period) != H0AR9_OK)\n\t\t\tbreak;\n\t}\n\n\tmemset((char *) pcOutputString, 0, configCOMMAND_INT_MAX_OUTPUT_SIZE);\n  sprintf((char *)pcOutputString, \"\\r\\n\");\n\treturn status;\n}\n/*-----------------------------------------------------------*/\n\n/* --- Save array topology and Command Snippets in Flash RO ---\n*/\nstatic Module_Status PollingSleepCLISafe(uint32_t period)\n{\n\tconst unsigned DELTA_SLEEP_MS = 100; // milliseconds\n\tlong numDeltaDelay =  period / DELTA_SLEEP_MS;\n\tunsigned lastDelayMS = period % DELTA_SLEEP_MS;\n\n\twhile (numDeltaDelay-- \u003e 0) {\n\t\tvTaskDelay(pdMS_TO_TICKS(DELTA_SLEEP_MS));\n\n\t\t// Look for ENTER key to stop the stream\n\t\tfor (uint8_t chr=0 ; chr\u003cMSG_RX_BUF_SIZE ; chr++)\n\t\t{\n\t\t\tif (UARTRxBuf[PcPort-1][chr] == '\\r') {\n\t\t\t\tUARTRxBuf[PcPort-1][chr] = 0;\n\t\t\t\treturn H0AR9_ERR_TERMINATED;\n\t\t\t}\n\t\t}\n\n\t\tif (stopStream)\n\t\t\treturn H0AR9_ERR_TERMINATED;\n\t}\n\n\tvTaskDelay(pdMS_TO_TICKS(lastDelayMS));\n\treturn H0AR9_OK;\n}\n/* -----------------------------------------------------------------------\n |\t\t\t\t\t\t\t\t  APIs\t\t\t\t\t\t\t          | \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t \t|\n/* -----------------------------------------------------------------------\n */\nvoid SampleColorToPort(uint8_t port,uint8_t module)\n{\n\tfloat buffer[3]; // Three Samples RED, GREEN, BLUE\n\tstatic uint8_t temp[12];\n\n\tSampleColorBuf(buffer);\n\n\n\t\ttemp[0] =*((__IO uint8_t* )(\u0026buffer[0]) + 3);\n\t\ttemp[1] =*((__IO uint8_t* )(\u0026buffer[0]) + 2);\n\t\ttemp[2] =*((__IO uint8_t* )(\u0026buffer[0]) + 1);\n\t\ttemp[3] =*((__IO uint8_t* )(\u0026buffer[0]) + 0);\n\n\t\ttemp[4] =*((__IO uint8_t* )(\u0026buffer[1]) + 3);\n\t\ttemp[5] =*((__IO uint8_t* )(\u0026buffer[1]) + 2);\n\t\ttemp[6] =*((__IO uint8_t* )(\u0026buffer[1]) + 1);\n\t\ttemp[7] =*((__IO uint8_t* )(\u0026buffer[1]) + 0);\n\n\t\ttemp[8] =*((__IO uint8_t* )(\u0026buffer[2]) + 3);\n\t\ttemp[9] =*((__IO uint8_t* )(\u0026buffer[2]) + 2);\n\t\ttemp[10] =*((__IO uint8_t* )(\u0026buffer[2]) + 1);\n\t\ttemp[11] =*((__IO uint8_t* )(\u0026buffer[2]) + 0);\n\n\t\twritePxITMutex(port,(char* )\u0026temp[0],12 * sizeof(uint8_t),10);\n\n}\n/*-----------------------------------------------------------*/\n\nvoid SampleDistanceToPort(uint8_t port,uint8_t module)\n{\n\tfloat buffer[1]; // Three Samples X, Y, Z\n\tstatic uint8_t temp[4];\n\n\tSampleDistanceBuff(buffer);\n\n\t\ttemp[0] =*((__IO uint8_t* )(\u0026buffer[0]) + 3);\n\t\ttemp[1] =*((__IO uint8_t* )(\u0026buffer[0]) + 2);\n\t\ttemp[2] =*((__IO uint8_t* )(\u0026buffer[0]) + 1);\n\t\ttemp[3] =*((__IO uint8_t* )(\u0026buffer[0]) + 0);\n\n\t\twritePxITMutex(port,(char* )\u0026temp[0],4 * sizeof(uint8_t),10);\n}\n/*-----------------------------------------------------------*/\nvoid SampleTemperatureToPort(uint8_t port,uint8_t module)\n{\n\tfloat buffer[1];\n\tstatic uint8_t temp[4];\n\n\tSampleTemperatureBuf(buffer);\n\n\tif(module == myID){\n\t\t\ttemp[0] =*((__IO uint8_t* )(\u0026buffer[0]) + 3);\n\t\t\ttemp[1] =*((__IO uint8_t* )(\u0026buffer[0]) + 2);\n\t\t\ttemp[2] =*((__IO uint8_t* )(\u0026buffer[0]) + 1);\n\t\t\ttemp[3] =*((__IO uint8_t* )(\u0026buffer[0]) + 0);\n\n\n\t\t\twritePxITMutex(port,(char* )\u0026temp[0],4 * sizeof(uint8_t),10);\n\t\t}\n\t\telse{\n\t\t\tmessageParams[0] =port;\n\t\t\tmessageParams[1] =*((__IO uint8_t* )(\u0026buffer[0]) + 3);\n\t\t\tmessageParams[2] =*((__IO uint8_t* )(\u0026buffer[0]) + 2);\n\t\t\tmessageParams[3] =*((__IO uint8_t* )(\u0026buffer[0]) + 1);\n\t\t\tmessageParams[4] =*((__IO uint8_t* )(\u0026buffer[0]) + 0);\n\n\t\t\tSendMessageToModule(module,CODE_PORT_FORWARD,sizeof(float)+1);\n\t\t}\n\n\n}\n/*-----------------------------------------------------------*/\nvoid SampleHumidityToPort(uint8_t port,uint8_t module)\n{\n\tfloat buffer[1];\n\tstatic uint8_t temp[4];\n\n\tSampleHumidityBuf(buffer);\n\n\t\ttemp[0] =*((__IO uint8_t* )(\u0026buffer[0]) + 3);\n\t\ttemp[1] =*((__IO uint8_t* )(\u0026buffer[0]) + 2);\n\t\ttemp[2] =*((__IO uint8_t* )(\u0026buffer[0]) + 1);\n\t\ttemp[3] =*((__IO uint8_t* )(\u0026buffer[0]) + 0);\n\n\t\twritePxITMutex(port,(char* )\u0026temp[0],4 * sizeof(uint8_t),10);\n}\n/*-----------------------------------------------------------*/\nvoid SamplePIRToPort(uint8_t port,uint8_t module)\n{\n\tfloat buffer;\n\tbool temp;\n\n\tSamplePIRBuf(\u0026buffer);\n\n\n\tif(module == myID){\n\t\ttemp = buffer;\n\t\twritePxITMutex(port,(char* )\u0026temp,sizeof(bool),10);\n\t}\n\telse{\n\t\tmessageParams[0] =port;\n\t\tmessageParams[1] =buffer;\n\t\tSendMessageToModule(module,CODE_PORT_FORWARD,sizeof(char)+1);\n\t}\n}\n/*-----------------------------------------------------------*/\n\nvoid SampleColorBuf(float *buffer)\n{\n\tuint16_t rgb[3];\n\tSampleColor(rgb,rgb+1,rgb+2);\n\tbuffer[0]=rgb[0];\n\tbuffer[1]=rgb[1];\n\tbuffer[2]=rgb[2];\n}\n/*-----------------------------------------------------------*/\nvoid SampleDistanceBuff(float *buffer)\n{\n\tuint16_t distance;\n\tSampleDistance(\u0026distance);\n\t*buffer = distance;\n}\n/*-----------------------------------------------------------*/\nvoid SampleTemperatureBuf(float *buffer)\n{\n\tSampleTemperature(buffer);\n}\n/*-----------------------------------------------------------*/\nvoid SampleHumidityBuf(float *buffer)\n{\n\tSampleHumidity(buffer);\n}\n/*-----------------------------------------------------------*/\nvoid SamplePIRBuf(float *buffer)\n{\n\tbool pir;\n    SamplePIR(\u0026pir);\n    *buffer = pir;\n}\n/*-----------------------------------------------------------*/\n\nvoid SampleColorToString(char *cstring, size_t maxLen)\n{\n\tuint16_t red = 0, green = 0, blue = 0;\n\tSampleColor(\u0026red, \u0026green, \u0026blue);\n\tRed=red;\n\tGreen=green;\n\tBlue=blue;\n\tsnprintf(cstring, maxLen, \"Red: %d, Green: %d, Blue: %d\\r\\n\", red, green, blue);\n}\n/*-----------------------------------------------------------*/\n\nvoid SampleDistanceToString(char *cstring, size_t maxLen)\n{\n\tuint16_t distance = 0;\n\tSampleDistance(\u0026distance);\n\tdistance1=distance;\n\tsnprintf(cstring, maxLen, \"Distance: %d\\r\\n\", distance);\n}\n/*-----------------------------------------------------------*/\n\nvoid SampleTemperatureToString(char *cstring, size_t maxLen)\n{\n\tfloat temprature = 0;\n\tSampleTemperature(\u0026temprature);\n\ttemp=temprature;\n\tchar Number[5]={0};\n\tuint16_t x;\n\tvolatile uint32_t temp1=1;\n\tuint16_t x0,x1,x2;\n\ttemp1=temp;\n\nx0 = (uint8_t) (temp*10 - temp1*10);\nx1 = (uint8_t) (temp1%10);\nx2 = (uint8_t) (temp1/10%10);\n\nif(x2 == 0)  {Number[0] = 0x20;} else {Number[0] = x2 +0x30;}\nNumber[1] = x1 +0x30;\nNumber[2] = '.';\nNumber[3] = x0 +0x30;\nNumber[4] = 0;\n//    x=*((long long*)\u0026temp);\n//\ttemp=atoff(Number);\n\tsnprintf(cstring, maxLen, \"Temperature:  %.4s\\r\\n\", Number);\n}\n/*-----------------------------------------------------------*/\n\nvoid SampleHumidityToString(char *cstring, size_t maxLen)\n{\n\tfloat humidity = 0;\n\tSampleHumidity(\u0026humidity);\n\thum=humidity;\n\tchar Number[5]={0};\n\tuint16_t x;\n\tvolatile uint32_t temp1=1;\n\tuint16_t x0,x1,x2;\n\ttemp1=hum;\n\nx0 = (uint8_t) (hum*10 - temp1*10);\nx1 = (uint8_t) (temp1%10);\nx2 = (uint8_t) (temp1/10%10);\n\nif(x2 == 0)  {Number[0] = 0x20;} else {Number[0] = x2 +0x30;}\nNumber[1] = x1 +0x30;\nNumber[2] = '.';\nNumber[3] = x0 +0x30;\nNumber[4] = 0;\n\tsnprintf(cstring, maxLen, \"Humidity: %.4s\\r\\n\", Number);\n}\n/*-----------------------------------------------------------*/\n\nvoid SamplePIRToString(char *cstring, size_t maxLen)\n{\n\tbool sample;\n\tSamplePIR(\u0026sample);\n\tSample=sample;\n\tsnprintf(cstring, maxLen, \"PIR: %d\\r\\n\", sample);\n}\n/*-----------------------------------------------------------*/\n\n\nvoid SampleTemperature(float *temperature)\n{\n\n\tbuf[0] = tempReg;\n\tHAL_I2C_Master_Transmit(\u0026hi2c2, tempHumAdd, buf, 1, HAL_MAX_DELAY);\n\tHAL_Delay(20);\n\tHAL_I2C_Master_Receive(\u0026hi2c2, tempHumAdd, buf, 2, HAL_MAX_DELAY);\n\tval = buf[0] \u003c\u003c 8 | buf[1];\n\t*temperature=((float)val/65536)*165.0-40.0;\n\n\n\n}\n/*-----------------------------------------------------------*/\nvoid SampleColor(uint16_t *Red, uint16_t *Green, uint16_t *Blue)\n{\n\t*Red = Read_Word(redReg);\n\t*Green = Read_Word(greenReg);\n\t*Blue = Read_Word(blueReg);\n}\n/*-----------------------------------------------------------*/\nvoid SampleDistance(uint16_t *distance)\n{\n\t*distance = Read_Word(distanceReg)/6.39;\n}\n\n/*-----------------------------------------------------------*/\nvoid SampleHumidity(float *humidity)\n{\n\tbuf[0] = humidityReg;\n\tHAL_I2C_Master_Transmit(\u0026hi2c2, tempHumAdd, buf, 1, HAL_MAX_DELAY);\n\tHAL_Delay(20);\n\tHAL_I2C_Master_Receive(\u0026hi2c2, tempHumAdd, buf, 2, HAL_MAX_DELAY);\n\tval = buf[0] \u003c\u003c 8 | buf[1];\n\t*humidity = (((float)val*100)/65536);\n}\n/*-----------------------------------------------------------*/\nvoid SamplePIR(bool *pir)\n{\n\t*pir=HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_6);/* USER CODE END WHILE */\n\t Delay_ms(2000);\n}\n/*-----------------------------------------------------------*/\nModule_Status StreamColorToPort(uint8_t port, uint8_t module, uint32_t period, uint32_t timeout)\n{\n\treturn StreamMemsToPort(port, module, period, timeout, SampleColorToPort);\n}\n/*-----------------------------------------------------------*/\n\nModule_Status StreamDistanceToPort(uint8_t port, uint8_t module, uint32_t period, uint32_t timeout)\n{\n\treturn StreamMemsToPort(port, module, period, timeout, SampleDistanceToPort);\n}\n/*-----------------------------------------------------------*/\n\nModule_Status StreamTemperatureToPort(uint8_t port, uint8_t module, uint32_t period, uint32_t timeout)\n{\n\treturn StreamMemsToPort(port, module, period, timeout, SampleTemperatureToPort);\n}\n/*-----------------------------------------------------------*/\n\nModule_Status StreamHumidityToPort(uint8_t port, uint8_t module, uint32_t period, uint32_t timeout)\n{\n\treturn StreamMemsToPort(port, module, period, timeout, SampleHumidityToPort);\n}\n/*-----------------------------------------------------------*/\n\nModule_Status StreamPIRToPort(uint8_t port, uint8_t module, uint32_t period, uint32_t timeout)\n{\n\treturn StreamMemsToPort(port, module, period, timeout, SamplePIRToPort);\n}\n/*-----------------------------------------------------------*/\n\nModule_Status StreamColorToBuffer(float *buffer, uint32_t period, uint32_t timeout)\n{\n\t return StreamMemsToBuf(buffer, period, timeout, SampleColorBuf);\n}\n...\n\nThis file has been truncated, please download it to see its full contents.","metadata":{"language":"cpp","linenums":false}},{"element_type":"code","content":"/* H0AR9_gpio.c\n BitzOS (BOS) V0.2.9 - Copyright (C) 2017-2023 Hexabitz\n All rights reserved\n\n File Name     : H0AR9_gpio.c\n Description   : Source code provides code for the configuration of all used GPIO pins .\n\n */\n\n/* Includes ------------------------------------------------------------------*/\n#include \"BOS.h\"\n\n/*  */\nBOS_Status GetPortGPIOs(uint8_t port,uint32_t *TX_Port,uint16_t *TX_Pin,uint32_t *RX_Port,uint16_t *RX_Pin);\n\n/*----------------------------------------------------------------------------*/\n/* Configure GPIO                                                             */\n/*----------------------------------------------------------------------------*/\n\n/** Pinout Configuration\n */\nvoid GPIO_Init(void){\n\t/* GPIO Ports Clock Enable */\n\t__GPIOC_CLK_ENABLE();\n\t__GPIOA_CLK_ENABLE();\n\t__GPIOD_CLK_ENABLE();\n\t__GPIOB_CLK_ENABLE();\n\t__GPIOF_CLK_ENABLE();\t\t// for HSE and Boot0\n\n\tIND_LED_Init();\n}\n\n//-- Configure indicator LED\nvoid IND_LED_Init(void){\n\tGPIO_InitTypeDef GPIO_InitStruct;\n\t\n\tGPIO_InitStruct.Pin = _IND_LED_PIN;\n\tGPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;\n\tGPIO_InitStruct.Pull = GPIO_NOPULL;\n\tGPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;\n\tHAL_GPIO_Init(_IND_LED_PORT,\u0026GPIO_InitStruct);\n\n\tGPIO_InitStruct.Pin = GPIO_PIN_8;\n\t\t\tGPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;\n\t\t\tGPIO_InitStruct.Pull = GPIO_NOPULL;\n\t\t\tGPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;\n\t\t\tHAL_GPIO_Init(GPIOB,\u0026GPIO_InitStruct);\n}\n/*-----------------------------------------------------------*/\nvoid SENSORS_GPIO_Init(void)\n{\n  GPIO_InitTypeDef GPIO_InitStruct;\n\n  /**I2C2 GPIO Configuration\n  PA6     ------\u003e I2C2_SDA\n  PA7     ------\u003e I2C2_SCL\n  */\n  GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;\n  GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;\n  GPIO_InitStruct.Pull = GPIO_NOPULL;\n  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;\n  GPIO_InitStruct.Alternate = GPIO_AF8_I2C2;\n  HAL_GPIO_Init(GPIOA, \u0026GPIO_InitStruct);\n    __HAL_RCC_I2C2_CLK_ENABLE();\n\n    /*Configure GPIO pin : PB6 as output*/\n    GPIO_InitStruct.Pin = GPIO_PIN_6;\n    GPIO_InitStruct.Mode =  GPIO_MODE_INPUT;\n    GPIO_InitStruct.Pull = GPIO_PULLDOWN;\n    HAL_GPIO_Init(GPIOB, \u0026GPIO_InitStruct);\n}\n/*-----------------------------------------------------------*/\n\n/* --- Check for factory reset condition: \n - P1 TXD is connected to last port RXD    \n */\nuint8_t IsFactoryReset(void){\n\tGPIO_InitTypeDef GPIO_InitStruct;\n\tuint32_t P1_TX_Port, P1_RX_Port, P_last_TX_Port, P_last_RX_Port;\n\tuint16_t P1_TX_Pin, P1_RX_Pin, P_last_TX_Pin, P_last_RX_Pin;\n\t\n\t/* -- Setup GPIOs -- */\n\n\t/* Enable all GPIO Ports Clocks */\n\t__GPIOA_CLK_ENABLE();\n\t__GPIOB_CLK_ENABLE();\n\t__GPIOC_CLK_ENABLE();\n\t__GPIOD_CLK_ENABLE();\n\t\n\t/* Get GPIOs */\n\tGetPortGPIOs(P1,\u0026P1_TX_Port,\u0026P1_TX_Pin,\u0026P1_RX_Port,\u0026P1_RX_Pin);\n\tGetPortGPIOs(P_LAST,\u0026P_last_TX_Port,\u0026P_last_TX_Pin,\u0026P_last_RX_Port,\u0026P_last_RX_Pin);\n\t\n\t/* TXD of first port */\n\tGPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;\n\tGPIO_InitStruct.Pull = GPIO_NOPULL;\n\tGPIO_InitStruct.Pin =P1_TX_Pin;\n\tHAL_GPIO_Init((GPIO_TypeDef* )P1_TX_Port,\u0026GPIO_InitStruct);\n\t\n\t/* RXD of last port */\n\tGPIO_InitStruct.Mode = GPIO_MODE_INPUT;\n\tGPIO_InitStruct.Pull = GPIO_PULLDOWN;\n\tGPIO_InitStruct.Pin =P_last_RX_Pin;\n\tHAL_GPIO_Init((GPIO_TypeDef* )P_last_RX_Port,\u0026GPIO_InitStruct);\n\t\n\t/* Check for factory reset conditions */\n\tHAL_GPIO_WritePin((GPIO_TypeDef* )P1_TX_Port,P1_TX_Pin,GPIO_PIN_RESET);\n\tDelay_ms_no_rtos(5);\n\tif(HAL_GPIO_ReadPin((GPIO_TypeDef* )P_last_RX_Port,P_last_RX_Pin) == RESET){\n\t\tHAL_GPIO_WritePin((GPIO_TypeDef* )P1_TX_Port,P1_TX_Pin,GPIO_PIN_SET);\n\t\tDelay_ms_no_rtos(5);\n\t\tif(HAL_GPIO_ReadPin((GPIO_TypeDef* )P_last_RX_Port,P_last_RX_Pin) == SET){\n\t\t\treturn 1;\n\t\t}\n\t}\n\t\n\t/* Clear flag for formated EEPROM if it was already set */\n\t/* Flag address (STM32F09x) - Last 4 words of SRAM */\n\t*((unsigned long* )0x20007FF0) =0xFFFFFFFF;\n\t\n\treturn 0;\n}\n\n/*-----------------------------------------------------------*/\n\n/* --- Get GPIO pins and ports of this array port\n */\nBOS_Status GetPortGPIOs(uint8_t port,uint32_t *TX_Port,uint16_t *TX_Pin,uint32_t *RX_Port,uint16_t *RX_Pin){\n\tBOS_Status result =BOS_OK;\n\t\n\t/* Get port UART */\n\tUART_HandleTypeDef *huart =GetUart(port);\n\t\n\tif(huart == \u0026huart1){\n#ifdef _Usart1\t\t\n\t\t*TX_Port =(uint32_t ) USART1_TX_PORT;\n\t\t*TX_Pin = USART1_TX_PIN;\n\t\t*RX_Port =(uint32_t ) USART1_RX_PORT;\n\t\t*RX_Pin = USART1_RX_PIN;\n#endif\n\t}\n#ifdef _Usart2\t\n\telse if(huart == \u0026huart2){\n\t\t*TX_Port =(uint32_t ) USART2_TX_PORT;\n\t\t*TX_Pin = USART2_TX_PIN;\n\t\t*RX_Port =(uint32_t ) USART2_RX_PORT;\n\t\t*RX_Pin = USART2_RX_PIN;\n\t}\n#endif\n#ifdef _Usart3\t\n\telse if(huart == \u0026huart3){\n\t\t*TX_Port =(uint32_t ) USART3_TX_PORT;\n\t\t*TX_Pin = USART3_TX_PIN;\n\t\t*RX_Port =(uint32_t ) USART3_RX_PORT;\n\t\t*RX_Pin = USART3_RX_PIN;\n\t}\n#endif\n#ifdef _Usart4\n\telse if(huart == \u0026huart4){\n\t\t*TX_Port =(uint32_t ) USART4_TX_PORT;\n\t\t*TX_Pin = USART4_TX_PIN;\n\t\t*RX_Port =(uint32_t ) USART4_RX_PORT;\n\t\t*RX_Pin = USART4_RX_PIN;\n\t}\n#endif\n#ifdef _Usart5\t\n\telse if(huart == \u0026huart5){\n\t\t*TX_Port =(uint32_t ) USART5_TX_PORT;\n\t\t*TX_Pin = USART5_TX_PIN;\n\t\t*RX_Port =(uint32_t ) USART5_RX_PORT;\n\t\t*RX_Pin = USART5_RX_PIN;\n\t}\n#endif\n#ifdef _Usart6\t\n\telse if(huart == \u0026huart6){\n\t\t*TX_Port =(uint32_t ) USART6_TX_PORT;\n\t\t*TX_Pin = USART6_TX_PIN;\n\t\t*RX_Port =(uint32_t ) USART6_RX_PORT;\n\t\t*RX_Pin = USART6_RX_PIN;\n\t}\n#endif\n#ifdef _Usart7\n\telse if (huart == \u0026huart7) \n\t{\t\t\n\t\t*TX_Port = (uint32_t)USART7_TX_PORT;\n\t\t*TX_Pin = USART7_TX_PIN;\n\t\t*RX_Port = (uint32_t)USART7_RX_PORT;\n\t\t*RX_Pin = USART7_RX_PIN;\n\t} \n#endif\n#ifdef _Usart8\t\n\telse if (huart == \u0026huart8) \n\t{\t\n\t\t*TX_Port = (uint32_t)USART8_TX_PORT;\n\t\t*TX_Pin = USART8_TX_PIN;\n\t\t*RX_Port = (uint32_t)USART8_RX_PORT;\n\t\t*RX_Pin = USART8_RX_PIN;\n\t} \n#endif\n\telse\n\t\tresult =BOS_ERROR;\n\t\n\treturn result;\n}\n\n/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/","metadata":{"language":"cpp","linenums":false}},{"element_type":"embed","content":"https://www.youtube.com/shorts/QbJlmUX6kw4?feature=share"}]