Code for the Hexiwear sensor system. Requires an Air Quality Click, Carbon Monoxide Click, and Buzzer Click for full functionality. Currently only reads values and displays to the OLED while testing and alerting the user of present threats. Future goals are to incorporate button presses with separate screens to display the data as well as using the KW40 drivers to transmit the data. Still in early stages of development, many unnecessary files will be removed and cleaned up once final product is completed within the next month. Driver.cpp is the main driver for the program and was written for purposes of this project. All other headers and functions were found on mbed.org from other developers repositories or provided by NXP Semiconductors for purposes of this project.

Dependencies:   Hexi_KW40Z images

Committer:
Gfolker
Date:
Tue Mar 28 21:41:06 2017 +0000
Revision:
2:aa8c291b3f9a
Parent:
0:f70b1d60f794
Application now supports data transmission via BLE

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Gfolker 0:f70b1d60f794 1 /* Includes ------------------------------------------------------------------*/
Gfolker 0:f70b1d60f794 2 #include "pwm_tone.h"
Gfolker 0:f70b1d60f794 3
Gfolker 0:f70b1d60f794 4 /* Private typedef -----------------------------------------------------------*/
Gfolker 0:f70b1d60f794 5 /* Private define ------------------------------------------------------------*/
Gfolker 0:f70b1d60f794 6 /* Private variables ---------------------------------------------------------*/
Gfolker 0:f70b1d60f794 7 /* Private function prototypes -----------------------------------------------*/
Gfolker 0:f70b1d60f794 8 /* Private functions ---------------------------------------------------------*/
Gfolker 0:f70b1d60f794 9
Gfolker 0:f70b1d60f794 10 /**
Gfolker 0:f70b1d60f794 11 * @brief Tune Function
Gfolker 0:f70b1d60f794 12 * @param name : Choose the PwmOut
Gfolker 0:f70b1d60f794 13 period : this param is tune value. (C_3...B_5)
Gfolker 0:f70b1d60f794 14 beat : this param is beat value. (1..16) 1 means 1/16 beat
Gfolker 0:f70b1d60f794 15 * @retval None
Gfolker 0:f70b1d60f794 16 */
Gfolker 0:f70b1d60f794 17 void Tune(PwmOut name, int period, int beat)
Gfolker 0:f70b1d60f794 18 {
Gfolker 0:f70b1d60f794 19 int delay;
Gfolker 0:f70b1d60f794 20
Gfolker 0:f70b1d60f794 21 delay = beat*63;
Gfolker 0:f70b1d60f794 22 name.period_us(period);
Gfolker 0:f70b1d60f794 23 name.write(0.50f); // 50% duty cycle
Gfolker 0:f70b1d60f794 24 wait_ms(delay); // 1 beat
Gfolker 0:f70b1d60f794 25 name.period_us(0); // Sound off
Gfolker 0:f70b1d60f794 26 }
Gfolker 0:f70b1d60f794 27
Gfolker 0:f70b1d60f794 28 /**
Gfolker 0:f70b1d60f794 29 * @brief Auto tunes Function
Gfolker 0:f70b1d60f794 30 * @param name : Choose the PwmOut
Gfolker 0:f70b1d60f794 31 period : this param is tune value. (C_3...B_5)
Gfolker 0:f70b1d60f794 32 beat : this param is beat value. (1..16) 1 means 1/16 beat
Gfolker 0:f70b1d60f794 33 * @retval None
Gfolker 0:f70b1d60f794 34 */
Gfolker 0:f70b1d60f794 35 void Auto_tunes(PwmOut name, int period, int beat)
Gfolker 0:f70b1d60f794 36 {
Gfolker 0:f70b1d60f794 37 int delay;
Gfolker 0:f70b1d60f794 38
Gfolker 0:f70b1d60f794 39 delay = beat*63;
Gfolker 0:f70b1d60f794 40 name.period_us(period);
Gfolker 0:f70b1d60f794 41 name.write(0.50f); // 50% duty cycle
Gfolker 0:f70b1d60f794 42 wait_ms(delay);
Gfolker 0:f70b1d60f794 43 }
Gfolker 0:f70b1d60f794 44
Gfolker 0:f70b1d60f794 45 /**
Gfolker 0:f70b1d60f794 46 * @brief Stop tunes Function
Gfolker 0:f70b1d60f794 47 * @param name : Choose the PwmOut
Gfolker 0:f70b1d60f794 48 * @retval None
Gfolker 0:f70b1d60f794 49 */
Gfolker 0:f70b1d60f794 50 void Stop_tunes(PwmOut name)
Gfolker 0:f70b1d60f794 51 {
Gfolker 0:f70b1d60f794 52 name.period_us(0);
Gfolker 0:f70b1d60f794 53 }
Gfolker 0:f70b1d60f794 54
Gfolker 0:f70b1d60f794 55 //void buzzer(PwmOut Buzzer, int ppm, float B_4, float B_5)
Gfolker 0:f70b1d60f794 56 //{
Gfolker 0:f70b1d60f794 57 //int counter = 0; /* Break condition to take another measurement */
Gfolker 0:f70b1d60f794 58 //if (ppm >=10 and ppm <=25) {
Gfolker 0:f70b1d60f794 59 //while (1) {
Gfolker 0:f70b1d60f794 60
Gfolker 0:f70b1d60f794 61 // if (led_green == 0 && led_red == 1 && led_blue == 1){
Gfolker 0:f70b1d60f794 62 // led_green = 0;
Gfolker 0:f70b1d60f794 63 // led_red = 0; /* Yellow LED */
Gfolker 0:f70b1d60f794 64 // led_blue = 1;
Gfolker 0:f70b1d60f794 65 //}
Gfolker 0:f70b1d60f794 66
Gfolker 0:f70b1d60f794 67 //else if (led_green == 0 && led_red == 0 && led_blue == 1) {
Gfolker 0:f70b1d60f794 68 // led_green = 1;
Gfolker 0:f70b1d60f794 69 // led_red = 1; /* Blink LED off */
Gfolker 0:f70b1d60f794 70 // led_blue = 1;
Gfolker 0:f70b1d60f794 71 //}
Gfolker 0:f70b1d60f794 72 //else {
Gfolker 0:f70b1d60f794 73 // led_green = 0;
Gfolker 0:f70b1d60f794 74 // led_red = 0; /* Blink LED on */
Gfolker 0:f70b1d60f794 75 // led_blue = 1;
Gfolker 0:f70b1d60f794 76 //}
Gfolker 0:f70b1d60f794 77 //counter++;
Gfolker 0:f70b1d60f794 78 //wait_ms(400);
Gfolker 0:f70b1d60f794 79 //if (counter >= 5)
Gfolker 0:f70b1d60f794 80 //return; /* After 20 iterations of the alarm, break */
Gfolker 0:f70b1d60f794 81 //}
Gfolker 0:f70b1d60f794 82 //}
Gfolker 0:f70b1d60f794 83 //else if (ppm > 25 and ppm < 100) {
Gfolker 0:f70b1d60f794 84 // while (1) {
Gfolker 0:f70b1d60f794 85
Gfolker 0:f70b1d60f794 86 //if (led_green == 0 && led_red == 1 && led_blue == 1){
Gfolker 0:f70b1d60f794 87 // led_green = 0;
Gfolker 0:f70b1d60f794 88 // led_red = 0; /* Yellow LED */
Gfolker 0:f70b1d60f794 89 // led_blue = 1;
Gfolker 0:f70b1d60f794 90 //}
Gfolker 0:f70b1d60f794 91
Gfolker 0:f70b1d60f794 92 // else if (led_green == 0 && led_red == 0 && led_blue == 1) {
Gfolker 0:f70b1d60f794 93 // led_green = 1;
Gfolker 0:f70b1d60f794 94 // led_red = 1; /* Blink LED off */
Gfolker 0:f70b1d60f794 95 // led_blue = 1;
Gfolker 0:f70b1d60f794 96 //}
Gfolker 0:f70b1d60f794 97 //else {
Gfolker 0:f70b1d60f794 98 // led_green = 0;
Gfolker 0:f70b1d60f794 99 // led_red = 0; /* Blink LED on */
Gfolker 0:f70b1d60f794 100 // led_blue = 1;
Gfolker 0:f70b1d60f794 101 //}
Gfolker 0:f70b1d60f794 102 // Tune(Buzzer, B_4, 10);
Gfolker 0:f70b1d60f794 103 //counter++;
Gfolker 0:f70b1d60f794 104 // wait_ms(250);
Gfolker 0:f70b1d60f794 105 //if (counter >= 5)
Gfolker 0:f70b1d60f794 106 //return; /* After 20 iterations of the alarm, break */
Gfolker 0:f70b1d60f794 107 // }
Gfolker 0:f70b1d60f794 108 //}
Gfolker 0:f70b1d60f794 109
Gfolker 0:f70b1d60f794 110 //else if (ppm >= 100) {
Gfolker 0:f70b1d60f794 111 //while (1) {
Gfolker 0:f70b1d60f794 112
Gfolker 0:f70b1d60f794 113 //if (led_green == 0 && led_red == 1 && led_blue ==1){
Gfolker 0:f70b1d60f794 114 //led_green = 1;
Gfolker 0:f70b1d60f794 115 //led_red = 0; /* Red LED */
Gfolker 0:f70b1d60f794 116 //led_blue = 1;
Gfolker 0:f70b1d60f794 117 //}
Gfolker 0:f70b1d60f794 118
Gfolker 0:f70b1d60f794 119 //else if (led_green == 1 && led_red == 0 && led_blue == 1) {
Gfolker 0:f70b1d60f794 120 // led_green = 1;
Gfolker 0:f70b1d60f794 121 // led_red = 1; /* Blink LED off */
Gfolker 0:f70b1d60f794 122 // led_blue = 1;
Gfolker 0:f70b1d60f794 123 //}
Gfolker 0:f70b1d60f794 124 //else {
Gfolker 0:f70b1d60f794 125 // led_green = 1;
Gfolker 0:f70b1d60f794 126 // led_red = 0; /* Blink LED on */
Gfolker 0:f70b1d60f794 127 // led_blue = 1;
Gfolker 0:f70b1d60f794 128 //}
Gfolker 0:f70b1d60f794 129 // Tune(Buzzer, B_5, 5);
Gfolker 0:f70b1d60f794 130 //counter++;
Gfolker 0:f70b1d60f794 131 // wait_ms(100);
Gfolker 0:f70b1d60f794 132 //if (counter >= 5)
Gfolker 0:f70b1d60f794 133 //return; /* After 20 iterations of the alarm, break */
Gfolker 0:f70b1d60f794 134 // }
Gfolker 0:f70b1d60f794 135 // }
Gfolker 0:f70b1d60f794 136 //}