Advertisement
Guest User

compas4

a guest
May 24th, 2012
479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.62 KB | None | 0 0
  1. #include <stm32f10x.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include "DWLOS_config.h"
  5. #include "DWLOS.h"
  6.  
  7. #define  __zKeyPad
  8. #include "main.h"
  9. #include "z_KeyPad.h"
  10. #include "z_LSM.h"
  11. #include "z_S65.h"
  12.  
  13.  
  14.  
  15. //==============================================================================
  16. // KeyPad manager
  17. //==============================================================================
  18. void KeyPad_Scan (void)
  19.  {
  20.   uint8_t b1, b2, b3, i;
  21.   uint32_t tmp_reg_H, tmp_reg_L;
  22.  
  23. //  LOG_ADD('K');
  24.  
  25.   tmp_reg_L = GPIOB -> CRL;
  26.   tmp_reg_H = GPIOB -> CRH;
  27.  
  28.   tmp_reg_L &= ~(GPIO_CRL_MODE0_1 | GPIO_CRL_MODE0_0 | GPIO_CRL_MODE1_1 | GPIO_CRL_MODE1_0);
  29.   tmp_reg_H &= ~(GPIO_CRH_MODE10_1 | GPIO_CRH_MODE10_0);
  30.  
  31.   i = 0;
  32.   i = BTN_BASE;
  33.   b1 = 0;
  34.   b2 = 0;
  35.   b3 = 0;
  36.  
  37.   GPIOB -> CRL = tmp_reg_L;
  38.   GPIOB -> CRH = tmp_reg_H;
  39.  
  40.   while (i < 255)
  41.    {
  42.     if (GPIOB -> IDR & GPIO_IDR_IDR0 && !b1)    b1 = i;
  43.     if (GPIOB -> IDR & GPIO_IDR_IDR1 && !b2)    b2 = i;
  44.     if (GPIOB -> IDR & GPIO_IDR_IDR10 && !b3)   b3 = i;
  45.  
  46.     i ++;
  47.    }
  48.  
  49.   if (!b1)  b1 = 250;
  50.   if (!b2)  b2 = 250;
  51.   if (!b3)  b3 = 250;
  52.  
  53.   if (b1 > BTN1_CLICK_LEVEL)    BTN1 ++;
  54.   if (b2 > BTN2_CLICK_LEVEL)    BTN2 ++;
  55.   if (b3 > BTN3_CLICK_LEVEL)    BTN3 ++;
  56.  
  57.  
  58.   GPIOB -> CRL |= GPIO_CRL_MODE0_1 | GPIO_CRL_MODE0_0 | GPIO_CRL_MODE1_1 | GPIO_CRL_MODE1_0;
  59.   GPIOB -> CRH |= GPIO_CRH_MODE10_1 | GPIO_CRH_MODE10_0;
  60.   GPIOB -> BSRR |= GPIO_BSRR_BR0 | GPIO_BSRR_BR1 | GPIO_BSRR_BR10;
  61.  
  62.   Set_Timer (KeyPad_Scan, 80);
  63.  }
  64.  
  65.  
  66.  
  67. void KeyPad_Watcher (void)
  68.  {
  69.   uint8_t tmp = 0;
  70.   static uint8_t uptime_view = 0;
  71.  
  72.   Set_Timer (KeyPad_Watcher, 170);
  73.   LOG_ADD('W');
  74.  
  75.   if (BTN1 >= BTN_REAL_CLICK)
  76.     tmp |= BTN1_ON;
  77.  
  78.   if (BTN2 >= BTN_REAL_CLICK)
  79.     tmp |= BTN2_ON;
  80.  
  81.   if (BTN3 >= BTN_REAL_CLICK)
  82.     tmp |= BTN3_ON;
  83.  
  84.   BTN1 = 0;
  85.   BTN2 = 0;
  86.   BTN3 = 0;
  87.  
  88.   if (tmp)
  89.    {
  90.     Key_live = Key_live << 3;
  91.     Key_live = Key_live | ((uint64_t) tmp);
  92.  
  93.     if ((Key_live & 0x07) == BTN1_ON)
  94.      {
  95.       if (GPIOA -> ODR & GPIO_ODR_ODR15)
  96.        {
  97.         LED1_OFF;
  98.        }
  99.       else
  100.        {
  101.         LED1_ON;
  102.        }
  103.      }
  104.  
  105.     else if ((Key_live & 0x07) == BTN1_ON)
  106.      {
  107.       uptime_view = ~uptime_view;
  108.      }
  109.  
  110.     else if ((Key_live & 0x07) == (BTN1_ON | BTN2_ON))
  111.      {
  112.       if (LSM_init_arr [17] & (3 << 4) == (1 << 4))
  113.        {
  114.         LSM_init_arr [17] = (1<<7)|(0<<4);
  115.        }
  116.       else
  117.        {
  118.         LSM_init_arr [17] = (1<<7)|(1<<4);
  119.        }
  120.       LSM_step = 0;
  121.       Set_Task (LSM_init);
  122.      }
  123.  
  124.     else if ((Key_live & 0x07) == BTN3_ON && (Key_live & (0x07 << 3)) != (BTN3_ON << 3))
  125.      {
  126.       LED1_ON;
  127.       LED2_ON;
  128.       Set_Timer (MAG_read, 1000);
  129.      }
  130.  
  131.     else if ((Key_live & ((0x07) | ((0x07) << 3))) == ((BTN1_ON | BTN3_ON) | ((BTN1_ON | BTN3_ON) << 3)) && S65_IS_ON())
  132.      {
  133.       Set_Task (S65_off);
  134.      }
  135.  
  136.     else if ((Key_live & ((0x07) | ((0x07) << 3))) == ((BTN1_ON | BTN2_ON) | ((BTN1_ON | BTN2_ON) << 3)))
  137.      {
  138.       LED1_OFF;
  139.       LED2_OFF;
  140.  
  141.       LSM_TEST_OFF;
  142.      }
  143.    }
  144.  
  145.   switch (bsd_symbol_i)
  146.    {
  147.     case 0: S65 -> txt [0] = '|'; break;
  148.     case 1: S65 -> txt [0] = '/'; break;
  149.     case 2: S65 -> txt [0] = '-'; break;
  150.     case 3: S65 -> txt [0] = '\\'; break;
  151.     case 4: S65 -> txt [0] = '|'; break;
  152.     case 5: S65 -> txt [0] = '/'; break;
  153.     case 6: S65 -> txt [0] = '-'; break;
  154.     case 7: S65 -> txt [0] = '\\'; break;
  155.     default: S65 -> txt [0] = ' '; break;
  156.    }
  157.   bsd_symbol_i = (bsd_symbol_i == 7) ? 0 : (bsd_symbol_i + 1);
  158.  
  159.   S65 -> x = 62;
  160.   S65 -> y = 110;
  161.   S65 -> len = 1;
  162.   S65_puts_n();
  163.  
  164.  
  165.   if (uptime_view)
  166.    {
  167.     sprintf (S65 -> txt, "%2dh %2dm %2ds", uptime_h, uptime_m, uptime_s);
  168.     S65 -> x = 1;
  169.     S65 -> y = 176;
  170.     S65 -> len = 11;
  171.     S65_puts_n();  
  172.    }
  173.   else
  174.    {
  175.     S65 -> txt [ 0] = ' ';
  176.     S65 -> txt [ 1] = ' ';
  177.     S65 -> txt [ 2] = ' ';
  178.     S65 -> txt [ 3] = ' ';
  179.     S65 -> txt [ 4] = ' ';
  180.     S65 -> txt [ 5] = ' ';
  181.     S65 -> txt [ 6] = ((tmp & (1 << 0)) ? 'x' : ' ');
  182.     S65 -> txt [ 7] = ' ';
  183.     S65 -> txt [ 8] = ((tmp & (1 << 1)) ? 'x' : ' ');
  184.     S65 -> txt [ 9] = ' ';
  185.     S65 -> txt [10] = ((tmp & (1 << 2)) ? 'x' : ' ');
  186.     S65 -> txt [11] = ' ';
  187.     S65 -> txt [12] = ' ';
  188.     S65 -> txt [13] = ' ';
  189.     S65 -> txt [14] = ' ';
  190.     S65 -> txt [15] = ' ';
  191.     S65 -> txt [16] = ' ';
  192.  
  193.  
  194.     S65 -> x = 1;
  195.     S65 -> y = 176;
  196.     S65 -> len = 17;
  197.     S65_puts_n();
  198.    }
  199. /*  S65 -> txt [0] = 'w';
  200.   S65 -> txt [1] = (LSM_TEST_IS_OFF()) ? '0' : '1';
  201.   S65 -> x = 3;
  202.   S65 -> y = 15;
  203.   S65 -> len = 6;
  204. //  Set_Task (S65_puts_n);
  205. //  S65_puts_n();
  206. //  S65_puts_n (3, 155, S65_txt, 3);// */
  207.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement