Delta / Mbed OS Delta_CLI

Fork of NNN40_CLI by Delta

Revision:
20:bd1760975052
Parent:
19:e2de6c1776eb
Child:
21:72d7a6e85d7f
--- a/CLI_Source/ble_cli.cpp	Wed Oct 19 06:49:09 2016 +0000
+++ b/CLI_Source/ble_cli.cpp	Wed Oct 19 10:34:28 2016 +0000
@@ -10,7 +10,7 @@
 // Genral configuration parameters
 #define BLE_DEBUG  0
 #define MAX_DEVNAME_LEN 32
-#define CLI_FWVERION "DELTA_CLI_V1.15"
+#define CLI_FWVERION "DELTA_CLI_V1.16"
 
 //0920 Silvia modify
 #if defined(TARGET_DELTA_DFBM_NQ620)
@@ -66,7 +66,6 @@
 extern Serial console;
 BLE deltaBLE; //gill 0904
 extern const char* cyntecCommandErrorNames[];
-//extern uint8_t isValidGPIO(uint8_t);
 
 /*************** GATT Configuration parameters************************/
 static bool connState = false; // gill 0904, define currently connecting state
@@ -88,7 +87,6 @@
 //DigitalOut led2(p13);
 DigitalOut BLEWriteInt(p13); // used in OnDataWritten()
 
-
 /******************************************************
  *               Function Definitions
  ******************************************************/
@@ -701,33 +699,31 @@
     cyntecPrintOk();
 }
 
-//uint8_t isValidGPIO(uint8_t num)
-//{
-//    uint8_t cfgPin[] = {0,4,5,6,7,13,21,23,24,25,29,30,31};
-//    uint8_t i;
-//
-//    for ( i = 0; i < sizeof(cfgPin) ; i++ ) {
-//        if ( num == cfgPin[i] )
-//            return 1;
-//    }
-//
-//    return 0;
-//}
-
 static void cynBLESystemOffCommand(void)
 {
     if (cyntecGetCommandTokenCnt() == 3) {
         uint8_t argLen = 0;
         uint8_t *arg = cyntecGetCommandArgument(0,&argLen);
         uint8_t gpioNum = cyntecAtoi( arg, argLen );
-        // Can only use 0,1,2,3,4,5,6,7,13,16,17,23,24,25,29
-        if (!isValidGPIO(gpioNum)) {
+
+        if (gpioNum < 1 || gpioNum > 4) {
             cyntecPrintError(CYNTEC_CMD_ERR_ARGUMENT_OUT_OF_RANGE);
             return;
         }
-        nrf_gpio_cfg_sense_input(gpioNum,
-                                 NRF_GPIO_PIN_PULLUP,
-                                 NRF_GPIO_PIN_SENSE_LOW);
+        if (gpioNum == 1)
+        	nrf_gpio_cfg_sense_input(BUTTON1, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
+#if defined(TARGET_DELTA_DFBM_NQ620)//Tsungta, temp use only, will be fix in NNN50
+        else if (gpioNum == 2)
+        	nrf_gpio_cfg_sense_input(BUTTON2, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);  
+        else if (gpioNum == 3)
+        	nrf_gpio_cfg_sense_input(BUTTON3, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW); 
+        else if (gpioNum == 4)
+        	nrf_gpio_cfg_sense_input(BUTTON4, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
+#endif        
+		else {
+			cyntecPrintError(CYNTEC_CMD_ERR_ARGUMENT_OUT_OF_RANGE);
+			return;
+		}         	        	      	
         cyntecPrintOk();
     } else if (cyntecGetCommandTokenCnt() == 2) {
         /* default wake up pin is uart Rx pin */
@@ -750,7 +746,7 @@
         uint8_t *arg = cyntecGetCommandArgument(0,&argLen);
         uint8_t gpioNum = cyntecAtoi( arg, argLen );
 
-        if (!isValidGPIO(gpioNum)) {
+        if (gpioNum < 1 || gpioNum > 4) {
             cyntecPrintError(CYNTEC_CMD_ERR_ARGUMENT_OUT_OF_RANGE);
             return;
         }
@@ -759,12 +755,16 @@
         uint8_t *action = cyntecGetCommandArgument(1,&argLen);
 
         if ( cyntecStrCmp(action,(unsigned char *)"set",argLen) == 1 ) {
-            nrf_gpio_cfg_output(gpioNum);
-            nrf_gpio_pin_set(gpioNum);
+			if (gpioNum == 1) { DigitalOut CLI_LED(LED1); CLI_LED = 1; }
+			else if (gpioNum == 2) { DigitalOut CLI_LED(LED2); CLI_LED = 1; }
+			else if (gpioNum == 3) { DigitalOut CLI_LED(LED3); CLI_LED = 1; }
+			else if (gpioNum == 4) { DigitalOut CLI_LED(LED4); CLI_LED = 1; }					
             cyntecPrintOk();
         } else if ( cyntecStrCmp(action,(unsigned char *)"clear",argLen) == 1 ) {
-            nrf_gpio_cfg_output(gpioNum);
-            nrf_gpio_pin_clear(gpioNum);
+			if (gpioNum == 1) { DigitalOut CLI_LED(LED1); CLI_LED = 0; }
+			else if (gpioNum == 2) { DigitalOut CLI_LED(LED2); CLI_LED = 0; }
+			else if (gpioNum == 3) { DigitalOut CLI_LED(LED3); CLI_LED = 0; }
+			else if (gpioNum == 4) { DigitalOut CLI_LED(LED4); CLI_LED = 0; }	
             cyntecPrintOk();
         } else {
             cyntecPrintError(CYNTEC_CMD_ERR_ARGUMENT_SYNTAX_ERROR);