#include <stdio.h>


 #include <unistd.h>

 #include <sys/mouse.h>



 #include <sys/consio.h>


#include <string.h>


#include <stdlib.h>


 #include <fcntl.h>

 #include <sys/ioctl.h>


// 간략하게 마우스 우클릭만 겁나게 하는  프로그램

 

 

  int main(void)

  {

      int cfd = -1;

      int mouseproto = MOUSE_PROTO_SYSMOUSE;

 

      struct mouse_info mouse_info;

 

      if(-1==(cfd=open("/dev/consolectl",O_RDWR,0)))

      {

          printf("failed /dev/consolectl\n");

      }

 

      int mfd = -1;

 

      if(-1==(mfd=open("/dev/sysmouse",O_RDWR)))

      {

          printf("failed /dev/sysmouse\n");

      }

 

      mouse_info_t delta;

      memset(&delta,0,sizeof(mouse_info_t));

 

 

      for(;;){

 

 

      delta.operation=MOUSE_ACTION;

      delta.u.data.buttons |=( 1<< (3-1));

     ioctl(cfd,CONS_MOUSECTL,&delta);

      printf("Buttons: %08x\n",delta.u.data.buttons);

 

      delta.u.data.buttons =0;

      printf("Buttons: %08x\n",delta.u.data.buttons);

      ioctl(cfd,CONS_MOUSECTL,&delta);

      sleep(1);

  }

 

 

 

return 0;

}



별것도 아닌걸 가지고 핵고생한거같다... 


'GNU > FreeBSD' 카테고리의 다른 글

dlopen , dlsym, dlclose  (0) 2016.07.12
마우스 컨트롤(mousesystem.c)  (0) 2016.07.08
마웅스 컨트롤(ums)  (0) 2016.07.08
마우스 컨트롤(sysmouse)  (0) 2016.07.08
마우스 컨트롤(Command)  (0) 2016.07.08

유닉스 에서는 공유 라이브러리(shared library) 혹은 shared Object (공유 객체)를 컴파일이 아닌


실행 시간에 동적으로 메모리에 올려서 사용할 수 있다.  이것을 하기 위해 도와주는것이


dlopen, dlsym, dlclose가 있다.



우선 dlopen


void *dlopen(const char *filename,int flag);


const char * filename : 공유 라이브러리 파일명을 의미하며 전체 경로 혹은 LD_LIBRARY_PATH 에 분리된 디렉토리중 에 존재하여야 한다.


int flag :

-> RTLD_LAZY : 실제로 사용되는 시점에 불러옴 ( dlsym 이 호출되어 함수등을 바인한 시점이 되었을때)

-> RTLD_NOW : dlopen 함수내에서 로딩을 끝냄


return values : 정상적으로 공유 라이브러리가 로딩되면 NULL 이 아닌 handle이 반환된다.

비정상적인 경우에 NULL이 반환 


dlopen 함수는 정상적인 호출시마다 공유 라이브러리에 대한 참조 count를 1증가 시킨다. 0 ~ 1로 증가할때애 메모리에 로딩 되어진다.


void *handle = NULL;

handle = dlopen("libmouse.so",RTLD_LAZY);


if(handle==NULL){

printf("%s Error -> Number is  :%d\n", errno);

return 0;

}


void *dlsym(void *handle, const char *symbol);


void *handle : dlopen 이 반환한 핸들 값


const char *symbol : 찾으려는 symbol(함수명)


return values : symbol 에 대한 위치 (Pointer)



공유 라이브러리에 해당 함수가



int init(mouse_t *mouse, int a, char **b) 로 선언이 되어있다면


사용해야되는 곳에서 받는 방법은


int (*init)(mouse_t *,int,char**) 로 바꿔서 쓴다.


원래 함수에서


함수명을 *로 묶는다.


int (*init)(mouse_t *mouse,int a, char **b)

이 후에 -> 해당 가변인자들을 없앤다.


int (*init)(mouse_t, int, char** )


이렇게 선언하고 


init = init로 받으면댐 ! 냐하핳


Example


void handler(mouse_t* mouse)


를 참조할 때에는


void(*handler)(mouse_t *)












dlclose는 아직 나중에 








'GNU > FreeBSD' 카테고리의 다른 글

종료  (0) 2016.07.20
마우스 컨트롤(mousesystem.c)  (0) 2016.07.08
마웅스 컨트롤(ums)  (0) 2016.07.08
마우스 컨트롤(sysmouse)  (0) 2016.07.08
마우스 컨트롤(Command)  (0) 2016.07.08

LIB=moused_mousesystems

SRCS=moused_mousesystems.c ../../moused.h


# This is needed to convince bsd.lib.mk to build a shared library

SHLIB_MAJOR=1


.include <bsd.lib.mk>


make file




/* 

 * new moused module for ums(4) mice

 *

 */


#include <sys/types.h>

#include <sys/mouse.h>

#include <sys/consio.h>

#include <fcntl.h>


#include <stdio.h>

#include <err.h>

#include <errno.h>


#include "../../moused.h"


static void (*logmsg)(int, int, const char *, ...) = NULL;


static void activity(rodent_t *rodent, char *packet);

static void printbits(char packet);


MOUSED_INIT_FUNC {

logmsg = rodent->logmsg;

}


MOUSED_PROBE_FUNC {

int level = 0;

rodent->mfd = open(rodent->device, O_RDWR);


if (-1 == rodent->mfd)

logfatal(1, "Unable to open %s", rodent->device);


for (level = 0; level < 3; level++) {

/* Set the driver operation level */

ioctl(rodent->mfd, MOUSE_SETLEVEL, &level);

ioctl(rodent->mfd, MOUSE_GETMODE, &(rodent->mode));

if (MOUSE_PROTO_MSC == rodent->mode.protocol)

break;

}

if (MOUSE_PROTO_MSC != rodent->mode.protocol)

return MODULE_PROBE_FAIL;


return MODULE_PROBE_SUCCESS;

}


MOUSED_RUN_FUNC {

char *packet;


ioctl(rodent->mfd, MOUSE_GETHWINFO, &(rodent->hw));

printf("NumButtons: %d\n", rodent->hw.buttons);


packet = malloc(rodent->mode.packetsize);


for (;;) {

int bytes, x;

bytes = read(rodent->mfd, packet, rodent->mode.packetsize);

if (bytes < 0)

logfatal(1, "Error reading from mousey");

if (bytes == rodent->mode.packetsize)

activity(rodent, packet);

}

}


static void activity(rodent_t *rodent, char *packet) {

mouse_info_t delta;

int x;


delta.operation = MOUSE_ACTION;

delta.u.data.buttons = 0;

delta.u.data.x = delta.u.data.y = delta.u.data.z = 0;


/*

for (x = 0; x < 8; x++)

printf("%02x ", (*(packet + x) & 0xff));

printf("\n");

*/

//printbits(*packet);


/* mouse(4) details what is in the 5-byte packets */


delta.u.data.buttons |= NBIT(*packet, 3) 

                    | NBIT(*packet, 2) << 1

| NBIT(*packet, 1) << 2;


/* Bytes 2 and 4 are horizontal */

delta.u.data.x = (*(packet + 1) + *(packet + 3)); 


/* Bytes 3 and 5 are vertical */

delta.u.data.y = 0 - (*(packet + 2) + *(packet + 4)); 


//printf("(%d,%d) ", delta.u.data.x, delta.u.data.y);

//printbits(delta.u.data.buttons);


rodent->update(&delta);

}


static void printbits(char byte) {

int x;

for (x = 1; x <= 8; x++) {

printf("%d", BIT(byte, x));

}

printf("\n");

}



'GNU > FreeBSD' 카테고리의 다른 글

종료  (0) 2016.07.20
dlopen , dlsym, dlclose  (0) 2016.07.12
마웅스 컨트롤(ums)  (0) 2016.07.08
마우스 컨트롤(sysmouse)  (0) 2016.07.08
마우스 컨트롤(Command)  (0) 2016.07.08

sysmouse랑 같이 쓰는 메이크파일


LIB=moused_sysmouse

SRCS=moused_sysmouse.c ../../moused.h


# This is needed to convince bsd.lib.mk to build a shared library

SHLIB_MAJOR=1


.include <bsd.lib.mk>








/* 

 * new moused module for ums(4) mice

 *

 */


#include <sys/types.h>

#include <sys/mouse.h>

#include <sys/consio.h>

#include <fcntl.h>


#include <stdio.h>

#include <err.h>

#include <errno.h>


#include "../../moused.h"


MOUSED_PROBE_FUNC {

rodent->mfd = open(rodent->device, O_RDWR);


if (-1 == rodent->mfd)

logfatal(1, "Unable to open %s", rodent->device);


return MODULE_PROBE_SUCCESS;

}



