nexpaq development module demo for MAX3010x sensor

Dependencies:   MAX30105 nexpaq_mdk

Fork of ALS_Prox_Demo by nexpaq

Temp Prox Demo

MAX32625NEXPAQ development module

This project is a demonstration application for the MAX32625NEXPAQ development module and a MAX3010x sensor.

This project demonstrates polling the proximity sensor to use it like a button and also polling the temperature sensor and sending the information back to the application running on the phone, and the phone controlling the threshold for the proximity sensor and controlling the on board RGB LED to create different colors.

nexpaq App Tile Files

temp_prox_demo.zip

Committer:
switches
Date:
Thu Feb 16 22:03:36 2017 +0000
Revision:
15:a99ffa637712
Parent:
14:6195f9b0bd1b
Updated MAX30105 library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nexpaq 0:b86eda0e990d 1 #include "mbed.h"
nexpaq 0:b86eda0e990d 2 #include "nexpaq_mdk.h"
switches 14:6195f9b0bd1b 3 #include "MAX30105.h"
nexpaq 0:b86eda0e990d 4
nexpaq 8:123fe6112b7a 5 PwmOut ledR(P2_4);
nexpaq 8:123fe6112b7a 6 PwmOut ledG(P2_5);
nexpaq 8:123fe6112b7a 7 PwmOut ledB(P2_6);
nexpaq 0:b86eda0e990d 8 DigitalIn button(P0_1, PullUp);
switches 14:6195f9b0bd1b 9 I2C i2c(P1_6, P1_7);
switches 14:6195f9b0bd1b 10 MAX30105 max30105(i2c);
nexpaq 0:b86eda0e990d 11
nexpaq 0:b86eda0e990d 12 /***** Definitions *****/
nexpaq 6:eb5c0139e5db 13 #define FUNCTION_TABLE_NUM 2
nexpaq 6:eb5c0139e5db 14 #define UUID_NUM 16 // UUID number is 16, don't change it
nexpaq 4:494741f7f5b2 15 #define LOOP_DELAY 100
nexpaq 10:a81682ee3e73 16 #define PROX_THRESHOLD 10
switches 14:6195f9b0bd1b 17 #define TEMP_INTERVAL 10 // about once per second
nexpaq 0:b86eda0e990d 18
nexpaq 0:b86eda0e990d 19 /***** Globals *****/
nexpaq 0:b86eda0e990d 20 void my_function_CMD_2700(unsigned char *pData, unsigned char len);
nexpaq 6:eb5c0139e5db 21 void my_function_CMD_2702(unsigned char *pData, unsigned char len);
nexpaq 0:b86eda0e990d 22 const MDK_REGISTER_CMD my_cmd_func_table[FUNCTION_TABLE_NUM] = {
nexpaq 6:eb5c0139e5db 23 {0x2700, my_function_CMD_2700}, // Command -> function
nexpaq 6:eb5c0139e5db 24 {0x2702, my_function_CMD_2702}, // Command -> function
nexpaq 0:b86eda0e990d 25 };
nexpaq 0:b86eda0e990d 26
switches 14:6195f9b0bd1b 27 int tempCnt = 0;
nexpaq 6:eb5c0139e5db 28 int prxThrsh = PROX_THRESHOLD ;
nexpaq 5:7d8e69b1d3b6 29 int lastPrx = 0;
nexpaq 5:7d8e69b1d3b6 30 unsigned char prxPress = 0x02;
gsteiert 3:9d15891f9352 31 int lastBtn = 1;
nexpaq 0:b86eda0e990d 32 unsigned char btnPress = 0x01;
nexpaq 0:b86eda0e990d 33
nexpaq 0:b86eda0e990d 34 /***** Functions *****/
nexpaq 6:eb5c0139e5db 35 void my_function_CMD_2700(unsigned char *pData, unsigned char len)
nexpaq 6:eb5c0139e5db 36 {
nexpaq 6:eb5c0139e5db 37 unsigned char response = 0x00;
nexpaq 8:123fe6112b7a 38 ledR = 1.0f - (pData[0] / 255.0f);
nexpaq 8:123fe6112b7a 39 ledG = 1.0f - (pData[1] / 255.0f);
nexpaq 8:123fe6112b7a 40 ledB = 1.0f - (pData[2] / 255.0f);
nexpaq 6:eb5c0139e5db 41 np_api_upload(0x2701, &response, 1);
nexpaq 6:eb5c0139e5db 42 }
nexpaq 6:eb5c0139e5db 43
nexpaq 6:eb5c0139e5db 44 void my_function_CMD_2702(unsigned char *pData, unsigned char len)
nexpaq 6:eb5c0139e5db 45 {
nexpaq 6:eb5c0139e5db 46 unsigned char response = 0x00;
nexpaq 6:eb5c0139e5db 47 prxThrsh = pData[0] ;
nexpaq 6:eb5c0139e5db 48 np_api_upload(0x2703, &response, 1);
nexpaq 6:eb5c0139e5db 49 }
nexpaq 6:eb5c0139e5db 50
switches 14:6195f9b0bd1b 51 void sendTEMP()
nexpaq 6:eb5c0139e5db 52 {
switches 14:6195f9b0bd1b 53 char dataBuf[2];
nexpaq 6:eb5c0139e5db 54 unsigned char pData[3];
nexpaq 6:eb5c0139e5db 55 pData[0] = 10;
switches 14:6195f9b0bd1b 56 pData[1] = 0xFF;
switches 14:6195f9b0bd1b 57 pData[2] = 0xFF;
switches 14:6195f9b0bd1b 58 if (max30105.readReg(MAX30105::REG_TEMP_CONFIG, dataBuf) == 0) {
switches 14:6195f9b0bd1b 59 dataBuf[0] = MAX30105::REG_TEMP_INT;
switches 14:6195f9b0bd1b 60 if (i2c.write(MAX30105_I2C_ADDR, dataBuf, 1) == 0) {
switches 14:6195f9b0bd1b 61 if (i2c.read(MAX30105_I2C_ADDR, dataBuf, 2) == 0) {
switches 14:6195f9b0bd1b 62 pData[1] = dataBuf[0];
switches 14:6195f9b0bd1b 63 pData[2] = dataBuf[1];
switches 14:6195f9b0bd1b 64 }
switches 14:6195f9b0bd1b 65 }
switches 14:6195f9b0bd1b 66 }
nexpaq 6:eb5c0139e5db 67 np_api_upload(0x2800, pData, 3);
switches 14:6195f9b0bd1b 68 max30105.writeReg(MAX30105::REG_TEMP_CONFIG, 0x01);
nexpaq 0:b86eda0e990d 69 }
nexpaq 0:b86eda0e990d 70
nexpaq 0:b86eda0e990d 71 /******************************************************************************/
nexpaq 6:eb5c0139e5db 72 void app_setup()
nexpaq 6:eb5c0139e5db 73 {
nexpaq 6:eb5c0139e5db 74 // np_api_set_app_version(0, 0, 3);
nexpaq 6:eb5c0139e5db 75 if ( np_api_register((MDK_REGISTER_CMD*)my_cmd_func_table, FUNCTION_TABLE_NUM) == MDK_REGISTER_FAILD ) {
nexpaq 6:eb5c0139e5db 76 // Register failed handle code
nexpaq 6:eb5c0139e5db 77 }
switches 14:6195f9b0bd1b 78 max30105.softReset(); // reset the MAX30105
switches 14:6195f9b0bd1b 79 max30105.shutDown(); // shut down while configuring
switches 14:6195f9b0bd1b 80 max30105.enableIntr(MAX30105::INTR_PROX); // enable proximity interrupt
switches 14:6195f9b0bd1b 81 max30105.setProx(0x40, PROX_THRESHOLD); // set proximity pulse amplitude and threshold
switches 14:6195f9b0bd1b 82 max30105.setSingleLED(); // configure single LED mode to initiate proximity detection
switches 14:6195f9b0bd1b 83 max30105.wakeUp(); // exit shutdown to start sensing
nexpaq 8:123fe6112b7a 84 ledR = 1.0f;
nexpaq 8:123fe6112b7a 85 ledG = 1.0f;
nexpaq 8:123fe6112b7a 86 ledB = 1.0f;
nexpaq 0:b86eda0e990d 87 }
nexpaq 0:b86eda0e990d 88
nexpaq 6:eb5c0139e5db 89 void app_loop()
nexpaq 6:eb5c0139e5db 90 {
switches 14:6195f9b0bd1b 91 if (max30105.getIntr1() & MAX30105::INTR_PROX) { // if the proximity interrupt occurs
nexpaq 9:b7cf4b7fd770 92 if (!lastPrx) {
nexpaq 5:7d8e69b1d3b6 93 np_api_upload(0x2800, &prxPress, 1);
nexpaq 5:7d8e69b1d3b6 94 }
switches 14:6195f9b0bd1b 95 max30105.writeReg(MAX30105::REG_MODE_CONFIG, MAX30105::MODE_1LED); // go back into proximity detection
nexpaq 5:7d8e69b1d3b6 96 lastPrx = 1;
nexpaq 5:7d8e69b1d3b6 97 } else {
nexpaq 9:b7cf4b7fd770 98 lastPrx = 0;
nexpaq 5:7d8e69b1d3b6 99 }
nexpaq 5:7d8e69b1d3b6 100
nexpaq 9:b7cf4b7fd770 101 if (!button && lastBtn) {
gsteiert 3:9d15891f9352 102 np_api_upload(0x2800, &btnPress, 1);
nexpaq 9:b7cf4b7fd770 103 }
nexpaq 9:b7cf4b7fd770 104 lastBtn = button;
nexpaq 6:eb5c0139e5db 105
switches 14:6195f9b0bd1b 106 tempCnt += 1;
switches 14:6195f9b0bd1b 107 if (tempCnt > TEMP_INTERVAL) {
switches 14:6195f9b0bd1b 108 sendTEMP();
switches 14:6195f9b0bd1b 109 tempCnt = 0;
nexpaq 6:eb5c0139e5db 110 }
nexpaq 0:b86eda0e990d 111 }
nexpaq 0:b86eda0e990d 112
nexpaq 6:eb5c0139e5db 113 int main(void)
nexpaq 6:eb5c0139e5db 114 {
nexpaq 6:eb5c0139e5db 115 np_api_init();
nexpaq 6:eb5c0139e5db 116 app_setup();
nexpaq 6:eb5c0139e5db 117 np_api_start();
nexpaq 6:eb5c0139e5db 118 while(1) {
nexpaq 6:eb5c0139e5db 119 app_loop();
nexpaq 6:eb5c0139e5db 120 np_api_bsl_chk();
nexpaq 6:eb5c0139e5db 121 Thread::wait(LOOP_DELAY);
nexpaq 6:eb5c0139e5db 122 }
nexpaq 6:eb5c0139e5db 123 return 0;
nexpaq 0:b86eda0e990d 124 }