Bernard Mentink / Mbed 2 deprecated MCS_LRF_EEP

Dependencies:   BLE_API mbed nRF51822

Fork of MCS_LRF by Farshad N

Files at this revision

API Documentation at this revision

Comitter:
bmentink
Date:
Tue Mar 06 21:34:31 2018 +0000
Parent:
20:fa5dfaf624a9
Commit message:
Added following:; 1. ACA modules that control VBUS and ID pins; 2. Turned off laser after powerup

Changed in this revision

ACA.cpp Show annotated file Show diff for this revision Revisions of this file
ACA.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ACA.cpp	Tue Mar 06 21:34:31 2018 +0000
@@ -0,0 +1,42 @@
+//
+// This module implements ACA Charge mode for USB connected phones to external charge source.
+// A state-machine is required that runs when phone is attached/detached 
+//
+
+#include "ACA.h"
+
+// ACA Charger state machine
+#define IDLE_STATE      0
+#define WAIT_STATE      1
+
+static  int state=WAIT_STATE;
+static  int delay = 0;
+
+// Runs every 20ms for now
+// For now we just set the ID resistors to there default settings
+void ACAChargerTask()
+{
+    switch(state)
+    {
+        case WAIT_STATE:
+            disableVBUS = 1;    // disable VBUS
+            ID_SW = 1;          // Enable 124k ID res
+            ID_SW1 = 0; 
+            delay++;
+            if(delay==20) {     // delay 400ms
+                state = IDLE_STATE;
+                delay=0;
+            }
+        break;
+        
+        case IDLE_STATE:
+             disableVBUS = 0;   //Enable VBUS, stay in this state till next power cycle
+        break;
+        
+        
+        default:
+        break;
+        
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ACA.h	Tue Mar 06 21:34:31 2018 +0000
@@ -0,0 +1,20 @@
+#pragma once
+
+#ifndef _ACA_
+#define _ACA_
+
+#include <stdio.h>
+
+#include "mbed.h"
+
+// Time interval for ACA Charger task
+#define ACA_CHARGER_TASK_TIME_MS    20
+
+extern DigitalOut disableVBUS;
+extern DigitalOut ID_SW;
+extern DigitalOut ID_SW1;
+extern DigitalIn  VBUS_IN;
+
+void ACAChargerTask(void);
+
+#endif // _ACA_
--- a/main.cpp	Mon Mar 05 22:14:16 2018 +0000
+++ b/main.cpp	Tue Mar 06 21:34:31 2018 +0000
@@ -21,6 +21,7 @@
 #include "UARTService.h"
 #include "bleHelper.h"
 #include "laser.h"
+#include "ACA.h"
 
 
 
@@ -74,6 +75,11 @@
 DigitalOut nReset(p30);
 DigitalIn LRF_BOOT(p25, PullNone);
 DigitalIn LRF_CAL(p0, PullNone);
+// IO For ACA
+DigitalOut disableVBUS(p8);
+DigitalOut ID_SW1(p7);
+DigitalOut ID_SW(p6);
+DigitalIn  VBUS_IN(p5, PullNone);
 #endif
 
 Serial* serialPtr;
@@ -86,6 +92,7 @@
 Ticker batteryChecker;
 Ticker activityChecker;
 Ticker connectionLedBlinker;
+Ticker ACACharger;
 uint16_t activityTimeout = ACTIVITY_TIMEOUT_SEC;
 
 // settings for blinking the connection LED- Blink to save power
@@ -93,9 +100,9 @@
 #define CONNECTION_LED_OFF_TIME_MS 2000
 #define CONNECTION_LED_ON_TIME_MS 20
 #define CONNECTION_LED_OFF_COUNT (CONNECTION_LED_OFF_TIME_MS / CONNECTION_LED_ON_TIME_MS)
-
+//
 
-const static char     DEVICE_NAME[]    = "MCS_LRF";
+const static char     DEVICE_NAME[]    = "MCS_EEP_01";
 const static char     MANUFACTURER[]   = "MCS";
 const static char     MODEL[]          = "Model 2";
 const static char     SERIAL_NO[]      = "SN 1234";
@@ -320,8 +327,7 @@
 }
 
 
-
-/* processor for the hardware trigger button */
+/* processor for the hardware trigger button */           
 void triggerFall()
 {
     resetActivityCheckerTask();
@@ -425,10 +431,14 @@
     laserPtr->enableMeasurement(true);
     laserPtr->setDistaceCallback(&distanceCallcack);
     laserPtr->turnLaserPowerOn();
+    laserPtr->setRedDot(false); // turn off dot initially
     
     // setup blinking connectionLed
     // connectionLed.period(2.0f);
     connectionLedBlinker.attach(connectionLedBlinkerTask, CONNECTION_LED_ON_TIME_MS / 1000.0f);
+    
+    // Setup task to implement ACA Charger mode on phone.
+    ACACharger.attach(ACAChargerTask, ACA_CHARGER_TASK_TIME_MS / 1000.0f);
 
     while (true) {
         ble.waitForEvent();