'GNU > FreeBSD' 카테고리의 다른 글

dlopen , dlsym, dlclose  (0) 2016.07.12
마우스 컨트롤(mousesystem.c)  (0) 2016.07.08
마우스 컨트롤(sysmouse)  (0) 2016.07.08
마우스 컨트롤(Command)  (0) 2016.07.08
마우스 컨트롤 (moused) 출처 git hub 분석중  (0) 2016.07.08

/* 

 * new moused module for ums(4) mice

 *

 */


#include <sys/types.h>

#include <sys/mouse.h>

#include <sys/consio.h>

#include <unistd.h>

#include <fcntl.h>


#include <stdio.h>

#include <err.h>

#include <errno.h>


#include "../../moused.h"


static void (*logmsg)(int, int, const char *, ...) = NULL;


static void activity(rodent_t *rodent, char *packet);

static void printbits(char packet);

static int tryproto(rodent_t *rodent, int proto);

static char *getmouseproto(int proto);


static int mouseproto = MOUSE_PROTO_SYSMOUSE;


static struct mouse_protomap {

int proto;

char *name;

} protomap[] = {

{ .proto = MOUSE_PROTO_SYSMOUSE, .name = "sysmouse" },

{ .proto = MOUSE_PROTO_MSC, .name = "mousesystems" },

};


MOUSED_INIT_FUNC {

int c;

char *type = "sysmouse";

logmsg = rodent->logmsg;


while (-1 != (c = getopt(argc, argv, "t:"))) {

switch (c) {

case 't':

type = optarg; break;

}

}


if (strcmp(type, "sysmouse") == 0) {

mouseproto = MOUSE_PROTO_SYSMOUSE;

} else if ((strcmp(type, "mousesystems") == 0)

 || (strcmp(type, "msc") == 0)) {

mouseproto = MOUSE_PROTO_MSC;

} else {

warnx("Unknown protocol '%s' - defaulting to sysmouse", type);

}

}


MOUSED_PROBE_FUNC {

int level = 0;

rodent->mfd = open(rodent->device, O_RDWR);


if (-1 == rodent->mfd)

logfatal(1, "Unable to open %s", rodent->device);


if (tryproto(rodent, mouseproto) == 0) { 

/* Try the other protocol */

mouseproto = (mouseproto == MOUSE_PROTO_SYSMOUSE ? 

 MOUSE_PROTO_MSC : MOUSE_PROTO_SYSMOUSE);

if (tryproto(rodent, mouseproto) == 0)

return MODULE_PROBE_FAIL;

}


return MODULE_PROBE_SUCCESS;

}


MOUSED_HANDLER_INIT_FUNC {

warnx("init");

if (NULL == rodent->packet)

rodent->packet = malloc(rodent->mode.packetsize);

}


MOUSED_HANDLER_FUNC {

int bytes;


bytes = read(rodent->mfd, rodent->packet, rodent->mode.packetsize);

if (bytes < 0)

return;

//logfatal(1, "Error reading from mousey");


if (bytes == rodent->mode.packetsize)

activity(rodent, rodent->packet);

else

logfatal(1, "Unexpected data. Needed packet of size %d, got %d",

rodent->mode.packetsize, bytes);

}


static void activity(rodent_t *rodent, char *packet) {

mouse_info_t delta;

int x;


delta.operation = MOUSE_ACTION;

delta.u.data.buttons = 0;

delta.u.data.x = delta.u.data.y = delta.u.data.z = 0;


if (0)

{

for (x = 0; x < 8; x++)

printf("%02x ", (*(packet + x) & 0xff));

printf("\n");

printbits(*packet);

}


/* sysmouse(4) details what is in the 8-byte packets */


delta.u.data.buttons |= NBIT(*packet, 3) 

                    | NBIT(*packet, 2) << 1

| NBIT(*packet, 1) << 2;


/* Bytes 2 and 4 are horizontal */

delta.u.data.x = (*(packet + 1) + *(packet + 3)); 


/* Bytes 3 and 5 are vertical */

delta.u.data.y = 0 - (*(packet + 2) + *(packet + 4)); 


/* sysmouse adds z-axis changes */

if (MOUSE_PROTO_SYSMOUSE == mouseproto)

delta.u.data.z = (*(packet + 5) + *(packet + 6));


rodent->update(&delta);

}


static void printbits(char byte) {

int x;

for (x = 1; x <= 8; x++) {

printf("%d", BIT(byte, x));

}

printf("\n");

}


static int tryproto(rodent_t *rodent, int proto) {

int level;

warnx("Trying %s protocol", getmouseproto(proto));


for (level = 0; level < 3; level++) {

/* Set the driver operation level */

ioctl(rodent->mfd, MOUSE_SETLEVEL, &level);

ioctl(rodent->mfd, MOUSE_GETMODE, &(rodent->mode));

if (mouseproto == rodent->mode.protocol)

return 1;

}


return 0;

}


static char *getmouseproto(int proto) {

int x;

for (x = 0; x < (sizeof(protomap) / sizeof(struct mouse_protomap)); x++) {

if (protomap[x].proto == proto)

return protomap[x].name;

}

}



'GNU > FreeBSD' 카테고리의 다른 글

마우스 컨트롤(mousesystem.c)  (0) 2016.07.08
마웅스 컨트롤(ums)  (0) 2016.07.08
마우스 컨트롤(Command)  (0) 2016.07.08
마우스 컨트롤 (moused) 출처 git hub 분석중  (0) 2016.07.08
Mouse_Control - 6 번째(moused)  (0) 2016.07.07

The command module reads line-based commands from stdin and tells the mouse to dance for you.


Commands:


movex <xdelta>

- Moves the mouse along the X axis left or right (depending on positive/negative values)

movey <ydelta>

- Moves the mouse along the Y axis up or down (depending on positive/negative values)

click <button1> [button2 ... buttonN]

- "clicks" using all of the specified buttons



Examples:

movex -4

- Move the mouse 4 pixels to the left.

movey 15

- Move the mouse 15 pixels down

click 2

- Click mouse button 2


make file


LIB=moused_command

SRCS=moused_command.c ../../moused.h


# This is needed to convince bsd.lib.mk to build a shared library

SHLIB_MAJOR=1


.include <bsd.lib.mk>




/* 

 * Demonstrative newmoused module

 *

 * Reads text-based commands from standard input tellint

 * the mouse how to move, etc.

 */


#include <sys/types.h>


#include <sys/mouse.h>

#include <sys/consio.h>


#include "../../moused.h"

#include <stdio.h>

#include <unistd.h>

#include <string.h>

#include <err.h>

#include <errno.h>


static const int BUFLEN = 512;


static void command(rodent_t *rodent, char *buf);


/* 

 * Normally we'd be poking rodent.device and such to figure out

 * if it's the kind of mouse we support. However, since this 

 * module doesn't actually access mouse hardware, we will

 * always return SUCCESS.

 *

 * XXX: Should we return FAIL if there is a device specified?

 * Or should we check if the device specified is a file or file descriptor?

 *

 */

MOUSED_PROBE_FUNC {

return MODULE_PROBE_SUCCESS;

}


