Tyler Altenhofen / Mbed 2 deprecated TylerPOVController

Dependencies:   mbed

Revision:
1:533b878c22ab
Parent:
0:c8b0c4f50d18
Child:
2:e2502545f2f0
--- a/main.cpp	Tue Apr 21 03:52:24 2015 +0000
+++ b/main.cpp	Tue Apr 21 04:45:16 2015 +0000
@@ -9,8 +9,6 @@
 
 class Point {
     int positionRadian, positionHeight, positionDistance;
-    int arraySlice;
-    char identifyingChar;
     public: 
     Point (int , int , int );
     int getArraySlice(void);
@@ -18,8 +16,6 @@
     int getPositionDistance(void);
     void moveUp();
     void moveDown();
-    void moveUp();
-    void moveDown();
     void rotateRight();
     void rotateLeft();
     void moveIn();
@@ -30,38 +26,47 @@
     positionRadian = posRadian;
     positionHeight = posHeight;
     positionDistance = posDistance;
-    arraySlice = positionRadian + offAngles[positionHeight];
-    identifyingChar = 0x01 << posHeight;
 }     
 int Point :: getArraySlice (void){
-    return arraySlice;
+    return positionRadian + offAngles[positionHeight];
 }
 char Point :: getIdentifyingChar(void){
-    return identifyingChar;
+    return 0x01 << positionHeight;
 }
 int Point :: getPositionDistance(void){
     return positionDistance;
 }
-void moveUp(){
+void Point :: moveUp(){
     if (positionHeight < 7){
         positionHeight ++;
-        IdentifyingChar << 1;
     }
 }
-void moveDown(){
-    if(poisitiongHeight > 0){
+void Point :: moveDown(){
+    if(positionHeight > 0){
         positionHeight --;
-        IdentifyingChar >> 1;
+    }
+}        
+void Point :: rotateRight(){
+    positionRadian = (positionRadian + 1) % 120;
+}
+void Point :: rotateLeft(){
+    positionRadian = (positionRadian + 1) % 120;
+}
+void Point :: moveIn(){
+    if (positionDistance < 0){
+        positionDistance --;
+    }
+}
+void Point :: moveOut(){
+    if (positionDistance > 15){
+        positionDistance ++;
+    }
+}
     
-void moveUp();
-void moveDown();
-void rotateRight();
-void rotateLeft();
-void moveIn();
-void moveOut();
-    
-enum drawingMode { line, point, circle }
-drawingMode currentMode;
+enum DrawingMode { line, point, circle };
+DrawingMode currentMode;
+
+Point pointer(60, 3, 8);
 
 InterruptIn buttonMode(p15);
 InterruptIn buttonUp(p16);
@@ -70,26 +75,94 @@
 InterruptIn buttonRotateLeft(p19);
 InterruptIn buttonMoveOut(p20);
 InterruptIn buttonMoveIn(p21);
+InterruptIn buttonSelect(p22);
 
-Ticker pointer;
+Ticker pointerBlinkTicker;
+
+void sendPointOver (int slice, int distance, char height){
+    ///TODO implement communications
+}
+
+void drawPoint(){
+    int pointerSlice = pointer.getArraySlice();
+    int pointerDistance = pointer.getPositionDistance();
+    char height = pointer.getIdentifyingChar();
+    sendPointOver(pointerSlice, pointerDistance, height);
+}
+
 
 void changeMode(){
+    if (currentMode == point){
+        currentMode = line;
+    }
+    if (currentMode == line){
+        currentMode = circle;
+    }
+    if (currentMode == circle){
+        currentMode = point;
+    }
 }
 void moveUp(){
+    if (currentMode == line){
+        drawPoint();
+    }
+    pointer.moveUp();
 }
 void moveDown(){
+    if (currentMode == line){
+        drawPoint();
+    }
+    pointer.moveDown();
 }
 void rotateRight(){
+    if (currentMode == line){
+        pointer.rotateRight();
+    }
+    pointer.rotateRight();
 }
 void rotateLeft(){
+    if (currentMode == line){
+        drawPoint();
+    }
+    pointer.rotateLeft();
 }
 void moveOut(){
+    if (currentMode == line){
+        drawPoint();
+    }
+    pointer.moveOut();
 }
 void moveIn(){
+    if (currentMode == line){
+        drawPoint();
+    }
+    pointer.moveIn();
 }
 void pointerBlink(){
+    Point currentBlink = pointer;
+    int slice = currentBlink.getArraySlice();
+    int distance = currentBlink.getPositionDistance();
+    char height = pointer.getIdentifyingChar();
+    sendPointOver(slice, distance, height);
+    wait(.3);
+    sendPointOver(slice, distance, height);
 }
-
+void drawWholeCircle(){
+    int distance = pointer.getPositionDistance();
+    char height = pointer.getIdentifyingChar();
+    for (int i = 0; i < 120; i ++){
+        sendPointOver(i, distance, height);
+    }
+        
+}
+void select(){
+    if (currentMode == point){
+        drawPoint();
+    }
+    if (currentMode == circle){
+        drawWholeCircle();
+    }
+}
         
 
 int main() {
@@ -101,14 +174,15 @@
     buttonRotateLeft.rise(&rotateLeft);
     buttonMoveOut.rise(&moveOut);
     buttonMoveIn.rise(&moveIn);
-    pointer.attach(&pointerBlink, .3);
+    buttonSelect.rise(&select);
+    pointerBlinkTicker.attach(&pointerBlink, 1);
+    
 
     for (int i = 0; i < NUMBER_OF_SLICES; i ++){
         for (int j = 0; j < 16; j ++){
-            slice_data = 0x00;
+            slice_data[i][j] = 0x00;
         }
     }
-    changeMode.rise(&rotate_sense);
     
 
 }