nkjnm
Dependencies: MAX44000 nexpaq_mdk
Fork of LED_Demo by
main.cpp@7:3a65ef12ba31, 2016-11-04 (annotated)
- Committer:
- nitsshukla
- Date:
- Fri Nov 04 12:06:04 2016 +0000
- Revision:
- 7:3a65ef12ba31
- Parent:
- 6:7b51d2ebef23
kghj;
Who changed what in which revision?
User | Revision | Line number | New 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 | 4:494741f7f5b2 | 12 | #define LOOP_DELAY 100 |
nexpaq | 0:b86eda0e990d | 13 | |
nexpaq | 0:b86eda0e990d | 14 | /***** Globals *****/ |
nexpaq | 0:b86eda0e990d | 15 | void my_function_CMD_2700(unsigned char *pData, unsigned char len); |
nexpaq | 0:b86eda0e990d | 16 | const MDK_REGISTER_CMD my_cmd_func_table[FUNCTION_TABLE_NUM] = { |
nexpaq | 6:7b51d2ebef23 | 17 | {0x2700, my_function_CMD_2700}, // Command -> function |
nexpaq | 0:b86eda0e990d | 18 | }; |
nexpaq | 0:b86eda0e990d | 19 | |
gsteiert | 3:9d15891f9352 | 20 | int lastBtn = 1; |
nexpaq | 0:b86eda0e990d | 21 | unsigned char btnPress = 0x01; |
nexpaq | 0:b86eda0e990d | 22 | |
nexpaq | 0:b86eda0e990d | 23 | /***** Functions *****/ |
nexpaq | 6:7b51d2ebef23 | 24 | void my_function_CMD_2700(unsigned char *pData, unsigned char len) |
nexpaq | 6:7b51d2ebef23 | 25 | { |
nexpaq | 6:7b51d2ebef23 | 26 | unsigned char response = 0x00; |
nexpaq | 6:7b51d2ebef23 | 27 | ledR = (pData[0]>0) ? LED_ON : LED_OFF ; |
nexpaq | 6:7b51d2ebef23 | 28 | ledG = (pData[1]>0) ? LED_ON : LED_OFF ; |
nitsshukla | 7:3a65ef12ba31 | 29 | ledB = (pData[2]>100) ? LED_ON : LED_OFF ; |
nexpaq | 6:7b51d2ebef23 | 30 | np_api_upload(0x2701, &response, 1); |
nexpaq | 0:b86eda0e990d | 31 | } |
nexpaq | 0:b86eda0e990d | 32 | |
nexpaq | 0:b86eda0e990d | 33 | /******************************************************************************/ |
nexpaq | 6:7b51d2ebef23 | 34 | void app_setup() |
nexpaq | 6:7b51d2ebef23 | 35 | { |
nexpaq | 6:7b51d2ebef23 | 36 | if ( np_api_register((MDK_REGISTER_CMD*)my_cmd_func_table, FUNCTION_TABLE_NUM) == MDK_REGISTER_FAILD ) { |
nexpaq | 6:7b51d2ebef23 | 37 | // Register failed handle code |
nexpaq | 6:7b51d2ebef23 | 38 | error("MDK Register Failed"); |
nexpaq | 6:7b51d2ebef23 | 39 | } |
nexpaq | 0:b86eda0e990d | 40 | } |
nexpaq | 0:b86eda0e990d | 41 | |
nexpaq | 6:7b51d2ebef23 | 42 | void app_loop() |
nexpaq | 6:7b51d2ebef23 | 43 | { |
nexpaq | 6:7b51d2ebef23 | 44 | if (!button && lastBtn) { |
gsteiert | 3:9d15891f9352 | 45 | np_api_upload(0x2800, &btnPress, 1); |
nexpaq | 6:7b51d2ebef23 | 46 | } |
nexpaq | 6:7b51d2ebef23 | 47 | lastBtn = button; |
nexpaq | 0:b86eda0e990d | 48 | } |
nexpaq | 0:b86eda0e990d | 49 | |
nexpaq | 6:7b51d2ebef23 | 50 | int main(void) |
nexpaq | 6:7b51d2ebef23 | 51 | { |
jowen | 2:3842948024ca | 52 | |
nexpaq | 6:7b51d2ebef23 | 53 | np_api_init(); |
nexpaq | 6:7b51d2ebef23 | 54 | app_setup(); |
nexpaq | 6:7b51d2ebef23 | 55 | np_api_start(); |
nexpaq | 6:7b51d2ebef23 | 56 | while(1) { |
nexpaq | 6:7b51d2ebef23 | 57 | Thread::wait(LOOP_DELAY); |
nexpaq | 6:7b51d2ebef23 | 58 | app_loop(); |
nexpaq | 6:7b51d2ebef23 | 59 | np_api_bsl_chk(); |
nexpaq | 6:7b51d2ebef23 | 60 | } |
nexpaq | 6:7b51d2ebef23 | 61 | |
nexpaq | 6:7b51d2ebef23 | 62 | return 0; |
nexpaq | 0:b86eda0e990d | 63 | } |
nexpaq | 0:b86eda0e990d | 64 |