MOUSED_INIT_FUNC {

int c;


while (-1 != (c = getopt(argc, argv, "t:"))) {

switch (c) {

case 't':

printf("'t' option: %s\n", optarg); break;

default:

printf("Foo: %c\n", optopt);

}

}


MOUSED_RUN_FUNC {

char buf[BUFLEN];

int len = 0;

memset(buf, 0, BUFLEN);


while (!feof(stdin)) {

int bytes;

char *eol;


/* Read data from stdin */

if (len < BUFLEN) {

bytes = fread(buf + len, 1, 1, stdin);

len += bytes;

} else {

/* we've hit buffer length, line is definately too long, reset */

warnx("Input buffer full, clearing... (Line too long?)");

len = 0;

}


/* Process data */

while (NULL != (eol = strchr(buf, '\n'))) {

/* Null the EOL so we can do string functions on it */

*eol = '\0';

command(rodent, buf);


/* Shift the buffer over */

strlcpy(buf, (eol + 1), BUFLEN);

len -= (eol - buf) + 1;

}

}

}


static void command(rodent_t *rodent, char *buf) {

char *string = buf;

char *tok;

int len = strlen(string);

mouse_info_t delta;

memset(&delta, 0, sizeof(mouse_info_t));


tok = strsep(&string, " ");


/* XXX: MOUSE_MOTION_EVENT and MOUSE_ACTION produce the same results?! */

//delta.operation = MOUSE_MOTION_EVENT; /* Seems to only let movement happen */

delta.operation = MOUSE_ACTION; /* appears to let mouse button actions work */

if (strcmp("movex", tok) == 0) {

tok = strsep(&string, " ");

delta.u.data.x = atoi(tok);

} else if (strcmp("movey", tok) == 0) {

tok = strsep(&string, " ");

delta.u.data.y = atoi(tok);

} else if (strcmp("click", tok) == 0) {

while (NULL != (tok = strsep(&string, " "))) {

int button = atoi(tok);

if (button > 0 && button < 32)

delta.u.data.buttons |= (1 << button - 1);

else

warnx("Invalid button: %d", button);

}

printf("Buttons: %08x\n", delta.u.data.buttons);

rodent->update(&delta);

delta.u.data.buttons = 0;

printf("Buttons: %08x\n", delta.u.data.buttons);

} else {

printf("Unknown command: %s\n", tok);

}


rodent->update(&delta);

}




출처 :git hub https://github.com/jordansissel/freebsd-newmoused/tree/master/moused/modules/sysmouse

'GNU > FreeBSD' 카테고리의 다른 글

마웅스 컨트롤(ums)  (0) 2016.07.08
마우스 컨트롤(sysmouse)  (0) 2016.07.08
마우스 컨트롤 (moused) 출처 git hub 분석중  (0) 2016.07.08
Mouse_Control - 6 번째(moused)  (0) 2016.07.07
Mouse_Control - 5 번째(Consio.h)  (0) 2016.07.06

코드를 분석 하자.


일단 moused.h



#ifndef MOUSED_H

#define MOUSED_H


#include <syslog.h>


struct rodentparam;

typedef struct rodentparam rodent_t;


struct rodentparam {

char *device;

char *modulename;

char *configfile;

int cfd;            /* /dev/consolectl fd */

int mfd;            /* mouse device fd */


mousemode_t mode;

mousehw_t hw;

mouse_info_t state;


char *packet;    /* Used repeatedly by a plugin, keep it here */


/* Modules will call this to pass deltas to sysmouse(4) */

int (*update)(struct mouse_info *);

void (*logmsg)(int, int, const char *, ...);


/* Module callbacks (called by moused) */

int (*init)(rodent_t *, int, char **);

int (*probe)(rodent_t *);

void (*run)(rodent_t *);                /* for standalone mode */


void (*handler)(rodent_t *);            /* for packet-handler mode */

void (*handler_init)(rodent_t *);       /* for packet-handler init*/


void (*timeout)(rodent_t *);            /* select(2) timeouts call this 

 * when in handler mode */

};


#define MOUSED_INIT_FUNC  int init(rodent_t *rodent, int argc, char **argv)

#define MOUSED_PROBE_FUNC int probe(rodent_t *rodent)

#define MOUSED_HANDLER_FUNC void handler(rodent_t *rodent)

#define MOUSED_HANDLER_INIT_FUNC void handler_init(rodent_t *rodent)


/*

 * *** XXX:DEPRECATED ***

 * Should this (RUN) method even be allowed? Is it useful to have the plugin 

 * handle things like select(2) calls and such?

 */

#define MOUSED_RUN_FUNC   void run(rodent_t *rodent)


/* Probe function return values */

#define MODULE_PROBE_FAIL    0

#define MODULE_PROBE_SUCCESS 1


/* Bit math, helpful for modules */

#define BIT(num, bit) (((num) & (1 << (bit - 1))) ? 1 : 0)

#define NBIT(num, bit) ((BIT(num,bit)) ^ 1)


#define logfatal(e, fmt, args...) do {                         \

logmsg(LOG_DAEMON | LOG_ERR, errno, fmt, ##args);           \

exit(e);                                                    \

} while (0)


#endif




moused.c

/* 
 * new moused
 *
 * $Id$
 */

#include <sys/cdefs.h>
__FBSDID("Happy Cakes!");

#include <sys/types.h>
#include <err.h>
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <dlfcn.h>
#include <sys/select.h>

/* sysmouse stuff */
#include <sys/mouse.h>
#include <sys/consio.h>

#include "moused.h"

static int verbose = 0;

static void logmsg(int log_pri, int errnum, const char *fmt, ...);
static int moused(int argc, char **argv);

/* Load a module into memory (dlopen, etc) */
static void loadmodule(char *path);

/* Modules will call this function when the mouse moves/changes */
static int update(mouse_info_t *delta);

/* Filter the input somehow? */
static void filter(mouse_info_t *delta, int noop);

static void packethandler_main();
void dumpstate(mouse_info_t *delta);

#define debug(level, fmt, args...) do {                        \
if (level <= verbose)                                       \
warnx(fmt, ##args);                                      \
} while (0)

#define MOUSED_OPTIONS "d:m:f:"

static rodent_t rodent = {
.device = NULL,
.modulename = NULL,
.configfile = "/etc/moused.conf",
.cfd = -1,
.mfd = -1,
.update = update, /* Modules call moused's update(...) to talk to sysmouse */
.logmsg = logmsg, /* Modules call moused's logmsg(...) log stuff */

.init = NULL,
.probe = NULL,
.run = NULL,

.handler = NULL,
};

int main(int argc, char **argv) {
int c;

while (-1 != (c = getopt(argc, argv, MOUSED_OPTIONS))) {
switch (c) {
case 'd':
rodent.device = optarg; break;
case 'm':
rodent.modulename = optarg; break;
case 'f':
rodent.configfile = optarg; break;
}
}

argc -= optind;
argv += optind;

if (NULL == rodent.device)
rodent.device = "/dev/psm0";

moused(argc, argv);

return 0;
}

int moused(int argc, char **argv) {
struct mouse_info mouse;

if (-1 == (rodent.cfd = open("/dev/consolectl", O_RDWR, 0))) {
logfatal(1, "Unable to open /dev/consolectl");
}

if (NULL != rodent.modulename) {
char path[256];
snprintf(path, 256, "modules/%s/libmoused_%s.so", 
rodent.modulename, rodent.modulename);
printf("Path: %s\n", path);
loadmodule(path);

if (NULL != rodent.init) {
/* Reset getopt stuffs (do it in case init() likes to use getopt) */
optreset = 1;
optind = 0;
rodent.init(&rodent, argc, argv);
}

if (NULL == rodent.probe)
logfatal(1, "Module '%s' has no PROBE function?!", rodent.modulename);

/* Check if this module is the right module for this mouse device */
if (rodent.probe(&rodent) == MODULE_PROBE_SUCCESS) {

/* Try the RUN method first */
//if (NULL != rodent.run)
//rodent.run(&rodent);
/* else */ if (NULL != rodent.handler)
packethandler_main();
else 
logfatal(1, "Module '%s' has no RUN function?!", rodent.modulename);

/* If we _EVER_ get here, something hs wrong */
warnx("Arrived at unexpected location (RUN or PACKETHANDLER method died?)");
}
} else {
warnx("No module selected.");
exit(1);
}
}

static void logmsg(int log_pri, int errnum, const char *fmt, ...) {
va_list ap;
char buf[256];

va_start(ap, fmt);
vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);

if (errnum) {
strlcat(buf, ": ", sizeof(buf));
strlcat(buf, strerror(errnum), sizeof(buf));
}

/* Syslog if we're in the background? */
warnx("%s", buf);
}

static void loadmodule(char *path) {
void *handle;

if (NULL == (handle = dlopen(path, RTLD_LAZY))) {
logfatal(1, "Unable open module '%s'.", rodent.modulename);
}

rodent.init = dlsym(handle, "init");
rodent.probe = dlsym(handle, "probe");
rodent.run = dlsym(handle, "run");
rodent.handler = dlsym(handle, "handler");
rodent.handler_init = dlsym(handle, "handler_init");
}

static int update(mouse_info_t *delta) {
mouse_info_t mydelta;

/* Store state and copy delta into mydelta if this isn't a no-op */
if (NULL != delta) {
memcpy(&mydelta, delta, sizeof(mouse_info_t));
memcpy(&(rodent.state), delta, sizeof(mouse_info_t));
}
else {
memset(&mydelta, 0, sizeof(mouse_info_t));
}

filter(&mydelta, (NULL == delta) ? 1 : 0);
return ioctl(rodent.cfd, CONS_MOUSECTL, &mydelta);
}

static int state = 0;
static int distance = 0;
#define NORMAL 0
#define SCROLLING 1
#define SCROLLREADY 2
#define SCROLLTIMEOUT 3

/* 
 * This is all the code a filter should have to be 
 * How should this be implemented?
 */
