Test program for CROC ObCP ENSMM

Dependencies:   mbed SimpleBLE X_NUCLEO_IDB0XA1

Fork of ObCP_ENSMM_Test by Joël Imbaud

Files at this revision

API Documentation at this revision

Comitter:
jimbaud
Date:
Mon Jan 14 09:23:49 2019 +0000
Parent:
5:1e3a5f498574
Commit message:
Test program for CROC ObCP

Changed in this revision

SimpleBLE.lib Show annotated file Show diff for this revision Revisions of this file
X_NUCLEO_IDB0XA1.lib 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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
nRF51822.lib Show diff for this revision Revisions of this file
diff -r 1e3a5f498574 -r 7d877f7e455d SimpleBLE.lib
--- a/SimpleBLE.lib	Fri Sep 02 11:23:57 2016 +0000
+++ b/SimpleBLE.lib	Mon Jan 14 09:23:49 2019 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/teams/mbed-x/code/SimpleBLE/#15329a3de04c
+https://developer.mbed.org/teams/mbed-x/code/SimpleBLE/#953b3164e80f
diff -r 1e3a5f498574 -r 7d877f7e455d X_NUCLEO_IDB0XA1.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/X_NUCLEO_IDB0XA1.lib	Mon Jan 14 09:23:49 2019 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/ST/code/X_NUCLEO_IDB0XA1/#fa98703ece8e
diff -r 1e3a5f498574 -r 7d877f7e455d main.cpp
--- a/main.cpp	Fri Sep 02 11:23:57 2016 +0000
+++ b/main.cpp	Mon Jan 14 09:23:49 2019 +0000
@@ -1,47 +1,99 @@
+
+
+// This program use SimpleBLE and X_NUCLEO_IDB0XA1 librairies, don't forget to includ it !!!
+
 #include "mbed.h"
 #include "SimpleBLE.h"
 
-DigitalOut led(LED1);
+
+
+    //Name of the brodcasted BLE
+    
+SimpleBLE ble("ObCP_ENSMM_CROC");
+
+const int addr = 0x90;      // define the I2C Address for TC74-A0 1001 000 0<-- R/W bit
+
+    // GPIO set
+
+    //Interrupt input
+
+InterruptIn user3(PC_13);  //User3
+InterruptIn user2(PC_12);  //User2
+InterruptIn user1(PC_11);  //User1
+
+    //Analog input
 
-// The first thing we need to do is create a SimpleBLE instance:
-// * first argument is the device name
-// * second is the advertisement interval in ms. (default 1000 ms.)
-SimpleBLE ble("DEVICE_NAME");
+AnalogIn  analog_value(PA_5);     //Analog input value
+AnalogIn  current(PA_4);          //PWM output current
+AnalogIn  analog_temp(PC_4);      //Analog temp sensor
+
+    //PWM output
+
+PwmOut PWMoutput(PB_8);          //Main PWM output
+PwmOut Green(PB_5);              //PWM Red LED
+PwmOut Red(PB_4);                //PWM Green LED
+PwmOut Blue(PB_0);               //PWM Blue LED
 
-// Now we can declare some variables that we want to expose.
-// After you created the variable you can use it like any other var,
-// but it's value will be automatically updated over Bluetooth!
+    //USART
+
+Serial terminal(PA_2, PA_3);      //TX, RX
+
+    //I2C Temp sensor
+
+I2C TC74(PB_7, PB_6);           //TC74 temp sensor I2C sda, scl
+
+
+    // Characteristic input
+SimpleChar<uint8_t> input = ble.readOnly_u8(0xA000, 0xA002);
 
-// F.e. here we declare service 0x180d (heartrate), char 0x2a37 (curr. value) as uint8_t
-SimpleChar<uint8_t> heartrate = ble.readOnly_u8(0x180D, 0x2A37, true /* notify */, 100 /* default value */);
+    // When characteristic LED RGB changing
+void LEDupdate(uint32_t newColor) {
+    
+    // read individual bytes
+    uint8_t* channels = (uint8_t*)&newColor;
+
+    // cast to float, as PwmOut expects a value between 0.0f and 1.0f
+    Red   = static_cast<float>(channels[0]) / 255.0f;
+    Green = static_cast<float>(channels[1]) / 255.0f;
+    Blue  = static_cast<float>(channels[2]) / 255.0f;
+}
+
+    // When characteristic PWM output changing
+
+void PWMupdate(uint8_t pwmvalue) {
+    
+    // cast to float, as PwmOut expects a value between 0.0f and 1.0f
+    PWMoutput   = static_cast<float>(pwmvalue) / 255.0f;
+    
+}
 
-// now we can use this variable everywhere in our code like a normal uint8_t
-void updateHeartrate() {
-      led = !led; // keep-alive LED
-    // we just loop between 100 and 180
-    heartrate = heartrate + 1;
-    if (heartrate > 180) {
-        heartrate = 100;
+// When characteristic input changing
+void Inputupdate() {
+    
+                        TC74.start();                //Start condition
+                        TC74.write(addr|1);          //Device Adress read mode
+                        input = TC74.read(0);        //Temp register value reading
+                        TC74.stop();                 //I2C stop                                                                                             
+    
+}
+
+// Characteritic PWM LED RGB
+SimpleChar<uint32_t> color = ble.writeOnly_u32(0x6200, 0x6201, &LEDupdate);
+
+// Characteristic PWM output
+SimpleChar<uint8_t> pwmout = ble.writeOnly_u8(0xA000, 0xA001, &PWMupdate);
+
+
+//Main program
+
+int main(int, char**) {
+      
+    ble.start();
+    Ticker t;
+    t.attach(&Inputupdate, 5.0f);
+    
+    while (1) {
+        
+        ble.waitForEvent();
     }
 }
-
-// And here we create a custom service (0x9310) and char (0x9311) with a callback
-void callback(uint32_t newValue) {
-    // whenever someone updates this var over Bluetooth, this function will be called
-    printf("My value was updated to %d\n", newValue);
-}
-// FYI, you can also use long UUID strings here instead of short services :-)
-SimpleChar<uint32_t> writeMe = ble.readWrite_u32(0x9310, 0x9311, &callback);
-
-int main(int, char**) {
-    // update the heart rate every second
-    Ticker t;
-    t.attach(updateHeartrate, 1.0f);
-    
-    // here's how we kick off our loop
-    ble.start();
-    while (1) {
-        ble.waitForEvent();
-    }
-
-}
\ No newline at end of file
diff -r 1e3a5f498574 -r 7d877f7e455d mbed.bld
--- a/mbed.bld	Fri Sep 02 11:23:57 2016 +0000
+++ b/mbed.bld	Mon Jan 14 09:23:49 2019 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/f9eeca106725
\ No newline at end of file
+https://os.mbed.com/users/mbed_official/code/mbed/builds/3a7713b1edbc
\ No newline at end of file
diff -r 1e3a5f498574 -r 7d877f7e455d nRF51822.lib
--- a/nRF51822.lib	Fri Sep 02 11:23:57 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#f7faad332abc