TaskScheduler.html 166 KB

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