static void filter(mouse_info_t *delta, int noop) {
if (noop == 1) {
if (state == SCROLLREADY) {
warnx("noop");
memcpy(delta, &(rodent.state), sizeof(mouse_info_t));
dumpstate(delta);
state = SCROLLTIMEOUT;
}
} else {
if (delta->u.data.buttons & (1<<1)) {
if (state == SCROLLTIMEOUT)
return;

state = SCROLLREADY;

/* Middle mouse is held */
if (delta->u.data.x != 0 || delta->u.data.y != 0) {
if (state == SCROLLREADY)
state = SCROLLING;

distance += delta->u.data.y;

#define THRESHOLD 3

if (distance > THRESHOLD) {
delta->u.data.z = 1;
distance = 0;
} else if (distance < -THRESHOLD) {
delta->u.data.z = -1;
distance = 0;
}

/* Do not move! */
delta->u.data.x = delta->u.data.y = 0;
}

/* Don't click middle */
delta->u.data.buttons &= ~(1<<1);
} else {
/* 
* We were ready to scroll, but the user let go of middle-mouse
* Fire mouse-down myself (in here), the mouse up will happen on it's
* own in update()
*/
if (SCROLLREADY == state) {
/* Send middle-mouse-down */
delta->u.data.buttons |= (1<<1);
ioctl(rodent.cfd, CONS_MOUSECTL, delta);
delta->u.data.buttons &= ~(1<<1);
}
state = NORMAL;
}
}
}

static void packethandler_main() {
fd_set fds;
struct timeval timeout;

timeout.tv_sec = 0;
timeout.tv_usec = 100000; /* 20mec */

if (NULL != rodent.handler_init)
rodent.handler_init(&rodent);

if (rodent.mfd == -1) {
rodent.mfd = open(rodent.device, O_RDWR);
if (rodent.mfd == -1) 
logfatal(1, "Failed trying to open '%s'", rodent.device);
}

FD_ZERO(&fds);
FD_SET(rodent.mfd, &fds);
for (;;) {
int c;

c = select(FD_SETSIZE, &fds, NULL, NULL, &timeout);
if (c < 0)
logfatal(1, "Error with select call");
else if (c > 0)
rodent.handler(&rodent);
else 
rodent.update(NULL); /* TIMEOUT HAPPENED */

FD_SET(rodent.mfd, &fds);
}
}

void dumpstate(mouse_info_t *delta) {
warnx("(%d,%d) z:%d b:%08x", delta->u.data.x, delta->u.data.y,
delta->u.data.z, delta->u.data.buttons);
}






// ./moused -m sysmouse -d /dev/sysmouse

makefile

# $FreeBSD: src/usr.sbin/moused/Makefile,v 1.6 2001/03/26 14:40:51 ru Exp $
#
PROG=   moused 
MAN=    moused.8

SRCS=   moused.c moused.h
.include <bsd.prog.mk>






'GNU > FreeBSD' 카테고리의 다른 글

마우스 컨트롤(sysmouse)  (0) 2016.07.08
마우스 컨트롤(Command)  (0) 2016.07.08
Mouse_Control - 6 번째(moused)  (0) 2016.07.07
Mouse_Control - 5 번째(Consio.h)  (0) 2016.07.06
Mouse_Control - 4 번째(Consio.h)  (0) 2016.07.04

NAME

     moused -- pass mouse data to the console driver

     moused -- 콘솔 드라이버에 마우스 데이터를 전달 한다.

SYNOPSIS

     moused [-DPRacdfs] [-I file] [-F rate] [-r resolution] [-S baudrate]

            [-VH [-U distance -L distance]] [-A exp[,offset]] [-a X[,Y]]

            [-C threshold] [-m N=M] [-w N] [-z target] [-t mousetype]

            [-l level] [-3 [-E timeout]] [-T distance[,time[,after]]] -p port


     moused [-Pd] -p port -i info


DESCRIPTION

     The moused utility and the console driver work together to support mouse

     operation in the text console and user programs.  They virtualize the

     mouse and provide user programs with mouse data in the standard format

     (see sysmouse(4)).


     The mouse daemon listens to the specified port for mouse data, interprets

     and then passes it via ioctls to the console driver.  The mouse daemon

     reports translation movement, button press/release events and movement of

     the roller or the wheel if available.  The roller/wheel movement is

     reported as ``Z'' axis movement.


     The console driver will display the mouse pointer on the screen and pro-

     vide cut and paste functions if the mouse pointer is enabled in the vir-

     tual console via vidcontrol(1).  If sysmouse(4) is opened by the user

     program, the console driver also passes the mouse data to the device so

     that the user program will see it.


     If the mouse daemon receives the signal SIGHUP, it will reopen the mouse

     port and reinitialize itself.  Useful if the mouse is attached/detached

     while the system is suspended.


     If the mouse daemon receives the signal SIGUSR1, it will stop passing

     mouse events.  Sending the signal SIGUSR1 again will resume passing mouse

     events.  Useful if your typing on a laptop is interrupted by accidentally

     touching the mouse pad.


     The following options are available:


     -3      Emulate the third (middle) button for 2-button mice.  It is emu-

             lated by pressing the left and right physical buttons simultane-

             ously.


     -C threshold

             Set double click speed as the maximum interval in msec between

             button clicks.  Without this option, the default value of 500

             msec will be assumed.  This option will have effect only on the

             cut and paste operations in the text mode console.  The user pro-

             gram which is reading mouse data via sysmouse(4) will not be

             affected.


     -D      Lower DTR on the serial port.  This option is valid only if

             mousesystems is selected as the protocol type.  The DTR line may

             need to be dropped for a 3-button mouse to operate in the

             mousesystems mode.

 -E timeout
             When the third button emulation is enabled (see above), the
             moused utility waits timeout msec at most before deciding whether
             two buttons are being pressed simultaneously.  The default time-
             out is 100 msec.

     -F rate
             Set the report rate (reports/sec) of the device if supported.

     -L distance
             When ``Virtual Scrolling'' is enabled, the -L option can be used
             to set the distance (in pixels) that the mouse must move before a
             scroll event is generated.  This effectively controls the
             scrolling speed.  The default distance is 2 pixels.

     -H      Enable ``Horizontal Virtual Scrolling''.  With this option set,
             holding the middle mouse button down will cause motion to be
             interpreted as horizontal scrolling.  Use the -U option to set
             the distance the mouse must move before the scrolling mode is
             activated and the -L option to set the scrolling speed.  This
             option may be used with or without the -V option.

     -I file
             Write the process id of the moused utility in the specified file.
             Without this option, the process id will be stored in
             /var/run/moused.pid.

     -P      Do not start the Plug and Play COM device enumeration procedure
             when identifying the serial mouse.  If this option is given
             together with the -i option, the moused utility will not be able
             to print useful information for the serial mouse.

     -R      Lower RTS on the serial port.  This option is valid only if
             mousesystems is selected as the protocol type by the -t option
             below.  It is often used with the -D option above.  Both RTS and
             DTR lines may need to be dropped for a 3-button mouse to operate
             in the mousesystems mode.

     -S baudrate
             Select the baudrate for the serial port (1200 to 9600).  Not all
             serial mice support this option.

     -T distance[,time[,after]]
             Terminate drift.  Use this option if mouse pointer slowly wanders
             when mouse is not moved.  Movements up to distance (for example
             4) pixels (X+Y) in time msec (default 500) are ignored, except
             during after msec (default 4000) since last real mouse movement.

     -V      Enable ``Virtual Scrolling''.  With this option set, holding the
             middle mouse button down will cause motion to be interpreted as
             scrolling.  Use the -U option to set the distance the mouse must
             move before the scrolling mode is activated and the -L option to
             set the scrolling speed.

     -U distance
             When ``Virtual Scrolling'' is enabled, the -U option can be used
             to set the distance (in pixels) that the mouse must move before
             the scrolling mode is activated.  The default distance is 3 pix-
             els.

 -A exp[,offset]

             Apply exponential (dynamic) acceleration to mouse movements: the

             faster you move the mouse, the more it will be accelerated.  That

             means that small mouse movements are not accelerated, so they are

             still very accurate, while a faster movement will drive the

             pointer quickly across the screen.


             The exp value specifies the exponent, which is basically the

             amount of acceleration.  Useful values are in the range 1.1 to

             2.0, but it depends on your mouse hardware and your personal

             preference.  A value of 1.0 means no exponential acceleration.  A

             value of 2.0 means squared acceleration (i.e. if you move the

             mouse twice as fast, the pointer will move four times as fast on

             the screen).  Values beyond 2.0 are possible but not recommended.

             A good value to start is probably 1.5.


             The optional offset value specifies the distance at which the

             acceleration begins.  The default is 1.0, which means that the

             acceleration is applied to movements larger than one unit.  If

             you specify a larger value, it takes more speed for the accelera-

             tion to kick in, i.e. the speed range for small and accurate

             movements is wider.  Usually the default should be sufficient,

             but if you're not satisfied with the behaviour, try a value of

             2.0.


             Note that the -A option interacts badly with the X server's own

             acceleration, which doesn't work very well anyway.  Therefore it

             is recommended to switch it off if necessary: ``xset m 1''.


     -a X[,Y]

             Accelerate or decelerate the mouse input.  This is a linear

             acceleration only.  Values less than 1.0 slow down movement, val-

             ues greater than 1.0 speed it up.  Specifying only one value sets

             the acceleration for both axes.


             You can use the -a and -A options at the same time to have the

             combined effect of linear and exponential acceleration.


     -c      Some mice report middle button down events as if the left and

             right buttons are being pressed.  This option handles this.


     -d      Enable debugging messages.


     -f      Do not become a daemon and instead run as a foreground process.

             Useful for testing and debugging.

  -i info
             Print specified information and quit.  Available pieces of infor-
             mation are:

             port      Port (device file) name, i.e. /dev/cuau0, /dev/mse0 and
                       /dev/psm0.
             if        Interface type: serial, bus, inport or ps/2.
             type      Protocol type.  It is one of the types listed under the
                       -t option below or sysmouse if the driver supports the
                       sysmouse data format standard.
             model     Mouse model.  The moused utility may not always be able
                       to identify the model.
             all       All of the above items.  Print port, interface, type
                       and model in this order in one line.

             If the moused utility cannot determine the requested information,
             it prints ``unknown'' or ``generic''.

     -l level
             Specifies at which level moused should operate the mouse driver.
             Refer to Operation Levels in psm(4) for more information on this.

     -m N=M  Assign the physical button M to the logical button N.  You may
             specify as many instances of this option as you like.  More than
             one physical button may be assigned to a logical button at the
             same time.  In this case the logical button will be down, if
             either of the assigned physical buttons is held down.  Do not put
             space around `='.

     -p port
             Use port to communicate with the mouse.

     -r resolution
             Set the resolution of the device; in Dots Per Inch, or low,
             medium-low, medium-high or high.  This option may not be sup-
             ported by all the device.

     -s      Select a baudrate of 9600 for the serial line.  Not all serial
             mice support this option.

  -t type

             Specify the protocol type of the mouse attached to the port.  You

             may explicitly specify a type listed below, or use auto to let

             the moused utility automatically select an appropriate protocol

             for the given mouse.  If you entirely omit this option in the

             command line, -t auto is assumed.  Under normal circumstances,

             you need to use this option only if the moused utility is not

             able to detect the protocol automatically (see Configuring Mouse

             Daemon).


             Note that if a protocol type is specified with this option, the

             -P option above is implied and Plug and Play COM device enumera-

             tion procedure will be disabled.


             Also note that if your mouse is attached to the PS/2 mouse port,

             you should always choose auto or ps/2, regardless of the brand

             and model of the mouse.  Likewise, if your mouse is attached to

             the bus mouse port, choose auto or busmouse.  Serial mouse proto-

             cols will not work with these mice.


             For the USB mouse, the protocol must be auto.  No other protocol

             will work with the USB mouse.


             Valid types for this option are listed below.


             For the serial mouse:

             microsoft        Microsoft serial mouse protocol.  Most 2-button

                              serial mice use this protocol.

             intellimouse     Microsoft IntelliMouse protocol.  Genius Net-

                              Mouse, ASCII Mie Mouse, Logitech MouseMan+ and

                              FirstMouse+ use this protocol too.  Other mice

                              with a roller/wheel may be compatible with this

                              protocol.

             mousesystems     MouseSystems 5-byte protocol.  3-button mice may

                              use this protocol.

             mmseries         MM Series mouse protocol.

             logitech         Logitech mouse protocol.  Note that this is for

                              old Logitech models.  mouseman or intellimouse

                              should be specified for newer models.

             mouseman         Logitech MouseMan and TrackMan protocol.  Some

                              3-button mice may be compatible with this proto-

                              col.  Note that MouseMan+ and FirstMouse+ use

                              intellimouse protocol rather than this one.

             glidepoint       ALPS GlidePoint protocol.

             thinkingmouse    Kensington ThinkingMouse protocol.

             mmhitab          Hitachi tablet protocol.

             x10mouseremote   X10 MouseRemote.

             kidspad          Genius Kidspad and Easypad protocol.

             versapad         Interlink VersaPad protocol.

             gtco_digipad     GTCO Digipad protocol.


             For the bus and InPort mouse:

             busmouse         This is the only protocol type available for the

                              bus and InPort mouse and should be specified for

                              any bus mice and InPort mice, regardless of the

                              brand.


             For the PS/2 mouse:

             ps/2             This is the only protocol type available for the

                              PS/2 mouse and should be specified for any PS/2

                              mice, regardless of the brand.

        For the USB mouse, auto is the only protocol type available for
             the USB mouse and should be specified for any USB mice, regard-
             less of the brand.

     -w N    Make the physical button N act as the wheel mode button.  While
             this button is pressed, X and Y axis movement is reported to be
             zero and the Y axis movement is mapped to Z axis.  You may fur-
             ther map the Z axis movement to virtual buttons by the -z option
             below.

     -z target
             Map Z axis (roller/wheel) movement to another axis or to virtual
             buttons.  Valid target maybe:
             x
             y    X or Y axis movement will be reported when the Z axis move-
                  ment is detected.
             N    Report down events for the virtual buttons N and N+1 respec-
                  tively when negative and positive Z axis movement is
                  detected.  There do not need to be physical buttons N and
                  N+1.  Note that mapping to logical buttons is carried out
                  after mapping from the Z axis movement to the virtual but-
                  tons is done.
             N1 N2
                  Report down events for the virtual buttons N1 and N2 respec-
                  tively when negative and positive Z axis movement is
                  detected.
             N1 N2 N3 N4
                  This is useful for the mouse with two wheels of which the
                  second wheel is used to generate horizontal scroll action,
                  and for the mouse which has a knob or a stick which can
                  detect the horizontal force applied by the user.

                  The motion of the second wheel will be mapped to the buttons
                  N3, for the negative direction, and N4, for the positive
                  direction.  If the buttons N3 and N4 actually exist in this
                  mouse, their actions will not be detected.

                  Note that horizontal movement or second roller/wheel move-
                  ment may not always be detected, because there appears to be
                  no accepted standard as to how it is encoded.

            Note also that some mice think left is the negative horizon-

                  tal direction; others may think otherwise.  Moreover, there

                  are some mice whose two wheels are both mounted vertically,

                  and the direction of the second vertical wheel does not

                  match the first one.


   Configuring Mouse Daemon

     The first thing you need to know is the interface type of the mouse you

     are going to use.  It can be determined by looking at the connector of

     the mouse.  The serial mouse has a D-Sub female 9- or 25-pin connector.

     The bus and InPort mice have either a D-Sub male 9-pin connector or a

     round DIN 9-pin connector.  The PS/2 mouse is equipped with a small,

     round DIN 6-pin connector.  Some mice come with adapters with which the

     connector can be converted to another.  If you are to use such an

     adapter, remember the connector at the very end of the mouse/adapter pair

     is what matters.  The USB mouse has a flat rectangular connector.


     The next thing to decide is a port to use for the given interface.  For

     the bus, InPort and PS/2 mice, there is little choice: the bus and InPort

     mice always use /dev/mse0, and the PS/2 mouse is always at /dev/psm0.

     There may be more than one serial port to which the serial mouse can be

     attached.  Many people often assign the first, built-in serial port

     /dev/cuau0 to the mouse.  You can attach multiple USB mice to your system

     or to your USB hub.  They are accessible as /dev/ums0, /dev/ums1, and so

     on.


     You may want to create a symbolic link /dev/mouse pointing to the real

     port to which the mouse is connected, so that you can easily distinguish

     which is your ``mouse'' port later.


     The next step is to guess the appropriate protocol type for the mouse.

     The moused utility may be able to automatically determine the protocol

     type.  Run the moused utility with the -i option and see what it says.

     If the command can identify the protocol type, no further investigation

     is necessary on your part.  You may start the daemon without explicitly

     specifying a protocol type (see EXAMPLES).


     The command may print sysmouse if the mouse driver supports this protocol

     type.

  Note that the type and model printed by the -i option do not necessarily
     match the product name of the pointing device in question, but they may
     give the name of the device with which it is compatible.

     If the -i option yields nothing, you need to specify a protocol type to
     the moused utility by the -t option.  You have to make a guess and try.
     There is rule of thumb:

     1.   The bus and InPort mice always use busmouse protocol regardless of
          the brand of the mouse.
     2.   The ps/2 protocol should always be specified for the PS/2 mouse
          regardless of the brand of the mouse.
     3.   You must specify the auto protocol for the USB mouse.
     4.   Most 2-button serial mice support the microsoft protocol.
     5.   3-button serial mice may work with the mousesystems protocol.  If it
          does not, it may work with the microsoft protocol although the third
          (middle) button will not function.  3-button serial mice may also
          work with the mouseman protocol under which the third button may
          function as expected.
     6.   3-button serial mice may have a small switch to choose between
          ``MS'' and ``PC'', or ``2'' and ``3''.  ``MS'' or ``2'' usually mean
          the microsoft protocol.  ``PC'' or ``3'' will choose the
          mousesystems protocol.
     7.   If the mouse has a roller or a wheel, it may be compatible with the
          intellimouse protocol.

     To test if the selected protocol type is correct for the given mouse,
     enable the mouse pointer in the current virtual console,

           vidcontrol -m on

     start the mouse daemon in the foreground mode,

           moused -f -p <selected_port> -t <selected_protocol>

     and see if the mouse pointer travels correctly according to the mouse
     movement.  Then try cut & paste features by clicking the left, right and
     middle buttons.  Type ^C to stop the command.

   Multiple Mice
     As many instances of the mouse daemon as the number of mice attached to
     the system may be run simultaneously; one instance for each mouse.  This
     is useful if the user wants to use the built-in PS/2 pointing device of a
     laptop computer while on the road, but wants to use a serial mouse when
     s/he attaches the system to the docking station in the office.  Run two
     mouse daemons and tell the application program (such as the X Window
     System) to use sysmouse(4), then the application program will always see
     mouse data from either mouse.  When the serial mouse is not attached, the
     corresponding mouse daemon will not detect any movement or button state
     change and the application program will only see mouse data coming from
     the daemon for the PS/2 mouse.  In contrast when both mice are attached
     and both of them are moved at the same time in this configuration, the
     mouse pointer will travel across the screen just as if movement of the
     mice is combined all together.

FILES

     /dev/consolectl  device to control the console

     /dev/mse%d       bus and InPort mouse driver

     /dev/psm%d       PS/2 mouse driver

     /dev/sysmouse    virtualized mouse driver

     /dev/ttyv%d      virtual consoles

     /dev/ums%d       USB mouse driver

     /var/run/moused.pid

                      process id of the currently running moused utility

     /var/run/MouseRemote

                      UNIX-domain stream socket for X10 MouseRemote events

EXAMPLES
           moused -p /dev/cuau0 -i type

     Let the moused utility determine the protocol type of the mouse at the
     serial port /dev/cuau0.  If successful, the command will print the type,
     otherwise it will say ``unknown''.

           moused -p /dev/cuau0
           vidcontrol -m on

     If the moused utility is able to identify the protocol type of the mouse
     at the specified port automatically, you can start the daemon without the
     -t option and enable the mouse pointer in the text console as above.

           moused -p /dev/mouse -t microsoft
           vidcontrol -m on

     Start the mouse daemon on the serial port /dev/mouse.  The protocol type
     microsoft is explicitly specified by the -t option.

           moused -p /dev/mouse -m 1=3 -m 3=1

     Assign the physical button 3 (right button) to the logical button 1 (log-
     ical left) and the physical button 1 (left) to the logical button 3 (log-
     ical right).  This will effectively swap the left and right buttons.

           moused -p /dev/mouse -t intellimouse -z 4

     Report negative Z axis movement (i.e., mouse wheel) as the button 4
     pressed and positive Z axis movement (i.e., mouse wheel) as the button 5
     pressed.

     If you add

           ALL ALL = NOPASSWD: /usr/bin/killall -USR1 moused

     to your /usr/local/etc/sudoers file, and bind

           killall -USR1 moused

     to a key in your window manager, you can suspend mouse events on your
     laptop if you keep brushing over the mouse pad while typing.

SEE ALSO
     kill(1), vidcontrol(1), xset(1), keyboard(4), mse(4), psm(4), screen(4),
     sysmouse(4), ums(4)

STANDARDS
     The moused utility partially supports ``Plug and Play External COM Device
     Specification'' in order to support PnP serial mice.  However, due to
     various degrees of conformance to the specification by existing serial
     mice, it does not strictly follow the version 1.0 of the standard.  Even
     with this less strict approach, it may not always determine an appropri-
     ate protocol type for the given serial mouse.


'GNU > FreeBSD' 카테고리의 다른 글

마우스 컨트롤(Command)  (0) 2016.07.08
마우스 컨트롤 (moused) 출처 git hub 분석중  (0) 2016.07.08
Mouse_Control - 5 번째(Consio.h)  (0) 2016.07.06
Mouse_Control - 4 번째(Consio.h)  (0) 2016.07.04
Mouse_Control - 4 번째  (0) 2016.07.04

/dev/consolectl  영어가 부족하여서 이게 맞는진 모르겠다. 


mouse_info_t mi;


fd = open("/dev/consolectl",O_RDWR);


if(fd==-1)

{

err();

}


else

{

std::cout<<"consolectl open success"<<std::endl;

}


mi.operation = MOUSE_HIDE


// 여기서 mouse_info_t 에 대해 보자

struct mouse_info {
	int		operation;
#define MOUSE_SHOW	0x01
#define MOUSE_HIDE	0x02
#define MOUSE_MOVEABS	0x03
#define MOUSE_MOVEREL	0x04
#define MOUSE_GETINFO	0x05
#define MOUSE_MODE	0x06
#define MOUSE_ACTION	0x07
#define MOUSE_MOTION_EVENT	0x08
#define MOUSE_BUTTON_EVENT	0x09
#define MOUSE_MOUSECHAR	0x0a
	union {
		mouse_data_t	data;
		mouse_mode_t	mode;
		mouse_event_t	event;
		int		mouse_char;
	}		u;
};

로 형식으로 되어있으며 operation 에서는 해당 하는 액션에 대해서 정의하고 있으며 u는 해당 모드나 데이터 이벤트등을 가지고있다.


consolectl 의 fd값을 이용하여서 ioctl 을 하기전에 operation 에 행동값을 지정한다.


이중 MOUSE_MOVEREL 을 예로 들면 Adds position supplied in u.data to current

			       position.

현재 위치에서 새로 제공된 u.data에 있는 값을 추가한다. 라고 되어있다.



mi.operation =MOUSE_MOVEREL;


mi.u.data.x = 100;

mi.u.data.y = 250;

ret = ioctl(fd,CONS_MOUSECTL,&mi);


로 하면 될줄 알았거니와 안된다. 다른 문제가 있는건가;








'GNU > FreeBSD' 카테고리의 다른 글

마우스 컨트롤 (moused) 출처 git hub 분석중  (0) 2016.07.08
Mouse_Control - 6 번째(moused)  (0) 2016.07.07
Mouse_Control - 4 번째(Consio.h)  (0) 2016.07.04
Mouse_Control - 4 번째  (0) 2016.07.04
COMMAND - top  (0) 2016.07.04
/*-
 * Copyright (c) 1991-1996 S�ren Schmidt
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer
 *    in this position and unchanged.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * $FreeBSD: src/sys/sys/consio.h,v 1.17.2.1 2006/10/04 06:09:11 ru Exp $
 */

#ifndef	_SYS_CONSIO_H_
#define	_SYS_CONSIO_H_

#ifndef _KERNEL
#include <sys/types.h>
#endif
#include <sys/ioccom.h>

/*
 * Console ioctl commands.  Some commands are named as KDXXXX, GIO_XXX, and
 * PIO_XXX, rather than CONS_XXX, for historical and compatibility reasons.
 * Some other CONS_XXX commands are works as wrapper around frame buffer 
 * ioctl commands FBIO_XXX.  Do not try to change all these commands, 
 * otherwise we shall have compatibility problems.
 */

/* get/set video mode */
#define KD_TEXT		0		/* set text mode restore fonts  */
#define KD_TEXT0	0		/* ditto			*/
#define KD_GRAPHICS	1		/* set graphics mode 		*/
#define KD_TEXT1	2		/* set text mode !restore fonts */
#define KD_PIXEL	3		/* set pixel mode		*/
#define KDGETMODE	_IOR('K', 9, int)
#define KDSETMODE	_IOWINT('K', 10)

/* set border color */
#define KDSBORDER	_IOWINT('K', 13)

/* set up raster(pixel) text mode */
struct _scr_size {
	int		scr_size[3];
};
typedef struct _scr_size	scr_size_t;

#define KDRASTER	_IOW('K', 100, scr_size_t)

/* get/set screen char map */
struct _scrmap {
	char		scrmap[256];
};
typedef struct _scrmap	scrmap_t;

#define GIO_SCRNMAP	_IOR('k', 2, scrmap_t)
#define PIO_SCRNMAP	_IOW('k', 3, scrmap_t)

/* get the current text attribute */
#define GIO_ATTR	_IOR('a', 0, int)

/* get the current text color */
#define GIO_COLOR	_IOR('c', 0, int)

/* get the adapter type (equivalent to FBIO_ADPTYPE) */
#define CONS_CURRENT	_IOR('c', 1, int)

/* get the current video mode (equivalent to FBIO_GETMODE) */
#define CONS_GET	_IOR('c', 2, int)

/* not supported? */
#define CONS_IO		_IO('c', 3)

/* set blank time interval */
#define CONS_BLANKTIME	_IOW('c', 4, int)

/* set/get the screen saver (these ioctls are current noop) */
struct ssaver	{
#define MAXSSAVER	16
	char		name[MAXSSAVER];
	int		num;
	long		time;
};
typedef struct ssaver	ssaver_t;

#define CONS_SSAVER	_IOW('c', 5, ssaver_t)
#define CONS_GSAVER	_IOWR('c', 6, ssaver_t)

/* set the text cursor type (obsolete, see CONS_CURSORSHAPE below) */
/*
#define CONS_BLINK_CURSOR (1 << 0)
#define CONS_CHAR_CURSOR (1 << 1)
*/
#define CONS_CURSORTYPE	_IOW('c', 7, int)

/* set the bell type to audible or visual */
#define CONS_VISUAL_BELL (1 << 0)
#define CONS_QUIET_BELL	(1 << 1)
#define CONS_BELLTYPE	_IOW('c', 8, int)

/* set the history (scroll back) buffer size (in lines) */
#define CONS_HISTORY	_IOW('c', 9, int)

/* clear the history (scroll back) buffer */
#define CONS_CLRHIST	_IO('c', 10)

/* mouse cursor ioctl */
struct mouse_data {
	int		x;
	int 		y;
	int 		z;
	int 		buttons;
};
typedef struct mouse_data mouse_data_t;

struct mouse_mode {
	int		mode;
	int		signal;
};
typedef struct mouse_mode mouse_mode_t;

struct mouse_event {
	int		id;			/* one based */
	int		value;
};
typedef struct mouse_event mouse_event_t;

struct mouse_info {
	int		operation;
#define MOUSE_SHOW	0x01
#define MOUSE_HIDE	0x02
#define MOUSE_MOVEABS	0x03
#define MOUSE_MOVEREL	0x04
#define MOUSE_GETINFO	0x05
#define MOUSE_MODE	0x06
#define MOUSE_ACTION	0x07
#define MOUSE_MOTION_EVENT	0x08
#define MOUSE_BUTTON_EVENT	0x09
#define MOUSE_MOUSECHAR	0x0a
	union {
		mouse_data_t	data;
		mouse_mode_t	mode;
		mouse_event_t	event;
		int		mouse_char;
	}		u;
};
typedef struct mouse_info mouse_info_t;

#define CONS_MOUSECTL	_IOWR('c', 10, mouse_info_t)

/* see if the vty has been idle */
#define CONS_IDLE	_IOR('c', 11, int)

/* set the screen saver mode */
#define CONS_NO_SAVER	(-1)
#define CONS_LKM_SAVER	0
#define CONS_USR_SAVER	1
#define CONS_SAVERMODE	_IOW('c', 12, int)

/* start the screen saver */
#define CONS_SAVERSTART	_IOW('c', 13, int)

/* set the text cursor shape (see also CONS_CURSORTYPE above) */
#define CONS_BLINK_CURSOR	(1 << 0)
#define CONS_CHAR_CURSOR	(1 << 1)
#define CONS_HIDDEN_CURSOR	(1 << 2)
#define CONS_CURSOR_ATTRS	(CONS_BLINK_CURSOR | CONS_CHAR_CURSOR |	\
				 CONS_HIDDEN_CURSOR)
#define CONS_RESET_CURSOR	(1 << 30)
#define CONS_LOCAL_CURSOR	(1 << 31)
#define CONS_CURSOR_FLAGS	(CONS_RESET_CURSOR | CONS_LOCAL_CURSOR)
struct cshape {
	/* shape[0]: flags, shape[1]: base, shape[2]: height */
	int		shape[3];
};
#define CONS_GETCURSORSHAPE _IOWR('c', 14, struct cshape)
#define CONS_SETCURSORSHAPE _IOW('c', 15, struct cshape)

/* set/get font data */
struct fnt8 {
	char		fnt8x8[8*256];
};
typedef struct fnt8	fnt8_t;

struct fnt14 {
	char		fnt8x14[14*256];
};
typedef struct fnt14	fnt14_t;

struct fnt16 {
	char		fnt8x16[16*256];
};
typedef struct fnt16	fnt16_t;

#define PIO_FONT8x8	_IOW('c', 64, fnt8_t)
#define GIO_FONT8x8	_IOR('c', 65, fnt8_t)
#define PIO_FONT8x14	_IOW('c', 66, fnt14_t)
#define GIO_FONT8x14	_IOR('c', 67, fnt14_t)
#define PIO_FONT8x16	_IOW('c', 68, fnt16_t)
#define GIO_FONT8x16	_IOR('c', 69, fnt16_t)

/* get video mode information */
struct colors	{
	char		fore;
	char		back;
};

struct vid_info {
	short		size;
	short		m_num;
	u_short		font_size;
	u_short		mv_row, mv_col;
	u_short		mv_rsz, mv_csz;
	u_short		mv_hsz;
	struct colors	mv_norm,
			mv_rev,
			mv_grfc;
	u_char		mv_ovscan;
	u_char		mk_keylock;
};
typedef struct vid_info vid_info_t;

#define CONS_GETINFO    _IOWR('c', 73, vid_info_t)

/* get version */
#define CONS_GETVERS	_IOR('c', 74, int)

/* get the video adapter index (equivalent to FBIO_ADAPTER) */
#define CONS_CURRENTADP	_IOR('c', 100, int)

/* get the video adapter information (equivalent to FBIO_ADPINFO) */
#define CONS_ADPINFO	_IOWR('c', 101, video_adapter_info_t)

/* get the video mode information (equivalent to FBIO_MODEINFO) */
#define CONS_MODEINFO	_IOWR('c', 102, video_info_t)

/* find a video mode (equivalent to FBIO_FINDMODE) */
#define CONS_FINDMODE	_IOWR('c', 103, video_info_t)

/* set the frame buffer window origin (equivalent to FBIO_SETWINORG) */
#define CONS_SETWINORG	_IOWINT('c', 104)

/* use the specified keyboard */
#define CONS_SETKBD	_IOWINT('c', 110)

/* release the current keyboard */
#define CONS_RELKBD	_IO('c', 111)

struct scrshot {
	int		x;
	int		y;
	int		xsize;
	int		ysize;
	u_int16_t*	buf;
};
typedef struct scrshot scrshot_t;

/* Snapshot the current video buffer */
#define CONS_SCRSHOT	_IOWR('c', 105, scrshot_t)

/* get/set the current terminal emulator info. */
#define TI_NAME_LEN	32
#define TI_DESC_LEN	64

struct term_info {
	int		ti_index;
	int		ti_flags;
	u_char		ti_name[TI_NAME_LEN];
	u_char		ti_desc[TI_DESC_LEN];
};
typedef struct term_info term_info_t;

#define CONS_GETTERM	_IOWR('c', 112, term_info_t)
#define CONS_SETTERM	_IOW('c', 113, term_info_t)

/*
 * Vty switching ioctl commands.
 */

/* get the next available vty */
#define VT_OPENQRY	_IOR('v', 1, int)

/* set/get vty switching mode */
#ifndef _VT_MODE_DECLARED
#define	_VT_MODE_DECLARED
struct vt_mode {
	char		mode;
#define VT_AUTO		0		/* switching is automatic 	*/
#define VT_PROCESS	1		/* switching controlled by prog */
#define VT_KERNEL	255		/* switching controlled in kernel */
	char		waitv;		/* not implemented yet 	SOS	*/
	short		relsig;
	short		acqsig;
	short		frsig;		/* not implemented yet	SOS	*/
};
typedef struct vt_mode vtmode_t;
#endif /* !_VT_MODE_DECLARED */

#define VT_SETMODE	_IOW('v', 2, vtmode_t)
#define VT_GETMODE	_IOR('v', 3, vtmode_t)

/* acknowledge release or acquisition of a vty */
#define VT_FALSE	0
#define VT_TRUE		1
#define VT_ACKACQ	2
#define VT_RELDISP	_IOWINT('v', 4)

/* activate the specified vty */
#define VT_ACTIVATE	_IOWINT('v', 5)

/* wait until the specified vty is activate */
#define VT_WAITACTIVE	_IOWINT('v', 6)

/* get the currently active vty */
#define VT_GETACTIVE	_IOR('v', 7, int)

/* get the index of the vty */
#define VT_GETINDEX	_IOR('v', 8, int)

/* prevent switching vtys */
#define VT_LOCKSWITCH	_IOW('v', 9, int)

/*
 * Video mode switching ioctl.  See sys/fbio.h for mode numbers.
 */

#define SW_B40x25 	_IO('S', M_B40x25)
#define SW_C40x25  	_IO('S', M_C40x25)
#define SW_B80x25  	_IO('S', M_B80x25)
#define SW_C80x25  	_IO('S', M_C80x25)
#define SW_BG320   	_IO('S', M_BG320)
#define SW_CG320   	_IO('S', M_CG320)
#define SW_BG640   	_IO('S', M_BG640)
#define SW_EGAMONO80x25 _IO('S', M_EGAMONO80x25)
#define SW_CG320_D    	_IO('S', M_CG320_D)
#define SW_CG640_E    	_IO('S', M_CG640_E)
#define SW_EGAMONOAPA 	_IO('S', M_EGAMONOAPA)
#define SW_CG640x350  	_IO('S', M_CG640x350)
#define SW_ENH_MONOAPA2 _IO('S', M_ENHMONOAPA2)
#define SW_ENH_CG640  	_IO('S', M_ENH_CG640)
#define SW_ENH_B40x25  	_IO('S', M_ENH_B40x25)
#define SW_ENH_C40x25  	_IO('S', M_ENH_C40x25)
#define SW_ENH_B80x25  	_IO('S', M_ENH_B80x25)
#define SW_ENH_C80x25  	_IO('S', M_ENH_C80x25)
#define SW_ENH_B80x43  	_IO('S', M_ENH_B80x43)
#define SW_ENH_C80x43  	_IO('S', M_ENH_C80x43)
#define SW_MCAMODE    	_IO('S', M_MCA_MODE)
#define SW_VGA_C40x25	_IO('S', M_VGA_C40x25)
#define SW_VGA_C80x25	_IO('S', M_VGA_C80x25)
#define SW_VGA_C80x30	_IO('S', M_VGA_C80x30)
#define SW_VGA_C80x50	_IO('S', M_VGA_C80x50)
#define SW_VGA_C80x60	_IO('S', M_VGA_C80x60)
#define SW_VGA_M80x25	_IO('S', M_VGA_M80x25)
#define SW_VGA_M80x30	_IO('S', M_VGA_M80x30)
#define SW_VGA_M80x50	_IO('S', M_VGA_M80x50)
#define SW_VGA_M80x60	_IO('S', M_VGA_M80x60)
#define SW_VGA11	_IO('S', M_VGA11)
#define SW_BG640x480	_IO('S', M_VGA11)
#define SW_VGA12	_IO('S', M_VGA12)
#define SW_CG640x480	_IO('S', M_VGA12)
#define SW_VGA13	_IO('S', M_VGA13)
#define SW_VGA_CG320	_IO('S', M_VGA13)
#define SW_VGA_CG640	_IO('S', M_VGA_CG640)
#define SW_VGA_MODEX	_IO('S', M_VGA_MODEX)

#define SW_PC98_80x25		_IO('S', M_PC98_80x25)
#define SW_PC98_80x30		_IO('S', M_PC98_80x30)
#define SW_PC98_EGC640x400	_IO('S', M_PC98_EGC640x400)
#define SW_PC98_PEGC640x400	_IO('S', M_PC98_PEGC640x400)
#define SW_PC98_PEGC640x480	_IO('S', M_PC98_PEGC640x480)

#define SW_VGA_C90x25	_IO('S', M_VGA_C90x25)
#define SW_VGA_M90x25	_IO('S', M_VGA_M90x25)
#define SW_VGA_C90x30	_IO('S', M_VGA_C90x30)
#define SW_VGA_M90x30	_IO('S', M_VGA_M90x30)
#define SW_VGA_C90x43	_IO('S', M_VGA_C90x43)
#define SW_VGA_M90x43	_IO('S', M_VGA_M90x43)
#define SW_VGA_C90x50	_IO('S', M_VGA_C90x50)
#define SW_VGA_M90x50	_IO('S', M_VGA_M90x50)
#define SW_VGA_C90x60	_IO('S', M_VGA_C90x60)
#define SW_VGA_M90x60	_IO('S', M_VGA_M90x60)

#define SW_TEXT_80x25	_IO('S', M_TEXT_80x25)
#define SW_TEXT_80x30	_IO('S', M_TEXT_80x30)
#define SW_TEXT_80x43	_IO('S', M_TEXT_80x43)
#define SW_TEXT_80x50	_IO('S', M_TEXT_80x50)
#define SW_TEXT_80x60	_IO('S', M_TEXT_80x60)
#define SW_TEXT_132x25	_IO('S', M_TEXT_132x25)
#define SW_TEXT_132x30	_IO('S', M_TEXT_132x30)
#define SW_TEXT_132x43	_IO('S', M_TEXT_132x43)
#define SW_TEXT_132x50	_IO('S', M_TEXT_132x50)
#define SW_TEXT_132x60	_IO('S', M_TEXT_132x60)

#define SW_VESA_CG640x400	_IO('V', M_VESA_CG640x400 - M_VESA_BASE)
#define SW_VESA_CG640x480	_IO('V', M_VESA_CG640x480 - M_VESA_BASE)
#define SW_VESA_800x600		_IO('V', M_VESA_800x600 - M_VESA_BASE)
#define SW_VESA_CG800x600	_IO('V', M_VESA_CG800x600 - M_VESA_BASE)
#define SW_VESA_1024x768	_IO('V', M_VESA_1024x768 - M_VESA_BASE)
#define SW_VESA_CG1024x768	_IO('V', M_VESA_CG1024x768 - M_VESA_BASE)
#define SW_VESA_1280x1024	_IO('V', M_VESA_1280x1024 - M_VESA_BASE)
#define SW_VESA_CG1280x1024	_IO('V', M_VESA_CG1280x1024 - M_VESA_BASE)
#define SW_VESA_C80x60		_IO('V', M_VESA_C80x60 - M_VESA_BASE)
#define SW_VESA_C132x25		_IO('V', M_VESA_C132x25 - M_VESA_BASE)
#define SW_VESA_C132x43		_IO('V', M_VESA_C132x43 - M_VESA_BASE)
#define SW_VESA_C132x50		_IO('V', M_VESA_C132x50 - M_VESA_BASE)
#define SW_VESA_C132x60		_IO('V', M_VESA_C132x60 - M_VESA_BASE)
#define SW_VESA_32K_320		_IO('V', M_VESA_32K_320 - M_VESA_BASE)
#define SW_VESA_64K_320		_IO('V', M_VESA_64K_320 - M_VESA_BASE)
#define SW_VESA_FULL_320	_IO('V', M_VESA_FULL_320 - M_VESA_BASE)
#define SW_VESA_32K_640		_IO('V', M_VESA_32K_640 - M_VESA_BASE)
#define SW_VESA_64K_640		_IO('V', M_VESA_64K_640 - M_VESA_BASE)
#define SW_VESA_FULL_640	_IO('V', M_VESA_FULL_640 - M_VESA_BASE)
#define SW_VESA_32K_800		_IO('V', M_VESA_32K_800 - M_VESA_BASE)
#define SW_VESA_64K_800		_IO('V', M_VESA_64K_800 - M_VESA_BASE)
#define SW_VESA_FULL_800	_IO('V', M_VESA_FULL_800 - M_VESA_BASE)
#define SW_VESA_32K_1024	_IO('V', M_VESA_32K_1024 - M_VESA_BASE)
#define SW_VESA_64K_1024	_IO('V', M_VESA_64K_1024 - M_VESA_BASE)
#define SW_VESA_FULL_1024	_IO('V', M_VESA_FULL_1024 - M_VESA_BASE)
#define SW_VESA_32K_1280	_IO('V', M_VESA_32K_1280 - M_VESA_BASE)
#define SW_VESA_64K_1280	_IO('V', M_VESA_64K_1280 - M_VESA_BASE)
#define SW_VESA_FULL_1280	_IO('V', M_VESA_FULL_1280 - M_VESA_BASE)

#endif /* !_SYS_CONSIO_H_ */


'GNU > FreeBSD' 카테고리의 다른 글

Mouse_Control - 6 번째(moused)  (0) 2016.07.07
Mouse_Control - 5 번째(Consio.h)  (0) 2016.07.06
Mouse_Control - 4 번째  (0) 2016.07.04
COMMAND - top  (0) 2016.07.04
Unix Errno 표기  (0) 2016.07.04

+ Recent posts