[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Is oncheck source available?



On Wed, Jan 28, 2004 at 02:18:16PM +0300, ?????? ?????? wrote:

> Hallo! You mentioned on sharp zaurus web page that you rewrote oncheck utility.
> Is the source available? If yes, where I can download it?

Attached, along with the source for ztsd, which translates the touchscreen
events from the Zaurus into what xfree86 supports (probably patching xfree86
is a better long-term solution).

-- 
 - mdz
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <stdio.h>

/*      oncheck.c - Check reset status of Sharp SL-5xxx
 *
 *      Copyright (C) Matt Zimmerman, 07/2002
 *  
 *      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., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *      Based on arch/arm/mach-sa1100/collie_apm.c
 */

/* include/asm-arm/sharp_apm.h */
#define APM_IOC_GET_ON_MODE 0x4128

/* Reset Controller Status Register, from
 * include/asm-arm/arch-sa1100/SA-1100.h */
#define RCSR_HWR        0x00000001      /* HardWare Reset                  */
#define RCSR_SWR        0x00000002      /* SoftWare Reset                  */
#define RCSR_WDR        0x00000004      /* Watch-Dog Reset                 */
#define RCSR_SMR        0x00000008      /* Sleep-Mode Reset                */

int main(int argc, char *argv[]) {
  int on_mode;
  int fd = -1;
  const char *status;

  if ((fd = open("/dev/apm_bios", O_RDWR)) < 0) {
    perror("open: /dev/apm_bios");
    return 1;
  }

  if ((on_mode = ioctl(fd, APM_IOC_GET_ON_MODE, NULL)) < 0) {
    perror("APM_IOC_GET_ON_MODE");
    return 1;
  }

  if (on_mode & RCSR_HWR)
    status = "HW Reset";
  else if (on_mode & RCSR_SWR)
    status = "SW Reset";
  else if (on_mode & RCSR_WDR)
    status = "WD Reset";
  else if (on_mode & RCSR_SMR)
    status = "SL Reset";
  else
    status = "Reset?";

  printf("%s\n", status);

  return 0;
}
/*
 * ztstransd - Convert Zaurus touchscreen events into iPAQ touchscreen
 * events
 *
 * ipaq_ts_dev should be a named pipe (fifo), from which programs
 * (such as the X server) will read touchscreen events
 *
 * Automatically calibrates based on coordinate minima and maxima.
 * Drag toward each corner to ensure proper calibration.
 *
 * Matt Zimmerman <mdz@debian.org>, 07/2002
 *
 * Descriptive comments and miscellaneous fixes by David Anders
 * <dave123@abcsinc.com>
 *
 */

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>

typedef struct
{
  unsigned short pressure;
  unsigned short x;
  unsigned short y;
  unsigned short pad;
} TS_EVENT;

typedef struct
{
  long x;
  long y;
  long pressure;
  long long millisecs;
} TS_EVENT_ZAURUS;

static int daemonize = 1;

/* /dev/sharp_ts is the touch screen node used on the Sharp
 * and OpenZaurus builds.
 */
static const char *real_ts_dev = "/dev/sharp_ts";

/* /dev/ts should be a named pipe (fifo)
 */
static const char *ipaq_ts_dev = "/dev/ts";
static const char *pidfile = "/var/run/ztsd.pid";

static int calibrated = 0;
static long min_x = 0, max_x = 1000, min_y = 0, max_y = 1000;

static int debug = 0;

static void convert_event(const TS_EVENT_ZAURUS *zaurus_event,
                          TS_EVENT *ipaq_event) {

/* This was determined by using the ipaq event structure from the
 * xfree86 code and comparing it to the touch screen header files
 * in the kernel for the zaurus, improved through trial and error
 */

  ipaq_event->y = (zaurus_event->x - min_x) * 240 / (max_x - min_x);
  ipaq_event->x = 320 - ((zaurus_event->y - min_y) * 320 / (max_y - min_y));
  ipaq_event->pressure = zaurus_event->pressure;

  if (debug)
    fprintf(stderr, "converted: x=%ld, y=%ld, pressure=%ld\n",
            ipaq_event->x, ipaq_event->y, ipaq_event->pressure);
}

static void calibrate(long x, long y) {
  if (x < min_x)
    min_x = x;
  else if (x > max_x)
    max_x = x;
  else if (y < min_y)
    min_y = y;
  else if (y > max_y)
    max_y = y;

  if (debug)
    fprintf(stderr, "calibrate: x=(%ld,%ld) y=(%ld,%ld)\n",
            min_x, max_x, min_y, max_y);
}

int main(int argc, char *argv[]) {
  int ch;
  int real_fd = -1;
  int ipaq_fd = -1;
  int pidfile_fd = -1;

  while ((ch = getopt(argc, argv, "fhvd")) != -1) {
    switch (ch) {
    case 'd':
      debug = 1;
      /* fall through */
    case 'f':
      daemonize = 0;
      break;
    case 'h':
      fprintf(stderr, "ztsd is used to translate Zaurus touch\n");
      fprintf(stderr, "screen events into iPAQ events for use with an\n");
      fprintf(stderr, "XFree86 built using the iPAQ touch screen driver\n");
      fprintf(stderr, "Options:\n");
      fprintf(stderr, "-d - debug\n");
      fprintf(stderr, "-f - don't fork\n");
      fprintf(stderr, "-v - version\n");
      return 0;
    case 'v':
      printf("ztstransd 0.1\n");
      return 0;
    }
  }

  real_fd = open(real_ts_dev, O_RDONLY);
  if (real_fd == -1) {
    perror(real_ts_dev);
    return -1;
  }

  ipaq_fd = open(ipaq_ts_dev, O_RDWR);
  if (ipaq_fd == -1) {
    perror(ipaq_ts_dev);
    return -1;
  }

  if (daemonize) {
    switch (fork()) {
    case 0:
      daemon(0,0);
      break;
    case -1:
      perror("fork");
      return -1;
    default:
      return 0;
    }
  }

  pidfile_fd = open(pidfile, O_WRONLY|O_CREAT, 0644);
  if (pidfile_fd == -1) {
    perror(pidfile);
    return -1;
  }

  /* XXX GNU-ism */
  dprintf(pidfile_fd, "%ld", getpid());

  close(pidfile_fd);
  

  for(;;) {
    static TS_EVENT_ZAURUS zaurus_event;
    static TS_EVENT ipaq_event;
    static int ret;

    memset(&ipaq_event, 0, sizeof(ipaq_event));
    memset(&zaurus_event, 0, sizeof(zaurus_event));

    ret = read(real_fd, &zaurus_event, sizeof(zaurus_event));

    if (ret == -1) {
      perror("read");
      return -1;
    } else if (ret < sizeof(zaurus_event)) {
      continue;
    }

    if (debug)
      fprintf(stderr, "x: %ld, y: %ld, pressure: %ld, ms: %ld\n",
              zaurus_event.x, zaurus_event.y, zaurus_event.pressure,
              zaurus_event.millisecs);

    calibrate(zaurus_event.x, zaurus_event.y);
    convert_event(&zaurus_event, &ipaq_event);

    ret = write(ipaq_fd, &ipaq_event, sizeof(ipaq_event));

    if (ret == -1) {
      perror("write");
      return -1;
    }
  }

  /* NOT REACHED */
  
  return 0;
}

Attachment: signature.asc
Description: Digital signature


Reply to: