jube808
August 10th, 2008, 01:52
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspsdk.h>
#include <pspctrl.h>
#include <stdio.h>
#include <string.h>
#include <oslib/oslib.h>
#include "../../commons/callbacks.h"
#include "../../commons/calibrate.h"
PSP_MODULE_INFO("TS_SAMPLE", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
PSP_HEAP_SIZE_KB(12*1024);
char tschar = 0 ;
int sioReadChar();
int xread = 0;
int yread = 0;
int rread = 0;
int backspace = 0;
char screentext[1];
char redraw = 0;
char newchar = 0;
POINT touched,touchedscaled,touchedfinal;
POINT cal[3];
POINT tcal[3];
MATRIX calmatrix;
void sioInit(int,int);
void sioPutString(const char *, int);
int initOSLib(){
oslInit(0);
oslInitGfx(OSL_PF_8888, 1);
oslInitAudio();
oslSetQuitOnLoadFailure(1);
oslSetKeyAutorepeatInit(40);
oslSetKeyAutorepeatInterval(10);
return 0;
}
int byte2word ( int bytehigh, int bytelow )
{
int tally = 0;
tally = bytehigh ;
tally = tally << 8 ;
tally = tally | bytelow ;
return tally ;
}
char getTSChar (int yaxis,int xaxis)
{
char retchar = 0;
if ((yaxis > 60) && (yaxis < 100))
{
if ((xaxis > 0) && (xaxis < 43))
retchar = 0x31;
if ((xaxis > 43) && (xaxis < 86))
retchar = 0x32;
if ((xaxis > 86) && (xaxis < 131))
retchar = 0x33;
if ((xaxis > 131) && (xaxis < 175))
retchar = 0x34;
if ((xaxis > 175) && (xaxis < 218))
retchar = 0x35;
if ((xaxis > 218) && (xaxis < 262))
retchar = 0x36;
if ((xaxis > 262) && (xaxis < 306))
retchar = 0x37;
if ((xaxis > 306) && (xaxis < 350))
retchar = 0x38;
if ((xaxis > 350) && (xaxis < 393))
retchar = 0x39;
if ((xaxis > 393) && (xaxis < 435))
retchar = 0x30;
if ((xaxis > 435) && (xaxis <480))
retchar = 0x3F;
return(retchar);
}
if ((yaxis > 100) && (yaxis < 141))
{
if ((xaxis > 0) && (xaxis < 43))
retchar = 51;
if ((xaxis > 43) && (xaxis < 86))
retchar = 0x57;
if ((xaxis > 86) && (xaxis < 131))
retchar = 0x45;
if ((xaxis > 131) && (xaxis < 175))
retchar = 0x52;
if ((xaxis > 175) && (xaxis < 218))
retchar = 0x54;
if ((xaxis > 218) && (xaxis < 262))
retchar = 0x59;
if ((xaxis > 262) && (xaxis < 306))
retchar = 0x55;
if ((xaxis > 306) && (xaxis < 350))
retchar = 0x49;
if ((xaxis > 350) && (xaxis < 393))
retchar = 0x4f;
if ((xaxis > 393) && (xaxis < 435))
retchar = 0x50;
if ((xaxis > 435) && (xaxis <480))
retchar = 0x3f;
return(retchar);
}
if ((yaxis > 141) && (yaxis < 180))
{
if ((xaxis > 0) && (xaxis < 43))
retchar = 0x41;
if ((xaxis > 43) && (xaxis < 86))
retchar = 53;
if ((xaxis > 86) && (xaxis < 131))
retchar = 0x44;
if ((xaxis > 131) && (xaxis < 175))
retchar = 0x46;
if ((xaxis > 175) && (xaxis < 218))
retchar = 0x47;
if ((xaxis > 218) && (xaxis < 262))
retchar = 0x48;
if ((xaxis > 262) && (xaxis < 306))
retchar = 0x4A;
if ((xaxis > 306) && (xaxis < 350))
retchar = 0x4B;
if ((xaxis > 350) && (xaxis < 393))
retchar = 0x4c;
if ((xaxis > 393) && (xaxis < 435))
retchar = 0x3A;
if ((xaxis > 435) && (xaxis <480))
retchar = 0x3b;
return(retchar);
}
if ((yaxis > 180) && (yaxis < 220))
{
if ((xaxis > 0) && (xaxis < 43))
retchar = 0x5A;
if ((xaxis > 43) && (xaxis < 86))
retchar = 0x58;
if ((xaxis > 86) && (xaxis < 131))
retchar = 0x43;
if ((xaxis > 131) && (xaxis < 175))
retchar = 0x56;
if ((xaxis > 175) && (xaxis < 218))
retchar = 0x42;
if ((xaxis > 218) && (xaxis < 262))
retchar = 0x4e;
if ((xaxis > 262) && (xaxis < 306))
retchar = 0x4d;
if ((xaxis > 306) && (xaxis < 350))
retchar = 0x2c;
if ((xaxis > 350) && (xaxis < 393))
retchar = 0x2e;
if ((xaxis > 393) && (xaxis < 435))
retchar = 0x40;
if ((xaxis > 435) && (xaxis <480))
retchar = 0x3f;
return(retchar);
}
if ((yaxis > 100) && (yaxis < 141))
{
if ((xaxis > 0) && (xaxis < 43))
backspace = 1;
if ((xaxis > 43) && (xaxis < 86))
retchar = 0x20;
if ((xaxis > 86) && (xaxis < 131))
retchar = 0x0d;
return(retchar);
}
return(0);
}
int pollThread (SceSize args ,void * argp)
{
int ch = -1;
int readhigh = 0;
int readlow = 0;
float xf,yf ;
char oldchar = 0;
int keyrepeat = 0;
while(running())
{
ch = sioReadChar();
if(ch == 255)
{
ch = sioReadChar();
if(ch == 255)
{
readhigh = sioReadChar();
readlow = sioReadChar();
xf = ((byte2word ( readhigh,readlow )) - 45 ) / 1.77708 ;
xread = (int)xf;
if (xread > 480)
xread = 480;
if (xread < 0)
xread = 0;
xread = 480 - xread;
readhigh = sioReadChar();
readlow = sioReadChar();
yf = ((byte2word ( readhigh,readlow )) - 107 ) / 2.59191 ;
yread = (int)yf;
if (yread > 272)
yread = 272;
if (yread < 0)
yread = 0;
yread = 272 - yread;
readhigh = sioReadChar();
readlow = sioReadChar();
rread = byte2word ( readhigh,readlow ) ;
oldchar = newchar;
newchar = getTSChar(yread,xread);
if ((!(oldchar == newchar)) || (keyrepeat > 12) )
{
screentext[0] = newchar;
keyrepeat = 0;
redraw = 1;
}
else
{
keyrepeat++;
}
}
}
}
}
void createPollThread(){
SceUID thid;
thid = sceKernelCreateThread("sio polling thread", pollThread, 20, 16384, 0, NULL);
sceKernelStartThread(thid, 0, NULL);
}
int main(void)
{
int baud=9600;
initOSLib();
oslIntraFontInit(INTRAFONT_CACHE_MED);
pspDebugScreenInit();
//Load image:
OSL_IMAGE *bkg = oslLoadImageFilePNG("tskbd.png", OSL_IN_RAM | OSL_SWIZZLED, OSL_PF_8888);
pspDebugScreenPrintf("immage loaded\n");
//Load font:
OSL_FONT *pgfFont = oslLoadFontFile("flash0:/font/ltn0.pgf");
oslIntraFontSetStyle(pgfFont, 1.0, RGBA(255,255,255,255), RGBA(0,0,0,0), INTRAFONT_ALIGN_CENTER);
oslSetFont(pgfFont);
pspDebugScreenPrintf("font set\n");
oslStartDrawing();
oslDrawImageXY(bkg, 0, 0);
oslEndDrawing();
setupCallbacks(); // [home] handler
sceDisplayWaitVblankStart();
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
// load siodriver
SceUID mod = pspSdkLoadStartModule("sioDriver.prx", PSP_MEMORY_PARTITION_KERNEL);
if (mod < 0)
{
sceKernelDelayThread(3000000);
sceKernelExitGame();
}
sceKernelDelayThread(1000000);
sioInit(baud,0);
sceKernelDelayThread(1000000);
createPollThread();
while(running())
{
if (redraw)
{
oslStartDrawing();
oslDrawImageXY(bkg, 0, 0);
oslDrawString(100, 25, screentext);
oslEndDrawing();
redraw = 0;
pspDebugScreenPrintf(screentext);
}
}
sceKernelExitGame();
return 0;
}
thats the source to the osk that video'ed, posting it to let developers know how the serial data stream looks like
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspsdk.h>
#include <pspctrl.h>
#include <stdio.h>
#include <string.h>
#include <oslib/oslib.h>
#include "../../commons/callbacks.h"
#include "../../commons/calibrate.h"
PSP_MODULE_INFO("TS_SAMPLE", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
PSP_HEAP_SIZE_KB(12*1024);
char tschar = 0 ;
int sioReadChar();
int xread = 0;
int yread = 0;
int rread = 0;
int backspace = 0;
char screentext[1];
char redraw = 0;
char newchar = 0;
POINT touched,touchedscaled,touchedfinal;
POINT cal[3];
POINT tcal[3];
MATRIX calmatrix;
void sioInit(int,int);
void sioPutString(const char *, int);
int initOSLib(){
oslInit(0);
oslInitGfx(OSL_PF_8888, 1);
oslInitAudio();
oslSetQuitOnLoadFailure(1);
oslSetKeyAutorepeatInit(40);
oslSetKeyAutorepeatInterval(10);
return 0;
}
int byte2word ( int bytehigh, int bytelow )
{
int tally = 0;
tally = bytehigh ;
tally = tally << 8 ;
tally = tally | bytelow ;
return tally ;
}
char getTSChar (int yaxis,int xaxis)
{
char retchar = 0;
if ((yaxis > 60) && (yaxis < 100))
{
if ((xaxis > 0) && (xaxis < 43))
retchar = 0x31;
if ((xaxis > 43) && (xaxis < 86))
retchar = 0x32;
if ((xaxis > 86) && (xaxis < 131))
retchar = 0x33;
if ((xaxis > 131) && (xaxis < 175))
retchar = 0x34;
if ((xaxis > 175) && (xaxis < 218))
retchar = 0x35;
if ((xaxis > 218) && (xaxis < 262))
retchar = 0x36;
if ((xaxis > 262) && (xaxis < 306))
retchar = 0x37;
if ((xaxis > 306) && (xaxis < 350))
retchar = 0x38;
if ((xaxis > 350) && (xaxis < 393))
retchar = 0x39;
if ((xaxis > 393) && (xaxis < 435))
retchar = 0x30;
if ((xaxis > 435) && (xaxis <480))
retchar = 0x3F;
return(retchar);
}
if ((yaxis > 100) && (yaxis < 141))
{
if ((xaxis > 0) && (xaxis < 43))
retchar = 51;
if ((xaxis > 43) && (xaxis < 86))
retchar = 0x57;
if ((xaxis > 86) && (xaxis < 131))
retchar = 0x45;
if ((xaxis > 131) && (xaxis < 175))
retchar = 0x52;
if ((xaxis > 175) && (xaxis < 218))
retchar = 0x54;
if ((xaxis > 218) && (xaxis < 262))
retchar = 0x59;
if ((xaxis > 262) && (xaxis < 306))
retchar = 0x55;
if ((xaxis > 306) && (xaxis < 350))
retchar = 0x49;
if ((xaxis > 350) && (xaxis < 393))
retchar = 0x4f;
if ((xaxis > 393) && (xaxis < 435))
retchar = 0x50;
if ((xaxis > 435) && (xaxis <480))
retchar = 0x3f;
return(retchar);
}
if ((yaxis > 141) && (yaxis < 180))
{
if ((xaxis > 0) && (xaxis < 43))
retchar = 0x41;
if ((xaxis > 43) && (xaxis < 86))
retchar = 53;
if ((xaxis > 86) && (xaxis < 131))
retchar = 0x44;
if ((xaxis > 131) && (xaxis < 175))
retchar = 0x46;
if ((xaxis > 175) && (xaxis < 218))
retchar = 0x47;
if ((xaxis > 218) && (xaxis < 262))
retchar = 0x48;
if ((xaxis > 262) && (xaxis < 306))
retchar = 0x4A;
if ((xaxis > 306) && (xaxis < 350))
retchar = 0x4B;
if ((xaxis > 350) && (xaxis < 393))
retchar = 0x4c;
if ((xaxis > 393) && (xaxis < 435))
retchar = 0x3A;
if ((xaxis > 435) && (xaxis <480))
retchar = 0x3b;
return(retchar);
}
if ((yaxis > 180) && (yaxis < 220))
{
if ((xaxis > 0) && (xaxis < 43))
retchar = 0x5A;
if ((xaxis > 43) && (xaxis < 86))
retchar = 0x58;
if ((xaxis > 86) && (xaxis < 131))
retchar = 0x43;
if ((xaxis > 131) && (xaxis < 175))
retchar = 0x56;
if ((xaxis > 175) && (xaxis < 218))
retchar = 0x42;
if ((xaxis > 218) && (xaxis < 262))
retchar = 0x4e;
if ((xaxis > 262) && (xaxis < 306))
retchar = 0x4d;
if ((xaxis > 306) && (xaxis < 350))
retchar = 0x2c;
if ((xaxis > 350) && (xaxis < 393))
retchar = 0x2e;
if ((xaxis > 393) && (xaxis < 435))
retchar = 0x40;
if ((xaxis > 435) && (xaxis <480))
retchar = 0x3f;
return(retchar);
}
if ((yaxis > 100) && (yaxis < 141))
{
if ((xaxis > 0) && (xaxis < 43))
backspace = 1;
if ((xaxis > 43) && (xaxis < 86))
retchar = 0x20;
if ((xaxis > 86) && (xaxis < 131))
retchar = 0x0d;
return(retchar);
}
return(0);
}
int pollThread (SceSize args ,void * argp)
{
int ch = -1;
int readhigh = 0;
int readlow = 0;
float xf,yf ;
char oldchar = 0;
int keyrepeat = 0;
while(running())
{
ch = sioReadChar();
if(ch == 255)
{
ch = sioReadChar();
if(ch == 255)
{
readhigh = sioReadChar();
readlow = sioReadChar();
xf = ((byte2word ( readhigh,readlow )) - 45 ) / 1.77708 ;
xread = (int)xf;
if (xread > 480)
xread = 480;
if (xread < 0)
xread = 0;
xread = 480 - xread;
readhigh = sioReadChar();
readlow = sioReadChar();
yf = ((byte2word ( readhigh,readlow )) - 107 ) / 2.59191 ;
yread = (int)yf;
if (yread > 272)
yread = 272;
if (yread < 0)
yread = 0;
yread = 272 - yread;
readhigh = sioReadChar();
readlow = sioReadChar();
rread = byte2word ( readhigh,readlow ) ;
oldchar = newchar;
newchar = getTSChar(yread,xread);
if ((!(oldchar == newchar)) || (keyrepeat > 12) )
{
screentext[0] = newchar;
keyrepeat = 0;
redraw = 1;
}
else
{
keyrepeat++;
}
}
}
}
}
void createPollThread(){
SceUID thid;
thid = sceKernelCreateThread("sio polling thread", pollThread, 20, 16384, 0, NULL);
sceKernelStartThread(thid, 0, NULL);
}
int main(void)
{
int baud=9600;
initOSLib();
oslIntraFontInit(INTRAFONT_CACHE_MED);
pspDebugScreenInit();
//Load image:
OSL_IMAGE *bkg = oslLoadImageFilePNG("tskbd.png", OSL_IN_RAM | OSL_SWIZZLED, OSL_PF_8888);
pspDebugScreenPrintf("immage loaded\n");
//Load font:
OSL_FONT *pgfFont = oslLoadFontFile("flash0:/font/ltn0.pgf");
oslIntraFontSetStyle(pgfFont, 1.0, RGBA(255,255,255,255), RGBA(0,0,0,0), INTRAFONT_ALIGN_CENTER);
oslSetFont(pgfFont);
pspDebugScreenPrintf("font set\n");
oslStartDrawing();
oslDrawImageXY(bkg, 0, 0);
oslEndDrawing();
setupCallbacks(); // [home] handler
sceDisplayWaitVblankStart();
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
// load siodriver
SceUID mod = pspSdkLoadStartModule("sioDriver.prx", PSP_MEMORY_PARTITION_KERNEL);
if (mod < 0)
{
sceKernelDelayThread(3000000);
sceKernelExitGame();
}
sceKernelDelayThread(1000000);
sioInit(baud,0);
sceKernelDelayThread(1000000);
createPollThread();
while(running())
{
if (redraw)
{
oslStartDrawing();
oslDrawImageXY(bkg, 0, 0);
oslDrawString(100, 25, screentext);
oslEndDrawing();
redraw = 0;
pspDebugScreenPrintf(screentext);
}
}
sceKernelExitGame();
return 0;
}
thats the source to the osk that video'ed, posting it to let developers know how the serial data stream looks like