MAX32625NEXPAQ Proximity Sensor Demo
Dependencies: MAX44000 nexpaq_dev nexpaq_mdk
Fork of lib_tst_demo by
main.cpp
00001 #include "mbed.h" 00002 #include "nexpaq_mdk.h" 00003 #include "MAX44000.h" 00004 00005 MAX44000 max44000(P1_6, P1_7); 00006 PwmOut ledR(P2_4); 00007 PwmOut ledG(P2_5); 00008 PwmOut ledB(P2_6); 00009 DigitalIn button(P0_1, PullUp); 00010 00011 /***** Definitions *****/ 00012 #define FUNCTION_TABLE_NUM 1 00013 #define UUID_NUM 16 //UUID number is 16, don't change it 00014 #define LOOP_DELAY 100 00015 #define PROX_THRESHOLD 10 00016 00017 /***** Globals *****/ 00018 void my_function_CMD_2700(unsigned char *pData, unsigned char len); 00019 const MDK_REGISTER_CMD my_cmd_func_table[FUNCTION_TABLE_NUM] = { 00020 {0x2700, my_function_CMD_2700}, // Command -> function 00021 }; 00022 00023 int lastPrx = 0; 00024 unsigned char prxPress = 0x02; 00025 int lastBtn = 1; 00026 unsigned char btnPress = 0x01; 00027 00028 /***** Functions *****/ 00029 void my_function_CMD_2700(unsigned char *pData, unsigned char len) 00030 { 00031 unsigned char response = 0x00; 00032 ledR = 1.0f - (pData[0] / 255.0f); 00033 ledG = 1.0f - (pData[1] / 255.0f); 00034 ledB = 1.0f - (pData[2] / 255.0f); 00035 np_api_upload(0x2701, &response, 1); 00036 } 00037 00038 /******************************************************************************/ 00039 void app_setup() 00040 { 00041 if ( np_api_register((MDK_REGISTER_CMD*)my_cmd_func_table, FUNCTION_TABLE_NUM) == MDK_REGISTER_FAILD ) { 00042 // Register failed handle code 00043 error("MDK Register Failed"); 00044 } 00045 max44000.init(MAX44000::MODE_ALS_PROX, MAX44000::ALSTIM_64X, MAX44000::ALSPGA_1X, MAX44000::DRV_10); 00046 ledR = 1.0f; 00047 ledG = 1.0f; 00048 ledB = 1.0f; 00049 } 00050 00051 void app_loop() 00052 { 00053 int proxData = max44000.readReg(MAX44000::REG_PRX_DATA); 00054 if (proxData > PROX_THRESHOLD) { 00055 if (!lastPrx) { 00056 np_api_upload(0x2800, &prxPress, 1); 00057 } 00058 lastPrx = 1; 00059 } else { 00060 lastPrx = 0; 00061 } 00062 00063 if (!button && lastBtn) { 00064 np_api_upload(0x2800, &btnPress, 1); 00065 } 00066 lastBtn = button; 00067 } 00068 00069 int main(void) 00070 { 00071 00072 np_api_init(); 00073 app_setup(); 00074 np_api_start(); 00075 00076 while(1) { 00077 Thread::wait(LOOP_DELAY); 00078 app_loop(); 00079 np_api_bsl_chk(); 00080 } 00081 00082 return 0; 00083 } 00084
Generated on Tue Jul 12 2022 20:48:41 by
1.7.2
