wonx/key.c
Hiroaki Sakai 96b108c909 In UNIXTimer.c, callback function is called every time the callback function is called
Fix to reconfigure.
(Add signal () in UNIXTimer_ON ())
(In IRIX, coping with the fact that the callback function is cleared for each call)

Since ualarm () is BSD dependent, it is modified to use alarm ().

Unit Timer class interval time setting unit changed from microseconds to milliseconds.

Supports serial communication.  (See WonxSerialPort, WWSerialPort, comm.c)

With printf () in key.c, when the function name was not displayed when displaying the return value
Fix.

Version 0.4 beta - from wonx-b04.tar.gz
2018-03-07 23:06:28 +00:00

203 lines
5.1 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*****************************************************************************/
/* ここから */
/*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "wonx_include/key.h"
#include "Wonx.h"
/*****************************************************************************/
/* 互換関数の定義 */
/*****************************************************************************/
/*
* Xサーバとの同期の整合性がとれなくなるなどの問題が考えられるので
* 互換関数の内部は UNIXTimer_Pause(), UNIXTimer_Unpause() でくくり,
* タイマ割り込みを一時停止して処理を行うまたunpause するまえに,
* かならず sync するようにする.
*/
/*
* タイマの一時停止の2重解除の問題が出てくるので,
* 互換関数から互換関数を呼んではいけない.
* (一時停止はネストされるが,いちおう)
* 似たような処理をする関数の場合は,必ず static な別関数に処理をまとめ,
* そっちを呼び出すようにすること.
* 引数の表示の問題もあるしね.
*/
int key_press_check(void)
{
XDisplay x_display;
int ret;
if (!Wonx_IsCreated()) Wonx_Create();
/* タイマを一時停止する */
UNIXTimer_Pause(WonxSystem_GetUNIXTimer(Wonx_GetWonxSystem()));
printf("call : key_press_check() : "); fflush(stdout);
x_display = WonxDisplay_GetXDisplay(Wonx_GetWonxDisplay());
XDisplay_Sync(x_display);
ret = XDisplay_GetKeyPress(x_display);
WonxDisplay_Sync(Wonx_GetWonxDisplay());
printf("call : key_press_check() : return value = 0x%04x\n", (int)ret);
fflush(stdout);
/* タイマをもとに戻す */
UNIXTimer_Unpause(WonxSystem_GetUNIXTimer(Wonx_GetWonxSystem()));
return (ret);
}
int key_hit_check(void)
{
XDisplay x_display;
int ret;
if (!Wonx_IsCreated()) Wonx_Create();
/* タイマを一時停止する */
UNIXTimer_Pause(WonxSystem_GetUNIXTimer(Wonx_GetWonxSystem()));
printf("call : key_hit_check() : "); fflush(stdout);
x_display = WonxDisplay_GetXDisplay(Wonx_GetWonxDisplay());
XDisplay_Sync(x_display);
ret = XDisplay_GetKeyPress(x_display);
WonxDisplay_Sync(Wonx_GetWonxDisplay());
printf("call : key_hit_check() : return value = 0x%04x\n", (int)ret);
fflush(stdout);
/* タイマをもとに戻す */
UNIXTimer_Unpause(WonxSystem_GetUNIXTimer(Wonx_GetWonxSystem()));
return (ret);
}
int key_wait(void)
{
XDisplay x_display;
int ret;
if (!Wonx_IsCreated()) Wonx_Create();
/* タイマを一時停止する */
UNIXTimer_Pause(WonxSystem_GetUNIXTimer(Wonx_GetWonxSystem()));
printf("call : key_wait() : "); fflush(stdout);
x_display = WonxDisplay_GetXDisplay(Wonx_GetWonxDisplay());
/*
* 以下はホットスポットになり得るので注意!
*/
ret = 0;
do {
XDisplay_Sync(x_display);
ret = XDisplay_GetKeyPress(x_display);
} while (ret == 0);
WonxDisplay_Sync(Wonx_GetWonxDisplay());
printf("call : key_wait() : return value = 0x%04x\n", (int)ret);
fflush(stdout);
/* タイマをもとに戻す */
UNIXTimer_Unpause(WonxSystem_GetUNIXTimer(Wonx_GetWonxSystem()));
return (ret);
}
void key_set_repeat(int rate, int delay)
{
if (!Wonx_IsCreated()) Wonx_Create();
/* タイマを一時停止する */
UNIXTimer_Pause(WonxSystem_GetUNIXTimer(Wonx_GetWonxSystem()));
printf("call : key_set_repeat() : rate = %d, delay = %d, ", rate, delay);
fflush(stdout);
WonxDisplay_Sync(Wonx_GetWonxDisplay());
printf("call : key_set_repeat() : return value = none\n"); fflush(stdout);
/* タイマをもとに戻す */
UNIXTimer_Unpause(WonxSystem_GetUNIXTimer(Wonx_GetWonxSystem()));
return;
}
int key_get_repeat(void)
{
int ret;
if (!Wonx_IsCreated()) Wonx_Create();
/* タイマを一時停止する */
UNIXTimer_Pause(WonxSystem_GetUNIXTimer(Wonx_GetWonxSystem()));
printf("call : key_get_repeat() : "); fflush(stdout);
ret = 0;
WonxDisplay_Sync(Wonx_GetWonxDisplay());
printf("call : key_get_repeat() : return value = 0x%04x\n", (int)ret);
fflush(stdout);
/* タイマをもとに戻す */
UNIXTimer_Unpause(WonxSystem_GetUNIXTimer(Wonx_GetWonxSystem()));
return (ret);
}
int key_hit_check_with_repeat(void)
{
XDisplay x_display;
int ret;
if (!Wonx_IsCreated()) Wonx_Create();
/* タイマを一時停止する */
UNIXTimer_Pause(WonxSystem_GetUNIXTimer(Wonx_GetWonxSystem()));
printf("call : key_hit_check_with_repeat() : "); fflush(stdout);
x_display = WonxDisplay_GetXDisplay(Wonx_GetWonxDisplay());
XDisplay_Sync(x_display);
ret = XDisplay_GetKeyPress(x_display);
WonxDisplay_Sync(Wonx_GetWonxDisplay());
printf("call : key_hit_check_with_repeat() : return value = 0x%04x\n",
(int)ret);
fflush(stdout);
/* タイマをもとに戻す */
UNIXTimer_Unpause(WonxSystem_GetUNIXTimer(Wonx_GetWonxSystem()));
return (ret);
}
/*****************************************************************************/
/* ここまで */
/*****************************************************************************/
/*****************************************************************************/
/* End of File. */
/*****************************************************************************/