Commit afa7b39e authored by kollo's avatar kollo

added raw_keyboard for framebuffer version

nun sendet es auch events (noch rudimentaer)
anpassung an android version raw_keyboard.
parent 5005f131
......@@ -4,3 +4,4 @@ Release notes for Version 1.25 (Sept 2016 -- )
- new Commands: HIDEK, SHOWK (Android)
- fixed bug in MERGE and FILESELECT
- new function VRFY()
- added raw keyboard support for framebuffer version (e.g. Raspberry pi + sense hat)
......@@ -79,14 +79,14 @@ LIBOBJS=xbasic.o tools.o loadprg.o file.o io.o io_basic.o parser.o variablen.o s
MAINOBJS= main.o xbbc.o xbvm.o xb2c.o
EXTRAOBJS= bytecode.o ccs.o framebuffer.o raw_mouse.o spat-a-fnt.o 5x7.o consolefont.o \
EXTRAOBJS= bytecode.o ccs.o framebuffer.o raw_mouse.o raw_keyboard.o spat-a-fnt.o 5x7.o consolefont.o \
unifont.o unifont57.o terminal.o 8x16.o
# Sources for libx11basic
LIBCSRC=$(LIBOBJS:.o=.c)
FBLIBOBJS= $(LIBOBJS) framebuffer.o raw_mouse.o consolefont.o terminal.o spat-a-fnt.o 8x16.o 5x7.o unifont.o unifont57.o
FBLIBOBJS= $(LIBOBJS) framebuffer.o raw_mouse.o raw_keyboard.o consolefont.o terminal.o spat-a-fnt.o 8x16.o 5x7.o unifont.o unifont57.o
LIBCSRCFB=$(FBLIBOBJS:.o=.c)
......@@ -103,7 +103,7 @@ DEPSRC= $(CSRC)
HSRC= aes.h afunctions.h android.h array.h bitmap.h bytecode.h \
consolefont.h decode.h defs.h fft.h file.h framebuffer.h functions.h \
gkommandos.h graphics.h io.h kommandos.h \
mathematics.h number.h options.h parameter.h parser.h raw_mouse.h \
mathematics.h number.h options.h parameter.h parser.h raw_mouse.h raw_keyboard.h \
sfunctions.h sound.h svariablen.h sysVstuff.h \
terminal.h type.h variablen.h virtual-machine.h \
window.h wort_sep.h x11basic.h xb2csol.h xbasic.h lodepng.h md5.h sha1.h
......
......@@ -48,6 +48,7 @@
#include "framebuffer.h"
#include "consolefont.h"
#include "raw_mouse.h"
#include "raw_keyboard.h"
#ifndef ANDROID
extern struct fb_var_screeninfo vinfo;
......@@ -67,6 +68,12 @@ G_CONTEXT screen;
void textscreen_redraw(int x, int y, int w,int h);
extern int bigfont;
/*TODO:
Evtl. moechte man verschiedene framebufferdevices ansprechen, z.B.
beim sense Hat für Raspberry Pi (/dev/fb1)
Momentan muss FB_DEVICENAME dafuer geaendert werden.
*/
void Fb_Open() {
#ifndef ANDROID
fbfd=open(FB_DEVICENAME, O_RDWR);
......@@ -75,13 +82,6 @@ void Fb_Open() {
perror(FB_DEVICENAME);
exit(EX_OSFILE);
}
#if DEBUG
printf("Framebuffer device now opened.\n");
#endif
#else
fbfd=1;
#endif
#ifndef ANDROID
// Get fixed screen information
if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) {
perror("ERROR: Could not get fixed screen information.");
......@@ -97,6 +97,7 @@ void Fb_Open() {
screen.clip_w=screen.width=vinfo.xres;
screen.clip_h=screen.height=vinfo.yres;
#else
fbfd=1;
screen.bpp=16;
screen.clip_w=screen.width=screen_info.width;
screen.clip_h=screen.height=screen_info.height;
......@@ -157,6 +158,7 @@ void Fb_Close() {
FB_hide_mouse();
#ifndef ANDROID
FB_close_mouse();
FB_close_keyboard();
#endif
fbfd = -1;
}
......@@ -226,23 +228,15 @@ inline void FB_PutPixel(int x, int y, unsigned short color) {
inline void Fb_Scroll(int target_y, int source_y, int height) {
void Fb_Scroll(int target_y, int source_y, int height) {
memmove(screen.pixels+target_y*screen.scanline,
screen.pixels+source_y*screen.scanline,height*screen.scanline);
}
void FB_set_color(unsigned short color) {
screen.fcolor=color;
}
void FB_set_bcolor(unsigned short color) {
screen.bcolor=color;
}
void FB_set_alpha(unsigned char alpha) {
screen.alpha=alpha;
}
void FB_set_textmode(unsigned int mode) {
screen.textmode=mode;
}
void FB_set_color(unsigned short color) {screen.fcolor=color; }
void FB_set_bcolor(unsigned short color) {screen.bcolor=color; }
void FB_set_alpha(unsigned char alpha) {screen.alpha=alpha; }
void FB_set_textmode(unsigned int mode) {screen.textmode=mode;}
void FB_set_clip(G_CONTEXT *screen,int x,int y,int w,int h) {
screen->clip_x=x;
......
......@@ -269,7 +269,7 @@ void Fb_BlitBitmap(int x, int y,unsigned int w, unsigned int h,unsigned short aC
void FB_copyarea(int x,int y,int w, int h, int tx,int ty);
int FB_get_color(unsigned char r, unsigned char g, unsigned char b);
void FB_setgraphmode(int n);
inline void Fb_Scroll(int target_y, int source_y, int height);
void Fb_Scroll(int target_y, int source_y, int height);
void Fb_Clear2(int y, int h, unsigned short color);
#endif
......@@ -30,6 +30,7 @@
#ifdef FRAMEBUFFER
#include "framebuffer.h"
#include "raw_mouse.h"
#include "raw_keyboard.h"
#elif defined USE_GEM
#include <osbind.h>
#include <gem.h>
......@@ -1271,6 +1272,9 @@ void c_keyevent(PARAMETER *plist,int e) {
if(e>4 && plist[4].typ!=PL_LEER) varcastint(plist[4].integer,plist[4].pointer,global_mousex);
if(e>5 && plist[5].typ!=PL_LEER) varcastint(plist[5].integer,plist[5].pointer,global_mousey);
#endif
#ifdef FRAMEBUFFER
FB_keyboard_events(1);
#endif
#if defined USE_X11 || defined FRAMEBUFFER
XEvent event;
graphics();
......@@ -1332,6 +1336,9 @@ void c_keyevent(PARAMETER *plist,int e) {
if(e>3 && plist[3].typ!=PL_LEER) varcastint(plist[3].integer,plist[3].pointer,event.key.keysym.mod);
if(e>4 && plist[4].typ!=PL_LEER) varcastint(plist[4].integer,plist[4].pointer,event.key.state);
#endif
#ifdef FRAMEBUFFER
FB_keyboard_events(0);
#endif
}
int f_eventf(int mask) {
......@@ -1399,6 +1406,7 @@ void c_allevent(PARAMETER *plist,int e) {
graphics();
#ifdef FRAMEBUFFER
FB_mouse_events(1);
FB_keyboard_events(1);
#endif
// printf("EVENT e=%d vnr=%d pointer=%x\n",e,plist->integer,plist->pointer);
......@@ -1498,6 +1506,7 @@ void c_allevent(PARAMETER *plist,int e) {
#if defined FRAMEBUFFER
FB_mouse_events(0);
FB_keyboard_events(0);
#endif
#elif defined USE_SDL
......
......@@ -1144,7 +1144,7 @@ void c_receive(PARAMETER *plist, int e) {
if(fff.blk_len<=0) fff.blk_len=64;
str.pointer=malloc(fff.blk_len+1);
#ifdef HAVE_USB
int ret=usb_bulk_read(fff.dptr,fff.ep_in,str.pointer,fff.blk_len,TIMEOUT);
int ret=usb_bulk_read((usb_dev_handle *)fff.dptr,fff.ep_in,str.pointer,fff.blk_len,TIMEOUT);
if(e>2) varcastint(plist[2].integer,plist[2].pointer,ret);
if(ret<0) {
printf("usb_bulk_read failed with code %i: %s\n", ret, usb_strerror());
......
/* raw_keyboard.c Routinen fuer Event-Driver (c) Markus Hoffmann */
/* This file is part of X11BASIC, the basic interpreter for Unix/X
* ======================================================================
* X11BASIC is free software and comes with NO WARRANTY - read the file
* COPYING for details
*/
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#ifndef ANDROID
#include <pthread.h>
#include <linux/input.h>
#endif
#include "framebuffer.h"
#include "raw_keyboard.h"
static int do_keyboard_events=0;
void FB_keyboard_events(int onoff) {do_keyboard_events=onoff;}
#ifndef ANDROID
static int keyboard_fd=-1;
static pthread_t keyboard_thread;
static int read_keyboard_event(struct input_event *keye) {
if(keyboard_fd>0) {
int bytes=read(keyboard_fd, keye, sizeof(struct input_event));
if(bytes==-1) perror("Error reading keyboard device");
else if(bytes==sizeof(struct input_event)) return 1;
}
return 0;
}
static void *keyboard_handler(void *ptr) {
// printf("keyboard_thread running...\n");
fd_set aset,rset;
FD_ZERO(&aset);
FD_SET(keyboard_fd, &aset);
struct input_event m;
XEvent e;
unsigned char state=0;
int rc;
while(1) {
rset=aset;
rc=select(keyboard_fd+1, &rset, NULL, NULL, NULL);
if(rc==0) break; /*TIMEOUT should not happen*/
else if(rc<0) printf("select failed: errno=%d\n",errno);
else {
if(FD_ISSET(keyboard_fd,&rset)) {
if(read_keyboard_event(&m)) {
if(do_keyboard_events && m.type==EV_KEY) {
e.xkey.time=(int)m.time.tv_sec; /* evtl könnte man noch die tv_usec verarbeiten */
e.xkey.keycode=m.code;
if(m.value) e.type=KeyPress;
else e.type=KeyRelease;
e.xkey.buf[1]=0;
/*TODO: hier muesste der Buchstabe rausgefunden
werden....*/
switch(m.code) {
case 0x01: e.xkey.buf[0]=27;e.xkey.ks=0xff1b;break;
case 0x0f: e.xkey.buf[0]=9;e.xkey.ks=0xff09;break;
case 0x1c: e.xkey.buf[0]=13;e.xkey.ks=(state<<8)|13;break;
case 0x39: e.xkey.buf[0]=' ';e.xkey.ks=(state<<8)|32;break;
case 0x67: e.xkey.buf[0]=0;e.xkey.ks=0xff00;break; /* UP */
case 0x68: e.xkey.buf[0]=0;e.xkey.ks=0xff52;break; /* Page UP*/
case 0x69: e.xkey.buf[0]=0;e.xkey.ks=0xff00;break; /* LEFT*/
case 0x6a: e.xkey.buf[0]=0;e.xkey.ks=0xff00;break; /* RIGHT*/
case 0x6c: e.xkey.buf[0]=0;e.xkey.ks=0xff00;break; /* DOWN*/
case 0x6d: e.xkey.buf[0]=0;e.xkey.ks=0xff54;break; /* Page DOWN*/
default: e.xkey.buf[0]=0;e.xkey.ks=0;break;
}
FB_put_event(&e);
}
#if DEBUG
if(m.type==EV_KEY) {
printf("EVENT: time=%d.%d type=%04x code=%04x value=%d ",(int)m.time.tv_sec,(int)m.time.tv_usec,m.type,m.code,m.value);
switch(m.type) {
case EV_KEY: printf("EV_KEY \n"); break;
case EV_REL: printf("EV_REL \n"); break;
case EV_ABS: printf("EV_ABS \n"); break;
case EV_SYN: printf("EV_SYN \n"); break;
case EV_MSC: printf("EV_MSC \n"); break;
default: printf("unknown\n"); break;
}
}
#endif
}
}
}
}
printf("keyboard_thread finished.\n");
return(NULL);
}
void FB_close_keyboard() {
if(keyboard_fd>0) {
pthread_cancel(keyboard_thread);
pthread_join(keyboard_thread, NULL);
close(keyboard_fd);
keyboard_fd = -1;
}
}
int Fb_Keyboard_Open() {
FB_close_keyboard();
keyboard_fd=open(KEYBOARD_DEVICE, O_RDONLY);
/* Jetzt einen Interrupthandler / thread starten, welcher die
Event-Ereignisse verarbeitet.*/
if(keyboard_fd>0) {
pthread_create(&keyboard_thread, NULL,keyboard_handler, (void*) NULL);
} else perror(KEYBOARD_DEVICE);
return keyboard_fd;
}
#endif
/* raw_keyboard.h Routinen fuer Event-Driver (c) Markus Hoffmann */
/* This file is part of X11BASIC, the basic interpreter for Unix/X
* ======================================================================
* X11BASIC is free software and comes with NO WARRANTY - read the file
* COPYING for details
*/
#define KEYBOARD_DEVICE "/dev/input/event4"
void FB_close_keyboard();
int Fb_Keyboard_Open();
void FB_keyboard_events(int onoff);
......@@ -29,6 +29,7 @@
#include "aes.h"
#ifdef FRAMEBUFFER
#include "raw_mouse.h"
#include "raw_keyboard.h"
#endif
......@@ -276,6 +277,7 @@ static int create_window2(int nummer,const char *title, const char* info,int x,i
Fb_Open();
#ifndef ANDROID
Fb_Mouse_Open();
Fb_Keyboard_Open();
#endif
window[nummer].x=window[nummer].y=0;
window[nummer].w=screen.width;
......@@ -790,7 +792,7 @@ void put_bitmap(const char *adr,int x,int y,unsigned int w, unsigned int h) {
SDL_FreeSurface(image);
#elif defined FRAMEBUFFER
Fb_BlitBitmap(x,y,w,h,window[usewindow].fcolor, window[usewindow].bcolor, window[usewindow].screen->graphmode, adr);
Fb_BlitBitmap(x,y,w,h,window[usewindow].fcolor, window[usewindow].bcolor, window[usewindow].screen->graphmode, (unsigned char *)adr);
#endif
}
......@@ -950,6 +952,7 @@ short form_do(OBJECT *tree,short startob) {
#if defined FRAMEBUFFER
FB_clear_events();
FB_mouse_events(1);
FB_keyboard_events(1);
#endif
/* erstes editierbare Objekt finden */
......@@ -1237,6 +1240,7 @@ short form_do(OBJECT *tree,short startob) {
} /* while */
#ifdef FRAMEBUFFER
FB_mouse_events(0);
FB_keyboard_events(0);
#endif
return(sbut);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment