a

Dependencies:   Led-libary TextLCD mbed

Fork of Mbed-Mensch-8 by Projekte_werkstatt

Revision:
28:94a949b0f03a
Parent:
27:15a37d3fb5c5
Child:
29:42646ca2f941
--- a/main.cpp	Fri Apr 08 11:37:12 2016 +0000
+++ b/main.cpp	Fri Apr 15 12:58:59 2016 +0000
@@ -2,7 +2,6 @@
 #include "WS2812B.h"
 #include "TextLCD.h"
 
-
 /*Todo list
 switch case aktualisieren
 Autoplay
@@ -19,8 +18,6 @@
 
 */
 
-
-
 I2C i2c(P0_5, P0_4);
 Serial port(P0_19, P0_18);
 BusOut myled(P1_8, P1_9, P1_10, P1_11, P1_0, P1_1, P1_3, P1_4, P1_6, P1_7, P1_12, P1_13);
@@ -44,6 +41,8 @@
 
 TextLCD lcd(p21, p22, p23, p24, p25, p26, TextLCD::LCD20x4);
 
+DigitalOut lcdLight(p9);
+
 InterruptIn DD_A(p29);//P29
 InterruptIn DD_B(p30);//P30
 InterruptIn DD_C(p35);//P35
@@ -72,18 +71,11 @@
 #define Spieler 4
 #define Steine 4
 
-//i DID NOTHING <<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-/*
-void ausfuehren
-void color
-*/
 char whichcolor;
 uint32_t changecolor[3];
-char selctecolor = 0;//1..R ,2...G,3...B
+char selctecolor = 0;//2..R ,1...G,3...B
 char KI[4] = {0,0,0,0};
 
-
-
 //until here
 
 char PlayPos[Spieler * Steine];   //Zahl zwischen 0 & 47 ((0xC0 -> Spieler)>>2 / 0x03 -> Stein)
@@ -144,6 +136,7 @@
 void print_menu();
 void print_zus();
 void print_pos();
+void print_color();
 void print_default();
 void posUpdate();
 char ausfuehren(uint32_t postion);
@@ -157,7 +150,7 @@
 char textPos[] = { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x4, 0x9, 0xA, 0xB, 0x4, 0xD, 0xE, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x11, 0x17, 0x18, 0x19, 0x12, 0x1B, 0x1C, 0xC, 0x14, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x11, 0x27, 0x28, 0x29, 0x13, 0x2B, 0x10, 0x2D, 0x15, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x11, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x17, 0x16, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x11, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x11, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F };
 
 char VHS = 0;
-char mSelected[256];
+char mSelected[50];
 char depth = 0;
 uint32_t postion = 0;//Dafür brauche ich die Methode
 char mDiceEn = 5;
@@ -369,16 +362,16 @@
     port.attach(&Control);
     /*
     Farben[0]=0x00FF00;//Rot
-    Farben[1]=0xFF0000;//Blau
-    Farben[2]=0x0000FF;//Grun
-    Farben[3]=0x00FFFF;//Gelb
+    Farben[1]=0x0000FF;//Blau
+    Farben[2]=0xFF0000;//Grun
+    Farben[3]=0xFFFF00;//Gelb
     Background = 0;    //Schwarz
     DiceC = 0x00FF00;  //Rot
     */
     Farben[0] = 0x000800;//Rot
-    Farben[1] = 0x080000;//Blau
-    Farben[2] = 0x000008;//Grun
-    Farben[3] = 0x000808;//Gelb
+    Farben[1] = 0x000008;//Blau
+    Farben[2] = 0x080000;//Grun
+    Farben[3] = 0x080800;//Gelb
     Background = 0;    //Schwarz
     DiceC = 0x000800;  //Rot
     /*
@@ -389,7 +382,10 @@
     Background = 0xFFFFFF;//Weiß
     DiceC = 0xFFFFFF;  //Weiß
     */
-
+    
+    lcdLight=1;
+    TestC = Background;
+    reset();
     __disable_irq();
     for (char i = 0; i < Spieler; i++)
     {
@@ -1084,6 +1080,8 @@
     port.printf("%c%c%c%c\n", 27 + ((color & 0xFC0000) >> 18), 27 + ((color & 0x03f000) >> 12), 27 + ((color & 0x000FC0) >> 6), 27 + (color & 0x00003F));
 }
 
+//--------------------------------------------------------------------------------------------------
+
 void dreh()
 {
     char temp = DD;
@@ -1210,18 +1208,6 @@
             out = 0;
             //Autoplay->zeit 4x
             break;
-        case 0x66:
-            out = 0;
-            //Farbe  Rot 
-            break;
-        case 0xa6:
-            out = 0;
-            //Farbe Green
-            break;
-        case 0xe6:
-            out = 0;
-            //Farbe blue
-            break;
         case 0x5a:
             out = 0;
             //hell special. -> Helligkeit 100%
@@ -1282,26 +1268,136 @@
             out = 0;
             //wuerfel helligkeit -> 50%
             break;
-        case 0x16:
-            //Farbe -> R
-            selctecolor = 1;
+            case 0x3d:
+            VHS = 1;
             break;
-        case 0x3d:
-            VHS = 1;
-            
+
+        case 0x16:
+            //Farbe -> 0
+            if(selctecolor == 0)
+                TestC = Farben[0];
+            else
+                Farben[0] = TestC;
+            selctecolor = 4;
             break;
         case 0x56:
             out = 0;
             //Farbe -> R
-            selctecolor++;
-            if(selctecolor>=4)
-            {
-                mSelected[depth - 1]=0;
-                out = 1;
-            }
+            if(selctecolor == 4)
+                selctecolor = 2;
+            else
+                selctecolor = 4;
+            break;
+        case 0x96:
+            out = 0;
+            //Farbe -> G
+            if(selctecolor == 4)
+                selctecolor = 3;
+            else
+                selctecolor = 4;
+            break;
+        case 0xd6:
+            out = 0;
+            //Farbe -> B
+            if(selctecolor == 4)
+                selctecolor = 1;
+            else
+                selctecolor = 4;
+            break;
+
+        case 0x26:
+            //Farbe -> 1
+            if(selctecolor == 0)
+                TestC = Farben[1];
+            else
+                Farben[1] = TestC;
+            selctecolor = 4;
+            break;
+        case 0x66:
+            out = 0;
+            //Farbe -> R
+            if(selctecolor == 4)
+                selctecolor = 2;
+            else
+                selctecolor = 4;
+            break;
+        case 0xa6:
+            out = 0;
+            //Farbe -> G
+            if(selctecolor == 4)
+                selctecolor = 3;
+            else
+                selctecolor = 4;
+            break;
+        case 0xe6:
+            out = 0;
+            //Farbe -> B
+            if(selctecolor == 4)
+                selctecolor = 1;
             else
-                mSelected[depth - 1]++;
+                selctecolor = 4;
+            break;
+
+            case 0x36:
+            //Farbe -> 2
+            if(selctecolor == 0)
+                TestC = Farben[2];
+            else
+                Farben[2] = TestC;
+            selctecolor = 4;
+            break;
+        case 0x76:
+            out = 0;
+            //Farbe -> R
+            if(selctecolor == 4)
+                selctecolor = 2;
+            else
+                selctecolor = 4;
+            break;
+        case 0xb6:
+            out = 0;
+            //Farbe -> G
+            if(selctecolor == 4)
+                selctecolor = 3;
+            else
+                selctecolor = 4;
             break;
+        case 0xf6:
+            out = 0;
+            //Farbe -> B
+            if(selctecolor == 4)
+                selctecolor = 1;
+            else
+                selctecolor = 4;
+            break;
+
+            case 0x46:
+            //Farbe -> R
+            selctecolor = 2;
+            TestC = Farben[3];
+            break;
+        case 0x86:
+            out = 0;
+            //Farbe -> R
+            selctecolor = 3;
+            mSelected[depth-1]++;
+            break;
+        case 0xc6:
+            out = 0;
+            //Farbe -> G
+            selctecolor = 1;
+            mSelected[depth-1]++;
+            break;
+        case 0x106:
+            //Farbe -> B
+            selctecolor=0;
+            mSelected[depth-1]=0;
+            Farben[3] = TestC;
+            TestC = Background;
+            FieldPrint();
+            FeldPrint();
+            break;
+
         case 0x7d:  //Ki enable p1
             out = 0;
             VHS = 1;
@@ -1359,13 +1455,15 @@
 
 void up()
 {
-    if (selctecolor)
+    if ((selctecolor>0)&&(selctecolor<4))
     {
-        char temp = TestC&0xff<<((3-selctecolor)<<1);
-        TestC = TestC&(0xFFFFFF-(0xff<<((3-selctecolor)<<1)));
+        char temp = 0xFF & (TestC >> (selctecolor * 8 - 8));
+        TestC = TestC&(0xFFFFFF-(0xFF<<(selctecolor * 8 - 8)));
         if(temp<0xFF)
             temp++;
-        TestC=TestC|temp<<((3-selctecolor)<<1);
+        TestC=TestC|(temp<<(selctecolor * 8 - 8));
+        DicePrint();
+        print_color();
     }
     else
         if (depth > 0)
@@ -1387,13 +1485,15 @@
 
 void down()
 {
-    if (selctecolor)
+    if ((selctecolor>0)&&(selctecolor<4))
     {
-        char temp = TestC&0xff<<((3-selctecolor)<<1);
-        TestC = TestC&(0xFFFFFF-(0xff<<((3-selctecolor)<<1)));
+        char temp = 0xFF & (TestC >> (selctecolor * 8 - 8));
+        TestC = TestC&(0xFFFFFF-(0xFF<<(selctecolor * 8 - 8)));
         if(temp>0)
             temp--;
-        TestC=TestC|temp<<((3-selctecolor)<<1);
+        TestC=TestC|(temp<<(selctecolor * 8 - 8));
+        DicePrint();
+        print_color();
     }
     else
         if (depth > 0)
@@ -1458,9 +1558,12 @@
         diceTick = 0;
         DiceAnim.attach(&DiceRun, 0.3);
     }
+    port.printf("Lpostion:(0x%x) ", postion);
     posUpdate();
-    port.printf("Lpostion:0x%x\n", postion);
-    if (depth > 0)
+    port.printf("0x%x(Depth:0x%x)\n", postion,depth);
+    if(selctecolor>0)
+        print_color();
+    else if (depth > 0)
     {
         print_menu();
         print_pos();
@@ -1472,7 +1575,8 @@
 void exit()
 {
     port.printf("LExit!\n");
-    if (depth > 0)
+    posUpdate();
+    if (depth > 0&&(selctecolor==0||selctecolor==4))
     {
         depth--;
         mSelected[depth] = 0;
@@ -1494,15 +1598,34 @@
         }
         DicePrint();
     }
-    posUpdate();
-    ausfuehren(postion);
-    if (depth > 0)
+    if(selctecolor>0)
+        print_color();
+
+    if(selctecolor==4)
     {
+        selctecolor=0;
+        posUpdate();
+        ausfuehren(postion);
+        TestC = Background;
+        FieldPrint();
+        FeldPrint();
         print_menu();
         print_pos();
     }
+    else if(selctecolor>0)
+        selctecolor=4;
     else
-        print_default();
+    {
+        posUpdate();
+        ausfuehren(postion);
+        if (depth > 0)
+        {
+            print_menu();
+            print_pos();
+        }
+        else
+            print_default();
+    }
 }
 
 void print_menu()
@@ -1587,6 +1710,7 @@
     port.printf("D%c%c                    \n", 27, 29);
     port.printf("D%c%c12345678901234567890\n", 27, 30);
 }
+
 void print_zus()
 {
     switch(postion){
@@ -1622,10 +1746,114 @@
             break;
         default:
             break;
-        
-        
+        }
+}
+
+void print_color()
+{
+    char temp = 0xFF & (TestC >> (selctecolor * 8 - 8));
+    char pos = 0;
+    switch (selctecolor)
+    {
+    case 4:
+        print_menu();
+        print_pos();
+        port.printf("D%c%c%d\n",30,28,0xFF & (TestC >> (2 * 8 - 8)));//X,Y
+        lcd.locate(3, 1);
+        lcd.printf("%d",0xFF & (TestC >> (2 * 8 - 8)));
+        port.printf("D%c%c%d\n",30,29,0xFF & (TestC >> (3 * 8 - 8)));
+        lcd.locate(3, 2);
+        lcd.printf("%d",0xFF & (TestC >> (3 * 8 - 8)));
+        port.printf("D%c%c%d\n",30,30,0xFF & (TestC >> (1 * 8 - 8)));
+        lcd.locate(3, 3);
+        lcd.printf("%d",0xFF & (TestC >> (1 * 8 - 8)));
+        break;
+    case 2://B
+        port.printf("D%c%c                    \n",27,28);
+        lcd.locate(0, 1);
+        lcd.printf("   ");
+        if(temp<100)
+        {
+            pos++;
+            if(temp<10)
+            pos++;
+        }
+        port.printf("D%c%c%d\n",27+pos,28,temp);
+        lcd.locate(pos, 1);
+        lcd.printf("%d",temp);
+        pos = 0;
+        port.printf("D%c%c",30,28);
+        while(temp>pos&pos<250)
+        {
+            pos+=15;
+            if(temp+7>=pos)
+            {
+                lcd.printf("-");
+                port.printf("-");
+            }
         }
-    
-    
-    
+        if(pos<250)
+            lcd.printf(" ");
+        port.printf("\n");
+        break;
+    case 3://R
+        port.printf("D%c%c                    \n",27,29);
+        lcd.locate(0, 2);
+        lcd.printf("   ");
+        if(temp<100)
+        {
+            pos++;
+            if(temp<10)
+            pos++;
+        }
+        port.printf("D%c%c%d\n",27+pos,29,temp);
+        lcd.locate(pos, 2);
+        lcd.printf("%d",temp);
+        pos = 0;
+        port.printf("D%c%c",30,29);
+        while(temp>pos&pos<250)
+        {
+            pos+=15;
+            if(temp+7>=pos)
+            {
+                lcd.printf("-");
+                port.printf("-");
+            }
+        }
+        if(pos<250)
+            lcd.printf(" ");
+        port.printf("\n");
+        break;
+    case 1://G
+        port.printf("D%c%c                    \n",27,30);
+        lcd.locate(0, 3);
+        lcd.printf("   ");
+        if(temp<100)
+        {
+            pos++;
+            if(temp<10)
+            pos++;
+        }
+        port.printf("D%c%c%d\n",27+pos,30,temp);
+        lcd.locate(pos, 3);
+        lcd.printf("%d",temp);
+        pos = 0;
+        port.printf("D%c%c",30,30);
+        while(temp>pos&pos<250)
+        {
+            pos+=15;
+            if(temp+7>=pos)
+            {
+                lcd.printf("-");
+                port.printf("-");
+            }
+        }
+        if(pos<250)
+            lcd.printf(" ");
+        port.printf("\n");
+        break;
+    default:
+        break;
+    }
+    lcd.locate(19, 0);
 }
\ No newline at end of file