Last active
January 16, 2016 14:58
-
-
Save TooTallNate/70047c16d24ff283c0e0 to your computer and use it in GitHub Desktop.
Ported to Node.js + FFI from: http://raspberrycompote.blogspot.com/2012/12/low-level-graphics-on-raspberry-pi-part_9509.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const ffi = require('ffi'); | |
const ref = require('ref'); | |
const Struct = require('ref-struct'); | |
const ArrayType = require('ref-array'); | |
const ioctl = ffi.ForeignFunction( | |
ffi.DynamicLibrary().get('ioctl'), | |
'int', ['int', 'int', 'void*'] | |
); | |
// #typedefs | |
const __u32 = ref.types.uint32; | |
// from <linux/fb.h> | |
const FBIOGET_VSCREENINFO = 0x4600; | |
const fb_bitfield = Struct([ | |
[__u32, 'offset'], /* beginning of bitfield */ | |
[__u32, 'length'], /* length of bitfield */ | |
[__u32, 'msb_right'] /* != 0 : Most significant bit is */ | |
/* right */ | |
]); | |
const fb_var_screeninfo = Struct([ | |
[__u32, 'xres'], /* visible resolution */ | |
[__u32, 'yres'], | |
[__u32, 'xres_virtual'], /* virtual resolution */ | |
[__u32, 'yres_virtual'], | |
[__u32, 'xoffset'], /* offset from virtual to visible */ | |
[__u32, 'yoffset'], /* resolution */ | |
[__u32, 'bits_per_pixel'], /* guess what */ | |
[__u32, 'grayscale'], /* != 0 Graylevels instead of colors */ | |
[fb_bitfield, 'red'], /* bitfield in fb mem if true color, */ | |
[fb_bitfield, 'green'], /* else only length is significant */ | |
[fb_bitfield, 'blue'], | |
[fb_bitfield, 'transp'], /* transparency */ | |
[__u32, 'nonstd'], /* != 0 Non standard pixel format */ | |
[__u32, 'activate'], /* see FB_ACTIVATE_* */ | |
[__u32, 'height'], /* height of picture in mm */ | |
[__u32, 'width'], /* width of picture in mm */ | |
[__u32, 'accel_flags'], /* (OBSOLETE) see fb_info.flags */ | |
/* Timing: All values in pixclocks, except pixclock (of course) */ | |
[__u32, 'pixclock'], /* pixel clock in ps (pico seconds) */ | |
[__u32, 'left_margin'], /* time from sync to picture */ | |
[__u32, 'right_margin'], /* time from picture to sync */ | |
[__u32, 'upper_margin'], /* time from sync to picture */ | |
[__u32, 'lower_margin'], | |
[__u32, 'hsync_len'], /* length of horizontal sync */ | |
[__u32, 'vsync_len'], /* length of vertical sync */ | |
[__u32, 'sync'], /* see FB_SYNC_* */ | |
[__u32, 'vmode'], /* see FB_VMODE_* */ | |
[__u32, 'rotate'], /* angle we rotate counter clockwise */ | |
[ArrayType(__u32, 5), 'reserved'] /* Reserved for future compatibility */ | |
]); | |
// Open the framebuffer device file for reading and writing | |
const fbfd = fs.openSync('/dev/fb0', 'w+'); | |
console.log('The framebuffer device opened: fd=%d', fbfd); | |
// Get variable screen information | |
const var_info = new fb_var_screeninfo(); | |
if (ioctl(fbfd, FBIOGET_VSCREENINFO, var_info.ref())) { | |
console.log("Error reading variable screen info."); | |
} | |
console.log("Display info %dx%d, %d bpp", | |
var_info.xres, var_info.yres, | |
var_info.bits_per_pixel ); | |
// close file | |
fs.closeSync(fbfd); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment