{"id":356,"date":"2011-01-03T03:01:31","date_gmt":"2011-01-03T03:01:31","guid":{"rendered":"http:\/\/louisc.co.uk\/FYP\/?p=356"},"modified":"2015-01-13T23:40:53","modified_gmt":"2015-01-13T23:40:53","slug":"a-library-dedicated-to-the-system","status":"publish","type":"post","link":"https:\/\/louisc.co.uk\/?p=356","title":{"rendered":"A LIBRARY DEDICATED TO THE SYSTEM"},"content":{"rendered":"<h1>Introduction<\/h1>\n<p>By this point much experience and understanding had been gained in the use of libraries and their ability to simplify what is going on in the main program. It was decided that a library will be written to support the lighting system as a whole. This will cut down on code repetition and allow for quicker implementation of new features and tweaks. Code written to date has been modified and transferred to the library.<\/p>\n<h2>The Library so far<\/h2>\n<p>The current status of the code allows for functions to be sent via wireless to the module and for these to be acted upon. Although the fade function has yet to be written the system is responding to simple commands and LED outputs are being manipulated wirelessly. The Driver class in the Library currently contains the following working functions:<\/p>\n<p><!--more--><\/p>\n<p>\u201cInitialize\u201d \u2013 This function initializes and configures the wireless module and the LED driver IC. It also begins a serial connection at 57600 baud and displays version number on the LCD screen.<\/p>\n<p>\u201ccheckRadio\u201d \u2013 This function checks the radio module to see if any commands have been received and are in the buffer. If there is a command available it will move it to the \u201creceived command\u201d (recCMD) variable for processing and return a \u201c1\u201d. If no command is available it will return a \u201c0\u201d.<\/p>\n<p>\u201cprocessCmd\u201d \u2013 This function should be run directly after checkRadio returns a \u201c1\u201d. It reads the \u201creceived command\u201d variable and run the correct function based on its content.<\/p>\n<p>The following functions are currently available commands which the driver unit will respond to, the data for each command is contained within the received command:<\/p>\n<p>\u201csetOut\u201d \u2013 this function sets the selected channel to the defined value. It does this by modifying the \u201cnextChanVal\u201d array.<\/p>\n<p>\u201csetAll\u201d &#8211;\u00a0 This function sets all channels on the selected bar to the defined value. It does this by modifying the \u201cnextChanVal\u201d array.<\/p>\n<p>\u201coutUpdate\u201d \u2013 This is called to push the \u201cnextChanVal\u201d array out to the LED lights and at the same time copy it to the \u201ccurrentChanVal\u201d array.<\/p>\n<p>The fade command will be replacing the \u201csetOut\u201d command which was created for testing purposes. For instant changes the fade time for the fade command will be set to \u201c0\u201d. If a time is given for the fade, the function will take the difference of the current and next values for each colour to create a step value per time segment which will then be run through using a loop.<\/p>\n<p>Some direct access commands will also be created which ignore the use of the current and next arrays for lower latency control. Any direct access commands will be prefixed with a \u201cD\u201d.<\/p>\n<h2>Code Excerpts<\/h2>\n<p>Some Code for the relevant functions:<\/p>\n<h3>ClightiveDrvr::initialize()<\/h3>\n<pre class=\"brush: cpp\">void ClightiveDrvr::initialize()\t\t\/\/Initialize Driver\r\n{\r\n\trf12_config(); \t\t\t\t\t\t\/\/Call ROM settings for wireless module\r\n\tTlc.init();\t\t\t\t\t\t\t\/\/Initialize TLC5940 with its Lib\r\n\r\n\tSerial.begin(57600);\r\n    Serial.print(\"\\nLED DRIVER FIRMWARE V0.0\\n\");\r\n\tfor( uint8_t chan = 0 ; chan &lt; 16 ; chan++ ){\r\n\tTlc.set( chan, 4095 );\r\n\tcurrentval[chan] = 4095;\r\n\t}\r\n\tTlc.update();\r\n    lcd.begin(16, 2);                   \/\/ set up the LCD's number of columns and rows\r\n    \/\/Display GRAPHIC INITIALIZATION SEQUENCE --------------------\r\n\tlcd.print(\"LED DRIVER V0.0\");\r\n    delay(2000);\r\n    lcd.clear();\r\n    lcd.home();\r\n    lcd.print(\"Louis Christodoulou\");\r\n    delay(1000);\r\n    for( uint8_t x = 1 ; x &lt; 21 ; x++){\r\n\t\tlcd.scrollDisplayLeft();\r\n\t\tdelay(500\/x);\r\n\t}\r\n\tlcd.clear();\r\n\tlcd.home();\r\n    lcd.print(\"Waiting...\");\r\n\t\/\/END INITIALIZATION --------------------------------\r\n}<\/pre>\n<h3>ClightiveDrvr::checkRadio()<\/h3>\n<pre class=\"brush: cpp\">uint8_t ClightiveDrvr::checkRadio()\t\t\/\/Check Radio for any recieved commands, returns 1 for command waiting\r\n{\r\n    if (rf12_recvDone() &amp;&amp; rf12_crc == 0) {\r\n\t\tlcd.setCursor(15, 0);\r\n\t\tlcd.print(\"&lt;\");\r\n        for (byte i = 0; i &lt; rf12_len; ++i)\r\n\t\t{\r\n            recCmd[i] = rf12_data[i];\r\n\t\t\t\/\/Serial.print(\"\\n\");\r\n\t\t\t\/\/Serial.print(recCmd[i], DEC);\r\n\t\t\tSerial.print(rf12_data[i]);\r\n\r\n\t\t}\r\n\t\tdelay(200); \/\/ otherwise LCD symbol isn't visible\r\n\t\tlcd.setCursor(15, 0);\r\n\t\tlcd.print(\" \");\r\n\t\treturn 1;\r\n    }\r\n\treturn 0;\r\n}<\/pre>\n<h3>ClightiveDrvr::processCmd()<\/h3>\n<pre class=\"brush: cpp\">void ClightiveDrvr::processCmd()\r\n{\r\n\r\n\tswitch(recCmd[0])\r\n\t{\r\n\t\tcase CMD_BLACKOUT:\r\n\t\t\tbreak;\r\n\r\n\t\tcase CMD_FADE:\r\n\r\n\t\t\tsetFade();\r\n\t\t\tbreak;\r\n\r\n\t\tcase CMD_OUTUPDATE:\r\n\t\t\toutUpdate();\r\n\t\t\tbreak;\r\n\r\n\t} \/\/ end switch\r\n}<\/pre>\n<p>As more functions are written this post will be updated.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction By this point much experience and understanding had been gained in the use of libraries and their ability to simplify what is going on in the main program. It was decided that a library will be written to support the lighting system as a whole. This will cut down on code repetition and allow for quicker implementation of new features and tweaks. Code written to date has been modified and transferred to the library. The Library [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":473,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[32],"tags":[34,35,42],"class_list":["post-356","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-lightive-reactive-lighting-system","tag-arduino","tag-atmel","tag-c"],"_links":{"self":[{"href":"https:\/\/louisc.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/356","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/louisc.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/louisc.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/louisc.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/louisc.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=356"}],"version-history":[{"count":8,"href":"https:\/\/louisc.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/356\/revisions"}],"predecessor-version":[{"id":546,"href":"https:\/\/louisc.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/356\/revisions\/546"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/louisc.co.uk\/index.php?rest_route=\/wp\/v2\/media\/473"}],"wp:attachment":[{"href":"https:\/\/louisc.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=356"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/louisc.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=356"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/louisc.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}