/***************************************************************************
 *   Copyright (C) 2006 by Frank Simon   *
 *   frank@linux   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef TOUCHDRIVER_H
#define TOUCHDRIVER_H

#include <vdr/keys.h>
#include <vdr/status.h>
#include <vdr/thread.h>
#include <vdr/tools.h>

// 
int64_t GetTime();
void scaletoscreen(int x, int y, int& rx, int& ry);
// Wichtig: Ausrichtung an Bytegrenzen

class cTouchFlipFlop
{
  bool state;
  uint64_t starttouchtime;
  uint64_t startuntouchtime;
  bool pretouched;
  bool preuntouched;
  int touchcount;
  void SetState(bool newstate) { state = newstate; }; 
  uint64_t deltatime(uint64_t t0);
  
 public:
  cTouchFlipFlop();
  void SignalPress();
  void SignalRelease();
  bool GetState() {return(state);};
  void CheckRelease();
};


class cTouchScreenEnhancer;

class cTouchDriver: public cThread, cStatus
{
 public:
  cTouchDriver(cTouchScreenEnhancer * callback);
  ~cTouchDriver(void);
  void On_Touch(int x, int y, bool touched);
  void OpenDevice();
  void ProcessInputEvent(bool touch, int x, int y);
  virtual void Action(void);
  bool IsOk();
  void Stop();
private:

  cTouchScreenEnhancer * mCallback;
  int hDevice;
  bool active;
  cTouchFlipFlop mTouchFlipFlop;
};


#endif
