Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Readers > Amazon Kindle > Kindle Developer's Corner

Notices

Reply
 
Thread Tools Search this Thread
Old 11-21-2009, 11:29 PM   #1
sanek_vi
Junior Member
sanek_vi can self-interpret dreams as they happen.sanek_vi can self-interpret dreams as they happen.sanek_vi can self-interpret dreams as they happen.sanek_vi can self-interpret dreams as they happen.sanek_vi can self-interpret dreams as they happen.sanek_vi can self-interpret dreams as they happen.sanek_vi can self-interpret dreams as they happen.sanek_vi can self-interpret dreams as they happen.sanek_vi can self-interpret dreams as they happen.sanek_vi can self-interpret dreams as they happen.sanek_vi can self-interpret dreams as they happen.
 
Posts: 1
Karma: 20654
Join Date: Nov 2009
Device: Kindle DX
Drawing to the e-ink screen

Hello.
I have a code I would like to share with the community. It draws a rectangle on the e-ink screen. To execute:

1. Cross-compile the code and upload it to Kindle (usbnet assumed)
Code:
$ arm-none-linux-gnueabi-gcc -o hello-kindle hello.c
$ cat hello-kindle | ssh root@192.168.2.2 "cat - > /var/tmp/root/hello-arm"
2. Execute the code on the kindle
Code:
[root@kindle root]# /usr/sbin/eips  -c
[root@kindle root]# ./hello-arm 
Size: 824 x 1200
[root@kindle root]# echo 2 > /proc/eink_fb/update_display

The code is below. Comments/Questions are welcomed.
Code:
#include <stdio.h>
// Read in header files
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <unistd.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
/*
ACCELEROMETER=/proc/accelerometer   (cat works, tail -f doesnt)                            
/dev/input/event0 - keyboard
/dev/input/event1 - pointer
*/

#define putpixel(_x, _y, _c) 						\
	if ((_x) & 01) {						\
		data[((_y)*width + (_x)) >> 1] &= 0xF0;			\
		data[((_y)*width + (_x)) >> 1] |= (_c & 0x0F);		\
	} else {							\
		data[((_y)*width + (_x)) >> 1] &= 0x0F;			\
		data[((_y)*width + (_x)) >> 1] |= ((_c & 0x0F) << 4);	\
	}

int main(int argc, char** argv) {
	int width = 0;
	int height = 0;
	int row, column, i, j;

	// open framebuffer device and read out info
	int fd = open("/dev/fb0", O_RDWR);
                                                                  
	struct fb_var_screeninfo screeninfo;
	ioctl(fd, FBIOGET_VSCREENINFO, &screeninfo);
                                                                  
	// determine size
	width = screeninfo.xres;
	height = screeninfo.yres;

	printf("Size: %d x %d\n", width, height);
                                                                  
	// embed framebuffer into memory
                                                                  
	unsigned char *data = (unsigned char*)
		mmap(0, width * height / 2,
			PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
                                                                  
	// Clear memory (4 bpp)
	memset(data, 0, width * height / 2);

	// Draw a box
	for (i = 100; i <= 200; ++i) {
		putpixel(300, i, 0xF);
		putpixel(400, i, 0xF);
		putpixel(i+200, 100, 0xF);
		putpixel(i+200, 200, 0xF);
	}
                                                                 
	// mask framebuffer out of memory
	munmap(data, width * height / 2);
}
sanek_vi is offline   Reply With Quote
Old 05-07-2014, 05:19 PM   #2
aryeh
Junior Member
aryeh began at the beginning.
 
Posts: 6
Karma: 10
Join Date: May 2014
Device: Kindle Paperwhite
Using mouse and drawing

I'm trying to create a kindle paperwhite drawing program as well as a framework for using the touch.

Spoiler:

this is what i have so far:
http://www.linuxquestions.org/questi...device-615178/
//================================================== ==
// cosmegg 1.0 - kindle cosmic egg demo
// Copyright (C) 2012 by geekmaster, with MIT license:
// http://www.opensource.org/licenses/mit-license.php
//----------------------------------------------------
// The speed is limited by the eink device drivers.
// Newer kindle models are faster, but need delays.
// This was tested on DX,DXG,K3,K4(Mini),K5(Touch).
//----------------------------------------------------



#include <stdio.h> // printf
//#include <curses.h>
#include <stdlib.h> // malloc, free, atoi
#include <string.h> // memset, memcpy
#include <unistd.h> // usleep
#include <fcntl.h> // open, close, write
#include <time.h> // time
#include <sys/ioctl.h> // ioctl
#include <sys/time.h> // gettime
#include <sys/mman.h> // mmap, munmap
#include <linux/fb.h> // screeninfo
#include <linux/input.h> //mouse

#define MOUSEFILE "/dev/input/event1"
#define FPS 5 // max frames/sec

enum eupd_op { EUPD_OPEN,EUPD_CLOSE,EUPD_UPDATE };
typedef unsigned char u8;
typedef unsigned int u32;

// function prototypes
inline void setpx(int,int,int);
int eupdate(int);
void line(int,int,int,int,int);
void circle(int,int,int);
int getmsec(void);

// global var7
u32 mpu=200; // msec/update
u8 *fb0=NULL; // framebuffer pointer
int fdFB=0; // fb0 file descriptor
u32 fs=0; // fb0 stride
u32 MX=0; // xres (visible)
u32 MY=0; // yres (visible)
u8 blk=0; // black
u8 wht=0; // white
u8 pb=0; // pixel bits

//===============================================
// cosmegg - kindle cosmic egg demo
// This works on all kindle eink models. Enjoy!
//-----------------------------------------------
void cosmegg(void) {
int x,y,tn;
struct fb_var_screeninfo screeninfo;
fdFB=open("/dev/fb0",O_RDWR); // eink framebuffer

// calculate model-specific vars
ioctl(fdFB,FBIOGET_VSCREENINFO,&screeninfo);
MX=screeninfo.xres; // max X+1
MY=screeninfo.yres/2; // max Y+1
pb=screeninfo.bits_per_pixel; // pixel bits
fs=screeninfo.xres_virtual*pb/8; // fb0 stride
blk=pb/8-1; // black
wht=~blk; // white
fb0=(u8 *)mmap(0,MY*fs,PROT_READ|PROT_WRITE,MAP_SHARED,fdF B,0); // map fb0
eupdate(EUPD_OPEN); // open fb0 update proc
int rx[1000],ry[1000],i_rx=0,i_ry=0,tst1,tst2;
int gchar,x,y,c,oldx,oldy,ctr; x=0;y=0;c=1;oldx=0;oldy=0;ctr=0;
int fd;
struct input_event ie;
int ctr=0;

if((fd = open(MOUSEFILE, O_RDONLY)) == -1) {
perror("opening device");
exit(EXIT_FAILURE);
}

while(read(fd, &ie, sizeof(struct input_event)))
{

if (ie.type==3 && ie.code==53)
x=ie.value;
if (!y && ie.type==3 && ie.code==54)
y=ie.value;
if (x && y)
{
setpx(x,y,c);

eupdate(EUPD_UPDATE);
}
}


// cleanup - close and free resources
eupdate(EUPD_UPDATE); // update display
eupdate(EUPD_CLOSE); // close fb0 update proc port
munmap(fb0,fs*(MY+1)); // unmap fb0
close(fdFB); // close fb0
}

//===============================
// eupdate - eink update display
// op (open, close, update)
//-------------------------------
int eupdate(int op) {
static int fdUpdate=-1;
if (EUPD_OPEN==op) { fdUpdate=open("/proc/eink_fb/update_display",O_WRONLY);
} else if (EUPD_CLOSE==op) { close(fdUpdate);
} else if (EUPD_UPDATE==op) {
if (-1==fdUpdate) { system("eips ''");
} else { write(fdUpdate,"1\n",2); }
} else { return -1; } // bad op code
return fdUpdate;
}

//========================================
// setpx - draw pixel using ordered dither
// x,y: screen coordinates, c: color(0-64).
// (This works on all eink kindle models.)
//----------------------------------------
inline void setpx(int x,int y,int c) {
static int dt[64] = { 1,33,9,41,3,35,11,43,49,17,57,25,51,19,59,27,13,45 ,5,
37,15,47,7,39,61,29,53,21,63,31,55,23,4,36,12,44,2 ,34,10,42,52,20,60,28,50,
18,58,26,16,48,8,40,14,46,6,38,64,32,56,24,62,30,5 4,22 }; // dither table
fb0[pb*x/8+fs*y]=((128&(c-dt[(7&x)+8*(7&y)]))/128*(blk&(240*(1&~x)|
15*(1&x)|fb0[pb*x/8+fs*y])))|((128&(dt[(7&x)+8*(7&y)]-c))/128*wht|
(blk&((240*(1&x)|15*(1&~x))&fb0[pb*x/8+fs*y]))); // geekmaster formula 42
}

//====================================
// getmsec - get msec since first call
// (tick counter wraps every 12 days)
//------------------------------------
int getmsec(void) {
int tc;
static int ts=0;
struct timeval tv;
gettimeofday(&tv,NULL); tc=tv.tv_usec/1000+1000*(0xFFFFF&tv.tv_sec);
if (0==tc) { ts=tc; }
return tc-ts;
}

//==================
// main - start here
//------------------
int main(int argc,char **argv) {
if (argc>1) { mpu=atoi(argv[1]); }
//initscr();
//clear();

cosmegg(); // do the cosmic egg demo
//clear();
//endwin();
return 0;
}

//==================================
// line - Bresenham's line algorithm
//----------------------------------
void line(int x0,int y0,int x1,int y1,int c) {
int dx,ny,sx,sy,e;
if (x1>x0) { dx=x1-x0; sx=1; } else { dx=x0-x1; sx=-1; }
if (y1>y0) { ny=y0-y1; sy=1; } else { ny=y1-y0; sy=-1; }
e=dx+ny;
for (; { setpx(x0,y0,c);
if (x0==x1&&y0==y1) { break; }
if (e+e>ny) { e+=ny; x0+=sx; }
if (e+e<dx) { e+=dx; y0+=sy; }
}
}


Last edited by Dr. Drib; 05-08-2014 at 11:34 AM.
aryeh is offline   Reply With Quote
Advert
Old 05-07-2014, 08:00 PM   #3
knc1
Going Viral
knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.
 
knc1's Avatar
 
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
Does your post contain a question?
knc1 is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Looking for reader that has e-ink screen Lindsaym Which one should I buy? 3 05-17-2010 07:14 PM
ink spot on screen starbuck Sony Reader 1 09-17-2009 03:13 AM
Nothing covering E-ink screen? schulzmc Amazon Kindle 6 02-24-2009 09:34 PM
e- Ink secondary screen? philippd News 3 05-19-2008 05:39 AM
New screen technology: P-Ink |2eason News 5 09-22-2007 04:04 PM


All times are GMT -4. The time now is 12:10 AM.


MobileRead.com is a privately owned, operated and funded community.