Stephen Ralph / Mbed 2 deprecated CryptoPenCreateKey

Dependencies:   mbed 4DGL-uLCD-SE SDFileSystem PinDetect

Files at this revision

API Documentation at this revision

Comitter:
sralph3
Date:
Thu Jan 03 22:33:59 2019 +0000
Commit message:
Pt. 1 | Creates encryption pad (ie. key)

Changed in this revision

4DGL-uLCD-SE.lib Show annotated file Show diff for this revision Revisions of this file
PinDetect.lib Show annotated file Show diff for this revision Revisions of this file
SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
Shiftbrite.h Show annotated file Show diff for this revision Revisions of this file
Speaker.h Show annotated file Show diff for this revision Revisions of this file
TMP36.cpp Show annotated file Show diff for this revision Revisions of this file
TMP36.h Show annotated file Show diff for this revision Revisions of this file
mainPart1.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
diff -r 000000000000 -r 5d459573c0dd 4DGL-uLCD-SE.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/4DGL-uLCD-SE.lib	Thu Jan 03 22:33:59 2019 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/4180_1/code/4DGL-uLCD-SE/#e39a44de229a
diff -r 000000000000 -r 5d459573c0dd PinDetect.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PinDetect.lib	Thu Jan 03 22:33:59 2019 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/AjK/code/PinDetect/#cb3afc45028b
diff -r 000000000000 -r 5d459573c0dd SDFileSystem.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Thu Jan 03 22:33:59 2019 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/SDFileSystem/#c8f66dc765d4
diff -r 000000000000 -r 5d459573c0dd Shiftbrite.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Shiftbrite.h	Thu Jan 03 22:33:59 2019 +0000
@@ -0,0 +1,26 @@
+#include "mbed.h"
+
+//Setup a new class for a Shiftbrite RGB LED module
+class Shiftbrite
+{
+public:
+    Shiftbrite(PinName pin_e, PinName pin_l, PinName pin_do, PinName pin_di, PinName pin_clk);
+    void write(int red, int green, int blue);
+
+private:
+//class sets up the pins
+    DigitalOut _pin_e;
+    DigitalOut _pin_l;
+    SPI _spi;
+};
+
+Shiftbrite::Shiftbrite(PinName pin_e, PinName pin_l, PinName pin_do, PinName pin_di, PinName pin_clk)
+    : _pin_e(pin_e), _pin_l(pin_l), _spi(pin_do, pin_di, pin_clk)
+{
+ // ADD CODE HERE
+}
+
+void Shiftbrite::write(int red, int green, int blue)
+{
+ // ADD CODE HERE
+}
diff -r 000000000000 -r 5d459573c0dd Speaker.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Speaker.h	Thu Jan 03 22:33:59 2019 +0000
@@ -0,0 +1,19 @@
+#include "mbed.h"
+// new class to play a note on Speaker based on PwmOut class
+class Speaker
+{
+public:
+    Speaker(PinName pin) : _pin(pin) {
+// _pin(pin) means pass pin to the Speaker Constructor
+    }
+// class method to play a note based on PwmOut class
+    void PlayNote(float frequency, float duration, float volume) {
+        _pin.period(1.0/frequency);
+        _pin = volume/2.0;
+        wait(duration);
+        _pin = 0.0;
+    }
+
+private:
+    PwmOut _pin;
+};
\ No newline at end of file
diff -r 000000000000 -r 5d459573c0dd TMP36.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TMP36.cpp	Thu Jan 03 22:33:59 2019 +0000
@@ -0,0 +1,31 @@
+#include "mbed.h"
+
+//Setup a new class for TMP36 sensor
+class TMP36
+{
+public:
+    TMP36(PinName pin);
+    TMP36();
+    operator float ();
+    float read();
+private:
+//class sets up the AnalogIn pin
+    AnalogIn _pin;
+};
+
+TMP36::TMP36(PinName pin) : _pin(pin)
+{
+// _pin(pin) means pass pin to the AnalogIn constructor
+}
+
+float TMP36::read()
+{
+//convert sensor reading to temperature in degrees C
+    return ((_pin.read()*3.3)-0.500)*100.0;
+}
+//overload of float conversion (avoids needing to type .read() in equations)
+TMP36::operator float ()
+{
+//convert sensor reading to temperature in degrees C
+    return ((_pin.read()*3.3)-0.500)*100.0;
+}
diff -r 000000000000 -r 5d459573c0dd TMP36.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TMP36.h	Thu Jan 03 22:33:59 2019 +0000
@@ -0,0 +1,12 @@
+#ifndef ADD_H
+#define ADD_H
+class TMP36{
+    public:
+    TMP36(PinName pin);
+    TMP36();
+    float read();
+    private:
+    //class sets up the AnalogIn pin
+    AnalogIn _pin;
+};
+#endif
\ No newline at end of file
diff -r 000000000000 -r 5d459573c0dd mainPart1.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mainPart1.cpp	Thu Jan 03 22:33:59 2019 +0000
@@ -0,0 +1,170 @@
+#include "mbed.h"
+#include "Speaker.h"
+#include "PinDetect.h"
+#include <ctime>
+#include "uLCD_4DGL.h"
+#include "SDFileSystem.h"
+#include "TMP36.h"
+uLCD_4DGL uLCD(p28, p27, p29); // serial tx, serial rx, reset pin;
+SDFileSystem sd(p5, p6, p7, p8, "sd");
+
+//declare objects for pins used with pushbuttons
+PinDetect pb1(p18);
+PinDetect pb2(p17);
+PinDetect pb3(p16);
+
+//declare a speaker object
+Speaker mySpeaker(p21);
+
+//declare enums
+enum InputType {YES,NO};
+enum StateType {Q0, Q1, Q2, Q3};
+
+//declare rest of variables
+InputType input = NO;
+StateType state = Q0;
+char cipherText [1001];
+bool isWritten= false;
+
+// Callback routine is interrupt activated by a debounced pb3 hit
+void pb3_hit_callback (void)
+{
+    // ADD CODE HERE THAT YOU WHAT TO RUN WHEN INTERUPT IS GENERATED
+    input = NO;
+}
+    // Callback routine is interrupt activated by a debounced pb1 hit
+void pb1_hit_callback (void)
+    {
+        mkdir("/sd/mydir", 0777);
+                FILE *fp = fopen("/sd/mydir/OTP.txt", "w");
+                if(fp == NULL) {
+                    uLCD.printf("Error Open \n");
+                 }
+         
+                uLCD.cls();
+                 fprintf(fp, "%s", cipherText);
+                fclose(fp);
+                uLCD.printf("Done;");
+        input = YES;
+}
+        
+// Callback routine is interrupt activated by a debounced pb2 hit
+void pb2_hit_callback (void)
+ {
+         input = NO;
+}
+
+    
+int main() {
+    
+    //instantiatenew class to set p15 to analog input
+    //to read and convert TMP36 sensor's voltage output
+    TMP36 myTMP36(p15);
+    float tempC1, tempC2, tDiff;
+    srand (time(NULL));
+    int ary [1000];
+    
+    for(int i=0; i< 1000; i++){
+        int rando=0;
+        int fin=0;
+        rando = rand();
+        
+        tempC1 = myTMP36.read();
+        //wait(.1);
+        tempC2 = myTMP36.read();
+        tDiff = (tempC1-tempC2)*1000;
+        int TRN = static_cast<int>(tDiff);
+        fin = TRN + rando;
+        fin = fin% 26;
+        ary[i]=fin;
+        }
+        
+    for (int i = 0; i < 1000; i++){
+         int asciiVal = ary[i]+65;
+        char asciiChar = asciiVal;
+        cipherText[i]=asciiChar;
+    }
+    char z;
+    z=' ';
+    cipherText [1000]= z;
+    
+    
+    //Make both positioncipher files and initialize them to 1;
+    mkdir("/sd/mydir", 0777);
+    FILE *fp = fopen("/sd/mydir/positionCipherSender.txt", "w");
+    if(fp == NULL) {
+        uLCD.printf("Error Open \n");
+    }
+    fprintf(fp, "%i", 0);
+    fclose(fp);
+    mkdir("/sd/mydir", 0777);
+    fp = fopen("/sd/mydir/positionCipherReceiver.txt", "w");
+    if(fp == NULL) {
+        uLCD.printf("Error Open \n");
+    }
+    fprintf(fp, "%i", 0);
+    fclose(fp);
+    
+    //Initialize pins
+    pb1.mode(PullUp);
+    pb2.mode(PullUp);
+    pb3.mode(PullUp);
+    
+    // Delay for initial pullup to take effect
+    wait(.01);
+    
+    // Setup Interrupt callback functions for a pb hit
+pb1.attach_deasserted(&pb1_hit_callback);
+pb2.attach_deasserted(&pb2_hit_callback);
+pb3.attach_deasserted(&pb3_hit_callback);
+
+// Start sampling pb inputs using interrupts
+pb1.setSampleFrequency(); //default is 20KHz sampling
+pb2.setSampleFrequency();
+pb3.setSampleFrequency();
+// pushbuttons now setup and running
+
+while(1) {
+    switch(state){
+        case(Q0):
+            //Produce output for this state
+            if(!isWritten){
+                uLCD.cls();
+                uLCD.printf("Save to SD?");
+                isWritten=true;
+            }
+            //calculate next state
+            if (input == YES){
+                input = NO;
+                state = Q1;
+                isWritten=false;
+                uLCD.cls();
+                }
+            else {
+                state = Q0;
+                }
+            break;
+        
+        case (Q1):
+             //Produce output for this state
+             if(!isWritten){
+                uLCD.cls();
+                uLCD.printf("Save to another SD?");
+                isWritten=true;
+            }
+                
+              //calculate next state
+              if (input == YES){
+                 input = NO;
+                 state = Q1;
+                 isWritten=false;
+                 }
+            else //input should be stay
+                state = Q1;
+            break;
+            
+        }
+        //end switch
+        //wait (0.1);
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 5d459573c0dd mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Jan 03 22:33:59 2019 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/824293ae5e43
\ No newline at end of file