Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
9.6 kB
2
Indexable
Never
#include "gd32vf103.h"
#include "drivers.h"
#include "lcd.h"

int main(void){
    int ms=0, s=0, firstKey=-1, secondKey=-1, enterKeyOne=-1, thirdKey=-1, fourthKey=-1, enterKeyTwo=-1, colorKey=-1, enterColorKey=-1, key, pKey=-1, c=0, idle=0;
    int lookUpTbl[16]={1,4,7,14,2,5,8,0,3,6,9,15,10,11,12,13};
    int dac=0, speed=-100;
    int adcr, tmpr;
    char digits[10][10]={"Zero ","One  ","Two  ","Three" ,"Four ","Five ","Six  ","Seven" ,"Eight" ,"Nine "};
    int colors[10]={0xFFFF, 0x0000, 0x001F, 0xF81F, 0x07E0, 0X8430, 0X7D7C, 0x7FFF, 0XFFE0, 0X31A6 };
                    /*vit,  Svart,   blå,   magenta, grön,  Grå,   ljusblå,  cyan,   Gul,   mörkgrå*/
  int col=-1;
  int val1=0, val2=0, val3=0, val4=0, x1, x2, y1, y2, a=0;
    t5omsi();                               // Initialize timer5 1kHz
    colinit();                              // Initialize column toolbox
    l88init();                              // Initialize 8*8 led toolbox
    keyinit();                              // Initialize keyboard toolbox
    Lcd_SetType(LCD_INVERTED);                // or use LCD_INVERTED!
    Lcd_Init();
    LCD_Clear(RED);
   // LCD_ShowStr(10, 10, "POLL VERSION", WHITE, TRANSPARENT);

    while (1) {
        idle++;                             // Manage Async events
        LCD_WR_Queue();                   // Manage LCD com queue!

        if (t5expq()) {                     // Manage periodic tasks
            l88row(colset());               // ...8*8LED and Keyboard
            ms++;                           // ...One second heart beat
            if (ms==1000){
              ms=0;
              //l88mem(0,s++);
            }
            if ((key=keyscan())>=0) {       // ...Any key pressed?
              if (pKey==key) c++;
                else {c=0; pKey=key;}
              l88mem(1,lookUpTbl[key]+(c<<4));

			        switch(lookUpTbl[key]){
			        case 0:

                LCD_ShowStr(10, 10, "Case 0", WHITE, TRANSPARENT);
                LCD_Clear(RED);
                // FIRST PART //
			          while(firstKey <= 0){
                  LCD_ShowStr(10, 10, "Case 0: FirstKey", WHITE, TRANSPARENT);
                  /*
                  KEEP WAITING FOR THE KEY TO BE PRESSED AND WHEN IT IS
                  PRESSED WE CHECK IF IT IS WITHIN 10 AND IF IT IS WE ASIGN VAL1
                  AND IF IT IS NOT WE CONTINUE THE WHILE LOOP UNTIL IT IS
                  WITHIN 10.
                  */
                  if(((firstKey=keyscan())>=0) && lookUpTbl[firstKey]<10){
                    // WE HAVE CHECKED THAT WE HAVE A KEY AND THAT KEY IS WITHIN 10 //
                    val1 = lookUpTbl[firstKey]*8;
                    LCD_Clear(RED);
                  }else{
                    firstKey = -1;
                    continue;
                  }
                }

                while(secondKey <= 0){
                  LCD_ShowStr(10, 10, "Case 0: SecondKey", WHITE, TRANSPARENT);
                  /*
                  KEEP WAITING FOR THE KEY TO BE PRESSED AND WHEN IT IS
                  PRESSED WE CHECK IF IT IS WITHIN 10 AND IF IT IS WE ASIGN VAL1
                  AND IF IT IS NOT WE CONTINUE THE WHILE LOOP UNTIL IT IS
                  WITHIN 10.
                  */
                  if((secondKey=keyscan())>=0 && lookUpTbl[secondKey]<10){
                    // WE HAVE CHECKED THAT WE HAVE A KEY AND THAT KEY IS WITHIN 10 //
                    val2 = lookUpTbl[secondKey]*8;
                    LCD_Clear(RED);
                  }else{
                    secondKey = -1;
                    continue;
                  }
                }

                while(enterKeyOne <= 0){
                  LCD_ShowStr(10, 10, "Case 0: EnterKeyOne", WHITE, TRANSPARENT);
                  /*
                  KEEP WAITING FOR THE KEY TO BE PRESSED AND WHEN IT IS
                  PRESSED WE CHECK IF IT IS WITHIN 10 AND IF IT IS WE ASIGN VAL1
                  AND IF IT IS NOT WE CONTINUE THE WHILE LOOP UNTIL IT IS
                  WITHIN 10.
                  */
                  if((enterKeyOne=keyscan())>=0 && lookUpTbl[enterKeyOne] == 10){
                    // WE HAVE CHECKED THAT WE HAVE A KEY AND THAT KEY IS WITHIN 10 //
                      y1=val1;
                      x1=val2;
                      LCD_Clear(RED);
                  }else{
                    enterKeyOne = -1;
                    continue;
                  }
                }

                // SECOND PART //
                while(thirdKey <= 0){
                  LCD_ShowStr(10, 10, "Case 0: thirdKey", WHITE, TRANSPARENT);
                  /*
                  KEEP WAITING FOR THE KEY TO BE PRESSED AND WHEN IT IS
                  PRESSED WE CHECK IF IT IS WITHIN 10 AND IF IT IS WE ASIGN VAL1
                  AND IF IT IS NOT WE CONTINUE THE WHILE LOOP UNTIL IT IS
                  WITHIN 10.
                  */
                  if((thirdKey=keyscan())>=0 && lookUpTbl[thirdKey]<10){
                    // WE HAVE CHECKED THAT WE HAVE A KEY AND THAT KEY IS WITHIN 10 //
                    val3 = lookUpTbl[thirdKey]*8;
                    LCD_Clear(RED);
                  }else{
                    thirdKey = -1;
                    continue;
                  }
                }

                while(fourthKey <= 0){
                  LCD_ShowStr(10, 10, "Case 0: fourthKey", WHITE, TRANSPARENT);
                  /*
                  KEEP WAITING FOR THE KEY TO BE PRESSED AND WHEN IT IS
                  PRESSED WE CHECK IF IT IS WITHIN 10 AND IF IT IS WE ASIGN VAL1
                  AND IF IT IS NOT WE CONTINUE THE WHILE LOOP UNTIL IT IS
                  WITHIN 10.
                  */
                  if((fourthKey=keyscan())>=0 && lookUpTbl[fourthKey]<10){
                    // WE HAVE CHECKED THAT WE HAVE A KEY AND THAT KEY IS WITHIN 10 //
                    val4 = lookUpTbl[fourthKey]*16;
                    LCD_Clear(RED);
                  }else{
                    fourthKey = -1;
                    continue;
                  }
                }

                while(enterKeyTwo <= 0){
                  LCD_ShowStr(10, 10, "Case 0: enterKeyTwo", WHITE, TRANSPARENT);
                  /*
                  KEEP WAITING FOR THE KEY TO BE PRESSED AND WHEN IT IS
                  PRESSED WE CHECK IF IT IS WITHIN 10 AND IF IT IS WE ASIGN VAL1
                  AND IF IT IS NOT WE CONTINUE THE WHILE LOOP UNTIL IT IS
                  WITHIN 10.
                  */
                  if((enterKeyTwo=keyscan())>=0 && lookUpTbl[enterKeyTwo] == 11){
                    // WE HAVE CHECKED THAT WE HAVE A KEY AND THAT KEY IS WITHIN 10 //
                      y2=val3;
                      x2=val4;
                      LCD_Clear(RED);
                  }else{
                    enterKeyTwo = -1;
                    continue;
                  }
                }
                // THIRD PART //
                while(colorKey <= 0){

                    LCD_ShowStr(10, 10, "Case 0: colorKey", WHITE, TRANSPARENT);
                  /*
                  KEEP WAITING FOR THE KEY TO BE PRESSED AND WHEN IT IS
                  PRESSED WE CHECK IF IT IS WITHIN 10 AND IF IT IS WE ASIGN VAL1
                  AND IF IT IS NOT WE CONTINUE THE WHILE LOOP UNTIL IT IS
                  WITHIN 10.
                  */
                  if((colorKey=keyscan())>=0 && lookUpTbl[colorKey] < 10){
                    // WE HAVE CHECKED THAT WE HAVE A KEY AND THAT KEY IS WITHIN 10 //
                      a=colors[lookUpTbl[key]];
                      LCD_Clear(RED);
                  }else{
                    colorKey = -1;
                    continue;
                  }
                }


                while(enterColorKey <= 0){
                  LCD_ShowStr(10, 10, "Case 0: colorKey", WHITE, TRANSPARENT);
                  /*
                  KEEP WAITING FOR THE KEY TO BE PRESSED AND WHEN IT IS
                  PRESSED WE CHECK IF IT IS WITHIN 10 AND IF IT IS WE ASIGN VAL1
                  AND IF IT IS NOT WE CONTINUE THE WHILE LOOP UNTIL IT IS
                  WITHIN 10.
                  */
                  if((enterColorKey=keyscan())>=0 && lookUpTbl[enterColorKey] == 12){
                    // WE HAVE CHECKED THAT WE HAVE A KEY AND THAT KEY IS WITHIN 10 //
                      col=a;
                      LCD_Clear(RED);
                  }else{
                    enterColorKey = -1;
                    continue;
                  }
                }

			          break;
			        case 13:
			          if(lookUpTbl[key]==13){
                  LCD_DrawRectangle(x1, y1, x2, y2, col);
                  LCD_Fill(x1, y1, x2, y2, col);
                  x1=0, x2=0, y1=0,y2=0;
                }
			          break;
			        case 14:
			          if(lookUpTbl[key]==14){
                  LCD_DrawLine(x1, y1, x2, y2, col);
                  x1=0, x2=0, y1=0,y2=0;
                }
			          break;
			        case 15:
			          if(lookUpTbl[key]==15){
                  LCD_Clear(RED);
                  x1=0, x2=0, y1=0,y2=0;
                }
			          break;
			      }

                // Draw_Circle(x1, y1, )





            }

            l88mem(2,idle>>8);              // ...Performance monitor
            l88mem(3,idle); idle=0;
        }
    }
}