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 Sep 17 16:21:40 2016 +0000
Revision:
0:b86eda0e990d
Child:
2:3842948024ca
checking in to share

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 0:b86eda0e990d 3
nexpaq 0:b86eda0e990d 4 DigitalOut ledR(P2_4, LED_OFF);
nexpaq 0:b86eda0e990d 5 DigitalOut ledG(P2_5, LED_OFF);
nexpaq 0:b86eda0e990d 6 DigitalOut ledB(P2_6, LED_OFF);
nexpaq 0:b86eda0e990d 7 DigitalIn button(P0_1, PullUp);
nexpaq 0:b86eda0e990d 8
nexpaq 0:b86eda0e990d 9 /***** Definitions *****/
nexpaq 0:b86eda0e990d 10 #define FUNCTION_TABLE_NUM 1
nexpaq 0:b86eda0e990d 11 #define UUID_NUM 16 //UUID number is 16, don't change it
nexpaq 0:b86eda0e990d 12 #define BUTTON_DEBOUNCE 5
nexpaq 0:b86eda0e990d 13 #define DBG_MSG
nexpaq 0:b86eda0e990d 14
nexpaq 0:b86eda0e990d 15 /***** Globals *****/
nexpaq 0:b86eda0e990d 16 void my_function_CMD_2700(unsigned char *pData, unsigned char len);
nexpaq 0:b86eda0e990d 17 const MDK_REGISTER_CMD my_cmd_func_table[FUNCTION_TABLE_NUM] = {
nexpaq 0:b86eda0e990d 18 {0x2700, my_function_CMD_2700}, // Command -> function
nexpaq 0:b86eda0e990d 19 };
nexpaq 0:b86eda0e990d 20
nexpaq 0:b86eda0e990d 21 int btnCnt = 0;
nexpaq 0:b86eda0e990d 22 int btnSts = 0;
nexpaq 0:b86eda0e990d 23 unsigned char btnPress = 0x01;
nexpaq 0:b86eda0e990d 24
nexpaq 0:b86eda0e990d 25 /***** Functions *****/
nexpaq 0:b86eda0e990d 26 void my_function_CMD_2700(unsigned char *pData, unsigned char len){
nexpaq 0:b86eda0e990d 27 unsigned char response = 0x00;
nexpaq 0:b86eda0e990d 28 ledR = (pData[0]>0) ? LED_ON : LED_OFF ;
nexpaq 0:b86eda0e990d 29 ledG = (pData[1]>0) ? LED_ON : LED_OFF ;
nexpaq 0:b86eda0e990d 30 ledB = (pData[2]>0) ? LED_ON : LED_OFF ;
nexpaq 0:b86eda0e990d 31 np_api_upload(0x2701, &response, 1);
nexpaq 0:b86eda0e990d 32 #ifdef DBG_MSG
nexpaq 0:b86eda0e990d 33 printf("LED Command Received\n\r");
nexpaq 0:b86eda0e990d 34 #endif
nexpaq 0:b86eda0e990d 35 }
nexpaq 0:b86eda0e990d 36
nexpaq 0:b86eda0e990d 37 /******************************************************************************/
nexpaq 0:b86eda0e990d 38 void app_setup(){
nexpaq 0:b86eda0e990d 39 // np_api_set_app_version(0, 0, 3);
nexpaq 0:b86eda0e990d 40 if ( np_api_register((MDK_REGISTER_CMD*)my_cmd_func_table, FUNCTION_TABLE_NUM) == MDK_REGISTER_FAILD ) {
nexpaq 0:b86eda0e990d 41 // Register failed handle code
nexpaq 0:b86eda0e990d 42 error("MDK Register Failed");
nexpaq 0:b86eda0e990d 43 }
nexpaq 0:b86eda0e990d 44 #ifdef DBG_MSG
nexpaq 0:b86eda0e990d 45 printf("MDK Commands Registered\n\r");
nexpaq 0:b86eda0e990d 46 #endif
nexpaq 0:b86eda0e990d 47 }
nexpaq 0:b86eda0e990d 48
nexpaq 0:b86eda0e990d 49 void app_loop() {
nexpaq 0:b86eda0e990d 50 if (btnSts) {
nexpaq 0:b86eda0e990d 51 btnCnt = (button) ? 0 : (btnCnt + 1);
nexpaq 0:b86eda0e990d 52 if (btnCnt >= BUTTON_DEBOUNCE) {
nexpaq 0:b86eda0e990d 53 np_api_upload(0x2800, &btnPress, 1);
nexpaq 0:b86eda0e990d 54 btnSts = !btnSts;
nexpaq 0:b86eda0e990d 55 btnCnt = 0;
nexpaq 0:b86eda0e990d 56 #ifdef DBG_MSG
nexpaq 0:b86eda0e990d 57 printf("Button Pressed\n\r");
nexpaq 0:b86eda0e990d 58 #endif
nexpaq 0:b86eda0e990d 59 }
nexpaq 0:b86eda0e990d 60 } else {
nexpaq 0:b86eda0e990d 61 btnCnt = (!button) ? 0 : (btnCnt + 1);
nexpaq 0:b86eda0e990d 62 if (btnCnt >= BUTTON_DEBOUNCE) {
nexpaq 0:b86eda0e990d 63 btnSts = !btnSts;
nexpaq 0:b86eda0e990d 64 btnCnt = 0;
nexpaq 0:b86eda0e990d 65 }
nexpaq 0:b86eda0e990d 66 }
nexpaq 0:b86eda0e990d 67 }
nexpaq 0:b86eda0e990d 68
nexpaq 0:b86eda0e990d 69 int main(void){
nexpaq 0:b86eda0e990d 70 np_api_init();
nexpaq 0:b86eda0e990d 71 app_setup();
nexpaq 0:b86eda0e990d 72 np_api_start();
nexpaq 0:b86eda0e990d 73 while(1){
nexpaq 0:b86eda0e990d 74 app_loop();
nexpaq 0:b86eda0e990d 75 np_api_bsl_chk();
nexpaq 0:b86eda0e990d 76 Thread::wait(50);
nexpaq 0:b86eda0e990d 77 }
nexpaq 0:b86eda0e990d 78 return 0;
nexpaq 0:b86eda0e990d 79 }
nexpaq 0:b86eda0e990d 80