TaskScheduler.html 150 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <HTML>
  3. <HEAD>
  4. <META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=utf-8">
  5. <TITLE></TITLE>
  6. <META NAME="GENERATOR" CONTENT="LibreOffice 3.5 (Linux)">
  7. <META NAME="CREATED" CONTENT="20150206;16300000">
  8. <META NAME="CHANGEDBY" CONTENT="Anatoli Arkhipenko">
  9. <META NAME="CHANGED" CONTENT="20151128;23410000">
  10. <META NAME="Info 1" CONTENT="">
  11. <META NAME="Info 2" CONTENT="">
  12. <META NAME="Info 3" CONTENT="">
  13. <META NAME="Info 4" CONTENT="">
  14. <STYLE TYPE="text/css">
  15. <!--
  16. @page { margin: 0.79in }
  17. P { margin-bottom: 0.08in; direction: ltr; color: #000000; widows: 0; orphans: 0 }
  18. P.western { font-family: "Liberation Serif", "Times New Roman", serif; font-size: 12pt; so-language: en-US }
  19. P.cjk { font-family: "WenQuanYi Micro Hei", "MS Mincho"; font-size: 12pt; so-language: zh-CN }
  20. P.ctl { font-family: "Lohit Hindi", "MS Mincho"; font-size: 12pt; so-language: hi-IN }
  21. A:link { color: #0000ff }
  22. -->
  23. </STYLE>
  24. </HEAD>
  25. <BODY LANG="en-US" TEXT="#000000" LINK="#0000ff" BGCOLOR="#ffffff" DIR="LTR">
  26. <P CLASS="western" STYLE="margin-bottom: 0in"><FONT SIZE=4 STYLE="font-size: 15pt"><B>Task
  27. Scheduler</B></FONT></P>
  28. <P CLASS="western" STYLE="margin-bottom: 0in"><B>cooperative
  29. multitasking for Arduino microcontrollers</B></P>
  30. <P CLASS="western" STYLE="margin-bottom: 0in; border-top: none; border-bottom: 1px solid #000000; border-left: none; border-right: none; padding-top: 0in; padding-bottom: 0.01in; padding-left: 0in; padding-right: 0in">
  31. <FONT SIZE=2 STYLE="font-size: 11pt"><B>Version 1.9.2: 2015-12-20</B></FONT></P>
  32. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  33. </P>
  34. <P CLASS="western" STYLE="margin-bottom: 0in"><B>OVERVIEW</B>:</P>
  35. <P CLASS="western" STYLE="margin-bottom: 0in">A lightweight
  36. implementation of cooperative multitasking (task scheduling)
  37. supporting:</P>
  38. <OL>
  39. <LI><P CLASS="western" STYLE="margin-bottom: 0in">Periodic task
  40. execution (with dynamic execution period in milliseconds –
  41. frequency of execution)</P>
  42. <LI><P CLASS="western" STYLE="margin-bottom: 0in">Number of
  43. iterations (limited or infinite number of iterations)</P>
  44. <LI><P CLASS="western" STYLE="margin-bottom: 0in">Execution of tasks
  45. in predefined sequence</P>
  46. <LI><P CLASS="western" STYLE="margin-bottom: 0in">Dynamic change of
  47. task execution parameters (frequency, number of iterations, callback
  48. methods)</P>
  49. <LI><P CLASS="western" STYLE="margin-bottom: 0in">Power saving via
  50. entering IDLE sleep mode when tasks are not scheduled to run</P>
  51. <LI><P CLASS="western" STYLE="margin-bottom: 0in">Support for
  52. event-driven task invocation via Status Request object</P>
  53. <LI><P CLASS="western" STYLE="margin-bottom: 0in">Support for task
  54. IDs and Control Points for error handling and watchdog timer</P>
  55. <LI><P CLASS="western" STYLE="margin-bottom: 0in">Support for Local
  56. Task Storage pointer (allowing use of same callback code for
  57. multiple tasks)</P>
  58. </OL>
  59. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  60. </P>
  61. <P CLASS="western" STYLE="margin-bottom: 0in">Scheduling overhead:
  62. between 15 and 18 microseconds per scheduling pass.</P>
  63. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  64. </P>
  65. <P CLASS="western" STYLE="margin-bottom: 0in"><B>TASK</B>:</P>
  66. <P CLASS="western" STYLE="margin-bottom: 0in">“Task” is a
  67. container concept that links together:</P>
  68. <OL>
  69. <LI><P CLASS="western" STYLE="margin-bottom: 0in">Program code
  70. performing specific task activities (callback methods)</P>
  71. <LI><P CLASS="western" STYLE="margin-bottom: 0in">Execution interval</P>
  72. <LI><P CLASS="western" STYLE="margin-bottom: 0in">Number of
  73. execution iterations</P>
  74. <LI><P CLASS="western" STYLE="margin-bottom: 0in">(Optionally)
  75. Execution event (Status Request)</P>
  76. <LI><P CLASS="western" STYLE="margin-bottom: 0in">(Optionally)
  77. Pointer to a Local Task Storage area</P>
  78. </OL>
  79. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  80. </P>
  81. <P CLASS="western" STYLE="margin-bottom: 0in"><B>Tasks</B> perform
  82. certain functions, which could require periodic or one-time
  83. execution, update of specific variables, or waiting for specific
  84. events. Tasks also could be controlling specific hardware, or
  85. triggered by hardware interrupts.
  86. </P>
  87. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  88. </P>
  89. <P CLASS="western" STYLE="margin-bottom: 0in">For execution purposes
  90. <B>Tasks</B> are linked into execution <B>chains</B>, which are
  91. processed by the <B>Scheduler</B> in the order they were added
  92. (linked together).</P>
  93. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  94. </P>
  95. <P CLASS="western" STYLE="margin-bottom: 0in">Each task performs its
  96. function via a callback method. Scheduler calls Task’s callback
  97. method periodically until task is disabled or runs out of iterations.
  98. In addition to “regular” callback method, two additional methods
  99. could be utilized for each task: a callback method invoked every time
  100. the task is enabled, and a callback method invoked once when the task
  101. is disabled. Those two special methods allow tasks to properly
  102. initiate themselves for execution, and clean-up after execution is
  103. over (E.g., setup pin modes on enable, and always bring pin level to
  104. LOW at the end).
  105. </P>
  106. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  107. </P>
  108. <P CLASS="western" STYLE="margin-bottom: 0in">Tasks are responsible
  109. for supporting <B>cooperative</B> <B>multitasking</B> by being “good
  110. neighbors”, i.e., running their callback methods quickly in a
  111. non-blocking way, and releasing control back to scheduler as soon as
  112. possible.
  113. </P>
  114. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  115. </P>
  116. <P CLASS="western" STYLE="margin-bottom: 0in"><B>Scheduler</B> is
  117. executing Tasks' callback methods in the order the tasks were added
  118. to the chain, from first to last. Scheduler stops and exists after
  119. processing the chain once in order to allow other statements in the
  120. main code of <B>loop()</B> method to run. This is referred to as a
  121. <B>“scheduling pass”.</B></P>
  122. <P CLASS="western" STYLE="margin-bottom: 0in">(Normally, there is no
  123. need to have any other statements in the <B>loop</B>() method other
  124. than the Scheduler's <B>execute</B>() method).</P>
  125. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  126. </P>
  127. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  128. <B>Below is the flowchart of a Task lifecycle:</B></P>
  129. <P CLASS="western" STYLE="margin-bottom: 0in"><IMG SRC="TaskScheduler_html.png" NAME="graphics1" ALIGN=BOTTOM WIDTH=664 HEIGHT=570 BORDER=0></P>
  130. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  131. </P>
  132. <P CLASS="western" STYLE="margin-bottom: 0in"><B>TaskScheduler</B>
  133. library maybe compiled with different compilation controls
  134. enabled/disabled. This is a way to limit TaskScheduler functionality
  135. (and size) for specific purpose (sketch). This is achieved by
  136. defining specific #<B>define</B> paramenters <I>before</I>
  137. TaskScheduler.h header file. Specifically:</P>
  138. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  139. </P>
  140. <P CLASS="western" STYLE="margin-bottom: 0in">If compiled with
  141. <FONT FACE="Courier New, monospace">_TASK_SLEEP_ON_IDLE_RUN</FONT>
  142. enabled, the scheduler will place processor into IDLE sleep mode (for
  143. approximately 1 ms, as the timer interrupt will wake it up), after
  144. what is determined to be an “idle” pass. An Idle Pass is a pass
  145. through the task chain when no Tasks were scheduled to run their
  146. callback methods. This is done to avoid repetitive idle passes
  147. through the chain when no tasks need to be executed. If any of the
  148. tasks in the chain always requires immediate execution (aInterval =
  149. 0), then there will be no IDLE sleep between task's callback method
  150. execution.</P>
  151. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  152. </P>
  153. <P CLASS="western" STYLE="margin-bottom: 0in"><B>Note: </B>Task
  154. Scheduler uses <B>millis()</B> to determine if tasks are ready to be
  155. invoked. Therefore, if you put your device to any “deep” sleep
  156. mode disabling timer interrupts, the <B>millis()</B> count will be
  157. suspended, leading to effective suspension of scheduling. Upon wake
  158. up, active tasks need to be re-enabled, which will effectively reset
  159. their internal time scheduling variables to the new value of
  160. <B>millis(). </B>Time spent in deep sleep mode should be considered
  161. “frozen”, i.e., if a task was scheduled to run in 1 second from
  162. now, and device was put to sleep for 5 minutes, upon wake up, the
  163. task will still be scheduled 1 second from the time of wake up.
  164. Executing <B>enable() </B>method on this tasks will make it run as
  165. soon as possible. This is a concern only for tasks which are required
  166. to run in a truly periodical manner (in absolute time terms).
  167. </P>
  168. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  169. </P>
  170. <P CLASS="western" STYLE="margin-bottom: 0in">In addition to
  171. time-only (<B>millis</B>() only) invocation, tasks can be scheduled
  172. to wait on an event employing StatusRequest objects (more about
  173. Status Requests later).</P>
  174. <P CLASS="western" STYLE="margin-bottom: 0in">Consider a scenario
  175. when one task (t1) is performing a function which affects execution
  176. of many tasks (t2, t3). In this case the task t1 will “signal”
  177. completion of its function via Status Request object. Tasks t2 and t3
  178. are “waiting” on the same Status Request object. As soon as
  179. status request completes, t2 and t3 are activated.</P>
  180. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  181. </P>
  182. <P CLASS="western" STYLE="margin-bottom: 0in">Alternative scenario is
  183. the ne task (t1) and waiting for the completion of a number of tasks
  184. (t2, t3). When done, t2 and t3 signal completion of their functions,
  185. t1 is invoked.
  186. </P>
  187. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  188. </P>
  189. <P CLASS="western" STYLE="margin-bottom: 0in">Please see the code
  190. examples at the end of this document, and included with the library
  191. package for details.</P>
  192. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  193. </P>
  194. <P CLASS="western" STYLE="margin-bottom: 0in"><B>COMPILE PARAMETERS:</B></P>
  195. <P CLASS="western" STYLE="margin-bottom: 0in">This library could be
  196. compiled in several configurations.</P>
  197. <P CLASS="western" STYLE="margin-bottom: 0in">Parameters (<B>#define</B>s)
  198. defining what functionality should or should not be included need be
  199. defined before the library header file in the body of arduino sketch.</P>
  200. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  201. </P>
  202. <P CLASS="western" STYLE="margin-bottom: 0in">#define
  203. <B>_TASK_TIMECRITICAL</B></P>
  204. <P CLASS="western" STYLE="margin-bottom: 0in">...will compile the
  205. library with time critical tracking option enabled.</P>
  206. <P CLASS="western" STYLE="margin-bottom: 0in">Time critical option
  207. keeps track when current execution took place relative to when it was
  208. scheduled, and where next execution time of the task falls. Two
  209. methods provide this information.
  210. </P>
  211. <P CLASS="western" STYLE="margin-bottom: 0in"><B>Task::getStartDelay()
  212. </B><SPAN STYLE="font-weight: normal">method: return number of
  213. milliseconds between current system time (millis) and point in time
  214. when the task was scheduled to start. A value of 0 (zero) indicates
  215. that task started right on time per schedule. </SPAN>
  216. </P>
  217. <P CLASS="western" STYLE="margin-bottom: 0in"><B>Task::getOverrun()</B>
  218. method: If <B>getOverrun </B>returns a negative value, this Task’s
  219. next execution time point is <I>already</I> in the past, and task is
  220. behind schedule. This most probably means that either task’s
  221. callback method's runtime is too long, or the execution interval is
  222. too short (and therefore schedule is too aggressive).</P>
  223. <P CLASS="western" STYLE="margin-bottom: 0in">A positive value
  224. indicates that task is on schedule, and callback methods have enough
  225. time to finish before the next scheduled pass.
  226. </P>
  227. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  228. </P>
  229. <P CLASS="western" STYLE="margin-bottom: 0in">#define
  230. <B>_TASK_SLEEP_ON_IDLE_RUN</B></P>
  231. <P CLASS="western" STYLE="margin-bottom: 0in">...will compile the
  232. library with the <B>sleep</B> option enabled (AVR boards only).</P>
  233. <P CLASS="western" STYLE="margin-bottom: 0in">When enabled, scheduler
  234. will put the microcontroller into <B>SLEEP_MODE_IDLE</B> state if
  235. none of the tasks’ callback methods were activated during execution
  236. pass. <B>IDLE</B> state is interrupted by timers once every 1 ms.
  237. Putting microcontroller to IDLE state helps conserve power. Device
  238. in SLEEP_MODE_IDLE wakes up to all hardware and timer interrupts, so
  239. scheduling is kept current.</P>
  240. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  241. </P>
  242. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  243. #define <B>_TASK_STATUS_REQUEST</B></P>
  244. <P CLASS="western" STYLE="margin-bottom: 0in">…will compile
  245. TaskScheduler with support for StatusRequest object. Status Requests
  246. are objects allowing tasks to wait on an event, and signal event
  247. completion to each other.
  248. </P>
  249. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  250. </P>
  251. <P CLASS="western" STYLE="margin-bottom: 0in">#define <B>_TASK_WDT_IDS</B></P>
  252. <P CLASS="western" STYLE="margin-bottom: 0in">…will compile
  253. TaskScheduler with support for Task IDs and Control Points. Each task
  254. can be (and is by default) assigned an ID, which could be used to
  255. identify the task in case there is a problem with it. Furthermore
  256. within the task, Control Points could be defined to further help with
  257. pinpointing potential problem areas. For instance, the tasks which
  258. deal with external resources (sensors, serial communications,
  259. anything hardware dependent) can be blocked (or hung), by failed
  260. hardware. In this case, a watchdog timer could be employed to trap
  261. such a failed task, and identify which one (by task id) and where in
  262. the task (by a control point) the problem is likely located.</P>
  263. <P CLASS="western" STYLE="margin-bottom: 0in">
  264. </P>
  265. <P CLASS="western" STYLE="margin-bottom: 0in"><B>Note: </B>by
  266. default, talk IDs are assigned sequentially (1, 2, 3, …) to the
  267. tasks as they are being created. Programmer can assign a specific
  268. task id. <B>Task ids are unsigned integers.</B></P>
  269. <P CLASS="western" STYLE="margin-bottom: 0in">Control points provide
  270. a way to identify potential problem points within a task. Control
  271. points are <B>unsigned integers </B>as well. Please note that there
  272. is only one control point per task, and it is set to zero when the
  273. task’s callback method is invoked (this is done to prevent “stray”
  274. control point from previous task(s) confusing the matters.</P>
  275. <P CLASS="western" STYLE="margin-bottom: 0in">Example #7 contains a
  276. test of task ID and control points functionality.
  277. </P>
  278. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  279. </P>
  280. <P CLASS="western" STYLE="margin-bottom: 0in">#define
  281. <B>_TASK_LTS_POINTER</B></P>
  282. <P CLASS="western" STYLE="margin-bottom: 0in">…will compile
  283. TaskScheduler with support for Local Task Storage pointer (LTS). LTS
  284. is a generic (void*) pointer which could be set to reference a
  285. variable or a structure specific to a particular task. A callback
  286. method can get access to specific variables by getting reference to a
  287. currently running task from the scheduler, and then casting (void*)
  288. LTS pointer to the appropriate pointer type.
  289. </P>
  290. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  291. </P>
  292. <P CLASS="western" STYLE="margin-bottom: 0in"><B>NOTE: </B>above
  293. parameters are<B> DISABLED </B>by default, and need to be explicitly
  294. enabled by placing appropriate #define statements in front of the
  295. #include statement for the TaskScheduler header file.</P>
  296. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  297. </P>
  298. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  299. </P>
  300. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  301. </P>
  302. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  303. </P>
  304. <P CLASS="western" STYLE="margin-bottom: 0in"><B>TASK PRIORITY AND
  305. COOPERATIVE MULTITASKING:</B></P>
  306. <P CLASS="western" STYLE="margin-bottom: 0in">TaskScheduler <B>does
  307. not support</B> task priority functionality. I have been thinking a
  308. lot about it (especially since Symbian's Active Objects, which
  309. TaskScheduler is inspired by, support it), but decided against it.
  310. </P>
  311. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  312. </P>
  313. <P CLASS="western" STYLE="margin-bottom: 0in">This is why:</P>
  314. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  315. </P>
  316. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  317. </P>
  318. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  319. </P>
  320. <P CLASS="western" STYLE="margin-bottom: 0in">1. Execution chains are
  321. simple and efficient. The main idea is to minimize scheduling
  322. overhead by Scheduler going through the chain. Implementing true
  323. priority would require looking ahead through the entire chain,
  324. ranking and aging tasks by priorities. It would slow the <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">execute()
  325. </FONT></FONT>loop significantly.</P>
  326. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  327. </P>
  328. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  329. </P>
  330. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  331. </P>
  332. <P CLASS="western" STYLE="margin-bottom: 0in">2. TaskScheduler is <B>NOT</B>
  333. a pre-emptive multi-tasking library. Nor is it a Real-Time OS. There
  334. is no way to break execution of one task in favor of another.
  335. Therefore callback methods require careful programming for
  336. cooperative behavior.</P>
  337. <P CLASS="western" STYLE="margin-bottom: 0in">This has, however,
  338. significant benefits: you don't need to worry about concurrency
  339. inside the callback method, since only one callback method runs at a
  340. time, and could not be interrupted. All resources are yours for that
  341. period of time, noone can switch the value of variables (except
  342. interrupt functions of course...), etc. It is a stable and
  343. predictable environment, and it helps a lot with writing stable code.
  344. </P>
  345. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  346. </P>
  347. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  348. </P>
  349. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  350. </P>
  351. <P CLASS="western" STYLE="margin-bottom: 0in">A number of things
  352. could be done instead of priorities:</P>
  353. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  354. </P>
  355. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  356. </P>
  357. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  358. </P>
  359. <P CLASS="western" STYLE="margin-bottom: 0in">1. Schedule your
  360. critical tasks to run more frequently than the other tasks</P>
  361. <P CLASS="western" STYLE="margin-bottom: 0in">. <BR>(Since you can
  362. control the interval, you could also change the task to run more or
  363. less frequently as the situation demands).</P>
  364. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  365. </P>
  366. <P CLASS="western" STYLE="margin-bottom: 0in">2. If one particular
  367. callback routine is critical, create a couple of tasks referring to
  368. the same callback and &quot;sprinkle&quot; them around the chain:</P>
  369. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  370. </P>
  371. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  372. </P>
  373. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  374. </P>
  375. <P CLASS="western" STYLE="margin-bottom: 0in"> <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">Scheduler
  376. ts;</FONT></FONT></P>
  377. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  378. </P>
  379. <P CLASS="western" STYLE="margin-bottom: 0in"> <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">Task
  380. t1(20, TASK_FOREVER, &amp;callback1, &amp;ts);</FONT></FONT></P>
  381. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  382. </P>
  383. <P CLASS="western" STYLE="margin-bottom: 0in"> <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">Task
  384. t2(1000, TASK_FOREVER, &amp;callback2, &amp;ts);</FONT></FONT></P>
  385. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  386. </P>
  387. <P CLASS="western" STYLE="margin-bottom: 0in"> <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">Task
  388. t3(20, TASK_FOREVER, &amp;callback1, &amp;ts);</FONT></FONT></P>
  389. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  390. </P>
  391. <P CLASS="western" STYLE="margin-bottom: 0in"> <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">Task
  392. t4(1000, TASK_FOREVER, &amp;callback4, &amp;ts);</FONT></FONT></P>
  393. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  394. </P>
  395. <P CLASS="western" STYLE="margin-bottom: 0in"> <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">t3.delay(10);</FONT></FONT></P>
  396. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  397. </P>
  398. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  399. </P>
  400. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  401. </P>
  402. <P CLASS="western" STYLE="margin-bottom: 0in">Note that t1 and t3
  403. call the same callback method, and are shifted in time by 10 millis.
  404. So effectively callback1 will be called every 10 millis, but would be
  405. &quot;sandwiched&quot; between t2 and t4.
  406. </P>
  407. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  408. </P>
  409. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  410. </P>
  411. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  412. </P>
  413. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  414. </P>
  415. <P CLASS="western" STYLE="margin-bottom: 0in">3. Use short efficient
  416. callback methods written for cooperative multitasking.</P>
  417. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  418. </P>
  419. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  420. </P>
  421. <P CLASS="western" STYLE="margin-bottom: 0in">What that means is:</P>
  422. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  423. </P>
  424. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  425. </P>
  426. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  427. </P>
  428. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">a)
  429. <B>DO NOT</B> use Arduino's <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">delay()</FONT></FONT><FONT FACE="Andale Mono, MS Mincho">
  430. </FONT>function. It is blocking and will hold the entire chain.
  431. Instead break the callback method into two, switch the callback
  432. method of the task where delay is necessary and delay the task by
  433. that number of millis. You get your delay, and other tasks get a
  434. chance to run:</P>
  435. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  436. </P>
  437. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  438. </P>
  439. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  440. </P>
  441. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">instead
  442. of:</P>
  443. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  444. </P>
  445. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  446. </P>
  447. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  448. </P>
  449. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  450. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">void
  451. callback() {</FONT></FONT></P>
  452. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  453. </P>
  454. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  455. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">...
  456. stuff</FONT></FONT></P>
  457. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  458. </P>
  459. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  460. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">delay(1000);</FONT></FONT></P>
  461. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  462. </P>
  463. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  464. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">...
  465. more stuff</FONT></FONT></P>
  466. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  467. </P>
  468. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  469. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">}</FONT></FONT></P>
  470. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  471. </P>
  472. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  473. </P>
  474. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  475. </P>
  476. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">do
  477. this:</P>
  478. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  479. </P>
  480. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  481. </P>
  482. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  483. </P>
  484. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  485. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">void
  486. callback1() {</FONT></FONT></P>
  487. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  488. </P>
  489. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  490. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">...
  491. stuff</FONT></FONT></P>
  492. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  493. </P>
  494. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  495. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">t1.setCallback(&amp;callback2);</FONT></FONT></P>
  496. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  497. </P>
  498. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  499. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">t1.delay(1000);</FONT></FONT></P>
  500. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  501. </P>
  502. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  503. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">}</FONT></FONT></P>
  504. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  505. </P>
  506. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  507. </P>
  508. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  509. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">void
  510. callback2() {</FONT></FONT></P>
  511. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  512. </P>
  513. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  514. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">...
  515. more stuff</FONT></FONT></P>
  516. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  517. </P>
  518. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  519. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">t1.setCallback(&amp;callback1);</FONT></FONT></P>
  520. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  521. </P>
  522. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  523. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">}</FONT></FONT></P>
  524. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  525. </P>
  526. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  527. </P>
  528. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  529. </P>
  530. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  531. </P>
  532. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  533. </P>
  534. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">b)
  535. Same goes to <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">pulseIn()</FONT></FONT>
  536. function. If you have to use it, set the timeout parameter such that
  537. it is not a default 1 second. PulseIn functionality could be achieved
  538. via pin interrupts, and that solution is non-blocking.</P>
  539. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  540. </P>
  541. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  542. </P>
  543. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  544. </P>
  545. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">c)
  546. Do don run long loops (for or do/while) in you callback methods. Make
  547. the main arduino loop be the loop driver for you:</P>
  548. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  549. </P>
  550. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  551. </P>
  552. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  553. </P>
  554. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">instead
  555. of:</P>
  556. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  557. </P>
  558. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  559. </P>
  560. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  561. </P>
  562. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  563. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">void
  564. callback() {</FONT></FONT></P>
  565. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  566. </P>
  567. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  568. </P>
  569. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  570. </P>
  571. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  572. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">for(int
  573. i=0; i&lt;1000; i++) {</FONT></FONT></P>
  574. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  575. </P>
  576. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  577. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">...
  578. stuff // one loop action</FONT></FONT></P>
  579. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  580. </P>
  581. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  582. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">}</FONT></FONT></P>
  583. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  584. </P>
  585. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  586. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">}</FONT></FONT></P>
  587. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  588. </P>
  589. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  590. </P>
  591. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  592. </P>
  593. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">do
  594. this:</P>
  595. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  596. </P>
  597. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  598. </P>
  599. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  600. </P>
  601. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  602. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">Task
  603. t1(TASK_IMMEDIATE, 1000, &amp;callback);</FONT></FONT></P>
  604. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  605. </P>
  606. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  607. </P>
  608. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  609. </P>
  610. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  611. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">void
  612. callback() {</FONT></FONT></P>
  613. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  614. </P>
  615. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  616. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">int
  617. i = t1.getRunCounter() -1;</FONT></FONT></P>
  618. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  619. </P>
  620. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  621. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">...
  622. stuff // one loop action</FONT></FONT></P>
  623. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  624. </P>
  625. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  626. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">}</FONT></FONT></P>
  627. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  628. </P>
  629. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  630. </P>
  631. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  632. </P>
  633. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">or
  634. this:</P>
  635. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  636. </P>
  637. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  638. </P>
  639. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  640. </P>
  641. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  642. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">Task
  643. t1(TASK_IMMEDIATE, 1000, &amp;callback, true, &amp;t1On);</FONT></FONT></P>
  644. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  645. </P>
  646. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  647. </P>
  648. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  649. </P>
  650. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  651. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">int
  652. i;</FONT></FONT></P>
  653. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  654. </P>
  655. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  656. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">bool
  657. t1On() {</FONT></FONT></P>
  658. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  659. </P>
  660. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  661. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">i
  662. = 0;</FONT></FONT></P>
  663. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  664. </P>
  665. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  666. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">return
  667. true;</FONT></FONT></P>
  668. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  669. </P>
  670. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  671. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">}</FONT></FONT></P>
  672. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  673. </P>
  674. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  675. </P>
  676. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  677. </P>
  678. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  679. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">void
  680. callback() {</FONT></FONT></P>
  681. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  682. </P>
  683. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  684. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">...
  685. stuff // one loop action</FONT></FONT></P>
  686. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  687. </P>
  688. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  689. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">i++;</FONT></FONT></P>
  690. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  691. </P>
  692. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  693. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">}</FONT></FONT></P>
  694. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  695. </P>
  696. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  697. </P>
  698. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  699. </P>
  700. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  701. </P>
  702. <P CLASS="western" ALIGN=CENTER STYLE="margin-left: 0.49in; margin-bottom: 0in">
  703. <B>REMEMBER: you are already inside the loop - take advantage of it. </B>
  704. </P>
  705. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  706. </P>
  707. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">d)
  708. Break long running callback methods into several shorter ones, and
  709. pass control from one to the other via <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">setCallback()
  710. </FONT></FONT>method:</P>
  711. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  712. </P>
  713. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  714. </P>
  715. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  716. </P>
  717. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  718. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">Task
  719. t1(TASK_IMMEDIATE, TASK_FAREVER, &amp;callback);</FONT></FONT></P>
  720. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  721. </P>
  722. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  723. </P>
  724. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  725. </P>
  726. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  727. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">void
  728. callback() {</FONT></FONT></P>
  729. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  730. </P>
  731. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  732. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">...
  733. do some stuff</FONT></FONT></P>
  734. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  735. </P>
  736. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  737. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">t1.setCallback(&amp;callback_step2);</FONT></FONT></P>
  738. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  739. </P>
  740. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  741. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">}</FONT></FONT></P>
  742. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  743. </P>
  744. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  745. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">void
  746. callback_step2() {</FONT></FONT></P>
  747. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  748. </P>
  749. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  750. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">...
  751. do more stuff</FONT></FONT></P>
  752. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  753. </P>
  754. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  755. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">t1.setCallback(&amp;callback_step3);</FONT></FONT></P>
  756. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  757. </P>
  758. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  759. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">}</FONT></FONT></P>
  760. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  761. </P>
  762. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  763. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">void
  764. callback_step3() {</FONT></FONT></P>
  765. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  766. </P>
  767. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  768. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">...
  769. do last part of the stuff</FONT></FONT></P>
  770. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  771. </P>
  772. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  773. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">t1.setCallback(&amp;callback);</FONT></FONT></P>
  774. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  775. </P>
  776. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  777. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">t1.delay(1000);</FONT></FONT></P>
  778. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  779. </P>
  780. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  781. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">}</FONT></FONT></P>
  782. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  783. </P>
  784. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  785. </P>
  786. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  787. </P>
  788. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">This
  789. will execute all parts of the callback function in three successive
  790. steps, sheduled immediately, but allowing other tasks in the chain to
  791. run. Notice that task is scheduled to run immediately, and 1 second
  792. period is achieved by delaying the task for 1000 millis at the last
  793. step.
  794. </P>
  795. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  796. </P>
  797. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Alternatively
  798. you could schedule the task to run every 1000 millis and use
  799. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">forceNextIteration()</FONT></FONT>
  800. method in steps 1 and 2 (but not 3!)</P>
  801. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  802. </P>
  803. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  804. </P>
  805. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  806. </P>
  807. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  808. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">Task
  809. t1(1000, TASK_FOREVER, &amp;callback);</FONT></FONT></P>
  810. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  811. </P>
  812. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  813. </P>
  814. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  815. </P>
  816. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  817. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">void
  818. callback() {</FONT></FONT></P>
  819. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  820. </P>
  821. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  822. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">...
  823. do some stuff</FONT></FONT></P>
  824. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  825. </P>
  826. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  827. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">t1.setCallback(&amp;callback_step2);</FONT></FONT></P>
  828. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  829. </P>
  830. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  831. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">t1.forceNextIteration();</FONT></FONT></P>
  832. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  833. </P>
  834. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  835. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">}</FONT></FONT></P>
  836. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  837. </P>
  838. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  839. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">void
  840. callback_step2() {</FONT></FONT></P>
  841. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  842. </P>
  843. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  844. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">...
  845. do more stuff</FONT></FONT></P>
  846. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  847. </P>
  848. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  849. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">t1.setCallback(&amp;callback_step3);</FONT></FONT></P>
  850. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  851. </P>
  852. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  853. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">t1.forceNextIteration();</FONT></FONT></P>
  854. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  855. </P>
  856. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  857. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">}</FONT></FONT></P>
  858. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  859. </P>
  860. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  861. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">void
  862. callback_step3() {</FONT></FONT></P>
  863. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  864. </P>
  865. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  866. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">...
  867. do last part of the stuff</FONT></FONT></P>
  868. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  869. </P>
  870. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  871. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">t1.setCallback(&amp;callback);</FONT></FONT></P>
  872. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  873. </P>
  874. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  875. <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt">}</FONT></FONT></P>
  876. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  877. </P>
  878. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  879. </P>
  880. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  881. </P>
  882. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  883. </P>
  884. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  885. </P>
  886. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">e)
  887. Compile the library with <FONT FACE="FreeMono, MS Mincho, monospace"><FONT SIZE=2 STYLE="font-size: 10pt"><B>_TASK_TIMECRITICAL</B></FONT></FONT>
  888. enabled and check if your tasks are falling behind schedule. If they
  889. are - you need to optimize your code further (or maybe re-evaluate
  890. your schedule). If they are not - all is well and you don't need to
  891. do anything. E.g., I have a spider robot which needs to measure
  892. distance, control motors, and keep track of the angle via querying
  893. gyroscope and accelerometer every 10 ms. The idea was to flash
  894. onboard LED if any of the tasks fall behind. At 10 ms interval for
  895. the gyro the LED does not flash, which means none of the tasks are
  896. blocking the others from starting on time.
  897. </P>
  898. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  899. </P>
  900. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  901. </P>
  902. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  903. </P>
  904. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  905. <FONT SIZE=4><B>API DOCUMENTATION:</B></FONT></P>
  906. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  907. <BR>
  908. </P>
  909. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  910. <FONT SIZE=4><B>TASKS:</B></FONT></P>
  911. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  912. <BR>
  913. </P>
  914. <P CLASS="western" STYLE="margin-bottom: 0in">CREATION:</P>
  915. <P CLASS="western" STYLE="margin-bottom: 0in"><B>Task();</B></P>
  916. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  917. </P>
  918. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Default
  919. constructor.
  920. </P>
  921. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Takes
  922. no parameters and creates a task that could be scheduled to run at
  923. every scheduling pass indefinitely, but does not have a callback
  924. method defined, so no code execution will actually take place.
  925. </P>
  926. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">All
  927. tasks are created <B>disabled</B> by default.</P>
  928. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  929. </P>
  930. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  931. <B>Task(unsigned long aInterval, long aIterations, void
  932. (*aCallback)(), Scheduler* aScheduler, bool aEnable, bool
  933. (*aOnEnable)(), void (*aOnDisable)())</B></P>
  934. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  935. </P>
  936. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Constructor
  937. with parameters.
  938. </P>
  939. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Creates
  940. a task that is scheduled to run every &lt;aInterval&gt; milliseconds,
  941. &lt;aIterations&gt; times, executing &lt;aCallback&gt; method on
  942. every pass.
  943. </P>
  944. <OL>
  945. <LI><P CLASS="western" STYLE="margin-bottom: 0in">aInterval is in
  946. milliseconds (<B>default = 0)</B></P>
  947. <LI><P CLASS="western" STYLE="margin-bottom: 0in">aIteration in
  948. number of times, -1 for indefinite execution (<B>default = -1)</B><BR><B>Note:
  949. </B>Tasks do not remember the number of iteration set initially.
  950. After the iterations are done, internal iteration counter is 0. If
  951. you need to perform another set of iterations, you need to set the
  952. number of iterations again. <BR><B>Note: </B>Tasks which performed
  953. all their iterations remain active.
  954. </P>
  955. <LI><P CLASS="western" STYLE="margin-bottom: 0in">aCallback is a
  956. pointer to a void callback method without parameters (<B>default =
  957. NULL)</B></P>
  958. <LI><P CLASS="western" STYLE="margin-bottom: 0in">aScheduler –
  959. <B>optional</B> reference to existing scheduler. If supplied (not
  960. NULL) this task will be appended to the task chain of the current
  961. scheduler). (<B>default = NULL)</B></P>
  962. <LI><P CLASS="western" STYLE="margin-bottom: 0in">aEnable –
  963. <B>optional</B>. Value of <B>true </B>will create task enabled.
  964. (<B>default = false)</B></P>
  965. <LI><P CLASS="western" STYLE="margin-bottom: 0in">aOnEnable is a
  966. pointer to a bool callback method without parameters, invoked when
  967. task is enabled. If OnEnable method returns <B>true</B>, task is
  968. enabled. If <B>OnEnable</B> method return <B>false</B>, task remains
  969. disabled (<B>default = NULL)</B></P>
  970. <LI><P CLASS="western" STYLE="margin-bottom: 0in">aOnDisable is a
  971. pointer to a void callback method without parameters, invoked when
  972. task is disabled (<B>default = NULL)</B></P>
  973. </OL>
  974. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  975. </P>
  976. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">All
  977. tasks are created <B>disabled</B> by default (unless <B>aEnable</B> =
  978. true). You have to explicitly enable the task for execution.</P>
  979. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  980. </P>
  981. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><B>NOTE:
  982. </B>OnEnable callback method is called immediately when task is
  983. enabled, which could be well ahead of the scheduled execution time of
  984. the task. Please bear that in mind – other tasks, hardware, serial
  985. interface may not even be initialized yet. It is always advisable to
  986. explicitly enable tasks with OnEnable methods after all
  987. initialization methods completed (e.g., at the end of <B>setup</B>()
  988. method)
  989. </P>
  990. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  991. </P>
  992. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Enabled
  993. task is scheduled for execution as soon as the Scheduler's <B>execute</B>()
  994. methods gets control. In order to delay first run of the task, use
  995. <B>enableDelayed</B> or <B>delay</B> method (for enabled tasks)
  996. method.</P>
  997. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  998. </P>
  999. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  1000. <B>Task(void (*aCallback)(), Scheduler* aScheduler, bool
  1001. (*aOnEnable)(), void (*aOnDisable)())</B></P>
  1002. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1003. </P>
  1004. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">If
  1005. compiled with support for Status Request objects, this constructor
  1006. creates a Task for activation on event (since such tasks must run
  1007. <B>waitFor() </B>method, their <I>interval</I>, <I>iteration</I> and
  1008. <I>enabled</I> status will be set by that method (<I>to 0, 1 and
  1009. false</I> respectively).</P>
  1010. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1011. </P>
  1012. <P CLASS="western" STYLE="margin-bottom: 0in"><B>INFORMATION</B></P>
  1013. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">The
  1014. following 3 “getter” methods return task status
  1015. (enabled/disabled), execution interval in milliseconds, number of
  1016. <I><B>remaining</B></I> iterations.
  1017. </P>
  1018. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1019. </P>
  1020. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><B>bool
  1021. isEnabled() </B>
  1022. </P>
  1023. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><B>unsigned
  1024. long getInterval()</B></P>
  1025. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><B>long
  1026. getIterations() </B>
  1027. </P>
  1028. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1029. </P>
  1030. <P CLASS="western" STYLE="margin-bottom: 0in"><B>long getOverrun()</B></P>
  1031. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in; font-weight: normal">
  1032. If library is compiled with <FONT FACE="Courier New, monospace">_TASK_TIMECRITICAL</FONT>
  1033. enabled, you can assess how much later the callback method was
  1034. invoked against when it was scheduled to be invoked. The return value
  1035. of <B>getOverrun() </B>method provides this information in
  1036. milliseconds.
  1037. </P>
  1038. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1039. </P>
  1040. <P CLASS="western" STYLE="margin-bottom: 0in"><B>long getOverrun()</B></P>
  1041. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">If
  1042. library is compiled with <FONT FACE="Courier New, monospace">_TASK_TIMECRITICAL</FONT>
  1043. enabled, tasks are monitored for “long running” scenario. A “long
  1044. running” task is a task that does not finish processing its
  1045. callback methods quickly, and thus creates a situation for itself and
  1046. other tasks where they don't run on a scheduled interval, but rather
  1047. “catch up” and are behind. When task scheduler sets the next
  1048. execution target time, it adds Task's execution interval to the
  1049. previously scheduled execution time:</P>
  1050. <P CLASS="western" ALIGN=CENTER STYLE="margin-left: 0.49in; margin-bottom: 0in">
  1051. <B>next execution time = current execution scheduled time + task
  1052. execution interval</B></P>
  1053. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1054. </P>
  1055. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">If
  1056. <B>next execution time</B> happens to be already in the past (<B>next
  1057. execution time</B> &lt; <B>millis()</B>), then task is considered
  1058. <I><B>overrun</B></I>. <B>GetOverrun</B> method returns number of
  1059. milliseconds between next execution time and current time. If the
  1060. <B>value is negative</B>, the task has overrun (cut into the) next
  1061. execution interval by that many milliseconds.
  1062. </P>
  1063. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Positive
  1064. value indicate number of milliseconds of slack this task has for
  1065. execution purposes.
  1066. </P>
  1067. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1068. </P>
  1069. <P CLASS="western" STYLE="margin-bottom: 0in"><B>unsigned long
  1070. getRunCounter()</B></P>
  1071. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Returns
  1072. the number of the current run. “Current run” is the number of
  1073. times a callback method has been invoked since the last time a task
  1074. was enabled. <BR><BR>
  1075. </P>
  1076. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><B>NOTE:
  1077. </B>The <B>runCounter</B> value is incremented <I>before</I> callback
  1078. method is invoked. If a task is checking the <B>runCounter</B> value
  1079. within its callback method, then the first run value is 1.
  1080. </P>
  1081. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">If
  1082. task T1 is checking the <B>runCounter</B> value of another task (T2)
  1083. , then value = 0 indicates that T2 has not been invoked yet, and
  1084. value = 1 indicates that T2 has run once.
  1085. </P>
  1086. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1087. </P>
  1088. <P CLASS="western" STYLE="margin-bottom: 0in"><B>bool
  1089. isFirstIteration()</B></P>
  1090. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Indicates
  1091. whether current pass is (or will be) a first iteration of the task.
  1092. </P>
  1093. <P CLASS="western" STYLE="margin-bottom: 0in"><B>bool
  1094. isLastIteration()</B></P>
  1095. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">For
  1096. tasks with a l<I>imited number of iterations only</I>, indicates
  1097. whether current pass is the last iteration.
  1098. </P>
  1099. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1100. </P>
  1101. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  1102. <B>CONTROL:</B></P>
  1103. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  1104. <BR>
  1105. </P>
  1106. <P CLASS="western" STYLE="margin-bottom: 0in"><B>void enable();</B></P>
  1107. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1108. </P>
  1109. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Enables
  1110. the task, and schedules it for immediate execution (without delay) at
  1111. this or next scheduling pass depending on when the task was enabled.
  1112. Scheduler will execute the next pass without any delay because there
  1113. is a task which was enabled and requires execution.
  1114. </P>
  1115. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1116. </P>
  1117. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><B>NOTE:
  1118. </B>if task being enabled is not assigned to a scheduler and is not
  1119. part of execution chain, then task <B>will not</B> be enabled.</P>
  1120. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1121. </P>
  1122. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><B>NOTE:
  1123. </B>enable() invokes task’s <B>OnEnable</B> method (if not NULL)
  1124. <B>immediately</B>, which can prepare task for execution. <B>OnEnable</B>
  1125. must return a value of <B>true</B> for task to be enabled. If
  1126. <B>OnEnable</B> returns <B>false</B>, task remains disabled.
  1127. <B>OnEnable</B> is invoked every time <B>enable</B> is called,
  1128. regardless if task is already enabled or not. Alignment to current
  1129. millis() is performed after <B>OnEnable</B> exits, so any changes to
  1130. the interval inside <B>OnEnable</B> is taken into consideration.</P>
  1131. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">TaskScheduler
  1132. allows tasks to be added to the a Scheduler and enabled at the time
  1133. of creation. <B>Be very careful</B> with such tasks – the <B>OnEnable
  1134. </B>method will be executed immediately, while certain objects (i.e.,
  1135. other Tasks, libraries) are not yet ready (e.g., <B>Wire.begin()</B>
  1136. was not yet called), or hardware not yet activated (pins not set to
  1137. INPUT or OUTPUT).
  1138. </P>
  1139. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">It
  1140. is very much recommended to to enable all tasks at the end of <B>setup()</B>
  1141. method after all initializations are done.
  1142. </P>
  1143. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">If
  1144. you require immediate execution of already enabled task, use
  1145. <B>forceNextIteratoin</B>() method instead of <B>enable</B>(): it
  1146. achieves the result, but does not call <B>OnEnable</B> method.
  1147. </P>
  1148. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1149. </P>
  1150. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><B>NOTE:</B>
  1151. in the event <B>enable</B>() method is called inside the <B>OnEnable</B>
  1152. callback method (thus basically creating indefinte loop),
  1153. TaskScheduler will only call <B>OnEnable</B> once (thus protecting
  1154. the Task against <B>OnEnable</B> infinite loop).
  1155. </P>
  1156. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1157. </P>
  1158. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  1159. <B>bool enableIfNot();</B></P>
  1160. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  1161. <BR>
  1162. </P>
  1163. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Enables
  1164. the task only if it was previously disabled. Returns previous enable
  1165. state: <B>true</B> if task was already enabled, and <B>false</B> if
  1166. task was disabled. Since <B>enable() </B>schedules Task for execution
  1167. immediately, this method provides a way to activate tasks and
  1168. schedule them for immediate execution only if they are not active
  1169. already.</P>
  1170. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1171. </P>
  1172. <P CLASS="western" STYLE="margin-bottom: 0in"><B>void delay();</B></P>
  1173. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1174. </P>
  1175. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Schedules
  1176. the task for execution after a delay (aInterval), but does not change
  1177. the enabled/disabled status of the task.
  1178. </P>
  1179. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1180. </P>
  1181. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><B>NOTE:
  1182. </B>a delay of 0 (zero) will delay task for current execution
  1183. interval. Use <B>forceNextIteration() </B>method to force execution
  1184. of the task’s callback during immediate next scheduling pass.
  1185. </P>
  1186. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1187. </P>
  1188. <P CLASS="western" STYLE="margin-bottom: 0in"><B>void
  1189. forceNextIteration();</B></P>
  1190. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1191. </P>
  1192. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Schedules
  1193. the task for execution during immediate next scheduling pass.</P>
  1194. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">The
  1195. Task must be already <I>enabled</I> prior to this method.
  1196. </P>
  1197. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1198. </P>
  1199. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><B>Note:
  1200. </B>Task’s schedule is adjusted to run from this moment in time.
  1201. For instance: if a task was running every 10 seconds: 10, 20, 30, ..,
  1202. calling <B>forceNextIteration </B>at 44th second of task execution
  1203. will make subsequent schedule look like: 44, 54, 64, 74, ..</P>
  1204. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1205. </P>
  1206. <P CLASS="western" STYLE="margin-bottom: 0in"><B>void
  1207. enableDelayed();</B></P>
  1208. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1209. </P>
  1210. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Enables
  1211. the task, and schedules it for execution after task's current
  1212. scheduling interval (aInterval).
  1213. </P>
  1214. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1215. </P>
  1216. <P CLASS="western" STYLE="margin-bottom: 0in"><B>void enableDelayed
  1217. (unsigned long aDelay);</B></P>
  1218. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1219. </P>
  1220. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Enables
  1221. the task, and schedules it for execution after a specific delay
  1222. (aDelay, which maybe different from aInterval).
  1223. </P>
  1224. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1225. </P>
  1226. <P CLASS="western" STYLE="margin-bottom: 0in"><B>void restart();</B></P>
  1227. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1228. </P>
  1229. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">For
  1230. tasks with limited number of iterations only, <B>restart</B> method
  1231. will re-enable the task, set the number of iterations back to last
  1232. set value, and schedule task for execution as soon as possible.</P>
  1233. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1234. </P>
  1235. <P CLASS="western" STYLE="margin-bottom: 0in"><B>void restartDelayed
  1236. (unsigned long aDelay);</B></P>
  1237. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1238. </P>
  1239. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Same
  1240. as <B>restart()</B> method, with the only difference being that Task
  1241. is scheduled to run first iteration after a delay = <B>aDelay</B>
  1242. milliseconds.</P>
  1243. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1244. </P>
  1245. <P CLASS="western" STYLE="margin-bottom: 0in"><B>bool disable();</B></P>
  1246. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1247. </P>
  1248. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Disables
  1249. the task. Scheduler will not execute this task any longer, even if it
  1250. remains in the chain. Task <B>can</B> be later re-enabled for
  1251. execution.
  1252. </P>
  1253. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Return
  1254. previous enabled state: <B>true</B> if task was enabled prior to
  1255. calling disable, and <B>false</B> otherwise.</P>
  1256. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">If
  1257. not NULL, task’s <B>OnDisable</B> method is invoked <B>immediately</B>.
  1258. <B>OnDisable</B> is invoked only if task was in enabled state.
  1259. Calling <B>disable</B> 3 times for instance will invoke <B>OnDisable</B>
  1260. only once.</P>
  1261. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1262. </P>
  1263. <P CLASS="western" STYLE="margin-bottom: 0in"><B>void set(unsigned
  1264. long aInterval, long aIterations, void (*aCallback)() , bool
  1265. (*aOnEnable)() , void (*aOnDisable)());</B></P>
  1266. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1267. </P>
  1268. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Allows
  1269. dynamic control of task execution parameters in one method call.
  1270. </P>
  1271. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><B>Note</B><B>:
  1272. </B>OnEnable and OnDisable parameters can be omitted. In that case
  1273. they will be assigned to <B>NULL</B> and respective methods will no
  1274. longer be called. Therefore it is advisable to use either all five
  1275. parameters explicitly, or employ individual “setter” methods
  1276. below instead.
  1277. </P>
  1278. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1279. </P>
  1280. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  1281. Next five “setter” methods allow changes of individual task
  1282. execution control parameters.
  1283. </P>
  1284. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><B>void
  1285. setInterval (unsigned long aInterval) </B>
  1286. </P>
  1287. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><B>void
  1288. setIterations (long aIterations) </B>
  1289. </P>
  1290. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><B>void
  1291. setCallback (void (*aCallback)()) </B>
  1292. </P>
  1293. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><B>void
  1294. setOnEnable (bool (*aCallback)()) </B>
  1295. </P>
  1296. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><B>void
  1297. setOnDisable (void (*aCallback)()) </B>
  1298. </P>
  1299. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1300. </P>
  1301. <P CLASS="western" STYLE="margin-bottom: 0in"><B>NOTE: </B>Next
  1302. execution time calculation takes place <B>after</B> the callback
  1303. method is called, so new interval will be used immediately by the
  1304. scheduler. For the situations when one task is changing the interval
  1305. parameter for the other, <B>setInterval</B> method calls <B>delay
  1306. </B>explicitly to guarantee schedule change, however it <B>does not
  1307. </B>enable the task if task is disabled.</P>
  1308. <P CLASS="western" STYLE="margin-bottom: 0in"><B>NOTE: </B>Tasks that
  1309. ran through all their allocated iterations are disabled.
  1310. <B>SetIterations()</B> method <B>DOES NOT</B> enable the task. Either
  1311. <B>enable</B> explicitly, or use <B>restart</B> methods.
  1312. </P>
  1313. <P CLASS="western" STYLE="margin-bottom: 0in">Please note that as a
  1314. result execution of the taks is <B>delayed</B> by the provided
  1315. interval. If immediate invocation is required, call
  1316. <B>forceNextIteration</B>() method after setting a new interval.
  1317. </P>
  1318. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1319. </P>
  1320. <P CLASS="western" STYLE="margin-bottom: 0in"><B>STATUS REQUEST
  1321. METHODS:</B></P>
  1322. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  1323. <BR>
  1324. </P>
  1325. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  1326. <B>void waitFor(StatusRequest* aStatusRequest, unsigned long
  1327. aInterval = 0, long aIterations = 1)</B></P>
  1328. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  1329. <B>void waitForDelayed(StatusRequest* aStatusRequest, unsigned long
  1330. aInterval = 0, long aIterations = 1)</B></P>
  1331. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  1332. <BR>
  1333. </P>
  1334. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">If
  1335. compiled with support for Status Requests, these methods make task
  1336. wait for the completion of <B>aStatusRequest</B> event.
  1337. </P>
  1338. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">By
  1339. default <B>waitFor() </B>sets tasks interval to <B>0 (zero)</B> for
  1340. immediate execution when event happens, and also sets the number of
  1341. <B>iterations to 1</B>. However, you can specify different interval
  1342. and number of iterations.
  1343. </P>
  1344. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">By
  1345. default <B>waitForDelayed() </B>sets tasks interval to a supplied
  1346. value or (if omitted or zero) keeps the current interval, so delayed
  1347. execution will take place when the event happens. It also sets the
  1348. number of <B>iterations to 1</B> by default if not supplied.
  1349. </P>
  1350. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">When
  1351. Status Request object completes, all tasks waiting on it are executed
  1352. during next scheduling pass. Tasks waiting via <B>waitFor</B>()
  1353. method are executed immediately. Tasks waiting via <B>waitForDelayed</B>()
  1354. method are activated, but executed after current or supplied interval
  1355. delay.
  1356. </P>
  1357. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><B>Note:
  1358. aStatusRequest</B> should be “activated” by calling <B>setWaiting()
  1359. </B>method before making a task wait on it. Otherwise, the task will
  1360. execute immediately.
  1361. </P>
  1362. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">The
  1363. sequence of events to use Status Request object is as follows:</P>
  1364. <OL>
  1365. <LI><P CLASS="western" STYLE="margin-bottom: 0in">Create a status
  1366. request object</P>
  1367. <LI><P CLASS="western" STYLE="margin-bottom: 0in">Activate status
  1368. request object (calling its <B>setWaiting</B>() method)</P>
  1369. <LI><P CLASS="western" STYLE="margin-bottom: 0in">Set up tasks to
  1370. wait of the event completion</P>
  1371. <LI><P CLASS="western" STYLE="margin-bottom: 0in">Signal completion
  1372. of event(s)</P>
  1373. </OL>
  1374. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1375. </P>
  1376. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1377. </P>
  1378. <P CLASS="western" STYLE="margin-bottom: 0in"><B>StatusRequest*
  1379. getStatusRequest()</B></P>
  1380. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Returns
  1381. a StatusReqeust object this Task was waiting on.
  1382. </P>
  1383. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1384. </P>
  1385. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1386. </P>
  1387. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  1388. <B>TASK ID, CONTROL POINTS METHODS:</B></P>
  1389. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  1390. <BR>
  1391. </P>
  1392. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  1393. <B>void setId(unsigned int aID);</B></P>
  1394. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  1395. <BR>
  1396. </P>
  1397. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">If
  1398. compiled with support for Task IDs, this method will set the task ID
  1399. explicitly.
  1400. </P>
  1401. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Calling
  1402. this method is not necessary as task IDs are assigned automatically
  1403. during task creation: 1, 2, 3, …</P>
  1404. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1405. </P>
  1406. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  1407. <B>unsigned int getId();</B></P>
  1408. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  1409. <BR>
  1410. </P>
  1411. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">If
  1412. compiled with support for Task IDs, this method return current task’s
  1413. ID.</P>
  1414. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1415. </P>
  1416. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  1417. <B>void setControlPoint (unsigned int aPoint);</B></P>
  1418. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  1419. <BR>
  1420. </P>
  1421. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">If
  1422. compiled with support for Task IDs, this method will set a control
  1423. point in the task’s code. Control points are similar to “try…catch”
  1424. blocks, with control point ID specifying where in the code the “try”
  1425. part started, and a mechanism like watchdog timer providing the
  1426. “catch” functionality.</P>
  1427. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1428. </P>
  1429. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  1430. <B>unsigned int getControlPoint()</B></P>
  1431. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in; page-break-after: avoid">
  1432. <BR>
  1433. </P>
  1434. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in; page-break-after: avoid">
  1435. If compiled with support for Task IDs, this method will return
  1436. currently set control point for this task.</P>
  1437. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  1438. <BR>
  1439. </P>
  1440. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  1441. <BR>
  1442. </P>
  1443. <P CLASS="western" STYLE="margin-bottom: 0in"><B>LOCAL TASK STORAGE
  1444. METHODS:</B></P>
  1445. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  1446. <BR>
  1447. </P>
  1448. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  1449. <B>void setLtsPointer(void *aPtr);</B></P>
  1450. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  1451. <BR>
  1452. </P>
  1453. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">If
  1454. compiled with support for LTS, this method will set the task's local
  1455. storage pointer.</P>
  1456. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1457. </P>
  1458. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  1459. <B>void *getLtsPointer();</B></P>
  1460. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  1461. <BR>
  1462. </P>
  1463. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">If
  1464. compiled with support for LTS, this method will return reference to
  1465. the task's local storage.</P>
  1466. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><B>Note:
  1467. </B>the value returned has type (void *), and needs to be re-cast
  1468. into appropriate pointer type. Please refer to example sketches for
  1469. implementation options.
  1470. </P>
  1471. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1472. </P>
  1473. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1474. </P>
  1475. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  1476. <BR>
  1477. </P>
  1478. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-inside: avoid; page-break-after: avoid">
  1479. <FONT SIZE=4><B>TASK SCHEDULER:</B></FONT></P>
  1480. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-inside: avoid; page-break-after: avoid">
  1481. <BR>
  1482. </P>
  1483. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-inside: avoid; page-break-after: avoid">
  1484. <B>CREATION:</B></P>
  1485. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-inside: avoid; page-break-after: avoid">
  1486. <BR>
  1487. </P>
  1488. <P CLASS="western" STYLE="margin-bottom: 0in"><B>Scheduler()</B><BR><BR>
  1489. </P>
  1490. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Default
  1491. constructor.
  1492. </P>
  1493. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Takes
  1494. no parameters. Creates task scheduler with default parameters and an
  1495. empty task queue.
  1496. </P>
  1497. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1498. </P>
  1499. <P CLASS="western" STYLE="margin-bottom: 0in"><B>void init()</B></P>
  1500. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1501. </P>
  1502. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Initializes
  1503. the task queue and scheduler parameters, Executed as part of
  1504. constructor, so don't need to be explicitly called after creation.</P>
  1505. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><B>Note:
  1506. </B>be default (if compiled with <FONT FACE="Courier New, monospace">_TASK_TIMECRITICAL</FONT>
  1507. enabled) scheduler is allowed to put processor to IDLE sleep mode. If
  1508. this behavior was changed via <B>allowSleep()</B> method, <B>inti()
  1509. </B>will <B>NOT</B> reset allow sleep particular parameter.
  1510. </P>
  1511. <P CLASS="western" STYLE="margin-bottom: 0in"><BR><B>void
  1512. addTask(Task&amp; aTask)</B></P>
  1513. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1514. </P>
  1515. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Adds
  1516. task aTask to the execution queue (or chain) of tasks by appending it
  1517. to the end of the chain. If two tasks are scheduled for execution,
  1518. the sequence will match the order in which tasks were appended to the
  1519. chain. However, in reality, due to different timing of task
  1520. execution, the actual order may be different.
  1521. </P>
  1522. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><B>Note:
  1523. </B>Currently, changing the execution sequence in a chain dynamically
  1524. is not supported.
  1525. </P>
  1526. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">If
  1527. you need to reorder the chain sequence – initialize the scheduler
  1528. and re-add the tasks in a different order.
  1529. </P>
  1530. <P CLASS="western" STYLE="margin-bottom: 0in"><BR><B>void
  1531. deleteTask(Task&amp; aTask)</B></P>
  1532. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1533. </P>
  1534. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Deletes
  1535. task aTask from the execution chain. The chain of remaining tasks is
  1536. linked together (i.e</P>
  1537. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">if
  1538. original task chain is 1 → 2 → 3 → 4, deleting 3 will result in
  1539. 1 → 2 → 4).</P>
  1540. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><B>Note:
  1541. </B>it is not required to delete a task from the chain. A disabled
  1542. task will not be executed anyway, but you save a few microseconds per
  1543. scheduling pass by deleting it, since it is not even considered for
  1544. execution.
  1545. </P>
  1546. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">An
  1547. example of proper use of this method would be running some sort of
  1548. <B>initialize</B> task in the chain, and then deleting it from the
  1549. chain since it only needs to run once.
  1550. </P>
  1551. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1552. </P>
  1553. <P CLASS="western" STYLE="margin-bottom: 0in"><B>void allowSleep(bool
  1554. aState) </B>
  1555. </P>
  1556. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1557. </P>
  1558. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Available
  1559. in API only if compiled with <FONT FACE="Courier New, monospace">_TASK_TIMECRITICAL</FONT>
  1560. enabled. Controls whether scheduler is allowed (<B>aState =true</B>),
  1561. or not (<B>aState =false</B>) to put processor into IDLE sleep mode
  1562. in case not tasks are scheduled to run.</P>
  1563. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">The
  1564. <B>default</B> behavior of scheduler upon creation is to allow sleep
  1565. mode.
  1566. </P>
  1567. <P CLASS="western" STYLE="margin-bottom: 0in"><BR><B>void enableAll()</B></P>
  1568. <P CLASS="western" STYLE="margin-bottom: 0in"><B>void disableAll()</B></P>
  1569. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1570. </P>
  1571. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">enables
  1572. and disables (respectively) all tasks in the chain. Convenient if
  1573. your need to enable/disable majority of the tasks (i.e. disable all
  1574. and then enable one).
  1575. </P>
  1576. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  1577. <BR><B>Task&amp; currentTask()<BR></B><BR>
  1578. </P>
  1579. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Returns
  1580. reference to the task, currently executing via <B>execute()</B> loop
  1581. <B>OR </B>for OnEnable and OnDisable methods, reference to the task
  1582. being enabled or disabled.
  1583. </P>
  1584. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">This
  1585. distinction is important because one task can activate the other, and
  1586. OnEnable should be referring to the task being enabled, not being
  1587. executed.
  1588. </P>
  1589. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Could
  1590. be used by callback methods to identify which Task actually invoked
  1591. this callback method.</P>
  1592. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1593. </P>
  1594. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  1595. <B>void* currentLts()<BR></B><BR>
  1596. </P>
  1597. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Returns
  1598. pointer to Local Task Storage of the task, currently executing via
  1599. <B>execute()</B> loop <B>OR </B>for OnEnable and OnDisable methods,
  1600. task being enabled or disabled.
  1601. </P>
  1602. <P CLASS="western" STYLE="margin-bottom: 0in"><BR><B>void execute()</B></P>
  1603. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1604. </P>
  1605. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Executes
  1606. one scheduling pass, including end-of-pass sleep. This method is
  1607. typically placed inside the <B>loop()</B> method of the sketch. Since
  1608. <B>execute</B> exits after every pass, you can put additional
  1609. statements after <B>execute</B> inside the <B>loop().</B></P>
  1610. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Generally,
  1611. execute will perform the following steps:</P>
  1612. <OL>
  1613. <LI><P CLASS="western" STYLE="margin-bottom: 0in">Ignore task
  1614. completely if it is disabled.</P>
  1615. <LI><P CLASS="western" STYLE="margin-bottom: 0in">Disable task if it
  1616. ran out of iterations (calling OnDesable, if necessary).</P>
  1617. <LI><P CLASS="western" STYLE="margin-bottom: 0in">Check if task is
  1618. waiting on a StatusRequest object, and make appropriate scheduling
  1619. arrangements</P>
  1620. <LI><P CLASS="western" STYLE="margin-bottom: 0in">Perform necessary
  1621. timing calculations</P>
  1622. <LI><P CLASS="western" STYLE="margin-bottom: 0in">Invoke task's
  1623. callback method, if it is time to do so, and one is provided.
  1624. </P>
  1625. <LI><P CLASS="western" STYLE="margin-bottom: 0in">Put
  1626. microcontroller to sleep (if requested and supported) if none of the
  1627. tasks were invoked.
  1628. </P>
  1629. </OL>
  1630. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1631. </P>
  1632. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><B>Please
  1633. NOTE:</B> schedule-related calculations are performed prior to task's
  1634. callback method invocation. This allows tasks to manipulate their
  1635. runtime parameters (like execution interval) directly.</P>
  1636. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1637. </P>
  1638. <P CLASS="western" STYLE="margin-bottom: 0in"><B>bool isOverrun()</B></P>
  1639. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">If
  1640. library is compiled with <FONT FACE="Courier New, monospace">_TASK_TIMECRITICAL</FONT>
  1641. enabled, this method returns <B>true</B> if currently invoked task
  1642. has overrun its scheduled start time when it was invoked. Returns
  1643. <B>false</B> if task has been invoked according to schedule.</P>
  1644. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1645. </P>
  1646. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1647. </P>
  1648. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  1649. <B>STATUS REQUEST:</B></P>
  1650. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  1651. <BR>
  1652. </P>
  1653. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  1654. <B>CREATION:</B></P>
  1655. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  1656. <BR>
  1657. </P>
  1658. <P CLASS="western" STYLE="margin-bottom: 0in"><B>StatusRequest()</B><BR><BR>
  1659. </P>
  1660. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Default
  1661. constructor.
  1662. </P>
  1663. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Takes
  1664. no parameters. Creates Status Request object, which is assigned a
  1665. status of “completed” on creation.
  1666. </P>
  1667. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1668. </P>
  1669. <P CLASS="western" STYLE="margin-bottom: 0in"><B>void
  1670. setWaiting(unsigned int aCount = 1)</B></P>
  1671. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Activates
  1672. Status Request object. By default each object is set to wait on one
  1673. event only, however, if <B>aCount</B> is supplied, Status Request can
  1674. wait on multiple events. For instance, <B>setWaiting(3)</B> will wait
  1675. on three signals. An example could be waiting for completion of
  1676. measurements from 3 sensors.
  1677. </P>
  1678. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1679. </P>
  1680. <P CLASS="western" STYLE="margin-bottom: 0in"><B>bool signal(int
  1681. aStatus)</B></P>
  1682. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Signals
  1683. completion of the event to the Status Request object, and passes a
  1684. completion code, which could be interrogated later.
  1685. </P>
  1686. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><B>Note:
  1687. </B> passing a <B>negative</B> status code to the status request
  1688. object is considered reporting an error condition, and will complete
  1689. the status request regardless of how many outstanding signals it is
  1690. still waiting for.
  1691. </P>
  1692. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><B>Note</B>:
  1693. only the latest status code is kept.</P>
  1694. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1695. </P>
  1696. <P CLASS="western" STYLE="margin-bottom: 0in"><B>bool signalComplete
  1697. (int aStatus)</B></P>
  1698. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Signals
  1699. completion of <B>ALL</B> events to the Status Request object, and
  1700. passes a completion code, which could be interrogated later. The
  1701. status request completes regardless of how many events it is still
  1702. waiting on.
  1703. </P>
  1704. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1705. </P>
  1706. <P CLASS="western" STYLE="margin-bottom: 0in"><B>bool pending() </B>
  1707. </P>
  1708. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Returns
  1709. <B>true</B> if status request is still waiting for event or events to
  1710. happen.</P>
  1711. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1712. </P>
  1713. <P CLASS="western" STYLE="margin-bottom: 0in"><B>bool completed () </B>
  1714. </P>
  1715. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Returns
  1716. <B>true</B> if status has completed.</P>
  1717. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1718. </P>
  1719. <P CLASS="western" STYLE="margin-bottom: 0in"><B>int getStatus()</B></P>
  1720. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Returns
  1721. the status code passed to the status request object by the <B>signal()
  1722. </B>and <B>signalComplete() </B>methods.
  1723. </P>
  1724. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Any
  1725. <B>positive</B> number is considered a successful completion status.</P>
  1726. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">A
  1727. 0 (zero) is considered a default successful completion status.</P>
  1728. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">Any
  1729. <B>negative</B> number is considered an error code and unsuccessful
  1730. completion of a request.</P>
  1731. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1732. </P>
  1733. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1734. </P>
  1735. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1736. </P>
  1737. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-after: avoid">
  1738. <B>CONSTANTS:</B></P>
  1739. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1740. </P>
  1741. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in; page-break-after: avoid">
  1742. <B>TASK_SECOND (1000)</B></P>
  1743. <P CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in">Task
  1744. interval of 1 second</P>
  1745. <P CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in"><BR>
  1746. </P>
  1747. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in; page-break-after: avoid">
  1748. <B>TASK_MINUTE (60000)</B></P>
  1749. <P CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in">Task
  1750. interval of 1 minute</P>
  1751. <P CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in"><BR>
  1752. </P>
  1753. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in; page-break-after: avoid">
  1754. <B>TASK_HOUR (3600000)</B></P>
  1755. <P CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in">Task
  1756. interval of 1 hour</P>
  1757. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in; page-break-after: avoid">
  1758. <B>TASK_FOREVER (-1)</B></P>
  1759. <P CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in">Task
  1760. number of iterations for infinite number of iterations</P>
  1761. <P CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in"><BR>
  1762. </P>
  1763. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in; page-break-after: avoid">
  1764. <B>TASK_ONCE (1)</B></P>
  1765. <P CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in">Task
  1766. single iteration</P>
  1767. <P CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in"><BR>
  1768. </P>
  1769. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in; page-break-after: avoid">
  1770. <B>TASK_IMMEDIATE (0)</B></P>
  1771. <P CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in">Task
  1772. interval for immediate execution</P>
  1773. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1774. </P>
  1775. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1776. </P>
  1777. <P CLASS="western" STYLE="margin-bottom: 0in; page-break-before: always; page-break-after: avoid">
  1778. <B>IMPLEMENTATION SCENARIOS AND IDEAS:</B></P>
  1779. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1780. </P>
  1781. <OL>
  1782. <LI><P CLASS="western" STYLE="margin-bottom: 0in"><B>EVENT DRIVEN
  1783. PROGRAMMING</B></P>
  1784. </OL>
  1785. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1786. </P>
  1787. <P CLASS="western" STYLE="margin-bottom: 0in">Each of the processes
  1788. of your application becomes a separate and distinct programming area,
  1789. which may or may not interact and control each other.
  1790. </P>
  1791. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1792. </P>
  1793. <P CLASS="western" STYLE="margin-bottom: 0in">Example:
  1794. </P>
  1795. <P CLASS="western" STYLE="margin-bottom: 0in">In a plant watering
  1796. system you need to measure soil humidity, control pump and display
  1797. the results</P>
  1798. <P CLASS="western" STYLE="margin-bottom: 0in">Each of the areas
  1799. becomes a task:</P>
  1800. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1801. </P>
  1802. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>Task
  1803. <B>tMeasure</B> (TMEASURE_INTERVAL*SECOND, TASK_FOREVER,
  1804. &amp;measureCallback);<BR>Task <B>tWater</B>
  1805. (TWATER_INTERVAL*SECOND, RETRIES, &amp;waterCallback);<BR>Task
  1806. <B>tDisplay</B> (TDISPLAY_INTERVAL*SECOND, TASK_FOREVER,
  1807. &amp;displayCallback); <BR></FONT></FONT><BR>
  1808. </P>
  1809. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>Scheduler
  1810. </FONT></FONT><FONT FACE="Courier New, monospace"><FONT SIZE=2><B>taskManager</B></FONT></FONT><FONT FACE="Courier New, monospace"><FONT SIZE=2>;</FONT></FONT><BR><BR>
  1811. </P>
  1812. <P CLASS="western" STYLE="margin-bottom: 0in">Further, once you turn
  1813. on the pump, you keep it running for TWATER_INTERVAL interval and
  1814. then turn it off. Turning off a pump is also a task which only needs
  1815. to run once for every time the pump is turned on:</P>
  1816. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1817. </P>
  1818. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>Task
  1819. </FONT></FONT><FONT FACE="Courier New, monospace"><FONT SIZE=2><B>tWaterOff</B></FONT></FONT><FONT FACE="Courier New, monospace"><FONT SIZE=2>
  1820. (WATERTIME*SECOND, TASK_ONCE,</FONT></FONT><FONT FACE="Courier New, monospace">
  1821. &amp;waterOffCallback);</FONT><BR><BR>
  1822. </P>
  1823. <P CLASS="western" STYLE="margin-bottom: 0in">Example of the callback
  1824. method:</P>
  1825. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1826. </P>
  1827. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>void
  1828. waterOffCallback() {<BR> motorOff();<BR>
  1829. tWater.enableDelayed();<BR>}</FONT></FONT></P>
  1830. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1831. </P>
  1832. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>or</FONT></FONT></P>
  1833. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1834. </P>
  1835. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>void
  1836. waterCallback() {<BR> if (tWater.getIterations()) {</FONT></FONT></P>
  1837. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>//
  1838. If this is not the last iteration = turn the pump on<BR>
  1839. motorOn();<BR> tWaterOff.set(parameters.watertime * TASK_SECOND,
  1840. TASK_ONCE, &amp;waterOffCallback);<BR>
  1841. tWaterOff.enableDelayed();<BR> return;<BR> }</FONT></FONT></P>
  1842. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>//
  1843. We could not reach target humidity – something is wrong<BR>
  1844. motorOff;<BR> taskManager.disableAll();<BR> tError.enable();<BR>}</FONT></FONT></P>
  1845. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1846. </P>
  1847. <P CLASS="western" STYLE="margin-bottom: 0in"><FONT FACE="Times New Roman, serif">Your
  1848. sample <B>setup</B>() and <B>loop</B>() (partially) are as follows. </FONT>
  1849. </P>
  1850. <P CLASS="western" STYLE="margin-bottom: 0in"><FONT FACE="Times New Roman, serif"><B>Note:
  1851. </B>please note that tWater is <B>not</B> activated during setup().
  1852. It is activated by tMeasure callback once the watering conditions are
  1853. met. </FONT>
  1854. </P>
  1855. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1856. </P>
  1857. <P CLASS="western" STYLE="margin-bottom: 0in"><FONT SIZE=2><FONT FACE="Times New Roman, serif"> void
  1858. </FONT><FONT FACE="Courier New, monospace">setup()</FONT></FONT></P>
  1859. <P CLASS="western" STYLE="margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>
  1860. ...</FONT></FONT></P>
  1861. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  1862. <FONT SIZE=2><FONT FACE="Courier New, monospace">tWater.setIterations(parameters.retries);<BR>
  1863. tWaterOff.setInterval(parameters.watertime * SECOND);<BR><BR><BR>
  1864. taskManager.init();<BR> taskManager.addTask(tMeasure);<BR>
  1865. taskManager.addTask(tDisplay);<BR> taskManager.addTask(tWater);<BR>
  1866. taskManager.addTask(tWaterOff);<BR> <BR> tMeasure.enable();<BR>
  1867. tDisplay.enable();<BR><BR> currentHumidity =
  1868. measureHumidity();<BR>}<BR><BR><BR>void loop ()<BR>{<BR>
  1869. taskManager.execute();<BR>}</FONT><FONT FACE="Times New Roman, serif"><BR></FONT></FONT><BR>
  1870. </P>
  1871. <OL START=2>
  1872. <LI><P CLASS="western" STYLE="margin-bottom: 0in">“<FONT FACE="Times New Roman, serif"><B>NATIVE”
  1873. SUPPORT FOR FINITE STATE MACHINE</B></FONT></P>
  1874. </OL>
  1875. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1876. </P>
  1877. <P CLASS="western" STYLE="margin-bottom: 0in"><FONT FACE="Times New Roman, serif">Define
  1878. “states” as callback method or methods. Each callback method
  1879. executes activities specific to a “state” and then “transitions”
  1880. to the next state by assigning next callback method to the task. </FONT>
  1881. </P>
  1882. <P CLASS="western" STYLE="margin-bottom: 0in"><FONT FACE="Times New Roman, serif">Transition
  1883. from one state to the next is achieved by setting next callback
  1884. method at the end of preceding one. </FONT>
  1885. </P>
  1886. <P CLASS="western" STYLE="margin-bottom: 0in"><FONT FACE="Times New Roman, serif"><B>Note:
  1887. </B>do not call the next callback method explicitly. Yield to the
  1888. scheduler, and let the scheduler take care of next iteration during
  1889. the next pass. (Thus giving other tasks change to run their callback
  1890. methods). </FONT>
  1891. </P>
  1892. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1893. </P>
  1894. <P CLASS="western" STYLE="margin-bottom: 0in"><FONT FACE="Times New Roman, serif">Example:
  1895. Blinking LED 2 times a second could be achieved this way</FONT></P>
  1896. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1897. </P>
  1898. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>Scheduler
  1899. ts;</FONT></FONT></P>
  1900. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>Task
  1901. tLedBlinker (500, TASK_FOREVER, &amp;ledOnCallback, &amp;ts, true);</FONT></FONT></P>
  1902. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1903. </P>
  1904. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>void
  1905. ledOnCallback() {</FONT></FONT></P>
  1906. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2> turnLedOn();</FONT></FONT></P>
  1907. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2> tLedBlinker.setCallback(&amp;ledOffCallback);</FONT></FONT></P>
  1908. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>}</FONT></FONT></P>
  1909. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1910. </P>
  1911. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>void
  1912. ledOffCallback() {</FONT></FONT></P>
  1913. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2> turnLedOff();</FONT></FONT></P>
  1914. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2> tLedBlinker.setCallback(&amp;ledOnCallback);</FONT></FONT></P>
  1915. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>}</FONT></FONT></P>
  1916. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1917. </P>
  1918. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>setup()
  1919. {</FONT></FONT></P>
  1920. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>}</FONT></FONT></P>
  1921. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1922. </P>
  1923. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>loop
  1924. () {</FONT></FONT></P>
  1925. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2> ts.execute();</FONT></FONT></P>
  1926. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>}</FONT></FONT><FONT FACE="Times New Roman, serif"><BR></FONT><BR>
  1927. </P>
  1928. <P CLASS="western" STYLE="margin-bottom: 0in"><FONT FACE="Times New Roman, serif">Obviously
  1929. the example is simple, but gives the idea of how the tasks could be
  1930. used to go through states.</FONT></P>
  1931. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1932. </P>
  1933. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1934. </P>
  1935. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1936. </P>
  1937. <OL START=3>
  1938. <LI><P CLASS="western" STYLE="margin-bottom: 0in"><FONT FACE="Times New Roman, serif"><B>MULTIPLE
  1939. POSSIBLE CALLBACKS FOR TASK</B></FONT></P>
  1940. </OL>
  1941. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1942. </P>
  1943. <P CLASS="western" STYLE="margin-bottom: 0in"><FONT FACE="Times New Roman, serif">There
  1944. may be a need to select an option for callback method based on
  1945. certain criteria, or randomly. </FONT>
  1946. </P>
  1947. <P CLASS="western" STYLE="margin-bottom: 0in"><FONT FACE="Times New Roman, serif">You
  1948. can achieve that by defining an array of callback method pointers and
  1949. selecting one based on the criteria you need. </FONT>
  1950. </P>
  1951. <P CLASS="western" STYLE="margin-bottom: 0in"><FONT FACE="Times New Roman, serif">Example:
  1952. when a robot detects an obstacle, it may go left, right backwards,
  1953. etc. Each of the “directions” or “behaviors” are represented
  1954. by a different callback methods. </FONT>
  1955. </P>
  1956. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1957. </P>
  1958. <P CLASS="western" STYLE="margin-bottom: 0in"><FONT FACE="Times New Roman, serif">Another
  1959. example of using multiple callbacks:</FONT></P>
  1960. <P CLASS="western" STYLE="margin-bottom: 0in"><FONT FACE="Times New Roman, serif">You
  1961. may need to “initialize” variables for a particular task.</FONT></P>
  1962. <P CLASS="western" STYLE="margin-bottom: 0in"><FONT FACE="Times New Roman, serif">In
  1963. this case, define a tasks with two callbacks:</FONT></P>
  1964. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1965. </P>
  1966. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>Task
  1967. <B>tWork</B> (T_INTERVAL, TASK_FOREVER, &amp;workCallbackInit);</FONT></FONT></P>
  1968. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">…</P>
  1969. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1970. </P>
  1971. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>void
  1972. workCallbackInit() {</FONT></FONT></P>
  1973. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2> //
  1974. do your initializationstuff here</FONT></FONT></P>
  1975. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2> </FONT></FONT></P>
  1976. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2> //
  1977. finally assigne the main callback method </FONT></FONT>
  1978. </P>
  1979. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2> tWork.setCallback(&amp;workCallback);</FONT></FONT></P>
  1980. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>}</FONT></FONT></P>
  1981. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  1982. </P>
  1983. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>void
  1984. workCallback() {</FONT></FONT></P>
  1985. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2> //
  1986. main callback method</FONT></FONT></P>
  1987. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2> …</FONT></FONT></P>
  1988. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>}</FONT></FONT></P>
  1989. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1990. </P>
  1991. <P CLASS="western" STYLE="margin-bottom: 0in"><FONT FACE="Times New Roman, serif">The
  1992. task will initialize during first execution pass and switch to
  1993. “regular” callback execution starting with second pass. There is
  1994. a delay between first and second passes of the task (scheduling
  1995. period, if defined). In order to execute the second pass immediately
  1996. after initialization first pass, change the above code like this:</FONT></P>
  1997. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  1998. </P>
  1999. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>void
  2000. workCallbackInit() {</FONT></FONT></P>
  2001. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2> //
  2002. do your initializationstuff here</FONT></FONT></P>
  2003. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2> </FONT></FONT></P>
  2004. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2> //
  2005. finally assigne the main callback method </FONT></FONT>
  2006. </P>
  2007. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2> tWork.setCallback(&amp;workCallback);</FONT></FONT></P>
  2008. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2> tWork.enable();</FONT></FONT></P>
  2009. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>}</FONT></FONT></P>
  2010. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  2011. </P>
  2012. <P CLASS="western" STYLE="margin-bottom: 0in"><FONT FACE="Times New Roman, serif">The
  2013. task will run initialization first, then immediately second pass, and
  2014. then switch to processing at regular intervals starting with a third
  2015. pass. </FONT>
  2016. </P>
  2017. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  2018. </P>
  2019. <OL START=3>
  2020. <LI><P CLASS="western" STYLE="margin-bottom: 0in"><FONT FACE="Times New Roman, serif"><B>INTERRUP-DRIVEN
  2021. EXECUTION SUPPORT </B></FONT>
  2022. </P>
  2023. </OL>
  2024. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  2025. </P>
  2026. <P CLASS="western" STYLE="margin-bottom: 0in"><FONT FACE="Times New Roman, serif">In
  2027. case of interrupt-driven program flow, tasks could be scheduled to
  2028. run once to request asynchronous execution (request), and then
  2029. re-enabled (restarted) again with a different callback method to
  2030. process the results. </FONT>
  2031. </P>
  2032. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  2033. </P>
  2034. <P CLASS="western" STYLE="margin-bottom: 0in"><FONT FACE="Times New Roman, serif"><B>Example</B>:
  2035. event driven distance calculation for ultrasonic pulses. EchoPin #6
  2036. triggers pin change interrupts on rising and falling edges to
  2037. determine the length of ultrasonic pulse.</FONT></P>
  2038. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  2039. </P>
  2040. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>#include
  2041. &lt;DirectIO.h&gt;<BR>#include &lt;TaskScheduler.h&gt;<BR>#include
  2042. &lt;PinChangeInt.h&gt;<BR><BR><BR>#define TRIGGERPIN 5<BR>#define
  2043. ECHOPIN 6<BR><BR>Output&lt;TRIGGERPIN&gt;
  2044. pTrigger;<BR>Input&lt;ECHOPIN&gt; pEcho;<BR><BR>Scheduler
  2045. r;<BR><BR>Task tMeasure(TASK_SECOND, TASK_FOREVER, &amp;measureCallback,
  2046. &amp;r, true);<BR>Task tDisplay(TASK_SECOND, TASK_FOREVER,
  2047. &amp;displayCallback, &amp;r, true);<BR>Task tPing(TASK_IMMEDIATE,
  2048. TASK_ONCE, &amp;pingCalcCallback, &amp;r, false);<BR><BR><BR>volatile
  2049. bool pulseBusy = false;<BR>volatile bool pulseTimeout =
  2050. false;<BR>volatile unsigned long pulseStart = 0;<BR>volatile unsigned
  2051. long pulseStop = 0;<BR>volatile unsigned long pingDistance =
  2052. 0;<BR><BR><BR>void pingTrigger(unsigned long aTimeout) {<BR> if
  2053. (pulseBusy) return; // do not trigger if in the middle of a pulse<BR>
  2054. if (pEcho == HIGH) return; // do not trigger if ECHO pin is high<BR>
  2055. <BR> pulseBusy = true;<BR> pulseTimeout = false;</FONT></FONT></P>
  2056. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2><BR>
  2057. pTrigger = LOW;<BR> delayMicroseconds(4);<BR> pTrigger = HIGH;<BR><BR>
  2058. tPing.setInterval (aTimeout);<BR><BR> delayMicroseconds(10);<BR>
  2059. pTrigger = LOW; <BR></FONT></FONT><BR>
  2060. </P>
  2061. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2062. <FONT FACE="Courier New, monospace"><FONT SIZE=2>tPing.restartDelayed();
  2063. // timeout countdown starts now<BR></FONT></FONT><BR>
  2064. </P>
  2065. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>//
  2066. will start the pulse clock on the rising edge of ECHO pin</FONT></FONT></P>
  2067. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2068. <FONT FACE="Courier New, monospace"><FONT SIZE=2>PCintPort::attachInterrupt(ECHOPIN,
  2069. &amp;pingStartClock, RISING); <BR>}<BR><BR></FONT></FONT><BR>
  2070. </P>
  2071. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>//
  2072. Start clock on the <B>rising</B> edge of the ultrasonic pulse<BR>void
  2073. pingStartClock() {<BR> pulseStart = micros();<BR>
  2074. PCintPort::detachInterrupt(ECHOPIN); // not sure this is necessary<BR>
  2075. PCintPort::attachInterrupt(ECHOPIN, &amp;pingStopClock, FALLING); <BR>
  2076. tPing.restartDelayed();<BR>}<BR><BR>// Stop clock on the <B>falling</B>
  2077. edge of the ultrasonic pulse<BR>void pingStopClock() {<BR> pulseStop
  2078. = micros();<BR> PcintPort::detachInterrupt(ECHOPIN);</FONT></FONT></P>
  2079. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2080. <FONT FACE="Courier New, monospace"><FONT SIZE=2>pingDistance =
  2081. pulseStop - pulseStart;<BR> pulseBusy = false;<BR> tPing.disable();
  2082. // disable timeout<BR>}<BR></FONT></FONT><BR>
  2083. </P>
  2084. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>//
  2085. Stop clock because of the timeout – the wave did not return<BR>void
  2086. pingCalcCallback() {<BR> if (pulseBusy) {<BR> pingStopClock();<BR>
  2087. }<BR> pulseTimeout = true;<BR>}<BR><BR><BR><BR>// Initial measure
  2088. callback sets the trigger<BR>void measureCallback() {<BR> if
  2089. (pulseBusy) { // already measuring, try again<BR>
  2090. tMeasure.enable();<BR> return;<BR> }<BR> pingTrigger(30); // 30
  2091. milliseconds or max range of ~5.1 meters<BR>
  2092. tMeasure.setCallback(&amp;measureCallbackWait);<BR>}<BR></FONT></FONT><BR>
  2093. </P>
  2094. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>//
  2095. Wait for the measurement to <BR>void measureCallbackWait() {<BR> if
  2096. (pulseBusy) return;<BR> tMeasure.setCallback(&amp;measureCallback);
  2097. <BR>}<BR><BR><BR>bool state = true;<BR><BR>void displayCallback() {<BR>
  2098. char d[256];<BR> <BR> unsigned long cm = pingDistance * 17 / 100;
  2099. // cm<BR> <BR> snprintf(d, 256, &quot;pulseStart =
  2100. %8lu\tpulseStop=%8lu\tdistance, cm=%8lu&quot;, pulseStart, pulseStop,
  2101. cm);<BR> Serial.println(d);<BR> <BR>}<BR><BR>void setup() {<BR> //
  2102. put your setup code here, to run once:<BR> <BR>
  2103. Serial.begin(115200);<BR> <BR><BR> pTrigger = LOW;<BR> pEcho =
  2104. LOW;<BR> <BR>}<BR><BR>void loop() {<BR> // put your main code here,
  2105. to run repeatedly:<BR> r.execute();<BR>}<BR></FONT></FONT><BR>
  2106. </P>
  2107. <OL START=3>
  2108. <LI><P CLASS="western" STYLE="margin-bottom: 0in"><FONT FACE="Times New Roman, serif"><B>USING
  2109. ONENABLE AND ONDISBALE METHODS </B></FONT>
  2110. </P>
  2111. </OL>
  2112. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  2113. </P>
  2114. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Times New Roman, serif">Consider
  2115. a task to flash onboard LED for 5 seconds with random frequency. Task
  2116. should be repeated every 30 seconds indefinitely. Since frequency is
  2117. random, there are two challenges:</FONT></P>
  2118. <OL START=3>
  2119. <OL>
  2120. <LI><P CLASS="western" STYLE="margin-bottom: 0in"><FONT FACE="Times New Roman, serif">We
  2121. need to make sure LED is turned OFF at the last iteration</FONT></P>
  2122. <LI><P CLASS="western" STYLE="margin-bottom: 0in"><FONT FACE="Times New Roman, serif">We
  2123. need to calculate random frequency every time</FONT></P>
  2124. </OL>
  2125. </OL>
  2126. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2127. </P>
  2128. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Times New Roman, serif">Below
  2129. is the implementation using TaskScheduler </FONT>
  2130. </P>
  2131. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2132. </P>
  2133. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2><BR></FONT></FONT><BR>
  2134. </P>
  2135. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>#define
  2136. _TASK_SLEEP_ON_IDLE_RUN</FONT></FONT></P>
  2137. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>#include
  2138. &lt;TaskScheduler.h&gt;</FONT></FONT></P>
  2139. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2140. </P>
  2141. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>#define
  2142. LEDPIN 13</FONT></FONT></P>
  2143. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2144. </P>
  2145. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2146. </P>
  2147. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>Scheduler
  2148. ts;</FONT></FONT></P>
  2149. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2150. </P>
  2151. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>Task
  2152. tWrapper(30000, TASK_FOREVER, &amp;WrapperCallback, &amp;ts, true);</FONT></FONT></P>
  2153. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>Task
  2154. tBlink(5000, TASK_ONCE, NULL, &amp;ts, false, &amp;BlinkOnEnable,
  2155. &amp;BlinkOnDisable);</FONT></FONT></P>
  2156. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>Task
  2157. tLED(TASK_IMMEDIATE, TASK_FOREVER, NULL, &amp;ts, false, NULL,
  2158. &amp;LEDOff);</FONT></FONT></P>
  2159. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2160. </P>
  2161. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>void
  2162. WrapperCallback() {</FONT></FONT></P>
  2163. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2164. <FONT FACE="Courier New, monospace"><FONT SIZE=2>Serial.println(&quot;In
  2165. WrapperCallback&quot;);</FONT></FONT></P>
  2166. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2167. <FONT FACE="Courier New, monospace"><FONT SIZE=2>tBlink.restartDelayed();
  2168. // LED blinking is initiated </FONT></FONT>
  2169. </P>
  2170. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2171. <FONT FACE="Courier New, monospace"><FONT SIZE=2>//every
  2172. 30 seconds for 5 seconds</FONT></FONT></P>
  2173. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>}</FONT></FONT></P>
  2174. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2175. </P>
  2176. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2177. </P>
  2178. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>//
  2179. Upon being enabled, tBlink will define the parameters</FONT></FONT></P>
  2180. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>//
  2181. and enable LED blinking task, which actually controls</FONT></FONT></P>
  2182. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>//
  2183. the hardware (LED in this example)</FONT></FONT></P>
  2184. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>bool
  2185. BlinkOnEnable() {</FONT></FONT></P>
  2186. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2187. <FONT FACE="Courier New, monospace"><FONT SIZE=2>Serial.println(&quot;In
  2188. BlinkOnEnable&quot;);</FONT></FONT></P>
  2189. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2190. <FONT FACE="Courier New, monospace"><FONT SIZE=2>tLED.setInterval(
  2191. 500 + random(501) );</FONT></FONT></P>
  2192. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2193. <FONT FACE="Courier New, monospace"><FONT SIZE=2>tLED.setCallback(
  2194. &amp;LEDOn);</FONT></FONT></P>
  2195. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2196. <FONT FACE="Courier New, monospace"><FONT SIZE=2>tLED.enable();</FONT></FONT></P>
  2197. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2198. </P>
  2199. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2200. <FONT FACE="Courier New, monospace"><FONT SIZE=2>return true; //
  2201. Task should be enabled</FONT></FONT></P>
  2202. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>}</FONT></FONT></P>
  2203. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2204. </P>
  2205. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>//
  2206. tBlink does not really need a callback method</FONT></FONT></P>
  2207. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>//
  2208. since it just waits for 5 seconds for the first </FONT></FONT>
  2209. </P>
  2210. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>//
  2211. and only iteration to occur. Once the iteration</FONT></FONT></P>
  2212. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>//
  2213. takes place, tBlink is disabled by the Scheduler, </FONT></FONT>
  2214. </P>
  2215. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>//
  2216. thus executing its OnDisable method below.</FONT></FONT></P>
  2217. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2218. </P>
  2219. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>void
  2220. BlinkOnDisable() {</FONT></FONT></P>
  2221. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2222. <FONT FACE="Courier New, monospace"><FONT SIZE=2>Serial.println(&quot;In
  2223. BlinkOnDisable&quot;);</FONT></FONT></P>
  2224. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2225. <FONT FACE="Courier New, monospace"><FONT SIZE=2>tLED.disable();</FONT></FONT></P>
  2226. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>}</FONT></FONT></P>
  2227. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2228. </P>
  2229. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>void
  2230. LEDOn () {</FONT></FONT></P>
  2231. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2232. <FONT FACE="Courier New, monospace"><FONT SIZE=2>Serial.println(&quot;In
  2233. LEDOn&quot;);</FONT></FONT></P>
  2234. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2235. <FONT FACE="Courier New, monospace"><FONT SIZE=2>digitalWrite(LEDPIN,
  2236. HIGH);</FONT></FONT></P>
  2237. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2238. <FONT FACE="Courier New, monospace"><FONT SIZE=2>tLED.setCallback(
  2239. &amp;LEDOff);</FONT></FONT></P>
  2240. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>}</FONT></FONT></P>
  2241. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2242. </P>
  2243. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>void
  2244. LEDOff () {</FONT></FONT></P>
  2245. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2246. <FONT FACE="Courier New, monospace"><FONT SIZE=2>Serial.println(&quot;In
  2247. LEDOff&quot;);</FONT></FONT></P>
  2248. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2249. <FONT FACE="Courier New, monospace"><FONT SIZE=2>digitalWrite(LEDPIN,
  2250. LOW);</FONT></FONT></P>
  2251. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2252. <FONT FACE="Courier New, monospace"><FONT SIZE=2>tLED.setCallback(
  2253. &amp;LEDOn);</FONT></FONT></P>
  2254. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>}</FONT></FONT></P>
  2255. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2256. </P>
  2257. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>//
  2258. Note that LEDOff method serves as OnDisable method</FONT></FONT></P>
  2259. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>//
  2260. to make sure the LED is turned off when the tBlink</FONT></FONT></P>
  2261. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>//
  2262. task finishes (or disabled ahead of time)</FONT></FONT></P>
  2263. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2264. </P>
  2265. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>void
  2266. setup() {</FONT></FONT></P>
  2267. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2268. </P>
  2269. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2270. <FONT FACE="Courier New, monospace"><FONT SIZE=2>Serial.begin(115200);
  2271. </FONT></FONT>
  2272. </P>
  2273. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2274. <FONT FACE="Courier New, monospace"><FONT SIZE=2>pinMode(LEDPIN,
  2275. OUTPUT); </FONT></FONT>
  2276. </P>
  2277. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>}</FONT></FONT></P>
  2278. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2279. </P>
  2280. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>void
  2281. loop() {</FONT></FONT></P>
  2282. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2283. <FONT FACE="Courier New, monospace"><FONT SIZE=2>// put your main
  2284. code here, to run repeatedly:</FONT></FONT></P>
  2285. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2286. </P>
  2287. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2288. <FONT FACE="Courier New, monospace"><FONT SIZE=2>ts.execute();</FONT></FONT></P>
  2289. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>}</FONT></FONT></P>
  2290. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2291. </P>
  2292. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2293. </P>
  2294. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2295. </P>
  2296. <OL START=3>
  2297. <LI><P CLASS="western" STYLE="margin-bottom: 0in"><FONT FACE="Times New Roman, serif"><B>USING
  2298. STATUS REQUEST OBJECTS </B></FONT>
  2299. </P>
  2300. </OL>
  2301. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2302. </P>
  2303. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Times New Roman, serif"><FONT SIZE=2 STYLE="font-size: 11pt">This
  2304. test emulates querying 3 sensors once every 10 seconds, each could
  2305. respond with a different delay (ultrasonic sensors for instance) and
  2306. printing a min value of the three when all three have reported their
  2307. values.</FONT></FONT></P>
  2308. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2309. </P>
  2310. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Times New Roman, serif"><FONT SIZE=2 STYLE="font-size: 11pt">The
  2311. overall timeout of 1 second is setup as well.</FONT></FONT></P>
  2312. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Times New Roman, serif"><FONT SIZE=2 STYLE="font-size: 11pt">An
  2313. error message needs to be printed if a timeout occurred instead of a
  2314. value.</FONT></FONT></P>
  2315. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2316. </P>
  2317. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2318. </P>
  2319. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>#define
  2320. _TASK_SLEEP_ON_IDLE_RUN</FONT></FONT></P>
  2321. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>#define
  2322. _TASK_STATUS_REQUEST</FONT></FONT></P>
  2323. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2324. </P>
  2325. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>#include
  2326. &lt;TaskScheduler.h&gt;</FONT></FONT></P>
  2327. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2328. </P>
  2329. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>StatusRequest
  2330. measure;</FONT></FONT></P>
  2331. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2332. </P>
  2333. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>Scheduler
  2334. ts; </FONT></FONT>
  2335. </P>
  2336. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2337. </P>
  2338. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>Task
  2339. tCycle(10000, TASK_FOREVER, &amp;CycleCallback, &amp;ts, true);</FONT></FONT></P>
  2340. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>Task
  2341. tMeasure(TASK_SECOND, TASK_ONCE, &amp;MeasureCallback, &amp;ts,
  2342. false, &amp;MeasureEnable, &amp;MeasureDisable);</FONT></FONT></P>
  2343. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>Task
  2344. tCalculate(&amp;CalcCallback, &amp;ts);</FONT></FONT></P>
  2345. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>Task
  2346. tSensor1(TASK_IMMEDIATE, TASK_ONCE, &amp;S1Callback, &amp;ts, false,
  2347. &amp;S1Enable);</FONT></FONT></P>
  2348. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>Task
  2349. tSensor2(TASK_IMMEDIATE, TASK_ONCE, &amp;S2Callback, &amp;ts, false,
  2350. &amp;S2Enable);</FONT></FONT></P>
  2351. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>Task
  2352. tSensor3(TASK_IMMEDIATE, TASK_ONCE, &amp;S3Callback, &amp;ts, false,
  2353. &amp;S3Enable);</FONT></FONT></P>
  2354. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2355. </P>
  2356. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2357. </P>
  2358. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>long
  2359. distance, d1, d2, d3;</FONT></FONT></P>
  2360. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2361. </P>
  2362. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>void
  2363. CycleCallback() {</FONT></FONT></P>
  2364. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2365. <FONT FACE="Courier New, monospace"><FONT SIZE=2>Serial.println(&quot;CycleCallback:
  2366. Initiating measurement cycle every 10 seconds&quot;);</FONT></FONT></P>
  2367. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2368. </P>
  2369. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2370. <FONT FACE="Courier New, monospace"><FONT SIZE=2>tMeasure.restartDelayed();</FONT></FONT></P>
  2371. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>}</FONT></FONT></P>
  2372. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2373. </P>
  2374. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2375. </P>
  2376. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2377. </P>
  2378. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>bool
  2379. MeasureEnable() {</FONT></FONT></P>
  2380. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2381. <FONT FACE="Courier New, monospace"><FONT SIZE=2>Serial.println(&quot;MeasureEnable:
  2382. Activating sensors&quot;); </FONT></FONT>
  2383. </P>
  2384. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2385. </P>
  2386. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2387. <FONT FACE="Courier New, monospace"><FONT SIZE=2>distance = 0;</FONT></FONT></P>
  2388. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2389. <FONT FACE="Courier New, monospace"><FONT SIZE=2>measure.setWaiting(3);
  2390. // Set the StatusRequest to wait for 3 signals. </FONT></FONT>
  2391. </P>
  2392. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2393. <FONT FACE="Courier New, monospace"><FONT SIZE=2>tCalculate.waitFor(&amp;measure);</FONT></FONT></P>
  2394. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2395. </P>
  2396. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2397. <FONT FACE="Courier New, monospace"><FONT SIZE=2>tSensor1.restart();</FONT></FONT></P>
  2398. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2399. <FONT FACE="Courier New, monospace"><FONT SIZE=2>tSensor2.restart();</FONT></FONT></P>
  2400. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2401. <FONT FACE="Courier New, monospace"><FONT SIZE=2>tSensor3.restart();</FONT></FONT></P>
  2402. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2403. </P>
  2404. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2405. <FONT FACE="Courier New, monospace"><FONT SIZE=2>return true;</FONT></FONT></P>
  2406. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>}</FONT></FONT></P>
  2407. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2408. </P>
  2409. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>void
  2410. MeasureCallback() {</FONT></FONT></P>
  2411. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2412. <FONT FACE="Courier New, monospace"><FONT SIZE=2>Serial.println(&quot;MeasureCallback:
  2413. Invoked by calculate task or one second later&quot;); </FONT></FONT>
  2414. </P>
  2415. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2416. </P>
  2417. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2418. <FONT FACE="Courier New, monospace"><FONT SIZE=2>if
  2419. (measure.pending()) {</FONT></FONT></P>
  2420. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2421. <FONT FACE="Courier New, monospace"><FONT SIZE=2>tCalculate.disable();</FONT></FONT></P>
  2422. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2423. <FONT FACE="Courier New, monospace"><FONT SIZE=2>measure.signalComplete(-1);
  2424. // signal error</FONT></FONT></P>
  2425. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2426. <FONT FACE="Courier New, monospace"><FONT SIZE=2>Serial.println(&quot;MeasureCallback:
  2427. Timeout!&quot;);</FONT></FONT></P>
  2428. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2429. <FONT FACE="Courier New, monospace"><FONT SIZE=2>}</FONT></FONT></P>
  2430. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2431. <FONT FACE="Courier New, monospace"><FONT SIZE=2>else {</FONT></FONT></P>
  2432. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2433. <FONT FACE="Courier New, monospace"><FONT SIZE=2>Serial.print(&quot;MeasureCallback:
  2434. Min distance=&quot;);Serial.println(distance);</FONT></FONT></P>
  2435. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2436. <FONT FACE="Courier New, monospace"><FONT SIZE=2>}</FONT></FONT></P>
  2437. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>}</FONT></FONT></P>
  2438. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2439. </P>
  2440. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>void
  2441. MeasureDisable() {</FONT></FONT></P>
  2442. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2443. <FONT FACE="Courier New, monospace"><FONT SIZE=2>Serial.println(&quot;MeasureDisable:
  2444. Cleaning up&quot;); </FONT></FONT>
  2445. </P>
  2446. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2447. </P>
  2448. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2449. <FONT FACE="Courier New, monospace"><FONT SIZE=2>tSensor1.disable();</FONT></FONT></P>
  2450. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2451. <FONT FACE="Courier New, monospace"><FONT SIZE=2>tSensor2.disable();</FONT></FONT></P>
  2452. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2453. <FONT FACE="Courier New, monospace"><FONT SIZE=2>tSensor3.disable();</FONT></FONT></P>
  2454. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>}</FONT></FONT></P>
  2455. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2456. </P>
  2457. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2458. </P>
  2459. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>void
  2460. CalcCallback() {</FONT></FONT></P>
  2461. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2462. <FONT FACE="Courier New, monospace"><FONT SIZE=2>Serial.println(&quot;CalcCallback:
  2463. calculating&quot;); </FONT></FONT>
  2464. </P>
  2465. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2466. <FONT FACE="Courier New, monospace"><FONT SIZE=2>distance = -1;</FONT></FONT></P>
  2467. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2468. <FONT FACE="Courier New, monospace"><FONT SIZE=2>if (
  2469. measure.getStatus() &gt;= 0) { // only calculate if statusrequest
  2470. ended successfully</FONT></FONT></P>
  2471. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2472. <FONT FACE="Courier New, monospace"><FONT SIZE=2>distance = d1 &lt;
  2473. d2 ? d1 : d2;</FONT></FONT></P>
  2474. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2475. <FONT FACE="Courier New, monospace"><FONT SIZE=2>distance = d3 &lt;
  2476. distance ? d3 : distance;</FONT></FONT></P>
  2477. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2478. <FONT FACE="Courier New, monospace"><FONT SIZE=2>tMeasure.forceNextIteration();</FONT></FONT></P>
  2479. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2480. <FONT FACE="Courier New, monospace"><FONT SIZE=2>}</FONT></FONT></P>
  2481. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>}</FONT></FONT></P>
  2482. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2483. </P>
  2484. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2485. </P>
  2486. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>/**
  2487. Simulation code for sensor 1</FONT></FONT></P>
  2488. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"> <FONT FACE="Courier New, monospace"><FONT SIZE=2>*
  2489. ----------------------------</FONT></FONT></P>
  2490. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2491. <FONT FACE="Courier New, monospace"><FONT SIZE=2>*/</FONT></FONT></P>
  2492. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>bool
  2493. S1Enable() {</FONT></FONT></P>
  2494. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2495. <FONT FACE="Courier New, monospace"><FONT SIZE=2>Serial.print(&quot;S1Enable:
  2496. Triggering sensor1. Delay=&quot;); </FONT></FONT>
  2497. </P>
  2498. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2499. </P>
  2500. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2501. <FONT FACE="Courier New, monospace"><FONT SIZE=2>tSensor1.setInterval(
  2502. random(1200) ); // Simulating sensor delay, which could go over 1
  2503. second and cause timeout</FONT></FONT></P>
  2504. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2505. <FONT FACE="Courier New, monospace"><FONT SIZE=2>d1 = 0;</FONT></FONT></P>
  2506. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2507. </P>
  2508. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2509. <FONT FACE="Courier New, monospace"><FONT SIZE=2>Serial.println(
  2510. tSensor1.getInterval() );</FONT></FONT></P>
  2511. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2512. <FONT FACE="Courier New, monospace"><FONT SIZE=2>return true;</FONT></FONT></P>
  2513. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>}</FONT></FONT></P>
  2514. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2515. </P>
  2516. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>void
  2517. S1Callback() {</FONT></FONT></P>
  2518. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2519. <FONT FACE="Courier New, monospace"><FONT SIZE=2>Serial.print(&quot;S1Callback:
  2520. Emulating measurement. d1=&quot;); </FONT></FONT>
  2521. </P>
  2522. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2523. <FONT FACE="Courier New, monospace"><FONT SIZE=2>d1 = random(501); //
  2524. pick a value from 0 to 500 &quot;centimeters&quot; simulating a
  2525. measurement </FONT></FONT>
  2526. </P>
  2527. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2528. <FONT FACE="Courier New, monospace"><FONT SIZE=2>measure.signal();</FONT></FONT></P>
  2529. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2530. </P>
  2531. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2532. <FONT FACE="Courier New, monospace"><FONT SIZE=2>Serial.println(d1); </FONT></FONT>
  2533. </P>
  2534. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>}</FONT></FONT></P>
  2535. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2536. </P>
  2537. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2538. </P>
  2539. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>/**
  2540. Simulation code for sensor 2</FONT></FONT></P>
  2541. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"> <FONT FACE="Courier New, monospace"><FONT SIZE=2>*
  2542. ----------------------------</FONT></FONT></P>
  2543. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2544. <FONT FACE="Courier New, monospace"><FONT SIZE=2>*/</FONT></FONT></P>
  2545. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>bool
  2546. S2Enable() {</FONT></FONT></P>
  2547. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2548. <FONT FACE="Courier New, monospace"><FONT SIZE=2>Serial.print(&quot;S2Enable:
  2549. Triggering sensor2. Delay=&quot;); </FONT></FONT>
  2550. </P>
  2551. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2552. </P>
  2553. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2554. <FONT FACE="Courier New, monospace"><FONT SIZE=2>tSensor2.setInterval(
  2555. random(1200) ); // Simulating sensor delay, which could go over 1
  2556. second and cause timeout</FONT></FONT></P>
  2557. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2558. <FONT FACE="Courier New, monospace"><FONT SIZE=2>d2 = 0;</FONT></FONT></P>
  2559. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2560. </P>
  2561. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2562. <FONT FACE="Courier New, monospace"><FONT SIZE=2>Serial.println(
  2563. tSensor2.getInterval() );</FONT></FONT></P>
  2564. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2565. <FONT FACE="Courier New, monospace"><FONT SIZE=2>return true;</FONT></FONT></P>
  2566. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>}</FONT></FONT></P>
  2567. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2568. </P>
  2569. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>void
  2570. S2Callback() {</FONT></FONT></P>
  2571. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2572. <FONT FACE="Courier New, monospace"><FONT SIZE=2>Serial.print(&quot;S2Callback:
  2573. Emulating measurement. d2=&quot;); </FONT></FONT>
  2574. </P>
  2575. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2576. <FONT FACE="Courier New, monospace"><FONT SIZE=2>d2 = random(501); //
  2577. pick a value from 0 to 500 &quot;centimeters&quot; simulating a
  2578. measurement</FONT></FONT></P>
  2579. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2580. <FONT FACE="Courier New, monospace"><FONT SIZE=2>measure.signal();</FONT></FONT></P>
  2581. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2582. </P>
  2583. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2584. <FONT FACE="Courier New, monospace"><FONT SIZE=2>Serial.println(d2);
  2585. </FONT></FONT>
  2586. </P>
  2587. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>}</FONT></FONT></P>
  2588. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2589. </P>
  2590. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2591. </P>
  2592. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>/**
  2593. Simulation code for sensor 3</FONT></FONT></P>
  2594. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"> <FONT FACE="Courier New, monospace"><FONT SIZE=2>*
  2595. ----------------------------</FONT></FONT></P>
  2596. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2597. <FONT FACE="Courier New, monospace"><FONT SIZE=2>*/</FONT></FONT></P>
  2598. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>bool
  2599. S3Enable() {</FONT></FONT></P>
  2600. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2601. <FONT FACE="Courier New, monospace"><FONT SIZE=2>Serial.print(&quot;S3Enable:
  2602. Triggering sensor3. Delay=&quot;); </FONT></FONT>
  2603. </P>
  2604. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2605. </P>
  2606. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2607. <FONT FACE="Courier New, monospace"><FONT SIZE=2>tSensor3.setInterval(
  2608. random(1200) ); // Simulating sensor delay, which could go over 1
  2609. second and cause timeout</FONT></FONT></P>
  2610. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2611. <FONT FACE="Courier New, monospace"><FONT SIZE=2>d3 = 0;</FONT></FONT></P>
  2612. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2613. </P>
  2614. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2615. <FONT FACE="Courier New, monospace"><FONT SIZE=2>Serial.println(
  2616. tSensor3.getInterval() );</FONT></FONT></P>
  2617. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2618. <FONT FACE="Courier New, monospace"><FONT SIZE=2>return true;</FONT></FONT></P>
  2619. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>}</FONT></FONT></P>
  2620. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2621. </P>
  2622. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>void
  2623. S3Callback() {</FONT></FONT></P>
  2624. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2625. <FONT FACE="Courier New, monospace"><FONT SIZE=2>Serial.print(&quot;S3Callback:
  2626. Emulating measurement. d3=&quot;); </FONT></FONT>
  2627. </P>
  2628. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2629. <FONT FACE="Courier New, monospace"><FONT SIZE=2>d3 = random(501); //
  2630. pick a value from 0 to 500 &quot;centimeters&quot; simulating a
  2631. measurement</FONT></FONT></P>
  2632. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2633. <FONT FACE="Courier New, monospace"><FONT SIZE=2>measure.signal();</FONT></FONT></P>
  2634. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2635. </P>
  2636. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2637. <FONT FACE="Courier New, monospace"><FONT SIZE=2>Serial.println(d3); </FONT></FONT>
  2638. </P>
  2639. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>}</FONT></FONT></P>
  2640. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2641. </P>
  2642. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2643. </P>
  2644. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>/**
  2645. Main Arduino code</FONT></FONT></P>
  2646. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"> <FONT FACE="Courier New, monospace"><FONT SIZE=2>*
  2647. Not much is left here - everything is taken care of by the framework</FONT></FONT></P>
  2648. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2649. <FONT FACE="Courier New, monospace"><FONT SIZE=2>*/</FONT></FONT></P>
  2650. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>void
  2651. setup() {</FONT></FONT></P>
  2652. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2653. </P>
  2654. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2655. <FONT FACE="Courier New, monospace"><FONT SIZE=2>Serial.begin(115200);</FONT></FONT></P>
  2656. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2657. <FONT FACE="Courier New, monospace"><FONT SIZE=2>Serial.println(&quot;TaskScheduler
  2658. StatusRequest Sensor Emulation Test. Complex Test.&quot;); </FONT></FONT>
  2659. </P>
  2660. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2661. <FONT FACE="Courier New, monospace"><FONT SIZE=2>randomSeed(analogRead(A1)+millis());</FONT></FONT></P>
  2662. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>}</FONT></FONT></P>
  2663. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2664. </P>
  2665. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>void
  2666. loop() {</FONT></FONT></P>
  2667. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in">
  2668. <FONT FACE="Courier New, monospace"><FONT SIZE=2>ts.execute();</FONT></FONT></P>
  2669. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>}</FONT></FONT></P>
  2670. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2671. </P>
  2672. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2673. </P>
  2674. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2675. </P>
  2676. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2677. </P>
  2678. <OL START=3>
  2679. <LI><P CLASS="western" STYLE="margin-bottom: 0in"><FONT FACE="Times New Roman, serif"><B>USING
  2680. LOCAL TASK STORAGE POINTER </B></FONT>
  2681. </P>
  2682. </OL>
  2683. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2684. </P>
  2685. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Times New Roman, serif"><FONT SIZE=2 STYLE="font-size: 11pt">Tasks
  2686. can store a pointer to specific variable, structure or array, which
  2687. represents variables specific for a particular task. This may be
  2688. needed if you plan to use same callback method for multiple tasks.</FONT></FONT></P>
  2689. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Times New Roman, serif"><FONT SIZE=2 STYLE="font-size: 11pt">Consider
  2690. a scenario where you have several sensors of the same type. The
  2691. actual process of triggering measurement and collecting information
  2692. is identical. The only difference is the sensor address and a
  2693. variable for storing the results. </FONT></FONT>
  2694. </P>
  2695. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Times New Roman, serif"><FONT SIZE=2 STYLE="font-size: 11pt">In
  2696. this case each of the tasks, which performs measurement will utilize
  2697. the same callback methods. The only difference will be the variables
  2698. (specific for each of the sensor). </FONT></FONT>
  2699. </P>
  2700. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2701. </P>
  2702. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Times New Roman, serif"><FONT SIZE=2 STYLE="font-size: 11pt">Let's
  2703. define a sensor data structure and declare a couple of variables (for
  2704. 2 sensors for instance)</FONT></FONT></P>
  2705. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2706. </P>
  2707. <P LANG="" CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in">
  2708. <FONT FACE="Courier New, monospace"><FONT SIZE=2>typedef struct {</FONT></FONT></P>
  2709. <P LANG="" CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in">
  2710. <FONT FACE="Courier New, monospace"><FONT SIZE=2> unsigned int
  2711. address;</FONT></FONT></P>
  2712. <P LANG="" CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in">
  2713. <FONT FACE="Courier New, monospace"><FONT SIZE=2> unsigned
  2714. long distance;</FONT></FONT></P>
  2715. <P LANG="" CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in">
  2716. <FONT FACE="Courier New, monospace"><FONT SIZE=2>} sensor_data;</FONT></FONT></P>
  2717. <P LANG="" CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in">
  2718. <BR>
  2719. </P>
  2720. <P LANG="" CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in">
  2721. <FONT FACE="Courier New, monospace"><FONT SIZE=2>sensor_data s1, s2; </FONT></FONT>
  2722. </P>
  2723. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2724. </P>
  2725. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Times New Roman, serif"><FONT SIZE=2 STYLE="font-size: 11pt">Two
  2726. separate tasks are running to collect sensor data.</FONT></FONT></P>
  2727. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Times New Roman, serif"><FONT SIZE=2 STYLE="font-size: 11pt">(Note
  2728. that both tasks refer to the same callback methods)</FONT></FONT></P>
  2729. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2730. </P>
  2731. <P LANG="" CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in">
  2732. <FONT FACE="Courier New, monospace"><FONT SIZE=2>Scheduler ts;</FONT></FONT></P>
  2733. <P CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2><SPAN LANG="">Task
  2734. t1(100, </SPAN>TASK_FOREVER<SPAN LANG="">, &amp;Measure, &amp;ts,
  2735. false, &amp;MeasureOn); </SPAN></FONT></FONT>
  2736. </P>
  2737. <P CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2><SPAN LANG="">Task
  2738. t2(100, </SPAN>TASK_FOREVER<SPAN LANG="">, &amp;Measure, &amp;ts,
  2739. false, &amp;MeasureOn); </SPAN></FONT></FONT>
  2740. </P>
  2741. <P CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in"><BR>
  2742. </P>
  2743. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Times New Roman, serif"><FONT SIZE=2 STYLE="font-size: 11pt">Assign
  2744. pointers to the respective variables in the <B>setup</B>() method:</FONT></FONT></P>
  2745. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2746. </P>
  2747. <P CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>void
  2748. setup() {</FONT></FONT></P>
  2749. <P CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in"><BR>
  2750. </P>
  2751. <P CLASS="western" STYLE="margin-left: 1.48in; margin-bottom: 0in">…</P>
  2752. <P CLASS="western" STYLE="margin-left: 1.48in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>t1.setLtsPointer(&amp;s1);</FONT></FONT></P>
  2753. <P CLASS="western" STYLE="margin-left: 1.48in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>t2.setLtsPointer(&amp;s2);</FONT></FONT></P>
  2754. <P CLASS="western" STYLE="margin-left: 1.48in; margin-bottom: 0in">…</P>
  2755. <P CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in"><BR>
  2756. </P>
  2757. <P CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>}</FONT></FONT></P>
  2758. <P CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in"><BR>
  2759. </P>
  2760. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Times New Roman, serif"><FONT SIZE=2 STYLE="font-size: 11pt">Obtain
  2761. reference to specific <B>sensor_data</B> structure inside the common
  2762. callback method:</FONT></FONT></P>
  2763. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2764. </P>
  2765. <P CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>void
  2766. Measure() {</FONT></FONT></P>
  2767. <P CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2> Task&amp;
  2768. T = ts.currentTask(); </FONT></FONT>
  2769. </P>
  2770. <P CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2> Sensor_data&amp;
  2771. V = *((sensor_data*) T.getLtsPointer());</FONT></FONT></P>
  2772. <P CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>//
  2773. For t1, V will be pointing at s1</FONT></FONT></P>
  2774. <P CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>//
  2775. For t2, V will be pointing at s2</FONT></FONT></P>
  2776. <P CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in"><BR>
  2777. </P>
  2778. <P CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>//
  2779. Alternatively use the Scheduler method:</FONT></FONT></P>
  2780. <P CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2> Sensor_data&amp;
  2781. V1 = *((sensor_data*) ts.currentLts());</FONT></FONT></P>
  2782. <P CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in"><BR>
  2783. </P>
  2784. <P CLASS="western" STYLE="margin-left: 0.98in; text-indent: 0.49in; margin-bottom: 0in">
  2785. …</P>
  2786. <P CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2> V.distance
  2787. = &lt;calculate your values here&gt;;</FONT></FONT></P>
  2788. <P CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>}</FONT></FONT></P>
  2789. <P CLASS="western" STYLE="margin-left: 0.98in; margin-bottom: 0in"><BR>
  2790. </P>
  2791. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2792. </P>
  2793. <OL START=3>
  2794. <LI><P CLASS="western" STYLE="margin-bottom: 0in"><FONT FACE="Times New Roman, serif"><B>FUTHER
  2795. INFROMATION</B></FONT></P>
  2796. </OL>
  2797. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2798. </P>
  2799. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>Please
  2800. refer to examples, provided with TaskScheduler package for further
  2801. information and implementation options.</FONT></FONT></P>
  2802. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><BR>
  2803. </P>
  2804. <P CLASS="western" STYLE="margin-left: 0.49in; margin-bottom: 0in"><FONT FACE="Courier New, monospace"><FONT SIZE=2>Real
  2805. time examples of TaskScheduler are available here:</FONT></FONT></P>
  2806. <OL>
  2807. <LI><P CLASS="western" STYLE="margin-bottom: 0in"><FONT COLOR="#0000ff"><U><A HREF="http://www.instructables.com/id/APIS-Automated-Plant-Irrigation-System/"><FONT FACE="Courier New, monospace">http://www.instructables.com/id/APIS-Automated-Plant-Irrigation-System/</FONT></A></U></FONT></P>
  2808. <LI><P CLASS="western" STYLE="margin-bottom: 0in"><FONT COLOR="#0000ff"><U><A HREF="http://www.instructables.com/id/Wave-your-hand-to-control-OWI-Robotic-Arm-no-strin/"><FONT FACE="Courier New, monospace">http://www.instructables.com/id/Wave-your-hand-to-control-OWI-Robotic-Arm-no-strin/</FONT></A></U></FONT></P>
  2809. <LI><P CLASS="western" STYLE="margin-bottom: 0in"><FONT COLOR="#0000ff"><U><A HREF="http://www.instructables.com/id/Arduino-Nano-based-Hexbug-Scarab-Robotic-Spider"><FONT FACE="Courier New, monospace">http://www.instructables.com/id/Arduino-Nano-based-Hexbug-Scarab-Robotic-Spider</FONT></A></U></FONT></P>
  2810. </OL>
  2811. <P CLASS="western" STYLE="margin-bottom: 0in"><BR>
  2812. </P>
  2813. <DIV TYPE=FOOTER>
  2814. <P STYLE="margin-top: 0.35in; margin-bottom: 0in"> <SDFIELD TYPE=PAGE SUBTYPE=RANDOM FORMAT=ARABIC>31</SDFIELD></P>
  2815. </DIV>
  2816. </BODY>
  2817. </HTML>