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:
nexpaq
Date:
Sat Oct 15 19:07:22 2016 +0000
Revision:
9:b7cf4b7fd770
Parent:
8:123fe6112b7a
Child:
10:a81682ee3e73
Applied auto formatting

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"
nexpaq 5:7d8e69b1d3b6 3 #include "MAX44000.h"
nexpaq 0:b86eda0e990d 4
nexpaq 5:7d8e69b1d3b6 5 MAX44000 max44000(P1_6, P1_7);
nexpaq 8:123fe6112b7a 6 PwmOut ledR(P2_4);
nexpaq 8:123fe6112b7a 7 PwmOut ledG(P2_5);
nexpaq 8:123fe6112b7a 8 PwmOut ledB(P2_6);
nexpaq 0:b86eda0e990d 9 DigitalIn button(P0_1, PullUp);
nexpaq 0:b86eda0e990d 10
nexpaq 0:b86eda0e990d 11 /***** Definitions *****/
nexpaq 6:eb5c0139e5db 12 #define FUNCTION_TABLE_NUM 2
nexpaq 6:eb5c0139e5db 13 #define UUID_NUM 16 // UUID number is 16, don't change it
nexpaq 4:494741f7f5b2 14 #define LOOP_DELAY 100
nexpaq 5:7d8e69b1d3b6 15 #define PROX_THRESHOLD 50
nexpaq 6:eb5c0139e5db 16 #define ALS_INTERVAL 10 // about once per second
nexpaq 0:b86eda0e990d 17
nexpaq 0:b86eda0e990d 18 /***** Globals *****/
nexpaq 0:b86eda0e990d 19 void my_function_CMD_2700(unsigned char *pData, unsigned char len);
nexpaq 6:eb5c0139e5db 20 void my_function_CMD_2702(unsigned char *pData, unsigned char len);
nexpaq 0:b86eda0e990d 21 const MDK_REGISTER_CMD my_cmd_func_table[FUNCTION_TABLE_NUM] = {
nexpaq 6:eb5c0139e5db 22 {0x2700, my_function_CMD_2700}, // Command -> function
nexpaq 6:eb5c0139e5db 23 {0x2702, my_function_CMD_2702}, // Command -> function
nexpaq 0:b86eda0e990d 24 };
nexpaq 0:b86eda0e990d 25
nexpaq 6:eb5c0139e5db 26 int alsCnt = 0;
nexpaq 6:eb5c0139e5db 27 int prxThrsh = PROX_THRESHOLD ;
nexpaq 5:7d8e69b1d3b6 28 int lastPrx = 0;
nexpaq 5:7d8e69b1d3b6 29 unsigned char prxPress = 0x02;
gsteiert 3:9d15891f9352 30 int lastBtn = 1;
nexpaq 0:b86eda0e990d 31 unsigned char btnPress = 0x01;
nexpaq 0:b86eda0e990d 32
nexpaq 0:b86eda0e990d 33 /***** Functions *****/
nexpaq 6:eb5c0139e5db 34 void my_function_CMD_2700(unsigned char *pData, unsigned char len)
nexpaq 6:eb5c0139e5db 35 {
nexpaq 6:eb5c0139e5db 36 unsigned char response = 0x00;
nexpaq 8:123fe6112b7a 37 ledR = 1.0f - (pData[0] / 255.0f);
nexpaq 8:123fe6112b7a 38 ledG = 1.0f - (pData[1] / 255.0f);
nexpaq 8:123fe6112b7a 39 ledB = 1.0f - (pData[2] / 255.0f);
nexpaq 6:eb5c0139e5db 40 np_api_upload(0x2701, &response, 1);
nexpaq 6:eb5c0139e5db 41 }
nexpaq 6:eb5c0139e5db 42
nexpaq 6:eb5c0139e5db 43 void my_function_CMD_2702(unsigned char *pData, unsigned char len)
nexpaq 6:eb5c0139e5db 44 {
nexpaq 6:eb5c0139e5db 45 unsigned char response = 0x00;
nexpaq 6:eb5c0139e5db 46 prxThrsh = pData[0] ;
nexpaq 6:eb5c0139e5db 47 np_api_upload(0x2703, &response, 1);
nexpaq 6:eb5c0139e5db 48 }
nexpaq 6:eb5c0139e5db 49
nexpaq 6:eb5c0139e5db 50 void sendALS()
nexpaq 6:eb5c0139e5db 51 {
nexpaq 6:eb5c0139e5db 52 unsigned char pData[3];
nexpaq 9:b7cf4b7fd770 53 max44000.writeReg(MAX44000::REG_MAIN_CONFIG, 0x20);
nexpaq 6:eb5c0139e5db 54 pData[0] = 10;
nexpaq 6:eb5c0139e5db 55 pData[1] = max44000.readReg(MAX44000::REG_ALS_DATA_HIGH);
nexpaq 6:eb5c0139e5db 56 pData[2] = max44000.readReg(MAX44000::REG_ALS_DATA_LOW);
nexpaq 6:eb5c0139e5db 57 np_api_upload(0x2800, pData, 3);
nexpaq 9:b7cf4b7fd770 58 max44000.writeReg(MAX44000::REG_MAIN_CONFIG, 0x30);
nexpaq 0:b86eda0e990d 59 }
nexpaq 0:b86eda0e990d 60
nexpaq 0:b86eda0e990d 61 /******************************************************************************/
nexpaq 6:eb5c0139e5db 62 void app_setup()
nexpaq 6:eb5c0139e5db 63 {
nexpaq 6:eb5c0139e5db 64 // np_api_set_app_version(0, 0, 3);
nexpaq 6:eb5c0139e5db 65 if ( np_api_register((MDK_REGISTER_CMD*)my_cmd_func_table, FUNCTION_TABLE_NUM) == MDK_REGISTER_FAILD ) {
nexpaq 6:eb5c0139e5db 66 // Register failed handle code
nexpaq 6:eb5c0139e5db 67 }
nexpaq 6:eb5c0139e5db 68 max44000.init(MAX44000::MODE_ALS_PROX, MAX44000::ALSTIM_64X, MAX44000::ALSPGA_1X, MAX44000::DRV_110);
nexpaq 8:123fe6112b7a 69 ledR = 1.0f;
nexpaq 8:123fe6112b7a 70 ledG = 1.0f;
nexpaq 8:123fe6112b7a 71 ledB = 1.0f;
nexpaq 0:b86eda0e990d 72 }
nexpaq 0:b86eda0e990d 73
nexpaq 6:eb5c0139e5db 74 void app_loop()
nexpaq 6:eb5c0139e5db 75 {
nexpaq 5:7d8e69b1d3b6 76 int proxData = max44000.readReg(MAX44000::REG_PRX_DATA);
nexpaq 6:eb5c0139e5db 77 if (proxData > prxThrsh) {
nexpaq 9:b7cf4b7fd770 78 if (!lastPrx) {
nexpaq 5:7d8e69b1d3b6 79 np_api_upload(0x2800, &prxPress, 1);
nexpaq 5:7d8e69b1d3b6 80 }
nexpaq 5:7d8e69b1d3b6 81 lastPrx = 1;
nexpaq 5:7d8e69b1d3b6 82 } else {
nexpaq 9:b7cf4b7fd770 83 lastPrx = 0;
nexpaq 5:7d8e69b1d3b6 84 }
nexpaq 5:7d8e69b1d3b6 85
nexpaq 9:b7cf4b7fd770 86 if (!button && lastBtn) {
gsteiert 3:9d15891f9352 87 np_api_upload(0x2800, &btnPress, 1);
nexpaq 9:b7cf4b7fd770 88 }
nexpaq 9:b7cf4b7fd770 89 lastBtn = button;
nexpaq 6:eb5c0139e5db 90
nexpaq 6:eb5c0139e5db 91 alsCnt += 1;
nexpaq 6:eb5c0139e5db 92 if (alsCnt > ALS_INTERVAL) {
nexpaq 6:eb5c0139e5db 93 sendALS();
nexpaq 6:eb5c0139e5db 94 alsCnt = 0;
nexpaq 6:eb5c0139e5db 95 }
nexpaq 0:b86eda0e990d 96 }
nexpaq 0:b86eda0e990d 97
nexpaq 6:eb5c0139e5db 98 int main(void)
nexpaq 6:eb5c0139e5db 99 {
nexpaq 6:eb5c0139e5db 100 np_api_init();
nexpaq 6:eb5c0139e5db 101 app_setup();
nexpaq 6:eb5c0139e5db 102 np_api_start();
nexpaq 6:eb5c0139e5db 103 while(1) {
nexpaq 6:eb5c0139e5db 104 app_loop();
nexpaq 6:eb5c0139e5db 105 np_api_bsl_chk();
nexpaq 6:eb5c0139e5db 106 Thread::wait(LOOP_DELAY);
nexpaq 6:eb5c0139e5db 107 }
nexpaq 6:eb5c0139e5db 108 return 0;
nexpaq 0:b86eda0e990d 109 }