Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Hexi_KW40Z Hexi_OLED_SSD1351
Revision 3:97bc87323258, committed 2016-11-04
- Comitter:
- GregC
- Date:
- Fri Nov 04 23:11:29 2016 +0000
- Parent:
- 2:8e7d89c2cbde
- Commit message:
- Very advanced Click Air Quality example for Hexiwear featuring OLED Display, Bluetooth, Cloud and Touch
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Hexi_KW40Z.lib Fri Nov 04 23:11:29 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/teams/Hexiwear/code/Hexi_KW40Z/#3f5ed7abc5c7
--- a/main.cpp Mon Oct 24 15:14:39 2016 +0000
+++ b/main.cpp Fri Nov 04 23:11:29 2016 +0000
@@ -6,6 +6,7 @@
#include "mbed.h"
#include "Hexi_OLED_SSD1351.h"
+#include "Hexi_KW40Z.h"
#include "images.h"
#include "new_images.h"
#include "string.h"
@@ -17,17 +18,29 @@
AnalogIn ain(PTB2);
SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); // SSD1351 OLED Driver (MOSI,SCLK,POWER,CS,RST,DC)
-DigitalOut led1(LED_GREEN);
+KW40Z kw40z_device(PTE24, PTE25); // Instantiate the Hexi KW40Z Driver (UART TX, UART RX)
+DigitalOut blueLed(LED3,1);
Serial pc(USBTX, USBRX);
+Thread txThread;
+
+/******************************************************************************
+* prototypes
+*******************************************************************************/
+void InitModules();
+void ReadSensor();
+void CalculatePPM();
+void DisplayAirQValue(uint16_t value);
+
+
/******************************************************************************
* Module Variable Definitions
*******************************************************************************/
-double ppm; // ppm
+uint16_t ppm;
-int value = 0;
-int value_old = 0;
+uint16_t value = 0;
+uint16_t value_old = 0;
uint16_t adc_rd;
//const uint8_t *image1; // old cover image
@@ -41,6 +54,76 @@
bool test = false; // used to put the program in text mode to check images
+/**************************************************************************************************
+* Call Back Functions
+**************************************************************************************************/
+
+void ButtonRight(void)
+{
+ kw40z_device.ToggleAdvertisementMode();
+}
+
+void ButtonLeft(void)
+{
+ kw40z_device.ToggleAdvertisementMode();
+}
+
+void PassKey(void)
+{
+ /* Display Bond Pass Key in a 95px by 18px textbox at x=0,y=40 */
+ sprintf(text,"%d", kw40z_device.GetPassKey());
+ oled.TextBox((uint8_t *)text,0,72,95,18);
+}
+
+
+
+/**************************************************************************************************
+* Function Main()
+* -------------------------------------------------------------------------------------------------
+* Overview:
+* Input: None
+* Output: None
+**************************************************************************************************/
+
+int main()
+{
+
+ InitModules();
+
+ while (true)
+ {
+
+ ReadSensor();
+ pc.printf("Sensor Value 0x%04X\n\r",ain.read_u16());
+
+ blueLed = !kw40z_device.GetAdvertisementMode(); /*Indicate BLE Advertisment Mode*/
+
+
+ CalculatePPM();
+ DisplayAirQValue(ppm);
+
+ Thread::wait(500);
+
+ }
+}
+
+/**************************************************************************************************
+* Function TxTask()
+**************************************************************************************************/
+
+void txTask(void){
+
+ while (true)
+ {
+
+ /*Notify Hexiwear App that it is running Sensor Tag mode*/
+ kw40z_device.SendSetApplicationMode(GUI_CURRENT_APP_SENSOR_TAG);
+
+ kw40z_device.SendPressure(10*ppm); //send ppm Air Quality Click value
+
+ Thread::wait(1000);
+ }
+}
/**************************************************************************************************
* Function InitModules()
@@ -65,6 +148,11 @@
oled_text_properties_t textProperties = {0}; // Get OLED Class Default Text Properties
oled.GetTextProperties(&textProperties);
+
+ /* Register callbacks to application functions */
+ kw40z_device.attach_buttonLeft(&ButtonLeft);
+ kw40z_device.attach_buttonRight(&ButtonRight);
+ kw40z_device.attach_passkey(&PassKey);
//PPM text now in the Bitmap
@@ -81,7 +169,8 @@
sprintf(text,"%i",value); // Format the value
oled.TextBox((uint8_t *)text,55,76,20,15); //Increase textbox for more digits
-
+
+ txThread.start(txTask); /*Start transmitting Sensor Tag Data */
}
@@ -122,7 +211,7 @@
Rs = Rl * (3.3 - Vrl)/Vrl; // Calculate sensor resistance
ratio = Rs/Rl; // Calculate ratio
lgPPM = (log10(ratio) * -0.8) + 0.9; // Calculate ppm
- ppm = pow(10,lgPPM); // Calculate ppm
+ ppm = 6* pow(10,lgPPM); // Calculate ppm
}
@@ -135,7 +224,7 @@
* Output: None
**************************************************************************************************/
-void DisplayAirQValue( uint16_t value )
+void DisplayAirQValue(uint16_t value )
{
if (value_old != value)
{
@@ -171,51 +260,4 @@
oled.TextBox((uint8_t *)text,55,76,20,15); //Increase textbox for more digits
}
value_old = value;
-}
-
-
-/**************************************************************************************************
-* Function Main()
-* -------------------------------------------------------------------------------------------------
-* Overview:
-* Input: None
-* Output: None
-**************************************************************************************************/
-
-int main()
-{
-
- InitModules();
- test = false; // use this to test the BMPS
-
-
- while (true)
- {
-
- ReadSensor();
- pc.printf("Sensor Value 0x%04X\n\r",ain.read_u16());
-
- // added a test to toggle through the images
- if (test == true)
- {
- int test_ppm = 10;
- for( int i = 0; i < 5; i++)
- {
- DisplayAirQValue(test_ppm);
- test_ppm += 50;
- led1 = !led1;
- Thread::wait(1000);
- }
- }
- else
- {
-
- CalculatePPM();
- DisplayAirQValue(ppm);
-
- led1 = !led1;
- Thread::wait(500);
- }
-
- }
}
\ No newline at end of file
--- a/mbed-os.lib Mon Oct 24 15:14:39 2016 +0000 +++ b/mbed-os.lib Fri Nov 04 23:11:29 2016 +0000 @@ -1,1 +1,1 @@ -https://github.com/ARMmbed/mbed-os/#670b0984ebf1207771ef5afbc1c64f85af349da1 +https://github.com/ARMmbed/mbed-os/#e2617cc0e17f5c3fc2bae6a589c9bcfd3d1a717b