⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ts.c

📁 一份触摸屏代码
💻 C
📖 第 1 页 / 共 2 页
字号:
  
  /************************ Touch Screen Update Task **************************/
  /*--------------------------------------------------------------------------*/
  // TouchTask- A continuous, very low priority task to update the touch
  //  position. This task sends mouse messages (PM_LBUTTONDOWN, PM_LBUTTONUP,
  //  and/or PM_POINTERMOVE) into PegMessageQueue, where PEG routes them
  //  to wherever they need to go.
  //
  //  This task is started by the InitializeTouchScreen function if the
  //  calibration completes OK.
  /*--------------------------------------------------------------------------*/
  void PegTouchTask(void)
  {
      PegMessage TouchMesg;
      PEGINT XPos, YPos, OldXPos, OldYPos;
      PEGUINT wLastState;
      PEGBOOL IsTouched;
  
      TouchMesg.pTarget = NULL;
  
      XPos = YPos = OldXPos = OldYPos = wLastState = 0;
  
      // First configure the hardware registers:
  
      TouchConfigureHardware();
  
      // Next run the calibration sequence:
  
      CalibrateTouchScreen();
  
      // Now continuously read and post touch screen messages:
  
      while(1)
      {
          TOUCH_DELAY(TOUCH_POLLING_PERIOD);
  
          IsTouched = GetScaledTouchPos(&XPos, &YPos);
  
          if (IsTouched)
          {
              if (wLastState & TS_TOUCH_SENT) // already sent a touch message?
              {
                  // check for a move message:
  
                  if (OldXPos != XPos || OldYPos != YPos)
                  {
                      // The screen is still touched, but the position
                      // changed. Send a PointerMove message to PEG
  
  
                      TouchMesg.wType = PM_POINTER_MOVE;
                      TouchMesg.Point.x = XPos;
                      TouchMesg.Point.y = YPos;
                      PegThing::MessageQueue()- Fold(&TouchMesg);
                      OldXPos = XPos;
                      OldYPos = YPos;
                  }
              }
              else
              {
                  // This is a new touch down. Send a LBUTTONDOWN message
                  // to PEG:
  
                  TouchMesg.wType = PM_LBUTTONDOWN;
                  TouchMesg.Point.x = XPos;
                  TouchMesg.Point.y = YPos;
  
                 #if defined(PEGSMX)
                  SendPegInputMessage(&TouchMesg);
                 #else
                  PegThing::MessageQueue()- Push(TouchMesg);
                 #endif
  
                  OldXPos = XPos;
                  OldYPos = YPos;
                  wLastState = TS_TOUCH_SENT;    // keep track of current state
              }
          }
          else
          {
              // here if the screen is NOT touched:
  
              if (wLastState & TS_TOUCH_SENT)        // was touch message sent?
              {
                  wLastState = 0;
                  TouchMesg.wType = PM_LBUTTONUP;
                  TouchMesg.Point.x = OldXPos;
                  TouchMesg.Point.y = OldYPos;
                  TouchMesg.iData = 0;
  
                 #if defined(PEGSMX)
                  SendPegInputMessage(&TouchMesg);
                 #else
                  PegThing::MessageQueue()- Push(TouchMesg);
                 #endif
              }
          }
      }
  }
  
  
  
  } // End of Extern 'C'
  
  
  /*--------------------------------------------------------------------------*/
  /*--------------------------------------------------------------------------*/
  // For the SMX and QUADROS operating systems, the touch task stack space
  // is taken care of for us during task creation. For PrKernel and ThreadX,
  // we define the stack space for our touch task below.
  /*--------------------------------------------------------------------------*/
  /*--------------------------------------------------------------------------*/
  
  #if defined(PEG_PRKERNEL) || defined(PEGX)
  
  #define PEG_TOUCH_STACK_SIZE PEG_STACK_SIZE
  #define PEG_TOUCH_PRIORITY   PEG_PRIORITY
  PEGLONG gbTouchTaskStack[PEG_TOUCH_STACK_SIZE / sizeof(PEGLONG)];
  
  #if defined(PEGX)
  TX_THREAD PegTouchThread;
  #endif
  
  #endif
  
  /*--------------------------------------------------------------------------*/
  /*--------------------------------------------------------------------------*/
  // InitializeTouchScreen-
  //
  // This is the external entry point. This should be called first thing
  // by the application software, or once during startup.
  /*--------------------------------------------------------------------------*/
  /*--------------------------------------------------------------------------*/
  
  void InitializeTouchScreen(void)
  {
     #if defined(PEGSMX)
  
      // start the touch task:
  
      TouchTask = create_task((CODE_PTR) PegTouchTask, LO, 8 * 1024);
      BUILD_HT(PegTouchTask, "PegTouch");
      startx(TouchTask);
  
     #elif defined(PEG_PRKERNEL)
  
      // start the touch task:
  
      T_CTSK TaskInfo;
  
      TaskInfo.tskatr = TA_ACT;
      TaskInfo.exinf = 0;
      TaskInfo.task = (FP) PegTouchTask;
      TaskInfo.itskpri = PEG_TOUCH_PRIORITY;
      TaskInfo.stksz = PEG_TOUCH_STACK_SIZE;
      TaskInfo.stk = gbPegTouchTaskStack;
  
      acre_tsk(&TaskInfo);
  
     #elif defined(PEG_QUADROS)
  
      // For RTXC Quadros, the TouchTask is already started for us
      // as part of system initialization, nothing to do here.
  
     #elif defined(PEGX)
  
      tx_thread_create(&PegTouchThread, "TouchTask", PegTouchTask,
          0, gbTouchTaskStack, PEG_TOUCH_STACK_SIZE, PEG_PRIORITY,
          0, 0, TX_AUTO_START);
  
     #endif
  
      // Don't return until touch screen is calibrated, to prevent
      // PEG from starting up too soon:
  
      while(!TouchCal.IsCalibrated)
      {
          TOUCH_DELAY(50);
      }
  }
  
  /*--------------------------------------------------------------------------*/
  // The group of functions below are are implemented once for each supported
  // operating system. The functions are:
  //
  // InstallTouchInterruptHandler()
  // TouchInterruptHandler()
  // WaitTouchDataReady()
  /*--------------------------------------------------------------------------*/
  
  
  extern "C" {
  
  #if defined(PEGSMX)
  /*--------------------------------------------------------------------------*/
  // Running with MicroDigital SMX RTOS
  /*--------------------------------------------------------------------------*/
  
  SCB_PTR         PegTouchSem;
  
  /*--------------------------------------------------------------------------*/
  void PegTouchLsr(void)
  {
      signalx(PegTouchSem);
  }
  
  /*--------------------------------------------------------------------------*/
  void InstallTouchInterruptHandler(void)
  {
      PegTouchSem = create_sema(1, NULL);
  
      bspSetIRQVect(PEN_DATA_IRQ, TouchInterruptHandler);
      bspConfigureIRQ(PEN_DATA_IRQ);
      bspUnmaskIRQ(PEN_DATA_IRQ);
  }
  
  
  /*--------------------------------------------------------------------------*/
  void TouchInterruptHandler(void)
  {
      // We interrupt on the input FIFO full. This means we have
      // 12 16-bit readings. Read them all into local copy, and disable
      // the ASP module to save power:
  
      PEGINT Loop;
  
      for (Loop = 0; Loop < ASP_FIFO_DEPTH; Loop++)
      {
          TouchResponseVals[Loop] = (PEGUSHORT) (pTouchRegs- DataIn);
      }
  
      // go back to idle mode
  
      pTouchRegs- Control = ASP_INIT_VAL;
  
      // start the high-level service routine (interrupts enabled)
  
      INVOKE(PegTouchLsr, 0);
  }
  
  
  /*--------------------------------------------------------------------------*/
  void WaitTouchDataReady(void)
  {
     test(PegTouchSem, INF);
  }
  
  
  #elif defined(PEG_QUADROS)
  
  /*--------------------------------------------------------------------------*/
  // Running with RTXC QUADROS RTOS
  // This is the same block of functions implemented for RTXC Quadros RTOS
  /*--------------------------------------------------------------------------*/
  
  #include "stdlib.h"
  #include "mc9328mxl.h"
  #include "kcounter.h"
  #include "ktask.h"
  
  void SetInterruptPriority(int IntNum, int Priority);
  
  /*--------------------------------------------------------------------------*/
  void InstallTouchInterruptHandler(void)
  {
     *AitcEnnum = PEN_DATA_IRQ;
     SetInterruptPriority(PEN_DATA_IRQ, 10);
  }
  
  /*--------------------------------------------------------------------------*/
  void TouchInterruptHandler(void)
  {
      // We interrupt on the input FIFO full. This means we have
      // 12 16-bit readings. Read them all into local copy, and disable

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -