{"id":275,"date":"2017-03-22T01:46:43","date_gmt":"2017-03-22T01:46:43","guid":{"rendered":"http:\/\/www.piboxproject.com\/?p=275"},"modified":"2017-03-22T01:46:43","modified_gmt":"2017-03-22T01:46:43","slug":"introduction-to-libpibox","status":"publish","type":"post","link":"https:\/\/www.piboxproject.com\/index.php\/2017\/03\/22\/introduction-to-libpibox\/","title":{"rendered":"Introduction to libpibox"},"content":{"rendered":"<div id=\"dslc-theme-content\"><div id=\"dslc-theme-content-inner\"><p><span style=\"color: #ff9900;\"><em>PiBox<\/em><\/span> is many things: a core development platform, a media center, a UI, and a learning tool.\u00a0 It&#8217;s also an infrastructure for application development. Most platforms have infrastructure support.\u00a0 Android has an array of <a href=\"https:\/\/developer.android.com\/guide\/platform\/index.html\">Java and C\/C++ libraries<\/a>.\u00a0 <a href=\"https:\/\/developer.tizen.org\/\">Tizen<\/a> has a build environment, but for the life of me I can&#8217;t find the basic APIs.\u00a0 In general these are full featured infrastructures for every possible application.\u00a0 PiBox is much simpler.\u00a0 It doesn&#8217;t really do a lot for you.\u00a0 It lets you figure out what libraries you want installed and build your C apps on top of those.\u00a0 But it does provide some basic infrastructure libraries for C apps.\u00a0 While it&#8217;s not quite a <a href=\"http:\/\/suckless.org\/\">suckless<\/a> philosophy, the goal is still be to simple and small.<\/p>\n<p>The two main components of the PiBox infrastructure are <em>libpibox<\/em> and <em>libpnc<\/em>.\u00a0 Both libraries are included in the core development platform.\u00a0 These libraries contain functions for dealing with common application features from debugging to networking to touchscreens.\u00a0 Applications within the media center, for example, make extensive use of both libraries.\u00a0 We&#8217;ll examine libpnc in another article.\u00a0 Let&#8217;s take a deeper look at libpibox.<\/p>\n<h3>libpibox<\/h3>\n<p>There are six API namespaces within libpibox:\u00a0 <em>pibox<\/em>, <em>piboxLogger<\/em>, <em>piboxMsg<\/em>, <em>rpi<\/em>, <em>touchProcessor<\/em> and <em>Parson<\/em>.\u00a0 The <em>pibox<\/em> functions include useful utility functions such as trimming white space or newlines from a string.\u00a0 This functional area is small as many libraries exist for handling utility functions.\u00a0 But to avoid loading multiple larger general purpose libraries just for their utilities, pibox functions allow sticking to a single lightweight library that includes other functional areas specific to PiBox.\u00a0 If you need a fully featured utility library with all the bells and whistles I recommend <a href=\"https:\/\/developer.gnome.org\/glib\/\">glib<\/a>.<\/p>\n<p>The <em>piboxLogger<\/em> functions are used for debugging code.\u00a0 The logging facilities allow for output to the console or to a file, provide up to 8 levels of detail and include support for optional timestamps.\u00a0 Logging can also be enabled or disabled at compile time.\u00a0 If the library is disabled at compile time the library calls in the app are simply ignored by the compiler.<\/p>\n<p>The PiBox protocol is used for messaging between apps and daemons.\u00a0 Apps can send messages to daemons using <em>piboxMsg<\/em>() which wraps the protocol and message passing in a single function call.\u00a0 Future development of this functional area will include receiver management for inbound messages.\u00a0 While the PiBox protocol is well defined, this functional area of libpibox is still under heavy development in order to provide easy-to-use APIs for message passing.<\/p>\n<p>The Raspberry Pi project supports the use of a text configuration file, called <a href=\"http:\/\/elinux.org\/RPiconfig\"><em>config.txt<\/em><\/a>, that can modify the bootloader operation at boot time.\u00a0 This includes features like loading overlays or setting the screen orientation.\u00a0 The <em>rpi<\/em> functions are provided for reading, modifying and writing config.txt entries.\u00a0 This allows apps to implement their own interfaces for changing the boot configuration.<\/p>\n<p>A recent addition to libpibox is generalized support for touchscreens.\u00a0 This support is a wrapper around the <a href=\"https:\/\/github.com\/kergoth\/tslib\">ts library<\/a> making it possible to map a touchscreen to 9 regions or absolute screen coordinates.\u00a0 Mapping the screen to 9 regions makes it easier to implement a consistent usage strategy for a touchscreen across multiple apps while having absolute coordinates allows apps to map a screen location to a specific action like activating a function for an icon.\u00a0 The new kiosk mode of VideoFE (a media center app) uses the region mode for fast forward, rewind, next video, prev video and so forth.<\/p>\n<p>Finally, the <a href=\"https:\/\/github.com\/kgabis\/parson\">Parson library<\/a> has been integrated into libpibox.\u00a0 Early development of PiBox focused on XML configuration files.\u00a0 During development it was discovered that JSON was a much simpler format and more easily integrated using a much smaller library (Parson is one C module and one header file).\u00a0 Parson provides an easy to use function set for managing JSON objects, including support for setting alternative malloc and free functions appropriate for embedded applications.\u00a0 Unlike the PiBox developed APIs, the Parson library uses the <em>json<\/em> prefix for all of its functions.<\/p>\n<h3>What&#8217;s next<\/h3>\n<p>There is still plenty of work to be done with libpibox.\u00a0 All PiBox APIs are described with function headers in the source code and each includes a header file with the list of available functions at the end.\u00a0 The Parson library is easier to decipher by reading its header file or by visiting the project web site.\u00a0 But I still need to add meaningful documentation.\u00a0\u00a0 A bunch of man pages would be the Linux way.\u00a0 I can then convert them to web pages as needed.<\/p>\n<p>Extending the library is an obvious chore &#8211; there are always more features that could be added, but I want to keep the library as small as possible.\u00a0 An import\u00a0 extension will be to the messaging APIs and to thread management.\u00a0 Apps will often want to exchange data with other apps.\u00a0 They can do it using the simplistic PiBox protocol.\u00a0 But they need senders and receivers.\u00a0 And they need generic parsers to place the data into usable structures (lists of data) for use by the apps.\u00a0 I have all of this done in one place or another but they need to be consolidated into general purpose functions.<\/p>\n<p>None of this is hard to do.\u00a0 It just takes time.\u00a0 And isn&#8217;t that the hardest resource to acquire!<\/p>\n<p>&nbsp;<\/p>\n<\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>PiBox is many things: a core development platform, a media center, a UI, and a learning tool.\u00a0 It&#8217;s also an infrastructure for application development. Most platforms have infrastructure support.\u00a0 Android has an array of Java and C\/C++ libraries.\u00a0 Tizen has a build environment, but for the life of me I can&#8217;t find the basic APIs.\u00a0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":307,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[2,1],"tags":[],"class_list":{"0":"post-275","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-tech","8":"category-uncategorized","9":"czr-hentry"},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.piboxproject.com\/wp-content\/uploads\/2017\/03\/code-inspect-e1490118165108.png?fit=640%2C583&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8du2Y-4r","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.piboxproject.com\/index.php\/wp-json\/wp\/v2\/posts\/275","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.piboxproject.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.piboxproject.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.piboxproject.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.piboxproject.com\/index.php\/wp-json\/wp\/v2\/comments?post=275"}],"version-history":[{"count":4,"href":"https:\/\/www.piboxproject.com\/index.php\/wp-json\/wp\/v2\/posts\/275\/revisions"}],"predecessor-version":[{"id":310,"href":"https:\/\/www.piboxproject.com\/index.php\/wp-json\/wp\/v2\/posts\/275\/revisions\/310"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.piboxproject.com\/index.php\/wp-json\/wp\/v2\/media\/307"}],"wp:attachment":[{"href":"https:\/\/www.piboxproject.com\/index.php\/wp-json\/wp\/v2\/media?parent=275"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.piboxproject.com\/index.php\/wp-json\/wp\/v2\/categories?post=275"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.piboxproject.com\/index.php\/wp-json\/wp\/v2\/tags?post=275"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}