You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ad...@apache.org on 2017/02/16 06:03:37 UTC

[1/9] incubator-mynewt-site git commit: Added etape sensor tutorial. PR #152.

Repository: incubator-mynewt-site
Updated Branches:
  refs/heads/asf-site e1ea942d8 -> a4d946d9f


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/unit_test/index.html
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/unit_test/index.html b/latest/os/tutorials/unit_test/index.html
index 3761b49..ac6acd2 100644
--- a/latest/os/tutorials/unit_test/index.html
+++ b/latest/os/tutorials/unit_test/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -369,6 +356,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>
@@ -653,8 +661,8 @@ the message shown below.</p>
     </li>
     <li class="pull-right">
     
-    <a href=../air_quality_sensor/>
-        Next: Basic Air Quality Sensor
+    <a href=../event_queue/>
+        Next: Add task to manage multiple events
         <span class="fa fa-arrow-right"></span>
     </a>
     

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/wi-fi_on_arduino/index.html
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/wi-fi_on_arduino/index.html b/latest/os/tutorials/wi-fi_on_arduino/index.html
index df0a476..e2291b6 100644
--- a/latest/os/tutorials/wi-fi_on_arduino/index.html
+++ b/latest/os/tutorials/wi-fi_on_arduino/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -369,6 +356,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/os/tutorials/pics/MyNewtSensorReader006.jpg
----------------------------------------------------------------------
diff --git a/os/tutorials/pics/MyNewtSensorReader006.jpg b/os/tutorials/pics/MyNewtSensorReader006.jpg
new file mode 100644
index 0000000..c15d69d
Binary files /dev/null and b/os/tutorials/pics/MyNewtSensorReader006.jpg differ

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/os/tutorials/pics/adc-demo-1.png
----------------------------------------------------------------------
diff --git a/os/tutorials/pics/adc-demo-1.png b/os/tutorials/pics/adc-demo-1.png
new file mode 100644
index 0000000..6e5de58
Binary files /dev/null and b/os/tutorials/pics/adc-demo-1.png differ

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/os/tutorials/pics/adc-demo-2.png
----------------------------------------------------------------------
diff --git a/os/tutorials/pics/adc-demo-2.png b/os/tutorials/pics/adc-demo-2.png
new file mode 100644
index 0000000..be2cce7
Binary files /dev/null and b/os/tutorials/pics/adc-demo-2.png differ

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/os/tutorials/pics/breadboard.png
----------------------------------------------------------------------
diff --git a/os/tutorials/pics/breadboard.png b/os/tutorials/pics/breadboard.png
new file mode 100644
index 0000000..39a2b9d
Binary files /dev/null and b/os/tutorials/pics/breadboard.png differ

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/v0_9_0/os/tutorials/pics/MyNewtSensorReader006.jpg
----------------------------------------------------------------------
diff --git a/v0_9_0/os/tutorials/pics/MyNewtSensorReader006.jpg b/v0_9_0/os/tutorials/pics/MyNewtSensorReader006.jpg
new file mode 100644
index 0000000..c15d69d
Binary files /dev/null and b/v0_9_0/os/tutorials/pics/MyNewtSensorReader006.jpg differ

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/v0_9_0/os/tutorials/pics/adc-demo-1.png
----------------------------------------------------------------------
diff --git a/v0_9_0/os/tutorials/pics/adc-demo-1.png b/v0_9_0/os/tutorials/pics/adc-demo-1.png
new file mode 100644
index 0000000..6e5de58
Binary files /dev/null and b/v0_9_0/os/tutorials/pics/adc-demo-1.png differ

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/v0_9_0/os/tutorials/pics/adc-demo-2.png
----------------------------------------------------------------------
diff --git a/v0_9_0/os/tutorials/pics/adc-demo-2.png b/v0_9_0/os/tutorials/pics/adc-demo-2.png
new file mode 100644
index 0000000..be2cce7
Binary files /dev/null and b/v0_9_0/os/tutorials/pics/adc-demo-2.png differ

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/v0_9_0/os/tutorials/pics/breadboard.png
----------------------------------------------------------------------
diff --git a/v0_9_0/os/tutorials/pics/breadboard.png b/v0_9_0/os/tutorials/pics/breadboard.png
new file mode 100644
index 0000000..39a2b9d
Binary files /dev/null and b/v0_9_0/os/tutorials/pics/breadboard.png differ


[9/9] incubator-mynewt-site git commit: Added etape sensor tutorial. PR #152.

Posted by ad...@apache.org.
Added etape sensor tutorial. PR #152.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/commit/a4d946d9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/tree/a4d946d9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/diff/a4d946d9

Branch: refs/heads/asf-site
Commit: a4d946d9fa6c677ec3d97156563df7980dad67a6
Parents: e1ea942
Author: aditihilbert <ad...@runtime.io>
Authored: Wed Feb 15 22:03:24 2017 -0800
Committer: aditihilbert <ad...@runtime.io>
Committed: Wed Feb 15 22:03:24 2017 -0800

----------------------------------------------------------------------
 develop/mkdocs/search_index.json                |  190 ++-
 develop/os/os_user_guide/index.html             |    4 +-
 develop/os/tutorials/STM32F303/index.html       |   34 +-
 develop/os/tutorials/add_newtmgr/index.html     |   34 +-
 develop/os/tutorials/add_shell/index.html       |   34 +-
 develop/os/tutorials/air_quality_ble/index.html |   72 +-
 .../os/tutorials/air_quality_sensor/index.html  |   64 +-
 develop/os/tutorials/arduino_zero/index.html    |   34 +-
 develop/os/tutorials/blehci_project/index.html  |   38 +-
 .../os/tutorials/bleprph/bleprph-adv/index.html |   34 +-
 .../os/tutorials/bleprph/bleprph-app/index.html |   34 +-
 .../bleprph/bleprph-chr-access/index.html       |   34 +-
 .../bleprph/bleprph-gap-event/index.html        |   34 +-
 .../tutorials/bleprph/bleprph-intro/index.html  |   34 +-
 .../bleprph/bleprph-svc-reg/index.html          |   34 +-
 develop/os/tutorials/bletiny_project/index.html |   34 +-
 develop/os/tutorials/blinky_console/index.html  |   34 +-
 develop/os/tutorials/blinky_primo/index.html    |   34 +-
 .../os/tutorials/blinky_sram_olimex/index.html  |   34 +-
 develop/os/tutorials/eddystone/index.html       |   34 +-
 develop/os/tutorials/event_queue/index.html     |   38 +-
 develop/os/tutorials/ibeacon/index.html         |   34 +-
 develop/os/tutorials/nRF52/index.html           |   34 +-
 develop/os/tutorials/nrf52_adc/index.html       | 1305 ++++++++++++++++++
 develop/os/tutorials/olimex/index.html          |   34 +-
 .../os/tutorials/pics/MyNewtSensorReader006.jpg |  Bin 0 -> 211399 bytes
 develop/os/tutorials/pics/adc-demo-1.png        |  Bin 0 -> 530153 bytes
 develop/os/tutorials/pics/adc-demo-2.png        |  Bin 0 -> 435709 bytes
 develop/os/tutorials/pics/breadboard.png        |  Bin 0 -> 546231 bytes
 develop/os/tutorials/pin-wheel-mods/index.html  |   34 +-
 develop/os/tutorials/project-slinky/index.html  |   34 +-
 .../tutorials/project-target-slinky/index.html  |   34 +-
 develop/os/tutorials/repo/add_repos/index.html  |   34 +-
 .../os/tutorials/repo/create_repo/index.html    |   34 +-
 .../os/tutorials/repo/private_repo/index.html   |   34 +-
 .../os/tutorials/repo/upgrade_repo/index.html   |   34 +-
 develop/os/tutorials/tasks_lesson/index.html    |   34 +-
 develop/os/tutorials/tutorials/index.html       |   34 +-
 develop/os/tutorials/unit_test/index.html       |   38 +-
 .../os/tutorials/wi-fi_on_arduino/index.html    |   34 +-
 latest/mkdocs/search_index.json                 |  190 ++-
 latest/os/os_user_guide/index.html              |    4 +-
 latest/os/tutorials/STM32F303/index.html        |   34 +-
 latest/os/tutorials/add_newtmgr/index.html      |   34 +-
 latest/os/tutorials/add_shell/index.html        |   34 +-
 latest/os/tutorials/air_quality_ble/index.html  |   72 +-
 .../os/tutorials/air_quality_sensor/index.html  |   64 +-
 latest/os/tutorials/arduino_zero/index.html     |   34 +-
 latest/os/tutorials/blehci_project/index.html   |   38 +-
 .../os/tutorials/bleprph/bleprph-adv/index.html |   34 +-
 .../os/tutorials/bleprph/bleprph-app/index.html |   34 +-
 .../bleprph/bleprph-chr-access/index.html       |   34 +-
 .../bleprph/bleprph-gap-event/index.html        |   34 +-
 .../tutorials/bleprph/bleprph-intro/index.html  |   34 +-
 .../bleprph/bleprph-svc-reg/index.html          |   34 +-
 latest/os/tutorials/bletiny_project/index.html  |   34 +-
 latest/os/tutorials/blinky_console/index.html   |   34 +-
 latest/os/tutorials/blinky_primo/index.html     |   34 +-
 .../os/tutorials/blinky_sram_olimex/index.html  |   34 +-
 latest/os/tutorials/eddystone/index.html        |   34 +-
 latest/os/tutorials/event_queue/index.html      |   38 +-
 latest/os/tutorials/ibeacon/index.html          |   34 +-
 latest/os/tutorials/nRF52/index.html            |   34 +-
 latest/os/tutorials/nrf52_adc/index.html        | 1305 ++++++++++++++++++
 latest/os/tutorials/olimex/index.html           |   34 +-
 .../os/tutorials/pics/MyNewtSensorReader006.jpg |  Bin 0 -> 211399 bytes
 latest/os/tutorials/pics/adc-demo-1.png         |  Bin 0 -> 530153 bytes
 latest/os/tutorials/pics/adc-demo-2.png         |  Bin 0 -> 435709 bytes
 latest/os/tutorials/pics/breadboard.png         |  Bin 0 -> 546231 bytes
 latest/os/tutorials/pin-wheel-mods/index.html   |   34 +-
 latest/os/tutorials/project-slinky/index.html   |   34 +-
 .../tutorials/project-target-slinky/index.html  |   34 +-
 latest/os/tutorials/repo/add_repos/index.html   |   34 +-
 latest/os/tutorials/repo/create_repo/index.html |   34 +-
 .../os/tutorials/repo/private_repo/index.html   |   34 +-
 .../os/tutorials/repo/upgrade_repo/index.html   |   34 +-
 latest/os/tutorials/tasks_lesson/index.html     |   34 +-
 latest/os/tutorials/tutorials/index.html        |   34 +-
 latest/os/tutorials/unit_test/index.html        |   38 +-
 latest/os/tutorials/wi-fi_on_arduino/index.html |   34 +-
 os/tutorials/pics/MyNewtSensorReader006.jpg     |  Bin 0 -> 211399 bytes
 os/tutorials/pics/adc-demo-1.png                |  Bin 0 -> 530153 bytes
 os/tutorials/pics/adc-demo-2.png                |  Bin 0 -> 435709 bytes
 os/tutorials/pics/breadboard.png                |  Bin 0 -> 546231 bytes
 .../os/tutorials/pics/MyNewtSensorReader006.jpg |  Bin 0 -> 211399 bytes
 v0_9_0/os/tutorials/pics/adc-demo-1.png         |  Bin 0 -> 530153 bytes
 v0_9_0/os/tutorials/pics/adc-demo-2.png         |  Bin 0 -> 435709 bytes
 v0_9_0/os/tutorials/pics/breadboard.png         |  Bin 0 -> 546231 bytes
 88 files changed, 4360 insertions(+), 1042 deletions(-)
----------------------------------------------------------------------



[8/9] incubator-mynewt-site git commit: Added etape sensor tutorial. PR #152.

Posted by ad...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/mkdocs/search_index.json
----------------------------------------------------------------------
diff --git a/develop/mkdocs/search_index.json b/develop/mkdocs/search_index.json
index 245f7c7..5613d59 100644
--- a/develop/mkdocs/search_index.json
+++ b/develop/mkdocs/search_index.json
@@ -1276,56 +1276,6 @@
             "title": "Testing on your target"
         }, 
         {
-            "location": "/os/tutorials/air_quality_sensor/", 
-            "text": "Air quality sensor project\n\n\nSetting up source tree for stuff you need\n\n\nTo start with, you need to create a new project under which you will do this development. So you type in:\n\n\n    $ mkdir $HOME/src\n    $ cd $HOME/src\n    $ newt new air_quality\n\n\n\n\n\nLet's say you are using Arduino Primo -- which is based on the Nordic Semi NRF52 chip -- as the platform. \nYou know you need the board support package for that hardware. You can look up its location, add it your \nproject, and fetch that along with the core OS components. Luckily, the Arduino Primo is supported in the \nMynewt Core, so there's nothing much to do here. \n\n\nYour project.yml file should look like this:\n\n\n    [user@IsMyLaptop:~/src/air_quality]$ emacs project.yml \n\n    [user@IsMyLaptop:~/src/air_quality]$ cat project.yml\n    project.name: \nair_quality\n\n\n    project.repositories:\n        - apache-mynewt-core\n\n    # Use github\ns distribution mechanism for core ASF libr
 aries.\n    # This provides mirroring automatically for us.\n    #\n    repository.apache-mynewt-core:\n        type: github\n        vers: 0-latest\n        user: apache\n        repo: incubator-mynewt-core\n\n    [user@IsMyLaptop:~/src/air_quality]$ newt install\n    apache-mynewt-core\n    [user@IsMyLaptop:~/src/air_quality]$ ls repos/\n    apache-mynewt-core\n\n\n\n\n\nGood. You want to make sure you have all the needed bits for supporting your board; \nso you decide to build the blinky project for the platform first.\n\n\nNow create a target for it and build it. Easiest way to proceed is to copy the existing target for blinky, and modify it to build for Arduino Primo board.\n\n\n[user@IsMyLaptop:~/src/air_quality]$ newt target copy my_blinky_sim blink_primo\nTarget successfully copied; targets/my_blinky_sim --\n targets/blink_primo\n[user@IsMyLaptop:~/src/air_quality]$ newt target set blink_primo bsp=@apache-mynewt-core/hw/bsp/arduino_primo_nrf52\nTarget targets/blink_nrf succe
 ssfully set target.bsp to @apache-mynewt-core/hw/bsp/arduino_primo_nrf52\n[user@IsMyLaptop:~/src/air_quality]$ newt build blink_primo\nCompiling hal_bsp.c\n...\nLinking blinky.elf\nApp successfully built: /Users/user/src/air_quality/bin/blink_primo/apps/blinky/blinky.elf\n\n\n\n\n\nGood.\n\n\nYou know that this platform uses bootloader, which means you have to create a target for that too.\n\n\n[user@IsMyLaptop:~/src/air_quality]$ newt target create boot_primo\nTarget targets/boot_nrf successfully created\n[user@IsMyLaptop:~/src/air_quality]$ newt target show\n@apache-mynewt-core/targets/unittest\n    bsp=hw/bsp/native\n    build_profile=debug\n    compiler=compiler/sim\ntargets/blink_primo\n    app=apps/blinky\n    bsp=@apache-mynewt-core/hw/bsp/arduino_primo_nrf52\n    build_profile=debug\ntargets/boot_primo\ntargets/my_blinky_sim\n    app=apps/blinky\n    bsp=@apache-mynewt-core/hw/bsp/native\n    build_profile=debug\n[user@IsMyLaptop:~/src/air_quality]$ newt target set boot_nrf 
 bsp=@apache-mynewt-core/hw/bsp/arduino_primo_nrf52\nTarget targets/boot_nrf successfully set target.bsp to @apache-mynewt-core/hw/bsp/arduino_primo_nrf52\n[user@IsMyLaptop:~/src/air_quality]$ newt target set boot_nrf app=@apache-mynewt-core/apps/boot\nTarget targets/boot_nrf successfully set target.app to @apache-mynewt-core/apps/boot\n[user@IsMyLaptop:~/src/air_quality]$ newt target set boot_nrf build_profile=optimized\nTarget targets/boot_nrf successfully set target.build_profile to optimized\n\n\n\n\n\nAnd then build it, and load it onto the board.\n\n\nnewt build boot_primo\n....\nLinking boot.elf\nApp successfully built: /Users/user/src/air_quality/bin/boot_primo/apps/boot/boot.elf\n[user@IsMyLaptop:~/src/air_quality]\n$ newt load boot_primo\n\n\n\n\n\nAt this point, you may (or may not) see a bunch of error messages about not being able to connect to\nyour board, not being able to load the image, etc. If that's the case, and you haven't already, you\nshould most definitely go 
 worth through the \nblinky_primo\n tutorial so that you\ncan properly communicate with your board.\n\n\nNext you must download the targets to board, and see that the LED actually blinks. You plug in the \nArduino Primo board to your laptop, and say:\n\n\n[user@IsMyLaptop:~/src/air_quality]$ newt load blink_primo\nLoading app image into slot 1\nError: couldn\nt open /Users/user/src/air_quality/bin/blink_primo/apps/blinky/blinky.img\n\nError: exit status 1\n\nload - Load app image to target for \ntarget-name\n.\n\nUsage:\n  newt load [flags]\n\nExamples:\n  newt load \ntarget-name\n\n\n\nGlobal Flags:\n  -l, --loglevel string   Log level, defaults to WARN. (default \nWARN\n)\n  -o, --outfile string    Filename to tee log output to\n  -q, --quiet             Be quiet; only display error output.\n  -s, --silent            Be silent; don\nt output anything.\n  -v, --verbose           Enable verbose output when executing commands.\nexit status 1\n\n\n\n\n\nAh. Forgot to create an image ou
 t of the blinky binary. Note that every time you want to build and \nload a new firmware image to a target board, you need to run 'create-image' on it.\n\n\n[user@IsMyLaptop:~/src/air_quality]$ newt create-image blink_primo 0.0.1\nApp image successfully generated: /Users/user/src/air_quality/bin/blink_primo/apps/blinky/blinky.img\nBuild manifest: /Users/user/src/air_quality/bin/blink_nrf/apps/blinky/manifest.json\n[user@IsMyLaptop:~/src/air_quality]$ newt load blink_primo\n\n\n\n\n\nAnd it's blinking.\n\n\nShortcut for doing build/create-image/load/debug steps all in one is 'newt run' command. Check \nout the usage from command line help.\n\n\nCreate test project\n\n\nNow that you have your system setup, you can start creating your own stuff.\nFirst you want to create a project for yourself - you could start by using blinky as a project \ntemplate, but since we're going to want to be able to access the data via Bluetooth, let's \nuse the \nbleprph\n Bluetooth Peripheral project inst
 ead.\n\n\n    [user@IsMyLaptop:~/src/air_quality]$ mkdir apps/air_quality\n    [user@IsMyLaptop:~/src/air_quality]$ cp repos/apache-mynewt-core/apps/bleprph/pkg.yml apps/air_quality/\n    [user@IsMyLaptop:~/src/air_quality]$ cp -Rp repos/apache-mynewt-core/apps/bleprph/src apps/air_quality/\n\n\n\n\n\nThen you modify the apps/air_quality/pkg.yml for air_quality in order to change the \npkg.name\n to be \napps/air_quality\n.\nYou'll need to add the \n@apache-mynewt-core/\n path to all the package dependencies, since the app no longer\nresides within the apache-mynewt-core repository.\n\n\n[user@IsMyLaptop:~/src/air_quality]$ cat apps/air_quality/pkg.yml\npkg.name: apps/air_quality\npkg.type: app\npkg.description: BLE Air Quality application.\npkg.author: \nApache Mynewt \ndev@mynewt.incubator.apache.org\n\npkg.homepage: \nhttp://mynewt.apache.org/\n\npkg.keywords:\n\npkg.deps: \n    - \n@apache-mynewt-core/kernel/os\n\n    - \n@apache-mynewt-core/sys/shell\n\n    - \n@apache-mynewt-c
 ore/sys/stats/full\n\n    - \n@apache-mynewt-core/sys/log/full\n\n    - \n@apache-mynewt-core/mgmt/newtmgr\n\n    - \n@apache-mynewt-core/mgmt/newtmgr/transport/ble\n\n    - \n@apache-mynewt-core/net/nimble/controller\n\n    - \n@apache-mynewt-core/net/nimble/host\n\n    - \n@apache-mynewt-core/net/nimble/host/services/ans\n\n    - \n@apache-mynewt-core/net/nimble/host/services/gap\n\n    - \n@apache-mynewt-core/net/nimble/host/services/gatt\n\n    - \n@apache-mynewt-core/net/nimble/host/store/ram\n\n    - \n@apache-mynewt-core/net/nimble/transport/ram\n\n    - \n@apache-mynewt-core/sys/console/full\n\n    - \n@apache-mynewt-core/sys/sysinit\n\n    - \n@apache-mynewt-core/sys/id\n\n\n\n\n\n\nAnd create a target for it:\n\n\n[user@IsMyLaptop:~/src/air_quality]$ newt target create air_q\nTarget targets/air_q successfully created\n[user@IsMyLaptop:~/src/air_quality]$ newt target set air_q bsp=@apache-mynewt-core/hw/bsp/arduino_primo_nrf52\nTarget targets/air_q successfully set target.b
 sp to @apache-mynewt-core/hw/bsp/arduino_primo_nrf52\n[user@IsMyLaptop:~/src/air_quality]$ newt target set air_q app=apps/air_quality \nTarget targets/air_q successfully set target.app to apps/air_quality\n[user@IsMyLaptop:~/src/air_quality]$ newt target set air_q build_profile=debug\nTarget targets/air_q successfully set target.build_profile to debug\n[user@IsMyLaptop:~/src/air_quality]$ newt build air_q\n ....\nLinking /Users/dsimmons/dev/myproj/bin/targets/air_q/app/apps/air_quality/air_quality.elf\nTarget successfully built: targets/air_q\n\n\n\n\n\nCreate packages for drivers\n\n\nOne of the sensors you want to enable is SenseAir K30, which will connect to the board over a serial port.\nTo start development of the driver, you first need to create a package description for it, and add stubs for sources.\n\n\nThe first thing to do is to create the directory structure for your driver:\n\n\n[user@IsMyLaptop:~/src/air_quality]$ mkdir -p libs/my_drivers/senseair/include/senseair\n[us
 er@IsMyLaptop:~/src/air_quality]$ mkdir -p libs/my_drivers/senseair/src\n\n\n\n\n\nNow you can add the files you need. You'll need a pkg.yml to describe the driver, and then header stub followed by source stub.\n\n\n[user@IsMyLaptop:~/src/air_quality]$ cat libs/my_drivers/senseair/pkg.yml\n\n\n\n\n\n#\n\n\n# Licensed to the Apache Software Foundation (ASF) under one\n\n\n# or more contributor license agreements.  See the NOTICE file\n\n\n# distributed with this work for additional information\n\n\n# regarding copyright ownership.  The ASF licenses this file\n\n\n# to you under the Apache License, Version 2.0 (the\n\n\n# \nLicense\n); you may not use this file except in compliance\n\n\n# with the License.  You may obtain a copy of the License at\n\n\n# \n\n\n#  http:\n//www.apache.org/licenses/LICENSE-2.0\n\n\n#\n\n\n# Unless required by applicable law or agreed to in writing,\n\n\n# software distributed under the License is distributed on an\n\n\n# \nAS IS\n BASIS, WITHOUT WARRANTIE
 S OR CONDITIONS OF ANY\n\n\n# KIND, either express or implied.  See the License for the\n\n\n# specific language governing permissions and limitations\n\n\n# under the License.\n\n\n#\n\n\npkg\n.\nname\n: \nlibs/my_drivers/senseair\n\n\npkg\n.\ndescription\n: \nHost\n \nside\n \nof\n \nthe\n \nnimble\n \nBluetooth\n \nSmart\n \nstack\n.\n\npkg\n.\nauthor\n: \nApache Mynewt \ndev@mynewt.incubator.apache.org\n\n\npkg\n.\nhomepage\n: \nhttp://mynewt.apache.org/\n\n\npkg\n.\nkeywords\n:\n    \n-\n \nble\n\n    \n-\n \nbluetooth\n\n\n\npkg\n.\ndeps\n:\n    \n-\n \n@apache-mynewt-core/kernel/os\n\n\n\n\n\n\n[user@IsMyLaptop:~/src/air_quality]$ cat libs/my_drivers/senseair/include/senseair/senseair.h\n\n\n\n\n\n/*\n\n\n * Licensed to the Apache Software Foundation (ASF) under one\n\n\n * or more contributor license agreements.  See the NOTICE file\n\n\n * distributed with this work for additional information\n\n\n * regarding copyright ownership.  The ASF licenses this file\n\n\n * to you 
 under the Apache License, Version 2.0 (the\n\n\n * \nLicense\n); you may not use this file except in compliance\n\n\n * with the License.  You may obtain a copy of the License at\n\n\n * \n\n\n *  http://www.apache.org/licenses/LICENSE-2.0\n\n\n *\n\n\n * Unless required by applicable law or agreed to in writing,\n\n\n * software distributed under the License is distributed on an\n\n\n * \nAS IS\n BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n\n\n * KIND, either express or implied.  See the License for the\n\n\n * specific language governing permissions and limitations\n\n\n * under the License.\n\n\n*/\n\n\n#ifndef _SENSEAIR_H_\n\n\n#define _SENSEAIR_H_\n\n\n\nvoid\n \nsenseair_init\n(\nvoid\n);\n\n\n#endif \n/* _SENSEAIR_H_ */\n\n\n\n\n\n\n[user@IsMyLaptop:~/src/air_quality]$ cat libs/my_drivers/senseair/src/senseair.c\n\n\n\n\n\n/**\n\n\n * Licensed to the Apache Software Foundation (ASF) under one\n\n\n * or more contributor license agreements.  See the NOTICE file\n\n\n * dis
 tributed with this work for additional information\n\n\n * regarding copyright ownership.  The ASF licenses this file\n\n\n * to you under the Apache License, Version 2.0 (the\n\n\n * \nLicense\n); you may not use this file except in compliance\n\n\n * with the License.  You may obtain a copy of the License at\n\n\n * \n\n\n *  http://www.apache.org/licenses/LICENSE-2.0\n\n\n *\n\n\n * Unless required by applicable law or agreed to in writing,\n\n\n * software distributed under the License is distributed on an\n\n\n * \nAS IS\n BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n\n\n * KIND, either express or implied.  See the License for the\n\n\n * specific language governing permissions and limitations\n\n\n * under the License.\n\n\n */\n\n\n\nvoid\n\n\nsenseair_init\n(\nvoid\n)\n{\n}\n\n\n\n\n\nAnd add dependency to this package in your project yml file.\n\n\nHere's the listing from apps/air_quality/pkg.yml\n\n\npkg.name: apps/air_quality\npkg.type: app\npkg.description: Air qualit
 y sensor test\npkg.keywords:\n\npkg.deps:\n    - \n@apache-mynewt-core/libs/console/full\n\n    - \n@apache-mynewt-core/libs/newtmgr\n\n    - \n@apache-mynewt-core/libs/os\n\n    - \n@apache-mynewt-core/libs/shell\n\n    - \n@apache-mynewt-core/sys/config\n\n    - \n@apache-mynewt-core/sys/log/full\n\n    - \n@apache-mynewt-core/sys/stats/full\n\n    - libs/my_drivers/senseair\n\n\n\n\n\nAnd add a call to your main() to initialize this driver.\n\n\n    [user@IsMyLaptop:~/src/air_quality]$ diff project/blinky/src/main.c project/air_quality/src/main.c\n    28a29\n    \n #include \nsenseair/senseair.h\n\n    190a192\n    \n senseair_init();\n    [user@IsMyLaptop:~/src/air_quality\n\n\n\n\n\nThe ble_prph app runs everything in one task handler. For this project, we're going to add a second\ntask handler to respond to the shell, and then handle communicating with the senseair sensor for us.\n\n\n/** shell task settings. */\n\n\n#define SHELL_TASK_PRIO           2\n\n\n#define SHELL_STACK
 _SIZE          (OS_STACK_ALIGN(336))\n\n\n\nstruct\n \nos_eventq\n \nshell_evq\n;\n\nstruct\n \nos_task\n \nshell_task\n;\n\nbssnz_t\n \nos_stack_t\n \nshell_stack\n[\nSHELL_STACK_SIZE\n];\n\n\n\n\n\nThat defines the task, now we need to initialize it, add a task handler, and we're going to \nuse this task as our default task handler.\n\n\n/**\n\n\n * Event loop for the main shell task.\n\n\n */\n\n\nstatic\n \nvoid\n\n\nshell_task_handler\n(\nvoid\n \n*unused\n)\n{\n    \nwhile\n (\n1\n) {\n        \nos_eventq_run\n(\nshell_evq\n);\n    }\n}\n\n\n\n\n\nAnd in your \nmain()\n add:\n\n\n    \n/* Initialize shell eventq */\n\n    \nos_eventq_init\n(\nshell_evq\n);\n\n    \n/* Create the shell task.  \n\n\n     * All shell operations are performed in this task.\n\n\n     */\n\n    \nos_task_init\n(\nshell_task\n, \nshell\n, \nshell_task_handler\n,\n                              \nNULL\n, \nSHELL_TASK_PRIO\n, \nOS_WAIT_FOREVER\n,\n                              \nshell_stack\n, \nSHELL_S
 TACK_SIZE\n);\n\n\n\n\n\nDon't forget to change your default task handler!\n\n\n    \nos_eventq_dflt_set\n(\nshell_evq\n);\n\n\n\n\n\nAnd then build it to make sure all goes well.\n\n\n[user@IsMyLaptop:~/src/air_quality]$ newt build air_q\nCompiling senseair.c\nArchiving senseair.a\nLinking air_quality.elf\nApp successfully built: /Users/user/src/air_quality/bin/air_q/apps/air_quality/air_quality.elf\n\n\n\n\n\nAll looks good.\n\n\nAdd CLI commands for testing drivers\n\n\nWhile developing the driver, you want to issue operations from console asking it to do stuff. We'll assume that you've already worked through the tutorial \non how to \nenable the CLI\n, so all we'll need to do is add the propper values to the project's \nsyscfg.yml\n file:\n\n\n[user@IsMyLaptop:~/src/air_quality]$ cat targets/air_q/syscfg.yml\nsyscfg.vals:\n    # Set as per blinky_primo\n    OPENOCD_DEBUG: 1\n    # Enable the shell task.\n    SHELL_TASK: 1\n    STATS_CLI: 1\n    CONSOLE_TICKS: 1\n    CONSOLE_PROM
 PT: 1\n\n\n\n\n\nThen register your senseair command with the shell by adding the following to \nlibs/my_drivers/senseair/src/senseair.c\n\n\n#include \nshell/shell.h\n\n\n#include \nconsole/console.h\n\n\n#include \nassert.h\n\n\n\n\nstatic\n \nint\n \nsenseair_shell_func\n(\nint\n \nargc\n, \nchar\n \n**argv\n);\n\nstatic\n \nstruct\n \nshell_cmd\n \nsenseair_cmd\n \n=\n {\n    .\nsc_cmd\n \n=\n \nsenseair\n,\n    .\nsc_cmd_func\n \n=\n \nsenseair_shell_func\n,\n};\n\n\nvoid\n\n\nsenseair_init\n(\nvoid\n)\n{\n    \nint\n \nrc\n;\n\n    \nrc\n \n=\n \nshell_cmd_register\n(\nsenseair_cmd\n);\n    \nassert\n(\nrc\n \n==\n \n0\n);\n}\n\n\nstatic\n \nint\n\n\nsenseair_shell_func\n(\nint\n \nargc\n, \nchar\n \n**argv\n)\n{\n    \nconsole_printf\n(\nYay! Somebody called!\\n\n);\n    \nreturn\n \n0\n;\n\n}\n\n\n\n\n\nNow you can you build this, download to target, and start minicom on your console port. If you haven't already, familiarize yourself with\nthe tutorial on how to connect a se
 rial port to your board \nhere\n.\n\n\nYou'll need to wire up your Board to a Serial converter first. On the Arduino Primo Board pin 1 is TX and pin 0 is RX so wire 1 to RX on your serial board, and 0 to TX on your serial board.\n\n\n    [user@IsMyLaptop:~]$ minicom -D /dev/tty.usbserial-AH02MIE2\n\n\n    Welcome to minicom 2.7\n\n    OPTIONS: \n    Compiled on Oct 12 2015, 07:48:30.\n    Port /dev/tty.usbserial-AH02MIE2, 13:44:40\n\n    Press CTRL-X Z for help on special keys\n\n    ?\n    419: \n ?\n    Commands:\n    641:     stat      echo         ?    prompt     ticks     tasks\n    643: mempools      date  senseair\n    644: \n senseair\n    Yay! Somebody called!\n    1125: \n\n    53611: \n tasks\n    Tasks:\n    54047:    task pri tid  runtime      csw    stksz   stkuse   lcheck   ncheck flg\n    54057:    idle 255   0    54048    66890       64       30        0        0   0\n    54068:  ble_ll   0   1        9    64986       80       58        0        0   0\n    54079: bl
 eprph   1   2        0        1      336       32        0        0   0\n    54090:   shell   2   3        0     2077      336      262        0        0   0\n    54101: \n\n\n\n\n\n\nThat's great. Your shell task is running, and is responding appropriately!\nYou can connect the hardware to your board and start developing code for the driver itself.\n\n\nUse of HAL for drivers\n\n\nThe sensor has a serial port connection, and that's how you are going to connect to it. Your original BSP, hw/bsp/arduino_primo_nrf52, has two UARTs set up.\nWe're using one for our shell/console. It also has a second UART set up as a 'bit-bang' UART but since the SenseAir only needs to\ncommunicate at 9600 baud, this bit-banged uart is plenty fast enough.\n\n\nYou'll have to make a small change to the \nsyscfg.yml\n file in your project's target directory to change  the pin definitions \nfor this second UART. Those changes are as follows:\n\n\n    UART_0_PIN_TX: 23\n    UART_0_PIN_RX: 24\n\n\n\n\n\nWith 
 this in place, you can refer to serial port where your SenseAir sensor by a logical number. This makes the code more platform independent - you could connect this sensor to another board, like Olimex. You will also use the HAL UART abstraction to do the UART port setup and data transfer. That way you don't need to have any platform dependent pieces within your little driver.\n\n\nYou will now see what the driver code ends up looking like. Here's the header file, filled in from the stub you created earlier.\n\n\n/*\n\n\n * Licensed to the Apache Software Foundation (ASF) under one\n\n\n * or more contributor license agreements.  See the NOTICE file\n\n\n * distributed with this work for additional information\n\n\n * regarding copyright ownership.  The ASF licenses this file\n\n\n * to you under the Apache License, Version 2.0 (the\n\n\n * \nLicense\n); you may not use this file except in compliance\n\n\n * with the License.  You may obtain a copy of the License at\n\n\n * \n\n\n *  
 http://www.apache.org/licenses/LICENSE-2.0\n\n\n *\n\n\n * Unless required by applicable law or agreed to in writing,\n\n\n * software distributed under the License is distributed on an\n\n\n * \nAS IS\n BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n\n\n * KIND, either express or implied.  See the License for the\n\n\n * specific language governing permissions and limitations\n\n\n * under the License.\n\n\n*/\n\n\n#ifndef _SENSEAIR_H_\n\n\n#define _SENSEAIR_H_\n\n\n\nenum\n \nsenseair_read_type\n {\n        \nSENSEAIR_CO2\n,\n};\n\n\nint\n \nsenseair_init\n(\nint\n \nuartno\n);\n\n\nint\n \nsenseair_read\n(\nenum\n \nsenseair_read_type\n);\n\n\n#endif \n/* _SENSEAIR_H_ */\n\n\n\n\n\n\nAs you can see, logical UART number has been added to the init routine. A 'read' function has been added, \nwhich is a blocking read. If you were making a commercial product, you would probably have a callback for reporting the results.\n\n\nAnd here is the source for the driver.\n\n\n/**\n\n\n * Li
 censed to the Apache Software Foundation (ASF) under one\n\n\n * or more contributor license agreements.  See the NOTICE file\n\n\n * distributed with this work for additional information\n\n\n * regarding copyright ownership.  The ASF licenses this file\n\n\n * to you under the Apache License, Version 2.0 (the\n\n\n * \nLicense\n); you may not use this file except in compliance\n\n\n * with the License.  You may obtain a copy of the License at\n\n\n *\n\n\n *  http://www.apache.org/licenses/LICENSE-2.0\n\n\n *\n\n\n * Unless required by applicable law or agreed to in writing,\n\n\n * software distributed under the License is distributed on an\n\n\n * \nAS IS\n BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n\n\n * KIND, either express or implied.  See the License for the\n\n\n * specific language governing permissions and limitations\n\n\n * under the License.\n\n\n */\n\n\n#include \nstring.h\n\n\n\n#include \nshell/shell.h\n\n\n#include \nconsole/console.h\n\n\n#include \nos/os.h
 \n\n\n\n#include \nhal/hal_uart.h\n\n\n\n#include \nsenseair/senseair.h\n\n\n\nstatic\n \nconst\n \nuint8_t\n \ncmd_read_co2\n[] \n=\n {\n    \n0xFE\n, \n0\nX44\n, \n0\nX00\n, \n0\nX08\n, \n0\nX02\n, \n0\nX9F\n, \n0\nX25\n\n};\n\n\nstatic\n \nint\n \nsenseair_shell_func\n(\nint\n \nargc\n, \nchar\n \n**argv\n);\n\nstatic\n \nstruct\n \nshell_cmd\n \nsenseair_cmd\n \n=\n {\n    .\nsc_cmd\n \n=\n \nsenseair\n,\n    .\nsc_cmd_func\n \n=\n \nsenseair_shell_func\n,\n};\n\n\nstruct\n \nsenseair\n { \n    \nint\n \nuart\n;\n    \nstruct\n \nos_sem\n \nsema\n;\n    \nconst\n \nuint8_t\n \n*tx_data\n;\n    \nint\n \ntx_off\n;\n    \nint\n \ntx_len\n;\n    \nuint8_t\n \nrx_data\n[\n32\n]; \n    \nint\n \nrx_off\n;\n    \nint\n \nvalue\n;\n} \nsenseair\n;\n\n\nstatic\n \nint\n\n\nsenseair_tx_char\n(\nvoid\n \n*arg\n)\n{\n    \nstruct\n \nsenseair\n \n*s\n \n=\n \nsenseair\n;\n    \nint\n \nrc\n;\n\n    \nif\n (\ns-\ntx_off\n \n=\n \ns-\ntx_len\n) {\n    \n/*\n\n\n         * Command tx finished
 .\n\n\n         */\n\n        \ns-\ntx_data\n \n=\n \nNULL\n;\n        \nreturn\n \n-\n1\n;\n    }\n\n    \nrc\n \n=\n \ns-\ntx_data\n[\ns-\ntx_off\n];\n    \ns-\ntx_off++\n;\n    \nreturn\n \nrc\n;\n}\n\n\n/*\n\n\n * CRC for modbus over serial port.\n\n\n */\n\n\nstatic\n \nconst\n \nuint16_t\n \nmb_crc_tbl\n[] \n=\n {\n    \n0x0000\n, \n0xcc01\n, \n0xd801\n, \n0x1400\n, \n0xf001\n, \n0x3c00\n, \n0x2800\n, \n0xe401\n,\n    \n0xa001\n, \n0x6c00\n, \n0x7800\n, \n0xb401\n, \n0x5000\n, \n0x9c01\n, \n0x8801\n, \n0x4400\n\n};\n\n\nstatic\n \nuint16_t\n\n\nmb_crc\n(\nconst\n \nuint8_t\n \n*data\n, \nint\n \nlen\n, \nuint16_t\n \ncrc\n)\n{\n    \nwhile\n (\nlen--\n \n \n0\n) {\n        \ncrc\n \n^=\n \n*data++\n;\n        \ncrc\n \n=\n (\ncrc\n \n \n4\n) \n^\n \nmb_crc_tbl\n[\ncrc\n \n \n0xf\n];\n        \ncrc\n \n=\n (\ncrc\n \n \n4\n) \n^\n \nmb_crc_tbl\n[\ncrc\n \n \n0xf\n];\n    }\n    \nreturn\n \ncrc\n;\n}\n\n\nstatic\n \nint\n\n\nmb_crc_check\n(\nconst\n \nvoid\n \n*pkt\n, \nint\n \
 nlen\n)\n{\n    \nuint16_t\n \ncrc\n, \ncmp\n;\n    \nuint8_t\n \n*bp\n \n=\n (\nuint8_t\n \n*\n)\npkt\n;\n\n    \nif\n (\nlen\n \n \nsizeof\n(\ncrc\n) \n+\n \n1\n) {\n        \nreturn\n \n-\n1\n;\n    }\n    \ncrc\n \n=\n \nmb_crc\n(\npkt\n, \nlen\n \n-\n \n2\n, \n0xffff\n);\n    \ncmp\n \n=\n \nbp\n[\nlen\n \n-\n \n2\n] \n|\n (\nbp\n[\nlen\n \n-\n \n1\n] \n \n8\n);\n    \nif\n (\ncrc\n \n!=\n \ncmp\n) {\n        \nreturn\n \n-\n1\n;\n    } \nelse\n {\n        \nreturn\n \n0\n;\n    }\n}\n\n\nstatic\n \nint\n\n\nsenseair_rx_char\n(\nvoid\n \n*arg\n, \nuint8_t\n \ndata\n)\n{\n    \nstruct\n \nsenseair\n \n*s\n \n=\n (\nstruct\n \nsenseair\n \n*\n)\narg\n;\n    \nint\n \nrc\n;\n\n    \nif\n (\ns-\nrx_off\n \n=\n \nsizeof\n(\ns-\nrx_data\n)) {\n        \ns-\nrx_off\n \n=\n \n0\n;\n    }\n    \ns-\nrx_data\n[\ns-\nrx_off\n] \n=\n \ndata\n;\n    \ns-\nrx_off++\n;\n\n    \nif\n (\ns-\nrx_off\n \n==\n \n7\n) {\n        \nrc\n \n=\n \nmb_crc_check\n(\ns-\nrx_data\n, \ns-\nrx_off\n);\n     
    \nif\n (\nrc\n \n==\n \n0\n) {\n            \ns-\nvalue\n \n=\n \ns-\nrx_data\n[\n3\n] \n*\n \n256\n \n+\n \ns-\nrx_data\n[\n4\n];\n            \nos_sem_release\n(\ns-\nsema\n);\n        }\n    }\n    \nreturn\n \n0\n;\n}\n\n\nvoid\n\n\nsenseair_tx\n(\nstruct\n \nsenseair\n \n*s\n, \nconst\n \nuint8_t\n \n*tx_data\n, \nint\n \ndata_len\n)\n{\n    \ns-\ntx_data\n \n=\n \ntx_data\n;\n    \ns-\ntx_len\n \n=\n \ndata_len\n;\n    \ns-\ntx_off\n \n=\n \n0\n;\n    \ns-\nrx_off\n \n=\n \n0\n;\n\n    \nhal_uart_start_tx\n(\ns-\nuart\n);\n}\n\n\nint\n\n\nsenseair_read\n(\nenum\n \nsenseair_read_type\n \ntype\n)\n{\n    \nstruct\n \nsenseair\n \n*s\n \n=\n \nsenseair\n;\n    \nconst\n \nuint8_t\n \n*cmd\n;\n    \nint\n \ncmd_len\n;\n    \nint\n \nrc\n;\n\n    \nif\n (\ns-\ntx_data\n) {\n        \n/*\n\n\n         * busy\n\n\n         */\n\n        \nreturn\n \n-\n1\n;\n    }\n    \nswitch\n (\ntype\n) {\n    \ncase\n \nSENSEAIR_CO2\n:\n        \ncmd\n \n=\n \ncmd_read_co2\n;\n        \ncmd_
 len\n \n=\n \nsizeof\n(\ncmd_read_co2\n);\n        \nbreak\n;\n    \ndefault\n:\n\n        \nreturn\n \n-\n1\n;\n    }\n    \nsenseair_tx\n(\ns\n, \ncmd\n, \ncmd_len\n);\n    \nrc\n \n=\n \nos_sem_pend\n(\ns-\nsema\n, \nOS_TICKS_PER_SEC\n \n/\n \n2\n);\n    \nif\n (\nrc\n \n==\n \nOS_TIMEOUT\n) {\n        \n/*\n\n\n         * timeout\n\n\n         */\n\n        \nreturn\n \n-\n2\n;\n    }\n    \nreturn\n \ns-\nvalue\n;\n}\n\n\nstatic\n \nint\n\n\nsenseair_shell_func\n(\nint\n \nargc\n, \nchar\n \n**argv\n)\n{\n    \nint\n \nvalue\n;\n    \nenum\n \nsenseair_read_type\n \ntype\n;\n\n    \nif\n (\nargc\n \n \n2\n) {\n\nusage\n:\n        \nconsole_printf\n(\n%s co2\\n\n, \nargv\n[\n0\n]);\n        \nreturn\n \n0\n;\n    }\n    \nif\n (\n!strcmp\n(\nargv\n[\n1\n], \nco2\n)) {\n        \ntype\n \n=\n \nSENSEAIR_CO2\n;\n    } \nelse\n {\n        \ngoto\n \nusage\n;\n    }\n    \nvalue\n \n=\n \nsenseair_read\n(\ntype\n);\n    \nif\n (\nvalue\n \n=\n \n0\n) {\n        \nconsole_printf\n(\n
 Got %d\\n\n, \nvalue\n);\n    } \nelse\n {\n        \nconsole_printf\n(\nError while reading: %d\\n\n, \nvalue\n);\n    }\n    \nreturn\n \n0\n;\n}\n\n\nint\n\n\nsenseair_init\n(\nint\n \nuartno\n)\n{\n    \nint\n \nrc\n;\n    \nstruct\n \nsenseair\n \n*s\n \n=\n \nsenseair\n;\n\n    \nrc\n \n=\n \nshell_cmd_register\n(\nsenseair_cmd\n);\n    \nif\n (\nrc\n) {\n        \nreturn\n \nrc\n;\n    }\n\n    \nrc\n \n=\n \nos_sem_init\n(\ns-\nsema\n, \n1\n);\n    \nif\n (\nrc\n) {\n        \nreturn\n \nrc\n;\n    }\n    \nrc\n \n=\n \nhal_uart_init_cbs\n(\nuartno\n, \nsenseair_tx_char\n, \nNULL\n,\n      \nsenseair_rx_char\n, \nsenseair\n);\n    \nif\n (\nrc\n) {\n        \nreturn\n \nrc\n;\n    }\n    \nrc\n \n=\n \nhal_uart_config\n(\nuartno\n, \n9600\n, \n8\n, \n1\n, \nHAL_UART_PARITY_NONE\n,\n      \nHAL_UART_FLOW_CTL_NONE\n);\n    \nif\n (\nrc\n) {\n        \nreturn\n \nrc\n;\n    }\n    \ns-\nuart\n \n=\n \nuartno\n;\n\n    \nreturn\n \n0\n;\n}\n\n\n\n\n\nAnd your modified main() for
  senseair driver init.\n\n\nint\n\n\nmain\n(\nint\n \nargc\n, \nchar\n \n**argv\n)\n{\n    ....\n    \nsenseair_init\n(\n0\n);\n    ....\n    }\n\n\n\n\n\nYou can see from the code that you are using the HAL interface to open a UART port, and using OS \nsemaphore as a way of blocking the task when waiting for read response to come back from the sensor.\n\n\nNow comes the fun part: Hooking up the sensor! It's fun because a) hooking up a sensor is always \nfun and b) the SenseAir sensor's PCB is entirely unlabeled, so you'll have to trust us on how to hook it up. \n\n\nSo here we go. \n\n\nYou'll have to do a little soldering. I soldered some header pins to the SenseAir K30 board to\nmake connecting wires easier using standard jumper wires, but you can also just solder wires\nstraight to the board if you prefer.\n\n\nHere's what your SenseAir board should look like once it's wired up:\n\n\n\n\nNow that you have that wired up, let's get the Arduino Primo wired up. A couple of things to
  note:\n\n\n\n\nThe Arduino Primo's 'console' UART is actually UART1. \n\n\nThe secondary (bit-banged) UART is UART0, so that's where we'll have to hook up the SenseAir.\n\n\n\n\nHere's what your Arduino Primo should now look like with everything wired in:\n\n\n\n\nEverything is wired and you're ready to go! Build and load your new app:\n\n\n$ newt build air_q\nBuilding target targets/air_q\nCompiling apps/air_quality/src/main.c\nArchiving apps_air_quality.a\nLinking myproj/bin/targets/air_q/app/apps/air_quality/air_quality.elf\nTarget successfully built: targets/air_q\n$ newt create-image air_q 1.0.0\nApp image succesfully generated: myproj/bin/targets/air_q/app/apps/air_quality/air_quality.img\n$ newt load air_q\nLoading app image into slot 1\n\n\n\n\n\nNow, you should be able to connect to your serial port and read values:\n\n\nuser@IsMyLaptop:~]$ minicom -D /dev/tty.usbserial-AH02MIE2\n\n\n    Welcome to minicom 2.7\n\n    OPTIONS: \n    Compiled on Oct 12 2015, 07:48:30.\n    P
 ort /dev/tty.usbserial-AH02MIE2, 13:44:40\n\n    Press CTRL-X Z for help on special keys\n\n    1185: \n ?\n    Commands:\n    1382:     stat      echo         ?    prompt     ticks     tasks\n    1390: mempools      date  senseair\n    1395: \n senseair\n    senseair co2\n    2143: \n senseair co2\n    Got 973\n\n\n\n\n\nAnd you're getting valid readings! Congratulations!\n\n\nNext we'll hook this all up via Bluetooth so that you can read those values remotely.", 
-            "title": "Basic Air Quality Sensor"
-        }, 
-        {
-            "location": "/os/tutorials/air_quality_sensor/#air-quality-sensor-project", 
-            "text": "", 
-            "title": "Air quality sensor project"
-        }, 
-        {
-            "location": "/os/tutorials/air_quality_sensor/#setting-up-source-tree-for-stuff-you-need", 
-            "text": "To start with, you need to create a new project under which you will do this development. So you type in:      $ mkdir $HOME/src\n    $ cd $HOME/src\n    $ newt new air_quality  Let's say you are using Arduino Primo -- which is based on the Nordic Semi NRF52 chip -- as the platform. \nYou know you need the board support package for that hardware. You can look up its location, add it your \nproject, and fetch that along with the core OS components. Luckily, the Arduino Primo is supported in the \nMynewt Core, so there's nothing much to do here.   Your project.yml file should look like this:      [user@IsMyLaptop:~/src/air_quality]$ emacs project.yml  \n    [user@IsMyLaptop:~/src/air_quality]$ cat project.yml\n    project.name:  air_quality \n\n    project.repositories:\n        - apache-mynewt-core\n\n    # Use github s distribution mechanism for core ASF libraries.\n    # This provides mirroring automatically for us.\n    #\n    repository.apache-mynewt-core:\n 
        type: github\n        vers: 0-latest\n        user: apache\n        repo: incubator-mynewt-core\n\n    [user@IsMyLaptop:~/src/air_quality]$ newt install\n    apache-mynewt-core\n    [user@IsMyLaptop:~/src/air_quality]$ ls repos/\n    apache-mynewt-core  Good. You want to make sure you have all the needed bits for supporting your board; \nso you decide to build the blinky project for the platform first.  Now create a target for it and build it. Easiest way to proceed is to copy the existing target for blinky, and modify it to build for Arduino Primo board.  [user@IsMyLaptop:~/src/air_quality]$ newt target copy my_blinky_sim blink_primo\nTarget successfully copied; targets/my_blinky_sim --  targets/blink_primo\n[user@IsMyLaptop:~/src/air_quality]$ newt target set blink_primo bsp=@apache-mynewt-core/hw/bsp/arduino_primo_nrf52\nTarget targets/blink_nrf successfully set target.bsp to @apache-mynewt-core/hw/bsp/arduino_primo_nrf52\n[user@IsMyLaptop:~/src/air_quality]$ newt build bl
 ink_primo\nCompiling hal_bsp.c\n...\nLinking blinky.elf\nApp successfully built: /Users/user/src/air_quality/bin/blink_primo/apps/blinky/blinky.elf  Good.  You know that this platform uses bootloader, which means you have to create a target for that too.  [user@IsMyLaptop:~/src/air_quality]$ newt target create boot_primo\nTarget targets/boot_nrf successfully created\n[user@IsMyLaptop:~/src/air_quality]$ newt target show\n@apache-mynewt-core/targets/unittest\n    bsp=hw/bsp/native\n    build_profile=debug\n    compiler=compiler/sim\ntargets/blink_primo\n    app=apps/blinky\n    bsp=@apache-mynewt-core/hw/bsp/arduino_primo_nrf52\n    build_profile=debug\ntargets/boot_primo\ntargets/my_blinky_sim\n    app=apps/blinky\n    bsp=@apache-mynewt-core/hw/bsp/native\n    build_profile=debug\n[user@IsMyLaptop:~/src/air_quality]$ newt target set boot_nrf bsp=@apache-mynewt-core/hw/bsp/arduino_primo_nrf52\nTarget targets/boot_nrf successfully set target.bsp to @apache-mynewt-core/hw/bsp/arduino_
 primo_nrf52\n[user@IsMyLaptop:~/src/air_quality]$ newt target set boot_nrf app=@apache-mynewt-core/apps/boot\nTarget targets/boot_nrf successfully set target.app to @apache-mynewt-core/apps/boot\n[user@IsMyLaptop:~/src/air_quality]$ newt target set boot_nrf build_profile=optimized\nTarget targets/boot_nrf successfully set target.build_profile to optimized  And then build it, and load it onto the board.  newt build boot_primo\n....\nLinking boot.elf\nApp successfully built: /Users/user/src/air_quality/bin/boot_primo/apps/boot/boot.elf\n[user@IsMyLaptop:~/src/air_quality]\n$ newt load boot_primo  At this point, you may (or may not) see a bunch of error messages about not being able to connect to\nyour board, not being able to load the image, etc. If that's the case, and you haven't already, you\nshould most definitely go worth through the  blinky_primo  tutorial so that you\ncan properly communicate with your board.  Next you must download the targets to board, and see that the LED ac
 tually blinks. You plug in the \nArduino Primo board to your laptop, and say:  [user@IsMyLaptop:~/src/air_quality]$ newt load blink_primo\nLoading app image into slot 1\nError: couldn t open /Users/user/src/air_quality/bin/blink_primo/apps/blinky/blinky.img\n\nError: exit status 1\n\nload - Load app image to target for  target-name .\n\nUsage:\n  newt load [flags]\n\nExamples:\n  newt load  target-name \n\n\nGlobal Flags:\n  -l, --loglevel string   Log level, defaults to WARN. (default  WARN )\n  -o, --outfile string    Filename to tee log output to\n  -q, --quiet             Be quiet; only display error output.\n  -s, --silent            Be silent; don t output anything.\n  -v, --verbose           Enable verbose output when executing commands.\nexit status 1  Ah. Forgot to create an image out of the blinky binary. Note that every time you want to build and \nload a new firmware image to a target board, you need to run 'create-image' on it.  [user@IsMyLaptop:~/src/air_quality]$ newt
  create-image blink_primo 0.0.1\nApp image successfully generated: /Users/user/src/air_quality/bin/blink_primo/apps/blinky/blinky.img\nBuild manifest: /Users/user/src/air_quality/bin/blink_nrf/apps/blinky/manifest.json\n[user@IsMyLaptop:~/src/air_quality]$ newt load blink_primo  And it's blinking.  Shortcut for doing build/create-image/load/debug steps all in one is 'newt run' command. Check \nout the usage from command line help.", 
-            "title": "Setting up source tree for stuff you need"
-        }, 
-        {
-            "location": "/os/tutorials/air_quality_sensor/#create-test-project", 
-            "text": "Now that you have your system setup, you can start creating your own stuff.\nFirst you want to create a project for yourself - you could start by using blinky as a project \ntemplate, but since we're going to want to be able to access the data via Bluetooth, let's \nuse the  bleprph  Bluetooth Peripheral project instead.      [user@IsMyLaptop:~/src/air_quality]$ mkdir apps/air_quality\n    [user@IsMyLaptop:~/src/air_quality]$ cp repos/apache-mynewt-core/apps/bleprph/pkg.yml apps/air_quality/\n    [user@IsMyLaptop:~/src/air_quality]$ cp -Rp repos/apache-mynewt-core/apps/bleprph/src apps/air_quality/  Then you modify the apps/air_quality/pkg.yml for air_quality in order to change the  pkg.name  to be  apps/air_quality .\nYou'll need to add the  @apache-mynewt-core/  path to all the package dependencies, since the app no longer\nresides within the apache-mynewt-core repository.  [user@IsMyLaptop:~/src/air_quality]$ cat apps/air_quality/pkg.yml\npkg.name: apps/air_q
 uality\npkg.type: app\npkg.description: BLE Air Quality application.\npkg.author:  Apache Mynewt  dev@mynewt.incubator.apache.org \npkg.homepage:  http://mynewt.apache.org/ \npkg.keywords:\n\npkg.deps: \n    -  @apache-mynewt-core/kernel/os \n    -  @apache-mynewt-core/sys/shell \n    -  @apache-mynewt-core/sys/stats/full \n    -  @apache-mynewt-core/sys/log/full \n    -  @apache-mynewt-core/mgmt/newtmgr \n    -  @apache-mynewt-core/mgmt/newtmgr/transport/ble \n    -  @apache-mynewt-core/net/nimble/controller \n    -  @apache-mynewt-core/net/nimble/host \n    -  @apache-mynewt-core/net/nimble/host/services/ans \n    -  @apache-mynewt-core/net/nimble/host/services/gap \n    -  @apache-mynewt-core/net/nimble/host/services/gatt \n    -  @apache-mynewt-core/net/nimble/host/store/ram \n    -  @apache-mynewt-core/net/nimble/transport/ram \n    -  @apache-mynewt-core/sys/console/full \n    -  @apache-mynewt-core/sys/sysinit \n    -  @apache-mynewt-core/sys/id   And create a target for it: 
  [user@IsMyLaptop:~/src/air_quality]$ newt target create air_q\nTarget targets/air_q successfully created\n[user@IsMyLaptop:~/src/air_quality]$ newt target set air_q bsp=@apache-mynewt-core/hw/bsp/arduino_primo_nrf52\nTarget targets/air_q successfully set target.bsp to @apache-mynewt-core/hw/bsp/arduino_primo_nrf52\n[user@IsMyLaptop:~/src/air_quality]$ newt target set air_q app=apps/air_quality \nTarget targets/air_q successfully set target.app to apps/air_quality\n[user@IsMyLaptop:~/src/air_quality]$ newt target set air_q build_profile=debug\nTarget targets/air_q successfully set target.build_profile to debug\n[user@IsMyLaptop:~/src/air_quality]$ newt build air_q\n ....\nLinking /Users/dsimmons/dev/myproj/bin/targets/air_q/app/apps/air_quality/air_quality.elf\nTarget successfully built: targets/air_q", 
-            "title": "Create test project"
-        }, 
-        {
-            "location": "/os/tutorials/air_quality_sensor/#create-packages-for-drivers", 
-            "text": "One of the sensors you want to enable is SenseAir K30, which will connect to the board over a serial port.\nTo start development of the driver, you first need to create a package description for it, and add stubs for sources.  The first thing to do is to create the directory structure for your driver:  [user@IsMyLaptop:~/src/air_quality]$ mkdir -p libs/my_drivers/senseair/include/senseair\n[user@IsMyLaptop:~/src/air_quality]$ mkdir -p libs/my_drivers/senseair/src  Now you can add the files you need. You'll need a pkg.yml to describe the driver, and then header stub followed by source stub.  [user@IsMyLaptop:~/src/air_quality]$ cat libs/my_drivers/senseair/pkg.yml  #  # Licensed to the Apache Software Foundation (ASF) under one  # or more contributor license agreements.  See the NOTICE file  # distributed with this work for additional information  # regarding copyright ownership.  The ASF licenses this file  # to you under the Apache License, Version 2.0 (the  # 
  License ); you may not use this file except in compliance  # with the License.  You may obtain a copy of the License at  #   #  http: //www.apache.org/licenses/LICENSE-2.0  #  # Unless required by applicable law or agreed to in writing,  # software distributed under the License is distributed on an  #  AS IS  BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY  # KIND, either express or implied.  See the License for the  # specific language governing permissions and limitations  # under the License.  #  pkg . name :  libs/my_drivers/senseair  pkg . description :  Host   side   of   the   nimble   Bluetooth   Smart   stack . pkg . author :  Apache Mynewt  dev@mynewt.incubator.apache.org  pkg . homepage :  http://mynewt.apache.org/  pkg . keywords :\n     -   ble \n     -   bluetooth  pkg . deps :\n     -   @apache-mynewt-core/kernel/os   [user@IsMyLaptop:~/src/air_quality]$ cat libs/my_drivers/senseair/include/senseair/senseair.h  /*   * Licensed to the Apache Software Foundation (ASF) u
 nder one   * or more contributor license agreements.  See the NOTICE file   * distributed with this work for additional information   * regarding copyright ownership.  The ASF licenses this file   * to you under the Apache License, Version 2.0 (the   *  License ); you may not use this file except in compliance   * with the License.  You may obtain a copy of the License at   *    *  http://www.apache.org/licenses/LICENSE-2.0   *   * Unless required by applicable law or agreed to in writing,   * software distributed under the License is distributed on an   *  AS IS  BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY   * KIND, either express or implied.  See the License for the   * specific language governing permissions and limitations   * under the License.  */  #ifndef _SENSEAIR_H_  #define _SENSEAIR_H_  void   senseair_init ( void ); #endif  /* _SENSEAIR_H_ */   [user@IsMyLaptop:~/src/air_quality]$ cat libs/my_drivers/senseair/src/senseair.c  /**   * Licensed to the Apache Software Fou
 ndation (ASF) under one   * or more contributor license agreements.  See the NOTICE file   * distributed with this work for additional information   * regarding copyright ownership.  The ASF licenses this file   * to you under the Apache License, Version 2.0 (the   *  License ); you may not use this file except in compliance   * with the License.  You may obtain a copy of the License at   *    *  http://www.apache.org/licenses/LICENSE-2.0   *   * Unless required by applicable law or agreed to in writing,   * software distributed under the License is distributed on an   *  AS IS  BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY   * KIND, either express or implied.  See the License for the   * specific language governing permissions and limitations   * under the License.   */  void  senseair_init ( void )\n{\n}  And add dependency to this package in your project yml file.  Here's the listing from apps/air_quality/pkg.yml  pkg.name: apps/air_quality\npkg.type: app\npkg.description: Air q
 uality sensor test\npkg.keywords:\n\npkg.deps:\n    -  @apache-mynewt-core/libs/console/full \n    -  @apache-mynewt-core/libs/newtmgr \n    -  @apache-mynewt-core/libs/os \n    -  @apache-mynewt-core/libs/shell \n    -  @apache-mynewt-core/sys/config \n    -  @apache-mynewt-core/sys/log/full \n    -  @apache-mynewt-core/sys/stats/full \n    - libs/my_drivers/senseair  And add a call to your main() to initialize this driver.      [user@IsMyLaptop:~/src/air_quality]$ diff project/blinky/src/main.c project/air_quality/src/main.c\n    28a29\n      #include  senseair/senseair.h \n    190a192\n      senseair_init();\n    [user@IsMyLaptop:~/src/air_quality  The ble_prph app runs everything in one task handler. For this project, we're going to add a second\ntask handler to respond to the shell, and then handle communicating with the senseair sensor for us.  /** shell task settings. */  #define SHELL_TASK_PRIO           2  #define SHELL_STACK_SIZE          (OS_STACK_ALIGN(336))  struct   os
 _eventq   shell_evq ; struct   os_task   shell_task ; bssnz_t   os_stack_t   shell_stack [ SHELL_STACK_SIZE ];  That defines the task, now we need to initialize it, add a task handler, and we're going to \nuse this task as our default task handler.  /**   * Event loop for the main shell task.   */  static   void  shell_task_handler ( void   *unused )\n{\n     while  ( 1 ) {\n         os_eventq_run ( shell_evq );\n    }\n}  And in your  main()  add:       /* Initialize shell eventq */ \n     os_eventq_init ( shell_evq );\n\n     /* Create the shell task.         * All shell operations are performed in this task.       */ \n     os_task_init ( shell_task ,  shell ,  shell_task_handler ,\n                               NULL ,  SHELL_TASK_PRIO ,  OS_WAIT_FOREVER ,\n                               shell_stack ,  SHELL_STACK_SIZE );  Don't forget to change your default task handler!       os_eventq_dflt_set ( shell_evq );  And then build it to make sure all goes well.  [user@IsMyLaptop:~/s
 rc/air_quality]$ newt build air_q\nCompiling senseair.c\nArchiving senseair.a\nLinking air_quality.elf\nApp successfully built: /Users/user/src/air_quality/bin/air_q/apps/air_quality/air_quality.elf  All looks good.", 
-            "title": "Create packages for drivers"
-        }, 
-        {
-            "location": "/os/tutorials/air_quality_sensor/#add-cli-commands-for-testing-drivers", 
-            "text": "While developing the driver, you want to issue operations from console asking it to do stuff. We'll assume that you've already worked through the tutorial \non how to  enable the CLI , so all we'll need to do is add the propper values to the project's  syscfg.yml  file:  [user@IsMyLaptop:~/src/air_quality]$ cat targets/air_q/syscfg.yml\nsyscfg.vals:\n    # Set as per blinky_primo\n    OPENOCD_DEBUG: 1\n    # Enable the shell task.\n    SHELL_TASK: 1\n    STATS_CLI: 1\n    CONSOLE_TICKS: 1\n    CONSOLE_PROMPT: 1  Then register your senseair command with the shell by adding the following to  libs/my_drivers/senseair/src/senseair.c  #include  shell/shell.h  #include  console/console.h  #include  assert.h  static   int   senseair_shell_func ( int   argc ,  char   **argv ); static   struct   shell_cmd   senseair_cmd   =  {\n    . sc_cmd   =   senseair ,\n    . sc_cmd_func   =   senseair_shell_func ,\n}; void  senseair_init ( void )\n{\n     int   rc ;\n\n     rc   = 
   shell_cmd_register ( senseair_cmd );\n     assert ( rc   ==   0 );\n} static   int  senseair_shell_func ( int   argc ,  char   **argv )\n{\n     console_printf ( Yay! Somebody called!\\n );\n     return   0 ;\n\n}  Now you can you build this, download to target, and start minicom on your console port. If you haven't already, familiarize yourself with\nthe tutorial on how to connect a serial port to your board  here .  You'll need to wire up your Board to a Serial converter first. On the Arduino Primo Board pin 1 is TX and pin 0 is RX so wire 1 to RX on your serial board, and 0 to TX on your serial board.      [user@IsMyLaptop:~]$ minicom -D /dev/tty.usbserial-AH02MIE2\n\n\n    Welcome to minicom 2.7\n\n    OPTIONS: \n    Compiled on Oct 12 2015, 07:48:30.\n    Port /dev/tty.usbserial-AH02MIE2, 13:44:40\n\n    Press CTRL-X Z for help on special keys\n\n    ?\n    419:   ?\n    Commands:\n    641:     stat      echo         ?    prompt     ticks     tasks\n    643: mempools      dat
 e  senseair\n    644:   senseair\n    Yay! Somebody called!\n    1125:  \n    53611:   tasks\n    Tasks:\n    54047:    task pri tid  runtime      csw    stksz   stkuse   lcheck   ncheck flg\n    54057:    idle 255   0    54048    66890       64       30        0        0   0\n    54068:  ble_ll   0   1        9    64986       80       58        0        0   0\n    54079: bleprph   1   2        0        1      336       32        0        0   0\n    54090:   shell   2   3        0     2077      336      262        0        0   0\n    54101:    That's great. Your shell task is running, and is responding appropriately!\nYou can connect the hardware to your board and start developing code for the driver itself.", 
-            "title": "Add CLI commands for testing drivers"
-        }, 
-        {
-            "location": "/os/tutorials/air_quality_sensor/#use-of-hal-for-drivers", 
-            "text": "The sensor has a serial port connection, and that's how you are going to connect to it. Your original BSP, hw/bsp/arduino_primo_nrf52, has two UARTs set up.\nWe're using one for our shell/console. It also has a second UART set up as a 'bit-bang' UART but since the SenseAir only needs to\ncommunicate at 9600 baud, this bit-banged uart is plenty fast enough.  You'll have to make a small change to the  syscfg.yml  file in your project's target directory to change  the pin definitions \nfor this second UART. Those changes are as follows:      UART_0_PIN_TX: 23\n    UART_0_PIN_RX: 24  With this in place, you can refer to serial port where your SenseAir sensor by a logical number. This makes the code more platform independent - you could connect this sensor to another board, like Olimex. You will also use the HAL UART abstraction to do the UART port setup and data transfer. That way you don't need to have any platform dependent pieces within your little driver.  You w
 ill now see what the driver code ends up looking like. Here's the header file, filled in from the stub you created earlier.  /*   * Licensed to the Apache Software Foundation (ASF) under one   * or more contributor license agreements.  See the NOTICE file   * distributed with this work for additional information   * regarding copyright ownership.  The ASF licenses this file   * to you under the Apache License, Version 2.0 (the   *  License ); you may not use this file except in compliance   * with the License.  You may obtain a copy of the License at   *    *  http://www.apache.org/licenses/LICENSE-2.0   *   * Unless required by applicable law or agreed to in writing,   * software distributed under the License is distributed on an   *  AS IS  BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY   * KIND, either express or implied.  See the License for the   * specific language governing permissions and limitations   * under the License.  */  #ifndef _SENSEAIR_H_  #define _SENSEAIR_H_  enu
 m   senseair_read_type  {\n         SENSEAIR_CO2 ,\n}; int   senseair_init ( int   uartno ); int   senseair_read ( enum   senseair_read_type ); #endif  /* _SENSEAIR_H_ */   As you can see, logical UART number has been added to the init routine. A 'read' function has been added, \nwhich is a blocking read. If you were making a commercial product, you would probably have a callback for reporting the results.  And here is the source for the driver.  /**   * Licensed to the Apache Software Foundation (ASF) under one   * or more contributor license agreements.  See the NOTICE file   * distributed with this work for additional information   * regarding copyright ownership.  The ASF licenses this file   * to you under the Apache License, Version 2.0 (the   *  License ); you may not use this file except in compliance   * with the License.  You may obtain a copy of the License at   *   *  http://www.apache.org/licenses/LICENSE-2.0   *   * Unless required by applicable law or agreed to in wri
 ting,   * software distributed under the License is distributed on an   *  AS IS  BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY   * KIND, either express or implied.  See the License for the   * specific language governing permissions and limitations   * under the License.   */  #include  string.h  #include  shell/shell.h  #include  console/console.h  #include  os/os.h  #include  hal/hal_uart.h  #include  senseair/senseair.h  static   const   uint8_t   cmd_read_co2 []  =  {\n     0xFE ,  0 X44 ,  0 X00 ,  0 X08 ,  0 X02 ,  0 X9F ,  0 X25 \n}; static   int   senseair_shell_func ( int   argc ,  char   **argv ); static   struct   shell_cmd   senseair_cmd   =  {\n    . sc_cmd   =   senseair ,\n    . sc_cmd_func   =   senseair_shell_func ,\n}; struct   senseair  { \n     int   uart ;\n     struct   os_sem   sema ;\n     const   uint8_t   *tx_data ;\n     int   tx_off ;\n     int   tx_len ;\n     uint8_t   rx_data [ 32 ]; \n     int   rx_off ;\n     int   value ;\n}  senseair ; static   i
 nt  senseair_tx_char ( void   *arg )\n{\n     struct   senseair   *s   =   senseair ;\n     int   rc ;\n\n     if  ( s- tx_off   =   s- tx_len ) {\n     /*           * Command tx finished.           */ \n         s- tx_data   =   NULL ;\n         return   - 1 ;\n    }\n\n     rc   =   s- tx_data [ s- tx_off ];\n     s- tx_off++ ;\n     return   rc ;\n} /*   * CRC for modbus over serial port.   */  static   const   uint16_t   mb_crc_tbl []  =  {\n     0x0000 ,  0xcc01 ,  0xd801 ,  0x1400 ,  0xf001 ,  0x3c00 ,  0x2800 ,  0xe401 ,\n     0xa001 ,  0x6c00 ,  0x7800 ,  0xb401 ,  0x5000 ,  0x9c01 ,  0x8801 ,  0x4400 \n}; static   uint16_t  mb_crc ( const   uint8_t   *data ,  int   len ,  uint16_t   crc )\n{\n     while  ( len--     0 ) {\n         crc   ^=   *data++ ;\n         crc   =  ( crc     4 )  ^   mb_crc_tbl [ crc     0xf ];\n         crc   =  ( crc     4 )  ^   mb_crc_tbl [ crc     0xf ];\n    }\n     return   crc ;\n} static   int  mb_crc_check ( const   void   *pkt ,  int   len 
 )\n{\n     uint16_t   crc ,  cmp ;\n     uint8_t   *bp   =  ( uint8_t   * ) pkt ;\n\n     if  ( len     sizeof ( crc )  +   1 ) {\n         return   - 1 ;\n    }\n     crc   =   mb_crc ( pkt ,  len   -   2 ,  0xffff );\n     cmp   =   bp [ len   -   2 ]  |  ( bp [ len   -   1 ]    8 );\n     if  ( crc   !=   cmp ) {\n         return   - 1 ;\n    }  else  {\n         return   0 ;\n    }\n} static   int  senseair_rx_char ( void   *arg ,  uint8_t   data )\n{\n     struct   senseair   *s   =  ( struct   senseair   * ) arg ;\n     int   rc ;\n\n     if  ( s- rx_off   =   sizeof ( s- rx_data )) {\n         s- rx_off   =   0 ;\n    }\n     s- rx_data [ s- rx_off ]  =   data ;\n     s- rx_off++ ;\n\n     if  ( s- rx_off   ==   7 ) {\n         rc   =   mb_crc_check ( s- rx_data ,  s- rx_off );\n         if  ( rc   ==   0 ) {\n             s- value   =   s- rx_data [ 3 ]  *   256   +   s- rx_data [ 4 ];\n             os_sem_release ( s- sema );\n        }\n    }\n     return   0 ;\n} void  se
 nseair_tx ( struct   senseair   *s ,  const   uint8_t   *tx_data ,  int   data_len )\n{\n     s- tx_data   =   tx_data ;\n     s- tx_len   =   data_len ;\n     s- tx_off   =   0 ;\n     s- rx_off   =   0 ;\n\n     hal_uart_start_tx ( s- uart );\n} int  senseair_read ( enum   senseair_read_type   type )\n{\n     struct   senseair   *s   =   senseair ;\n     const   uint8_t   *cmd ;\n     int   cmd_len ;\n     int   rc ;\n\n     if  ( s- tx_data ) {\n         /*           * busy           */ \n         return   - 1 ;\n    }\n     switch  ( type ) {\n     case   SENSEAIR_CO2 :\n         cmd   =   cmd_read_co2 ;\n         cmd_len   =   sizeof ( cmd_read_co2 );\n         break ;\n     default : \n         return   - 1 ;\n    }\n     senseair_tx ( s ,  cmd ,  cmd_len );\n     rc   =   os_sem_pend ( s- sema ,  OS_TICKS_PER_SEC   /   2 );\n     if  ( rc   ==   OS_TIMEOUT ) {\n         /*           * timeout           */ \n         return   - 2 ;\n    }\n     return   s- value ;\n} static   
 int  senseair_shell_func ( int   argc ,  char   **argv )\n{\n     int   value ;\n     enum   senseair_read_type   type ;\n\n     if  ( argc     2 ) { usage :\n         console_printf ( %s co2\\n ,  argv [ 0 ]);\n         return   0 ;\n    }\n     if  ( !strcmp ( argv [ 1 ],  co2 )) {\n         type   =   SENSEAIR_CO2 ;\n    }  else  {\n         goto   usage ;\n    }\n     value   =   senseair_read ( type );\n     if  ( value   =   0 ) {\n         console_printf ( Got %d\\n ,  value );\n    }  else  {\n         console_printf ( Error while reading: %d\\n ,  value );\n    }\n     return   0 ;\n} int  senseair_init ( int   uartno )\n{\n     int   rc ;\n     struct   senseair   *s   =   senseair ;\n\n     rc   =   shell_cmd_register ( senseair_cmd );\n     if  ( rc ) {\n         return   rc ;\n    }\n\n     rc   =   os_sem_init ( s- sema ,  1 );\n     if  ( rc ) {\n         return   rc ;\n    }\n     rc   =   hal_uart_init_cbs ( uartno ,  senseair_tx_char ,  NULL ,\n       senseair_rx_c
 har ,  senseair );\n     if  ( rc ) {\n         return   rc ;\n    }\n     rc   =   hal_uart_config ( uartno ,  9600 ,  8 ,  1 ,  HAL_UART_PARITY_NONE ,\n       HAL_UART_FLOW_CTL_NONE );\n     if  ( rc ) {\n         return   rc ;\n    }\n     s- uart   =   uartno ;\n\n     return   0 ;\n}  And your modified main() for senseair driver init.  int  main ( int   argc ,  char   **argv )\n{\n    ....\n     senseair_init ( 0 );\n    ....\n    }  You can see from the code that you are using the HAL interface to open a UART port, and using OS \nsemaphore as a way of blocking the task when waiting for read response to come back from the sensor.  Now comes the fun part: Hooking up the sensor! It's fun because a) hooking up a sensor is always \nfun and b) the SenseAir sensor's PCB is entirely unlabeled, so you'll have to trust us on how to hook it up.   So here we go.   You'll have to do a little soldering. I soldered some header pins to the SenseAir K30 board to\nmake connecting wires easier u
 sing standard jumper wires, but you can also just solder wires\nstraight to the board if you prefer.  Here's what your SenseAir board should look like once it's wired up:   Now that you have that wired up, let's get the Arduino Primo wired up. A couple of things to note:   The Arduino Primo's 'console' UART is actually UART1.   The secondary (bit-banged) UART is UART0, so that's where we'll have to hook up the SenseAir.   Here's what your Arduino Primo should now look like with everything wired in:   Everything is wired and you're ready to go! Build and load your new app:  $ newt build air_q\nBuilding target targets/air_q\nCompiling apps/air_quality/src/main.c\nArchiving apps_air_quality.a\nLinking myproj/bin/targets/air_q/app/apps/air_quality/air_quality.elf\nTarget successfully built: targets/air_q\n$ newt create-image air_q 1.0.0\nApp image succesfully generated: myproj/bin/targets/air_q/app/apps/air_quality/air_quality.img\n$ newt load air_q\nLoading app image into slot 1  Now, 
 you should be able to connect to your serial port and read values:  user@IsMyLaptop:~]$ minicom -D /dev/tty.usbserial-AH02MIE2\n\n\n    Welcome to minicom 2.7\n\n    OPTIONS: \n    Compiled on Oct 12 2015, 07:48:30.\n    Port /dev/tty.usbserial-AH02MIE2, 13:44:40\n\n    Press CTRL-X Z for help on special keys\n\n    1185:   ?\n    Commands:\n    1382:     stat      echo         ?    prompt     ticks     tasks\n    1390: mempools      date  senseair\n    1395:   senseair\n    senseair co2\n    2143:   senseair co2\n    Got 973  And you're getting valid readings! Congratulations!  Next we'll hook this all up via Bluetooth so that you can read those values remotely.", 
-            "title": "Use of HAL for drivers"
-        }, 
-        {
-            "location": "/os/tutorials/air_quality_ble/", 
-            "text": "Air quality sensor project via Bluetooth\n\n\nThis is a follow-on project to the \nBasic Air Quality Sensor\n project; so it is\nassumed that you have worked through that project and have your CO\n2\n sensor working properly with\nyour Arduino Primo board. \n\n\nSo let's get started making this thing Bluetooth enabled!\n\n\nAdd Bluetooth GATT Services\n\n\nSince we already built the previous demo on the \nbluetooth peripheral\n basic\napp most of the bluetooth plumbing has already been taken care of for us. What's left is for us\nto add the required GATT services for advertising the Carbon Dioxide sensor so that\nother devices can get those values.\n\n\nFirst, we'll define the GATT Services in \napps/air_quality/src/bleprph.h\n.\n\n\n/* Sensor Data */\n\n\n/* e761d2af-1c15-4fa7-af80-b5729002b340 */\n\n\nstatic\n \nconst\n \nble_uuid128_t\n \ngatt_svr_svc_co2_uuid\n \n=\n\n    \nBLE_UUID128_INIT\n(\n0x40\n, \n0xb3\n, \n0x20\n, \n0x90\n, \n0x72\n, \n0xb5\n, \n0x80
 \n, \n0xaf\n,\n                     \n0xa7\n, \n0x4f\n, \n0x15\n, \n0x1c\n, \n0xaf\n, \n0xd2\n, \n0x61\n, \n0xe7\n);\n\n#define CO2_SNS_TYPE          0xDEAD\n\n\n#define CO2_SNS_STRING \nSenseAir K30 CO2 Sensor\n\n\n#define CO2_SNS_VAL           0xBEAD\n\n\n\nuint16_t\n \ngatt_co2_val\n; \n\n\n\n\n\nYou can use any hex values you choose for the sensor type and sensor values, and you can \neven forget the sensor type and sensor string definitions altogether but they make\nthe results look nice in our Bluetooth App for Mac OS X and iOS.\n\n\nNext we'll add those services to \napps/air_quality/src/gatt_svr.c\n.\n\n\nstatic\n \nint\n\n\ngatt_svr_sns_access\n(\nuint16_t\n \nconn_handle\n, \nuint16_t\n \nattr_handle\n,\n    \nstruct\n \nble_gatt_access_ctxt\n \n*ctxt\n,\n    \nvoid\n \n*arg\n);\n\n\nstatic\n \nuint16_t\n \ngatt_co2_val_len\n;\n\n\n\n\n\nMake sure it is added as \nprimary\n service.\n\n\nstatic\n \nconst\n \nstruct\n \nble_gatt_svc_def\n \ngatt_svr_svcs\n[] \n=\n {\n    {\
 n        \n/*** Service: Security test. */\n\n        .\ntype\n \n=\n \nBLE_GATT_SVC_TYPE_PRIMARY\n,\n        .\nuuid\n \n=\n \ngatt_svr_svc_sec_test_uuid\n.\nu\n,\n        .\ncharacteristics\n \n=\n (\nstruct\n \nble_gatt_chr_def\n[]) { {\n            \n/*** Characteristic: Random number generator. */\n\n            .\nuuid\n \n=\n \ngatt_svr_chr_sec_test_rand_uuid\n.\nu\n,\n            .\naccess_cb\n \n=\n \ngatt_svr_chr_access_sec_test\n,\n            .\nflags\n \n=\n \nBLE_GATT_CHR_F_READ\n \n|\n \nBLE_GATT_CHR_F_READ_ENC\n,\n        }, {\n            \n/*** Characteristic: Static value. */\n\n            .\nuuid\n \n=\n \ngatt_svr_chr_sec_test_static_uuid\n,.\nu\n\n            .\naccess_cb\n \n=\n \ngatt_svr_chr_access_sec_test\n,\n            .\nflags\n \n=\n \nBLE_GATT_CHR_F_READ\n \n|\n\n                     \nBLE_GATT_CHR_F_WRITE\n \n|\n \nBLE_GATT_CHR_F_WRITE_ENC\n,\n        }, {\n            \n0\n, \n/* No more characteristics in this service. */\n\n        } },\n    },\n
         {\n            \n/*** CO2 Level Notification Service. */\n\n            .\ntype\n \n=\n \nBLE_GATT_SVC_TYPE_PRIMARY\n,\n            .\nuuid\n \n=\n \ngatt_svr_svc_co2_uuid\n.\nu\n,\n            .\ncharacteristics\n \n=\n (\nstruct\n \nble_gatt_chr_def\n[]) { {\n                .\nuuid\n \n=\n \nBLE_UUID16_DECLARE\n(\nCO2_SNS_TYPE\n),\n                .\naccess_cb\n \n=\n \ngatt_svr_sns_access\n,\n                .\nflags\n \n=\n \nBLE_GATT_CHR_F_READ\n,\n            }, {\n                .\nuuid\n \n=\n \nBLE_UUID16_DECLARE\n(\nCO2_SNS_VAL\n),\n                .\naccess_cb\n \n=\n \ngatt_svr_sns_access\n,\n                .\nflags\n \n=\n \nBLE_GATT_CHR_F_NOTIFY\n,\n            }, {\n                \n0\n, \n/* No more characteristics in this service. */\n\n            } },\n        },\n\n        {\n            \n0\n, \n/* No more services. */\n\n        },\n    };\n\n\n\n\n\nNext we need to tell the GATT Server how to handle requests for CO\n2\n readings :\n\n\nsstatic\n \n
 int\n\n\ngatt_svr_sns_access\n(\nuint16_t\n \nconn_handle\n, \nuint16_t\n \nattr_handle\n,\n                          \nstruct\n \nble_gatt_access_ctxt\n \n*ctxt\n,\n                          \nvoid\n \n*arg\n)\n{\n    \nuint16_t\n \nuuid16\n;\n    \nint\n \nrc\n;\n\n    \nuuid16\n \n=\n \nble_uuid_u16\n(\nctxt-\nchr-\nuuid\n);\n\n    \nswitch\n (\nuuid16\n) {\n    \ncase\n \nCO2_SNS_TYPE\n:\n        \nassert\n(\nctxt-\nop\n \n==\n \nBLE_GATT_ACCESS_OP_READ_CHR\n);\n        \nrc\n \n=\n \nos_mbuf_append\n(\nctxt-\nom\n, \nCO2_SNS_STRING\n, \nsizeof\n \nCO2_SNS_STRING\n);\n        \nBLEPRPH_LOG\n(\nINFO\n, \nCO2 SENSOR TYPE READ: %s\\n\n, \nCO2_SNS_STRING\n);\n        \nreturn\n \nrc\n \n==\n \n0\n \n?\n \n0\n \n:\n \nBLE_ATT_ERR_INSUFFICIENT_RES\n;\n\n    \ncase\n \nCO2_SNS_VAL\n:\n        \nif\n (\nctxt-\nop\n \n==\n \nBLE_GATT_ACCESS_OP_WRITE_CHR\n) {\n            \nrc\n \n=\n \ngatt_svr_chr_write\n(\nctxt-\nom\n, \n0\n,\n                                    \nsizeof\n \ngatt_co2_v
 al\n,\n                                    \ngatt_co2_val\n,\n                                    \ngatt_co2_val_len\n);\n            \nreturn\n \nrc\n;\n        } \nelse\n \nif\n (\nctxt-\nop\n \n==\n \nBLE_GATT_ACCESS_OP_READ_CHR\n) {\n            \nrc\n \n=\n \nos_mbuf_append\n(\nctxt-\nom\n, \ngatt_co2_val\n,\n                                \nsizeof\n \ngatt_co2_val\n);\n            \nreturn\n \nrc\n \n==\n \n0\n \n?\n \n0\n \n:\n \nBLE_ATT_ERR_INSUFFICIENT_RES\n;\n        }\n\n    \ndefault\n:\n\n        \nassert\n(\n0\n);\n        \nreturn\n \nBLE_ATT_ERR_UNLIKELY\n;\n    }\n}\n\n\n\n\n\nNow it's time to go into our \napps/air_quality/src/main.c\n and change how we read CO\n2\n readings and \nrespond to requests. \n\n\nWe'll need a task handler with an event queue for the CO\n2\n readings -- they were handled by the shell task in the previous tutorial but now it needs to be replaced by a different handler as shown below.\n\n\n/* CO2 Task settings */\n\n\n#define CO2_TASK_PRIO
            5\n\n\n#define CO2_STACK_SIZE          (OS_STACK_ALIGN(336))\n\n\nstruct\n \nos_eventq\n \nco2_evq\n;\n\nstruct\n \nos_task\n \nco2_task\n;\n\nbssnz_t\n \nos_stack_t\n \nco2_stack\n[\nCO2_STACK_SIZE\n];\n\n\n\n\n\nAnd of course we'll need to go to our \nmain()\n and do all the standard task and event setup we\nnormally do by adding the following. Again, remember to delete all the shell event queues and tasks.\n\n\n/* Initialize sensor eventq */\n\n\nos_eventq_init\n(\nco2_evq\n);\n\n\n/* Create the CO2 reader task.  \n\n\n * All sensor reading operations are performed in this task.\n\n\n */\n\n\nos_task_init\n(\nco2_task\n, \nsensor\n, \nco2_task_handler\n,\n            \nNULL\n, \nCO2_TASK_PRIO\n, \nOS_WAIT_FOREVER\n,\n            \nco2_stack\n, \nCO2_STACK_SIZE\n);\n\n\n\n\n\nWe'll also need to add a task handler -- since we initialized it above:\n\n\n/**\n\n\n * Event loop for the sensor task.\n\n\n */\n\n\nstatic\n \nvoid\n\n\nco2_task_handler\n(\nvoid\n \n*unused\n)\
 n{    \n    \nwhile\n (\n1\n) {\n        \nco2_read_event\n();\n        \n/* Wait 2 second */\n\n        \nos_time_delay\n(\nOS_TICKS_PER_SEC\n \n*\n \n2\n);\n\n    }\n}\n\n\n\n\n\nAnd finally, we'll take care of that \nco2_read_event()\n function:\n\n\nint\n\n\nco2_read_event\n(\nvoid\n)\n{\n    \nint\n \nvalue\n;\n    \nenum\n \nsenseair_read_type\n \ntype\n \n=\n \nSENSEAIR_CO2\n;\n    \nuint16_t\n \nchr_val_handle\n;\n    \nint\n \nrc\n;\n\n    \nvalue\n \n=\n \nsenseair_read\n(\ntype\n);\n    \nif\n (\nvalue\n \n=\n \n0\n) {\n        \nconsole_printf\n(\nGot %d\\n\n, \nvalue\n);\n    } \nelse\n {\n        \nconsole_printf\n(\nError while reading: %d\\n\n, \nvalue\n);\n        \ngoto\n \nerr\n;\n    }\n    \ngatt_co2_val\n \n=\n \nvalue\n;\n    \nrc\n \n=\n \nble_gatts_find_chr\n(\ngatt_svr_svc_co2_uuid\n.\nu\n, \nBLE_UUID16_DECLARE\n(\nCO2_SNS_VAL\n), \nNULL\n, \nchr_val_handle\n);\n    \nassert\n(\nrc\n \n==\n \n0\n);\n    \nble_gatts_chr_updated\n(\nchr_val_handle\n);\n    \n
 return\n (\n0\n);\n\nerr\n:\n    \nreturn\n (\nrc\n);\n}\n\n\n\n\n\nYou'll notice that it looks eeirily similar to a portion of the shell event we created \nearlier. This one simply reads and updates the CO\n2\n value and sends that over BLE to any\nconnected clients instead. \n\n\nWe can now build, create-image and load the app onto our Arduino Primo board, and then \nconnect and see the updated values! The image below shows the results using MyNewt Sensor Reader,\na Mac OS X app developed for connecting to MyNewt devices over Bluetooth but you can also use LightBlue\nor any other application that can connect to, and read, Bluetooth data.\n\n\n\n\nCongratulations!!", 
-            "title": "Bluetooth-enabled Air Quality Sensor"
-        }, 
-        {
-            "location": "/os/tutorials/air_quality_ble/#air-quality-sensor-project-via-bluetooth", 
-            "text": "This is a follow-on project to the  Basic Air Quality Sensor  project; so it is\nassumed that you have worked through that project and have your CO 2  sensor working properly with\nyour Arduino Primo board.   So let's get started making this thing Bluetooth enabled!", 
-            "title": "Air quality sensor project via Bluetooth"
-        }, 
-        {
-            "location": "/os/tutorials/air_quality_ble/#add-bluetooth-gatt-services", 
-            "text": "Since we already built the previous demo on the  bluetooth peripheral  basic\napp most of the bluetooth plumbing has already been taken care of for us. What's left is for us\nto add the required GATT services for advertising the Carbon Dioxide sensor so that\nother devices can get those values.  First, we'll define the GATT Services in  apps/air_quality/src/bleprph.h .  /* Sensor Data */  /* e761d2af-1c15-4fa7-af80-b5729002b340 */  static   const   ble_uuid128_t   gatt_svr_svc_co2_uuid   = \n     BLE_UUID128_INIT ( 0x40 ,  0xb3 ,  0x20 ,  0x90 ,  0x72 ,  0xb5 ,  0x80 ,  0xaf ,\n                      0xa7 ,  0x4f ,  0x15 ,  0x1c ,  0xaf ,  0xd2 ,  0x61 ,  0xe7 ); #define CO2_SNS_TYPE          0xDEAD  #define CO2_SNS_STRING  SenseAir K30 CO2 Sensor  #define CO2_SNS_VAL           0xBEAD  uint16_t   gatt_co2_val ;   You can use any hex values you choose for the sensor type and sensor values, and you can \neven forget the sensor type and sensor string definitions alt
 ogether but they make\nthe results look nice in our Bluetooth App for Mac OS X and iOS.  Next we'll add those services to  apps/air_quality/src/gatt_svr.c .  static   int  gatt_svr_sns_access ( uint16_t   conn_handle ,  uint16_t   attr_handle ,\n     struct   ble_gatt_access_ctxt   *ctxt ,\n     void   *arg ); static   uint16_t   gatt_co2_val_len ;  Make sure it is added as  primary  service.  static   const   struct   ble_gatt_svc_def   gatt_svr_svcs []  =  {\n    {\n         /*** Service: Security test. */ \n        . type   =   BLE_GATT_SVC_TYPE_PRIMARY ,\n        . uuid   =   gatt_svr_svc_sec_test_uuid . u ,\n        . characteristics   =  ( struct   ble_gatt_chr_def []) { {\n             /*** Characteristic: Random number generator. */ \n            . uuid   =   gatt_svr_chr_sec_test_rand_uuid . u ,\n            . access_cb   =   gatt_svr_chr_access_sec_test ,\n            . flags   =   BLE_GATT_CHR_F_READ   |   BLE_GATT_CHR_F_READ_ENC ,\n        }, {\n             /*** Charact
 eristic: Static value. */ \n            . uuid   =   gatt_svr_chr_sec_test_static_uuid ,. u \n            . access_cb   =   gatt_svr_chr_access_sec_test ,\n            . flags   =   BLE_GATT_CHR_F_READ   | \n                      BLE_GATT_CHR_F_WRITE   |   BLE_GATT_CHR_F_WRITE_ENC ,\n        }, {\n             0 ,  /* No more characteristics in this service. */ \n        } },\n    },\n        {\n             /*** CO2 Level Notification Service. */ \n            . type   =   BLE_GATT_SVC_TYPE_PRIMARY ,\n            . uuid   =   gatt_svr_svc_co2_uuid . u ,\n            . characteristics   =  ( struct   ble_gatt_chr_def []) { {\n                . uuid   =   BLE_UUID16_DECLARE ( CO2_SNS_TYPE ),\n                . access_cb   =   gatt_svr_sns_access ,\n                . flags   =   BLE_GATT_CHR_F_READ ,\n            }, {\n                . uuid   =   BLE_UUID16_DECLARE ( CO2_SNS_VAL ),\n                . access_cb   =   gatt_svr_sns_access ,\n                . flags   =   BLE_GATT_CHR_F_
 NOTIFY ,\n            }, {\n                 0 ,  /* No more characteristics in this service. */ \n            } },\n        },\n\n        {\n             0 ,  /* No more services. */ \n        },\n    };  Next we need to tell the GATT Server how to handle requests for CO 2  readings :  sstatic   int  gatt_svr_sns_access ( uint16_t   conn_handle ,  uint16_t   attr_handle ,\n                           struct   ble_gatt_access_ctxt   *ctxt ,\n                           void   *arg )\n{\n     uint16_t   uuid16 ;\n     int   rc ;\n\n     uuid16   =   ble_uuid_u16 ( ctxt- chr- uuid );\n\n     switch  ( uuid16 ) {\n     case   CO2_SNS_TYPE :\n         assert ( ctxt- op   ==   BLE_GATT_ACCESS_OP_READ_CHR );\n         rc   =   os_mbuf_append ( ctxt- om ,  CO2_SNS_STRING ,  sizeof   CO2_SNS_STRING );\n         BLEPRPH_LOG ( INFO ,  CO2 SENSOR TYPE READ: %s\\n ,  CO2_SNS_STRING );\n         return   rc   ==   0   ?   0   :   BLE_ATT_ERR_INSUFFICIENT_RES ;\n\n     case   CO2_SNS_VAL :\n       
   if  ( ctxt- op   ==   BLE_GATT_ACCESS_OP_WRITE_CHR ) {\n             rc   =   gatt_svr_chr_write ( ctxt- om ,  0 ,\n                                     sizeof   gatt_co2_val ,\n                                     gatt_co2_val ,\n                                     gatt_co2_val_len );\n             return   rc ;\n        }  else   if  ( ctxt- op   ==   BLE_GATT_ACCESS_OP_READ_CHR ) {\n             rc   =   os_mbuf_append ( ctxt- om ,  gatt_co2_val ,\n                                 sizeof   gatt_co2_val );\n             return   rc   ==   0   ?   0   :   BLE_ATT_ERR_INSUFFICIENT_RES ;\n        }\n\n     default : \n         assert ( 0 );\n         return   BLE_ATT_ERR_UNLIKELY ;\n    }\n}  Now it's time to go into our  apps/air_quality/src/main.c  and change how we read CO 2  readings and \nrespond to requests.   We'll need a task handler with an event queue for the CO 2  readings -- they were handled by the shell task in the previous tutorial but now it needs to be replaced by
  a different handler as shown below.  /* CO2 Task settings */  #define CO2_TASK_PRIO           5  #define CO2_STACK_SIZE          (OS_STACK_ALIGN(336))  struct   os_eventq   co2_evq ; struct   os_task   co2_task ; bssnz_t   os_stack_t   co2_stack [ CO2_STACK_SIZE ];  And of course we'll need to go to our  main()  and do all the standard task and event setup we\nnormally do by adding the following. Again, remember to delete all the shell event queues and tasks.  /* Initialize sensor eventq */  os_eventq_init ( co2_evq ); /* Create the CO2 reader task.     * All sensor reading operations are performed in this task.   */  os_task_init ( co2_task ,  sensor ,  co2_task_handler ,\n             NULL ,  CO2_TASK_PRIO ,  OS_WAIT_FOREVER ,\n             co2_stack ,  CO2_STACK_SIZE );  We'll also need to add a task handler -- since we initialized it above:  /**   * Event loop for the sensor task.   */  static   void  co2_task_handler ( void   *unused )\n{    \n     while  ( 1 ) {\n         co2
 _read_event ();\n         /* Wait 2 second */ \n         os_time_delay ( OS_TICKS_PER_SEC   *   2 );\n\n    }\n}  And finally, we'll take care of that  co2_read_event()  function:  int  co2_read_event ( void )\n{\n     int   value ;\n     enum   senseair_read_type   type   =   SENSEAIR_CO2 ;\n     uint16_t   chr_val_handle ;\n     int   rc ;\n\n     value   =   senseair_read ( type );\n     if  ( value   =   0 ) {\n         console_printf ( Got %d\\n ,  value );\n    }  else  {\n         console_printf ( Error while reading: %d\\n ,  value );\n         goto   err ;\n    }\n     gatt_co2_val   =   value ;\n     rc   =   ble_gatts_find_chr ( gatt_svr_svc_co2_uuid . u ,  BLE_UUID16_DECLARE ( CO2_SNS_VAL ),  NULL ,  chr_val_handle );\n     assert ( rc   ==   0 );\n     ble_gatts_chr_updated ( chr_val_handle );\n     return  ( 0 ); err :\n     return  ( rc );\n}  You'll notice that it looks eeirily similar to a portion of the shell event we created \nearlier. This one simply reads and up
 dates the CO 2  value and sends that over BLE to any\nconnected clients instead.   We can now build, create-image and load the app onto our Arduino Primo board, and then \nconnect and see the updated values! The image below shows the results using MyNewt Sensor Reader,\na Mac OS X app developed for connecting to MyNewt devices over Bluetooth but you can also use LightBlue\nor any other application that can connect to, and read, Bluetooth data.   Congratulations!!", 
-            "title": "Add Bluetooth GATT Services"
-        }, 
-        {
             "location": "/os/tutorials/event_queue/", 
             "text": "How to define a task which uses event queues to manage multiple events\n\n\nIntroduction\n\n\nEvent queue is a mechanism by which you can serialize incoming events for your task. You can use it to get info about arrived hardware interrupts, callout expirations and messages from other tasks.\n\n\nThe benefit of doing inter-task communication this way is that there should be less resources that need to be locked.\n\n\nThe benefit of doing interrupt processing in a task context instead of inside an interrupt context is that you are not blocking other HW interrupts when doing the work. The same goes for high priority tasks in the system; they're blocked until the interrupt handler returns. From the task context you'll also be able to access other OS facilities; you can sleep while waiting for a lock, for example.\n\n\n\n\nExample app\n\n\nHere you are going to write an app which demonstrates the use of event queues for communication between tasks. You will  also use
  OS callouts for timer expiration and another event from a GPIO interrupt.\n\n\nYou will  use inputs from 3 sources to toggle 3 GPIO outputs on my STM32F3discovery board.\n\n\n\n\nCreate project\n\n\nYou start by creating a project and populating it with repositories incubator-mynewt-core and mynewt_stm32f3. See \nSTM32F3 tutorial\n if you need help with this. You can also read the tutorial on \nAdditional Repositories\n for a more thorough understanding. \n\n\n \n\n\nCreate application\n\n\nHere's what the pkg.yml looks for the application.\n\n\n[marko@IsMyLaptop:~/src/events]$ cat apps/event_sample/pkg.yml\npkg.name: apps/event_sample\npkg.type: app\n\npkg.deps:\n    - \n@apache-mynewt-core/libs/os\n\n    - \n@apache-mynewt-core/hw/hal\n\n    - \n@apache-mynewt-core/libs/console/stub\n\n\n\n\n\n\n\n\nInitialize the event queue structure\n\n\nThis must be done before anyone tries to place events to the queue. Here it's done before any task gets created. Initialization is done by ca
 lling \nos_eventq_init()\n.\n\n\n#define MY_TASK_PRIO        4\n\n\n#define MY_TASK_STACK_SZ    512\n\n\n\nstatic\n \nstruct\n \nos_eventq\n \nmy_eventq\n;\n\nstatic\n \nos_stack_t\n \nmy_task_stack\n[\nMY_TASK_STACK_SZ\n];\n\nstatic\n \nstruct\n \nos_task\n \nmy_task_str\n;\n\n\nvoid\n\n\ninit_tasks\n(\nvoid\n)\n{\n    \nstruct\n \nos_task\n \ntaskid\n;\n\n    \nos_eventq_init\n(\nmy_eventq\n);\n    \nos_task_init\n(\nmy_task_str\n, \ntask\n, \nmy_task\n, \nNULL\n, \nMY_TASK_PRIO\n,\n        \nOS_WAIT_FOREVER\n, \nmy_task_stack\n, \nMY_TASK_STACK_SZ\n);\n\n\n\n\n\n\n\nProcessing events\n\n\nHere event processing is done inside \nmy_task\n. The main loop of the task is pulling events from the queue, and then taking action. We look at the type of the event to figure out what to do.\n\n\nThe code snippet shows what the main loop of the event handler looks like. Events are removed from the head of the queue using os_eventq_get\n\n\nvoid\n\n\nmy_task\n(\nvoid\n \n*arg\n)\n{\n    \nstruc
 t\n \nos_event\n \n*ev\n;\n\n    \nwhile\n (\n1\n) {\n        \nev\n \n=\n \nos_eventq_get\n(\nmy_eventq\n);\n        \nswitch\n (\nev-\nev_type\n) {\n        \n/* more event types here */\n\n        \ndefault\n:\n\n            \nassert\n(\n0\n);\n        }\n    }\n}\n\n\n\n\n\n\n\nEvent types\n\n\nYou can define your own event types. Some numbers are already reserved by the OS, so you should not use those as your own types.\n\n\nReserved event types are defined in \nlibs/os/include/os/os_eventq.h\n. One example of a reserved type is OS_EVENT_T_TIMER, which is used as type in OS callouts.\n\n\nYou should start your event numbers from \nOS_EVENT_T_PERUSER\n, and go higher.\n\n\nYou are going to generate events from GPIO interrupt handler, from another task as well as from a callout. OS callout already has a type, but you'll need to define types for the other uses.\n\n\n#define MY_TASK_GPIO_EVENT  (OS_EVENT_T_PERUSER)\n\n\n#define MY_TASK_TASK_EVENT  (OS_EVENT_T_PERUSER + 1)\n\n\n\n\n
 \n\n\n\nPosting events from another task\n\n\nEvents are posted to a queue by calling \nos_eventq_put()\n. You need to preallocate memory for the event structure. Here it's done by declaring the event structure as a global variable.\n\n\nNote that you can call \nos_eventq_put()\n with an event which has already been queued. In that case, the call has no effect; the position of the event is not changed within the queue.\n\n\nIn the code snippet we declare the os_event structure, and initialize it. We also create the event generating task, and periodically post event to the event queue.\n\n\n#define GEN_TASK_PRIO       3\n\n\n#define GEN_TASK_STACK_SZ   512\n\n\n\nstatic\n \nstruct\n \nos_event\n \ngen_task_ev\n;\n\nstatic\n \nos_stack_t\n \ngen_task_stack\n[\nGEN_TASK_STACK_SZ\n];\n\nstatic\n \nstruct\n \nos_task\n \ngen_task_str\n;\n\n\nvoid\n\n\ngen_task\n(\nvoid\n \n*arg\n)\n{\n    \nwhile\n (\n1\n) {\n        \nos_time_delay\n(\nOS_TICKS_PER_SEC\n \n/\n \n4\n);\n        \nos_even
 tq_put\n(\nmy_eventq\n, \ngen_task_ev\n);\n    }\n}\n\n\nvoid\n\n\ninit_tasks\n(\nvoid\n)\n{\n    \n/* .... */\n\n    \ngen_task_ev\n.\nev_type\n \n=\n \nMY_TASK_TASK_EVENT\n;\n    \nos_task_init\n(\ngen_task_str\n, \ngen_task\n, \ngen_task\n, \nNULL\n, \nGEN_TASK_PRIO\n,\n        \nOS_WAIT_FOREVER\n, \ngen_task_stack\n, \nGEN_TASK_STACK_SZ\n);\n}\n\n\n\n\n\n\n\nCallout events\n\n\nYou can get timer events delivered to your task's event queue with OS callout. Check \ncallout documentation\n for description on how to use the API.\n\n\nFor this example, you'll use only one type of callout; so you can use the simpler structure.\n\n\nIn the code snippet we declare the os_callout structure and initialize it. Then we arm the timer.\n\n\nstatic\n \nstruct\n \nos_callout\n \nmy_callout\n;\n\n\nvoid\n\n\ninit_tasks\n(\nvoid\n)\n{\n    \n/* .... */\n\n\n    \nos_callout_init\n(\nmy_callout\n, \nmy_eventq\n, \nNULL\n);\n    \nos_callout_reset\n(\nmy_callout\n, \nOS_TICKS_PER_SEC\n);\n}\n\n\n\n
 \n\n\n\nPosting events from interrupt handler\n\n\nAnother place where posting events makes sense is from an interrupt handler. In this tutorial you will do it when GPIO changes state.\n\n\nYou'll use HAL GPIO interface to register a routine which is getting called from the interrupt handler context. This routine will then post event to your queue.\n\n\nOn STM32F3Discovery board, there is a button connected to PA0. The identifier for this GPIO pin is 0.\n\n\nstatic\n \nstruct\n \nos_event\n \ngpio_ev\n;\n\n\nvoid\n\n\ninit_tasks\n(\nvoid\n)\n{\n    \n/* .... */\n\n\n    \ngpio_ev\n.\nev_type\n \n=\n \nMY_TASK_GPIO_EVENT\n;\n    \nhal_gpio_irq_init\n(\n0\n, \nmy_gpio_irq\n, \nNULL\n, \nGPIO_TRIG_RISING\n,\n        \nGPIO_PULL_NONE\n);\n    \nhal_gpio_irq_enable\n(\n0\n);\n}\n\n\nstatic\n \nvoid\n\n\nmy_gpio_irq\n(\nvoid\n \n*arg\n)\n{\n    \nos_eventq_put\n(\nmy_eventq\n, \ngpio_ev\n);\n}\n\n\n\n\n\n\n\nEvent processing finalized\n\n\nNow that you are posting events from different so
 urces, you will fill in the parts in the task main loop to trigger different behaviors depending on event type.\n\n\nYou'll drive different LEDs depending on what type of event arrived. LEDs on this board are connected to PE8, PE9, PE10 and so on. These have GPIO identifiers starting from 72 onwards.\n\n\n#define TASK_LED        72\n\n\n#define CALLOUT_LED     73\n\n\n#define GPIO_LED        74\n\n\n\nvoid\n\n\ninit_tasks\n(\nvoid\n)\n{\n    \n/* .... */\n\n    \nhal_gpio_init_out\n(\nTASK_LED\n, \n1\n);\n    \nhal_gpio_init_out\n(\nCALLOUT_LED\n, \n1\n);\n    \nhal_gpio_init_out\n(\nGPIO_LED\n, \n1\n);\n}\n\n\n\n\n\nAnd here is the new main loop for your task. Note that when callout event arrives, we re-arm the callout.\n\n\nvoid\n\n\nmy_task\n(\nvoid\n \n*arg\n)\n{\n    \nstruct\n \nos_event\n \n*ev\n;\n\n    \nwhile\n (\n1\n) {\n        \nev\n \n=\n \nos_eventq_get\n(\nmy_eventq\n);\n        \nswitch\n (\nev-\nev_type\n) {\n        \ncase\n \nMY_TASK_TASK_EVENT\n:\n            \n
 hal_gpio_toggle\n(\nTASK_LED\n);\n            \nbreak\n;\n        \ncase\n \nOS_EVENT_T_TIMER\n:\n            \nhal_gpio_toggle\n(\nCALLOUT_LED\n);\n            \nos_callout_reset\n(\nmy_callout\n, \nOS_TICKS_PER_SEC\n \n/\n \n2\n);\n            \nbreak\n;\n        \ncase\n \nMY_TASK_GPIO_EVENT\n:\n            \nhal_gpio_toggle\n(\nGPIO_LED\n);\n            \nbreak\n;\n        \ndefault\n:\n\n            \nassert\n(\n0\n);\n        }\n    }\n}\n\n\n\n\n\n\n\nNow you're done. Once you load this to your board, the task LED will blink at an interval of 250ms, the callout LED with an interval of 500ms, and the GPIO LED every time you press the button.\n\n\n\n\nCode for the example\n\n\n#include \nos/os.h\n\n\n#include \nbsp/bsp.h\n\n\n#include \nhal/hal_gpio.h\n\n\n#include \nassert.h\n\n\n\n\n#define MY_TASK_PRIO        4\n\n\n#define MY_TASK_STACK_SZ    512\n\n\n\n#define GEN_TASK_PRIO       3\n\n\n#define GEN_TASK_STACK_SZ   512\n\n\n\n#define MY_TASK_GPIO_EVENT  (OS_EVENT_T_PERUSER)
 \n\n\n#define MY_TASK_TASK_EVENT  (OS_EVENT_T_PERUSER + 1)\n\n\n\n#define TASK_LED        72\n\n\n#define CALLOUT_LED     73\n\n\n#define GPIO_LED        74\n\n\n\nstatic\n \nstruct\n \nos_eventq\n \nmy_eventq\n;\n\nstatic\n \nos_stack_t\n \nmy_task_stack\n[\nMY_TASK_STACK_SZ\n];\n\nstatic\n \nstruct\n \nos_task\n \nmy_task_str\n;\n\n\nstatic\n \nstruct\n \nos_event\n \ngen_task_ev\n;\n\nstatic\n \nos_stack_t\n \ngen_task_stack\n[\nGEN_TASK_STACK_SZ\n];\n\nstatic\n \nstruct\n \nos_task\n \ngen_task_str\n;\n\n\nstatic\n \nstruct\n \nos_callout\n \nmy_callout\n;\n\n\nstatic\n \nstruct\n \nos_event\n \ngpio_ev\n;\n\n\nvoid\n\n\nmy_task\n(\nvoid\n \n*arg\n)\n{\n    \nstruct\n \nos_event\n \n*ev\n;\n\n    \nwhile\n (\n1\n) {\n        \nev\n \n=\n \nos_eventq_get\n(\nmy_eventq\n);\n        \nswitch\n (\nev-\nev_type\n) {\n        \ncase\n \nMY_TASK_TASK_EVENT\n:\n            \nhal_gpio_toggle\n(\nTASK_LED\n);\n            \nbreak\n;\n        \ncase\n \nOS_EVENT_T_TIMER\n:\n            \nh
 al_gpio_toggle\n(\nCALLOUT_LED\n);\n            \nos_callout_reset\n(\nmy_callout\n, \nOS_TICKS_PER_SEC\n \n/\n \n2\n);\n            \nbreak\n;\n        \ncase\n \nMY_TASK_GPIO_EVENT\n:\n            \nhal_gpio_toggle\n(\nGPIO_LED\n);\n            \nbreak\n;\n        \ndefault\n:\n\n            \nassert\n(\n0\n);\n        }\n    }\n}\n\n\nstatic\n \nvoid\n\n\nmy_gpio_irq\n(\nvoid\n \n*arg\n)\n{\n    \nos_eventq_put\n(\nmy_eventq\n, \ngpio_ev\n);\n}\n\n\nvoid\n\n\ngen_task\n(\nvoid\n \n*arg\n)\n{\n    \nwhile\n (\n1\n) {\n        \nos_time_delay\n(\nOS_TICKS_PER_SEC\n \n/\n \n4\n);\n        \nos_eventq_put\n(\nmy_eventq\n, \ngen_task_ev\n);\n    }\n}\n\n\nvoid\n\n\ninit_tasks\n(\nvoid\n)\n{\n    \nos_eventq_init\n(\nmy_eventq\n);\n    \nos_task_init\n(\nmy_task_str\n, \ntask\n, \nmy_task\n, \nNULL\n, \nMY_TASK_PRIO\n,\n        \nOS_WAIT_FOREVER\n, \nmy_task_stack\n, \nMY_TASK_STACK_SZ\n);\n\n    \ngen_task_ev\n.\nev_type\n \n=\n \nMY_TASK_TASK_EVENT\n;\n    \nos_task_init\n(\ngen_task
 _str\n, \ngen_task\n, \ngen_task\n, \nNULL\n, \nGEN_TASK_PRIO\n,\n        \nOS_WAIT_FOREVER\n, \ngen_task_stack\n, \nGEN_TASK_STACK_SZ\n);\n\n    \nos_callout_init\n(\nmy_callout\n, \nmy_eventq\n, \nNULL\n);\n    \nos_callout_reset\n(\nmy_callout\n, \nOS_TICKS_PER_SEC\n);\n\n    \ngpio_ev\n.\nev_type\n \n=\n \nMY_TASK_GPIO_EVENT\n;\n    \nhal_gpio_irq_init\n(\n0\n, \nmy_gpio_irq\n, \nNULL\n, \nGPIO_TRIG_RISING\n,\n        \nGPIO_PULL_NONE\n);\n    \nhal_gpio_irq_enable\n(\n0\n);\n\n    \nhal_gpio_init_out\n(\nTASK_LED\n, \n1\n);\n    \nhal_gpio_init_out\n(\nCALLOUT_LED\n, \n1\n);\n    \nhal_gpio_init_out\n(\nGPIO_LED\n, \n1\n);\n}\n\n\nint\n\n\nmain\n(\nint\n \nargc\n, \nchar\n \n**argv\n)\n{\n    \nos_init\n();\n\n    \ninit_tasks\n();\n    \nos_start\n();\n    \nassert\n(\n0\n);\n    \nreturn\n \n0\n;\n}", 
             "title": "Add task to manage multiple events"
@@ -1966,6 +1916,146 @@
             "title": "Start btmgmt to send commands"
         }, 
         {
+            "location": "/os/tutorials/air_quality_sensor/", 
+            "text": "Air quality sensor project\n\n\nSetting up source tree for stuff you need\n\n\nTo start with, you need to create a new project under which you will do this development. So you type in:\n\n\n    $ mkdir $HOME/src\n    $ cd $HOME/src\n    $ newt new air_quality\n\n\n\n\n\nLet's say you are using Arduino Primo -- which is based on the Nordic Semi NRF52 chip -- as the platform. \nYou know you need the board support package for that hardware. You can look up its location, add it your \nproject, and fetch that along with the core OS components. Luckily, the Arduino Primo is supported in the \nMynewt Core, so there's nothing much to do here. \n\n\nYour project.yml file shoul

<TRUNCATED>


[2/9] incubator-mynewt-site git commit: Added etape sensor tutorial. PR #152.

Posted by ad...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/nrf52_adc/index.html
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/nrf52_adc/index.html b/latest/os/tutorials/nrf52_adc/index.html
new file mode 100644
index 0000000..b007e1e
--- /dev/null
+++ b/latest/os/tutorials/nrf52_adc/index.html
@@ -0,0 +1,1305 @@
+<!DOCTYPE html>
+<html lang="en">
+    <head>
+        <meta charset="utf-8">
+        <meta http-equiv="X-UA-Compatible" content="IE=edge">
+        <meta name="viewport" content="width=device-width, initial-scale=1.0">
+        
+        
+        <!-- This is broken by doc revisioning.
+        <link rel="canonical" href="http://mynewt.apache.org/os/tutorials/nrf52_adc/"> -->
+        <link rel="shortcut icon" href="../../../img/favicon.ico">
+
+	    <title>Add an Analog Sensor - Apache Mynewt</title>
+
+        <link href="../../../css/bootstrap-3.0.3.min.css" rel="stylesheet">
+        <link rel="stylesheet" href="../../../css/highlight.css">
+        <link href="../../../css/base.css" rel="stylesheet">
+        <link href="../../../css/custom.css" rel="stylesheet">
+        <link href="../../../css/v2.css" rel="stylesheet">
+        <link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
+        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
+        <link href="../../../extra.css" rel="stylesheet">
+
+        <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
+        <!--[if lt IE 9]>
+            <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
+            <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
+        <![endif]-->
+
+        
+            <script>
+                (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
+                (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
+                m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
+                })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
+
+                ga('create', 'UA-72162311-1', 'auto');
+                ga('send', 'pageview');
+            </script>
+        
+    </head>
+
+
+    <body class="Add an Analog Sensor">
+
+
+        <div class="container">
+    <div class="row v2-main-banner">
+        <a class="logo-cell" href="/">
+            <img class="logo" src="/img/logo.png">
+        </a>
+        <div class="tagline-cell">
+            <h4 class="tagline">An OS to build, deploy and securely manage billions of devices</h4>
+        </div>
+        <div class="news-cell">
+            <div class="well">
+                <h4>Latest News:</h4> <a href="/download">Apache Mynewt 1.0.0-b1</a> released (Dec 13, 2016)
+            </div>
+        </div>
+    </div>
+</div>
+
+        
+
+
+
+
+
+
+<nav id="navbar" class="navbar navbar-inverse affix-top" data-spy="affix" data-offset-top="150" role="navigation">
+    <div class="container">
+        <!-- Collapsed navigation -->
+        <div class="navbar-header">
+            <!-- Expander button -->
+            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
+                <span class="sr-only">Toggle navigation</span>
+                <span class="icon-bar"></span>
+                <span class="icon-bar"></span>
+                <span class="icon-bar"></span>
+            </button>
+
+        </div>
+
+        <!-- Expanded navigation -->
+        <div class="navbar-collapse collapse">
+            <!-- Main navigation -->
+            <ul class="nav navbar-nav navbar-right">
+                <li 
+  class=""
+>
+                    <a href="/"><i class="fa fa-home" style="font-size: larger;"></i></a>
+                </li>
+                <li 
+  class="important"
+>
+                    <a href="/quick-start/">Quick Start</a>
+                </li>
+                <li 
+  class=""
+>
+                    <a href="/about/">About</a>
+                </li>
+                <li 
+  class=""
+>
+                    <a href="/talks/">Talks</a>
+                </li>
+                <li 
+  class="active"
+>
+                    <a href="/latest/os/introduction">Documentation</a>
+                </li>
+                <li 
+  class=""
+>
+                    <a href="/download/">Download</a>
+                </li>
+                <li 
+  class=""
+>
+                    <a href="/community/">Community</a>
+                </li>
+                <li 
+  class=""
+>
+                    <a href="/events/">Events</a>
+                </li>
+            </ul>
+
+            <!-- Search, Navigation and Repo links -->
+            <ul class="nav navbar-nav navbar-right">
+                
+            </ul>
+        </div>
+    </div>
+</nav>
+
+        
+
+        <div class="container">
+            
+                <div class="row">
+                    <div class="col-md-3 v2-sidebar sidebar-container"><div id="docSidebar" class="hidden-print" role="complementary">
+    <div class="top">
+        <div role="search">
+            <form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
+                <div class="form-group">
+                    <input type="text" name="q" class="form-control" placeholder="Search documentation" />
+                </div>
+            </form>
+        </div>
+    </div>
+    <ul class="toc-nav">
+      <li class="doc-version">
+<select class="form-control" onchange="if (this.value) window.location.href=this.value">
+    
+    <option
+      value="/develop/os/introduction"
+      selected="selected"
+    >
+      Version: develop (latest)
+    </option>
+    
+    <option
+      value="/v0_9_0/os/introduction"
+      
+    >
+      Version: 0.9.0
+    </option>
+    
+</select>
+</li>
+      
+        
+      
+        
+      
+        
+      
+        
+      
+        
+      
+        
+      
+        
+      
+        
+      
+        
+          
+  
+  
+    <li ><a href="../../introduction/">Mynewt Documentation</a>
+  
+  
+    <ul>
+          
+              
+          
+              
+                
+  
+  
+    <li ><a href="../../get_started/get_started/">Basic Setup</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../../get_started/vocabulary/">Concepts</a>
+    </li>
+
+              
+          
+              
+                
+  
+  
+    <li ><a href="../tutorials/">Tutorials</a>
+  
+  
+    <ul>
+          
+              
+          
+              
+                
+  
+  
+    <li><a href="
+  ../arduino_zero/
+">Project Blinky</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+  
+  
+    <li ><a href="../repo/add_repos/">Work with repositories</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../tasks_lesson/">Tasks and Priority Management</a>
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../wi-fi_on_arduino/">Enable Wi-Fi on Arduino Zero</a>
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../unit_test/">Write a Test Suite for a Package</a>
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../event_queue/">Add task to manage multiple events</a>
+    </li>
+
+              
+          
+              
+                
+  
+  
+    <li><a href="
+  ../project-slinky/
+">Project Slinky for remote comms</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../add_newtmgr/">Enable Newt Manager in any app</a>
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../add_shell/">Enable the OS Shell and Console</a>
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../bletiny_project/">BLE app to check stats via console</a>
+    </li>
+
+              
+          
+              
+                
+  
+  
+    <li ><a href="../bleprph/bleprph-intro/">BLE peripheral project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../ibeacon/">BLE iBeacon</a>
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../eddystone/">BLE Eddystone</a>
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../blehci_project/">BLE HCI interface</a>
+    </li>
+
+              
+          
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li class="active">
+      <a href="./">Add an Analog Sensor</a>
+    </li>
+
+              
+          
+    </ul>
+  
+    </li>
+
+              
+          
+              
+                
+  
+  
+    <li ><a href="../../os_user_guide/">OS User Guide</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+  
+  
+    <li><a href="
+  ../../../network/ble/ble_intro/
+">BLE User Guide</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+  
+  
+    <li ><a href="../../../newt/newt_intro/">Newt Tool Guide</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+  
+  
+    <li ><a href="../../../newtmgr/overview/">Newt Manager Guide</a>
+  
+  
+    </li>
+
+              
+          
+    </ul>
+  
+    </li>
+
+        
+      
+        
+          
+  
+  
+    <li><a href="
+  ../../../faq/how_to_edit_docs/
+">Appendix</a>
+  
+  
+    </li>
+
+        
+      
+    </ul>
+</div></div>
+
+                    <div class="col-md-9" role="main">
+                        <div class="doc-header">
+                            <div role="navigation" aria-label="breadcrumbs navigation">
+  <ul class="wy-breadcrumbs pull-right">
+    <li><a href="/latest/os/introduction">Docs</a></li>
+    
+    
+        
+          <li>&raquo; <a href="../../introduction/">Mynewt Documentation</a></li>
+        
+      
+        
+          <li>&raquo; <a href="../tutorials/">Tutorials</a></li>
+        
+      
+      
+        <li>&raquo; Add an Analog Sensor</li>
+      
+    
+    
+  </ul>
+</div>
+                        </div>
+                        
+                            <h2 id="adding-an-analog-sensor-on-nrf52">Adding an Analog Sensor on nRF52</h2>
+<p><br></p>
+<h3 id="objective">Objective</h3>
+<p>We will be adding an analog sensor to the NRF52DK development board and using the Analog to Digital Converter
+(ADC) to read the values from the sensor. It's also using Bluetooth to allow you to connect to the app and
+read the value of the sensor. Please see the following section for the required hardware
+in order to complete this tutorial.</p>
+<p><br></p>
+<h3 id="hardware-needed">Hardware needed</h3>
+<ul>
+<li>nRF52 Development Kit (one of the following)<ul>
+<li>Dev Kit from Nordic - PCA 10040</li>
+<li>Eval Kit from Rigado - BMD-300-EVAL-ES</li>
+</ul>
+</li>
+<li>eTape Liquid Sensor -- buy from <a href="https://www.adafruit.com/products/1786">Adafruit</a></li>
+<li>Laptop running Mac OS</li>
+<li>It is assumed you have already installed newt tool. </li>
+<li>It is assumed you already installed native tools as described <a href="../../get_started/native_tools/">here</a></li>
+</ul>
+<p><br></p>
+<h3 id="create-a-project">Create a project.</h3>
+<p>Create a new project to hold your work.  For a deeper understanding, you can read about project creation in 
+<a href="../../get_started/project_create/">Get Started -- Creating Your First Project</a>
+or just follow the commands below.</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%">    $ mkdir ~/dev
+    $ cd ~/dev
+    $ newt new myadc
+    Downloading project skeleton from apache/incubator-mynewt-blinky...
+    Installing skeleton in myadc...
+    Project myadc successfully created.
+    $ cd myadc
+</pre></div>
+
+
+<p><br></p>
+<h3 id="add-additional-repositories">Add Additional Repositories</h3>
+<p>The board-specific libraries for the NRF52dk board are in an external repository at present, so
+you'll need to include that remote repository and install it as well. If you're not familiar
+with using repositories, see the section on <a href="../repo/add_repos/">repositories</a> before
+continuing. Or just copy and paste the following.</p>
+<p>In your <code>project.yml</code> file, add <code>mynewt_nordic</code> to the <code>project.repositories</code> section, and 
+then add the proper repository definition. When you're done, your <code>project.yml</code> file
+should look like this:</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%">project.name: &quot;my_project&quot;
+
+project.repositories:
+    - apache-mynewt-core
+<span style="background-color: #ffffcc">    - mynewt_nordic
+</span>
+# Use github&#39;s distribution mechanism for core ASF libraries.
+# This provides mirroring automatically for us.
+#
+repository.apache-mynewt-core:
+    type: github
+    vers: 0-dev
+    user: apache
+    repo: incubator-mynewt-core
+<span style="background-color: #ffffcc">repository.mynewt_nordic:
+</span><span style="background-color: #ffffcc">    type: github
+</span><span style="background-color: #ffffcc">    vers: 0-latest
+</span><span style="background-color: #ffffcc">    user: runtimeinc
+</span><span style="background-color: #ffffcc">    repo: mynewt_nordic
+</span></pre></div>
+
+
+<p><br></p>
+<h3 id="install-everything">Install Everything</h3>
+<p>Now that you have defined the needed repositories, it's time to install everything so
+that you can get started.</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%">    $ newt install -v 
+    apache-mynewt-core
+    Downloading repository description for apache-mynewt-core... success!
+    ...
+    apache-mynewt-core successfully installed version 0.9.0-none
+    ...
+    mynewt_nordic
+    Downloading repository description for mynewt_nordic... success!
+    ...
+    mynewt_nordic successfully installed version 0.9.9-none
+</pre></div>
+
+
+<p><br></p>
+<h3 id="create-the-targets">Create the targets</h3>
+<p>Create two targets - one for the bootloader and one for the nrf52 board.  </p>
+<p><font color="#F2853F">
+Note: The correct bsp must be chosen for the board you are using. </font></p>
+<ul>
+<li>For the Nordic Dev Kit choose @apache-mynewt-core/hw/bsp/nrf52dk instead (in the highlighted lines)</li>
+<li>For the Rigado Eval Kit choose @apache-mynewt-core/hw/bsp/bmd300eval instead (in the highlighted lines)</li>
+</ul>
+<p>For the app itself we're going to extend the <a href="belpprph/bleprph-app.md">bleprph</a> app so that we
+get the Bluetooth communications built in, so the first thing we'll need to do is copy that app
+into our own app directory:</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%">$ mkdir -p apps/nrf52_adc
+$ cp -Rp repos/apache-mynewt-core/apps/bleprph/* apps/nrf52_adc
+</pre></div>
+
+
+<p>Next, you'll modify the <code>pkg.yml</code> file for your app. Note the change in <code>pkg.name</code> and <code>pkg.description</code>. Also make sure that you specify the full path of all the packages with the prefix <code>@apache-mynewt-core/</code> as shown in the third highlighted line.</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%">$ cat apps/nrf52_adc/pkg.yml
+...
+<span style="background-color: #ffffcc">pkg.name: apps/nrf52_adc
+</span>pkg.type: app
+<span style="background-color: #ffffcc">pkg.description: Simple BLE peripheral application for ADC Sensors.
+</span>pkg.author: &quot;Apache Mynewt &lt;dev@mynewt.incubator.apache.org&gt;&quot;
+pkg.homepage: &quot;http://mynewt.apache.org/&quot;
+pkg.keywords:
+
+pkg.deps: 
+<span style="background-color: #ffffcc">    - &quot;@apache-mynewt-core/boot/split&quot;
+</span>    - &quot;@apache-mynewt-core/kernel/os&quot;
+    - &quot;@apache-mynewt-core/mgmt/imgmgr&quot;
+    - &quot;@apache-mynewt-core/mgmt/newtmgr&quot;
+    - &quot;@apache-mynewt-core/mgmt/newtmgr/transport/ble&quot;
+    - &quot;@apache-mynewt-core/net/nimble/controller&quot;
+    - &quot;@apache-mynewt-core/net/nimble/host&quot;
+    - &quot;@apache-mynewt-core/net/nimble/host/services/ans&quot;
+    - &quot;@apache-mynewt-core/net/nimble/host/services/gap&quot;
+    - &quot;@apache-mynewt-core/net/nimble/host/services/gatt&quot;
+    - &quot;@apache-mynewt-core/net/nimble/host/store/ram&quot;
+    - &quot;@apache-mynewt-core/net/nimble/transport/ram&quot;
+    - &quot;@apache-mynewt-core/sys/console/full&quot;
+    - &quot;@apache-mynewt-core/sys/log/full&quot;
+    - &quot;@apache-mynewt-core/sys/stats/full&quot;
+    - &quot;@apache-mynewt-core/sys/sysinit&quot;
+    - &quot;@apache-mynewt-core/sys/id&quot;
+</pre></div>
+
+
+<p>Great! We have our very own app so let's make sure we have all of our targets set
+correctly:</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%">$ newt target create nrf52_adc
+$ newt target set nrf52_adc app=apps/nrf52_adc
+<span style="background-color: #ffffcc">Target targets/nrf52_adc successfully set target.app to apps/nrf52_adc
+</span>$ newt target set nrf52_adc bsp=@apache-mynewt-core/hw/bsp/nrf52dk
+$ newt target set nrf52_adc build_profile=debug
+
+$ newt target create nrf52_boot
+<span style="background-color: #ffffcc">$ newt target set nrf52_boot app=@apache-mynewt-core/apps/boot
+</span>$ newt target set nrf52_boot bsp=@apache-mynewt-core/hw/bsp/nrf52dk
+$ newt target set nrf52_boot build_profile=optimized
+
+$ newt target show 
+targets/nrf52_adc
+    app=apps/nrf52_adc
+    bsp=@apache-mynewt-core/hw/bsp/nrf52dk
+    build_profile=debug
+targets/nrf52_boot
+    app=@apache-mynewt-core/apps/boot
+    bsp=@apache-mynewt-core/hw/bsp/nrf52dk
+    build_profile=optimized
+</pre></div>
+
+
+<p><font color="#F2853F">
+Note: If you've already built and installed a bootloader for your NRF52dk then you do
+not need to create a target for it here, or build and load it as below. </font>
+<br></p>
+<h3 id="build-the-target-executables">Build the target executables</h3>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%">$ newt build nrf52_boot
+...
+Compiling boot.c
+Archiving boot.a
+Linking boot.elf
+App successfully built: ~/dev/myadc/bin/nrf52_boot/apps/boot/boot.elf
+</pre></div>
+
+
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%">$ newt build nrf52_adc
+...
+Compiling main.c
+Archiving nrf52_adc.a
+Linking nrf52_adc.elf
+App successfully built: ~/dev/myadc/bin/nrf52_adc/apps/nrf52_adc/nrf52_adc.elf
+</pre></div>
+
+
+<p><br></p>
+<h3 id="sign-and-create-the-nrf52_adc-application-image">Sign and create the nrf52_adc application image</h3>
+<p>You must sign and version your application image to download it using newt to the board. 
+Use the newt create-image command to perform this action. You may assign an arbitrary 
+version (e.g. 1.0.0) to the image.</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%">$ newt create-image nrf52_adc 1.0.0
+App image successfully generated: ~/dev/myadc/bin/nrf52_adc/apps/nrf52_adc/nrf52_adc.img
+Build manifest: ~/dev/myadc/bin/nrf52_adc/apps/nrf52_adc/manifest.json
+</pre></div>
+
+
+<p><br></p>
+<h3 id="connect-the-board">Connect the board</h3>
+<p>Connect the evaluation board via micro-USB to your PC via USB cable.</p>
+<p><br></p>
+<h3 id="download-to-the-target">Download to the target</h3>
+<p>Download the bootloader first and then the nrf52_adc executable to the target platform. 
+Don't forget to reset the board if you don't see the LED blinking right away!</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%">$ newt load nrf52_boot
+$ newt load nrf52_adc
+</pre></div>
+
+
+<p><br></p>
+<p><strong>Note:</strong> If you want to erase the flash and load the image again, you can use JLinkExe to issue an <code>erase</code> command.</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%">$ JLinkExe -device nRF52 -speed 4000 -if SWD
+SEGGER J-Link Commander V5.12c (Compiled Apr 21 2016 16:05:51)
+DLL version V5.12c, compiled Apr 21 2016 16:05:45
+
+Connecting to J-Link via USB...O.K.
+Firmware: J-Link OB-SAM3U128-V2-NordicSemi compiled Mar 15 2016 18:03:17
+Hardware version: V1.00
+S/N: 682863966
+VTref = 3.300V
+
+
+Type &quot;connect&quot; to establish a target connection, &#39;?&#39; for help
+J-Link&gt;erase
+Cortex-M4 identified.
+Erasing device (0;?i?)...
+Comparing flash   [100%] Done.
+Erasing flash     [100%] Done.
+Verifying flash   [100%] Done.
+J-Link: Flash download: Total time needed: 0.363s (Prepare: 0.093s, Compare: 0.000s, Erase: 0.262s, Program: 0.000s, Verify: 0.000s, Restore: 0.008s)
+Erasing done.
+J-Link&gt;exit
+$
+</pre></div>
+
+
+<p><br></p>
+<p>So you have a BLE app, but really all you've done is change the name of the <strong>bleprph</strong> app to <strong>nrf52_adc</strong> and load that.
+Not all that impressive, and it certainly won't read an Analog Sensor right now. So let's do that next. In order to 
+read an ADC sensor, and since the ADC package is in an external, licensed, repository, we'll create a driver for it
+here in our app that will leverage the existing driver in the external repository. It adds another layer of 
+indirection, but it will also give us a look at building our own driver, so we'll do it this way. </p>
+<p><br></p>
+<h3 id="building-a-driver">Building a Driver</h3>
+<p>The first thing to do is to create the directory structure for your driver:</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%">[user@IsMyLaptop:~/src/air_quality]$ mkdir -p libs/my_drivers/myadc/include/myadc
+[user@IsMyLaptop:~/src/air_quality]$ mkdir -p libs/my_drivers/myadc/src
+</pre></div>
+
+
+<p>Now you can add the files you need. You'll need a pkg.yml to describe the driver, and then header stub followed by source stub.</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%">[user@IsMyLaptop:~/src/air_quality]$ cat libs/my_drivers/myadc/pkg.yml
+</pre></div>
+
+
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%"><span style="color: #633820">#</span>
+<span style="color: #633820"># Licensed to the Apache Software Foundation (ASF) under one</span>
+<span style="color: #633820"># or more contributor license agreements.  See the NOTICE file</span>
+<span style="color: #633820"># distributed with this work for additional information</span>
+<span style="color: #633820"># regarding copyright ownership.  The ASF licenses this file</span>
+<span style="color: #633820"># to you under the Apache License, Version 2.0 (the</span>
+<span style="color: #633820"># &quot;License&quot;); you may not use this file except in compliance</span>
+<span style="color: #633820"># with the License.  You may obtain a copy of the License at</span>
+<span style="color: #633820"># </span>
+<span style="color: #633820">#  http:</span><span style="color: #177500">//www.apache.org/licenses/LICENSE-2.0</span>
+<span style="color: #633820">#</span>
+<span style="color: #633820"># Unless required by applicable law or agreed to in writing,</span>
+<span style="color: #633820"># software distributed under the License is distributed on an</span>
+<span style="color: #633820"># &quot;AS IS&quot; BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY</span>
+<span style="color: #633820"># KIND, either express or implied.  See the License for the</span>
+<span style="color: #633820"># specific language governing permissions and limitations</span>
+<span style="color: #633820"># under the License.</span>
+<span style="color: #633820">#</span>
+<span style="color: #000000">pkg</span>.<span style="color: #000000">name</span>: <span style="color: #000000">libs/my_drivers/myadc</span>
+<span style="color: #000000">pkg</span>.<span style="color: #000000">deps</span>:
+    <span style="color: #000000">-</span> <span style="color: #C41A16">&quot;@apache-mynewt-core/hw/hal&quot;</span>
+    <span style="color: #000000">-</span> <span style="color: #C41A16">&quot;@mynewt_nordic/hw/drivers/adc/adc_nrf52&quot;</span>
+</pre></div>
+
+
+<p>First, let's create the required header file <code>myadc.h</code> in the includes directory i.e. <code>libs/my_drivers/myadc/include/myadc/myadc.h</code>.
+It's a pretty straightforward header file, since we only need to do 2 things:</p>
+<ul>
+<li>Initialize the ADC device</li>
+<li>Read ADC Values</li>
+</ul>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%"><span style="color: #633820">#ifndef _NRF52_ADC_H_</span>
+<span style="color: #633820">#define _NRF52_ADC_H_</span>
+
+<span style="color: #A90D91">void</span> <span style="color: #000000">*</span> <span style="color: #000000">adc_init</span>(<span style="color: #A90D91">void</span>);
+<span style="color: #A90D91">int</span> <span style="color: #000000">adc_read</span>(<span style="color: #A90D91">void</span> <span style="color: #000000">*buffer</span>, <span style="color: #A90D91">int</span> <span style="color: #000000">buffer_len</span>);
+
+<span style="color: #633820">#endif </span><span style="color: #177500">/* _NRF52_ADC_H_ */</span><span style="color: #633820"></span>
+</pre></div>
+
+
+<p>Next we'll need a corresponding source file <code>myadc.c</code> in the src directory. This is where
+we'll implement the specifics of the driver:</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%"><span style="color: #633820">#include &lt;assert.h&gt;</span>
+<span style="color: #633820">#include &lt;os/os.h&gt;</span>
+<span style="color: #177500">/* ADC */</span>
+<span style="color: #633820">#include &quot;myadc/myadc.h&quot;</span>
+<span style="color: #633820">#include &quot;nrf.h&quot;</span>
+<span style="color: #633820">#include &quot;app_util_platform.h&quot;</span>
+<span style="color: #633820">#include &quot;app_error.h&quot;</span>
+<span style="color: #633820">#include &lt;adc/adc.h&gt;</span>
+<span style="color: #633820">#include &lt;adc_nrf52/adc_nrf52.h&gt;</span>
+<span style="color: #633820">#include &quot;nrf_drv_saadc.h&quot;</span>
+
+
+<span style="color: #633820">#define ADC_NUMBER_SAMPLES (2)</span>
+<span style="color: #633820">#define ADC_NUMBER_CHANNELS (1)</span>
+
+<span style="color: #A90D91">nrf_drv_saadc_config_t</span> <span style="color: #000000">adc_config</span> <span style="color: #000000">=</span> <span style="color: #000000">NRF_DRV_SAADC_DEFAULT_CONFIG</span>;
+
+<span style="color: #A90D91">struct</span> <span style="color: #000000">adc_dev</span> <span style="color: #000000">*adc</span>;
+<span style="color: #A90D91">uint8_t</span> <span style="color: #000000">*sample_buffer1</span>;
+<span style="color: #A90D91">uint8_t</span> <span style="color: #000000">*sample_buffer2</span>;
+
+<span style="color: #A90D91">static</span> <span style="color: #A90D91">struct</span> <span style="color: #000000">adc_dev</span> <span style="color: #000000">os_bsp_adc0</span>;
+<span style="color: #A90D91">static</span> <span style="color: #A90D91">nrf_drv_saadc_config_t</span> <span style="color: #000000">os_bsp_adc0_config</span> <span style="color: #000000">=</span> {
+    .<span style="color: #000000">resolution</span>         <span style="color: #000000">=</span> <span style="color: #000000">MYNEWT_VAL</span>(<span style="color: #000000">ADC_0_RESOLUTION</span>),
+    .<span style="color: #000000">oversample</span>         <span style="color: #000000">=</span> <span style="color: #000000">MYNEWT_VAL</span>(<span style="color: #000000">ADC_0_OVERSAMPLE</span>),
+    .<span style="color: #000000">interrupt_priority</span> <span style="color: #000000">=</span> <span style="color: #000000">MYNEWT_VAL</span>(<span style="color: #000000">ADC_0_INTERRUPT_PRIORITY</span>),
+};
+<span style="color: #A90D91">void</span> <span style="color: #000000">*</span>
+<span style="color: #000000">adc_init</span>(<span style="color: #A90D91">void</span>)
+{
+    <span style="color: #A90D91">int</span> <span style="color: #000000">rc</span> <span style="color: #000000">=</span> <span style="color: #1C01CE">0</span>;
+
+    <span style="color: #000000">rc</span> <span style="color: #000000">=</span> <span style="color: #000000">os_dev_create</span>((<span style="color: #A90D91">struct</span> <span style="color: #000000">os_dev</span> <span style="color: #000000">*</span>) <span style="color: #000000">&amp;os_bsp_adc0</span>, <span style="color: #C41A16">&quot;adc0&quot;</span>,
+            <span style="color: #000000">OS_DEV_INIT_KERNEL</span>, <span style="color: #000000">OS_DEV_INIT_PRIO_DEFAULT</span>,
+            <span style="color: #000000">nrf52_adc_dev_init</span>, <span style="color: #000000">&amp;os_bsp_adc0_config</span>);
+    <span style="color: #000000">assert</span>(<span style="color: #000000">rc</span> <span style="color: #000000">==</span> <span style="color: #1C01CE">0</span>);
+    <span style="color: #A90D91">nrf_saadc_channel_config_t</span> <span style="color: #000000">cc</span> <span style="color: #000000">=</span> <span style="color: #000000">NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE</span>(<span style="color: #000000">NRF_SAADC_INPUT_AIN1</span>);
+    <span style="color: #000000">cc</span>.<span style="color: #000000">gain</span> <span style="color: #000000">=</span> <span style="color: #000000">NRF_SAADC_GAIN1_6</span>;
+    <span style="color: #000000">cc</span>.<span style="color: #000000">reference</span> <span style="color: #000000">=</span> <span style="color: #000000">NRF_SAADC_REFERENCE_INTERNAL</span>;
+    <span style="color: #000000">adc</span> <span style="color: #000000">=</span> (<span style="color: #A90D91">struct</span> <span style="color: #000000">adc_dev</span> <span style="color: #000000">*</span>) <span style="color: #000000">os_dev_open</span>(<span style="color: #C41A16">&quot;adc0&quot;</span>, <span style="color: #1C01CE">0</span>, <span style="color: #000000">&amp;adc_config</span>);
+    <span style="color: #000000">assert</span>(<span style="color: #000000">adc</span> <span style="color: #000000">!=</span> <span style="color: #A90D91">NULL</span>);
+    <span style="color: #000000">adc_chan_config</span>(<span style="color: #000000">adc</span>, <span style="color: #1C01CE">0</span>, <span style="color: #000000">&amp;cc</span>);
+    <span style="color: #000000">sample_buffer1</span> <span style="color: #000000">=</span> <span style="color: #000000">malloc</span>(<span style="color: #000000">adc_buf_size</span>(<span style="color: #000000">adc</span>, <span style="color: #000000">ADC_NUMBER_CHANNELS</span>, <span style="color: #000000">ADC_NUMBER_SAMPLES</span>));
+    <span style="color: #000000">sample_buffer2</span> <span style="color: #000000">=</span> <span style="color: #000000">malloc</span>(<span style="color: #000000">adc_buf_size</span>(<span style="color: #000000">adc</span>, <span style="color: #000000">ADC_NUMBER_CHANNELS</span>, <span style="color: #000000">ADC_NUMBER_SAMPLES</span>));
+    <span style="color: #000000">memset</span>(<span style="color: #000000">sample_buffer1</span>, <span style="color: #1C01CE">0</span>, <span style="color: #000000">adc_buf_size</span>(<span style="color: #000000">adc</span>, <span style="color: #000000">ADC_NUMBER_CHANNELS</span>, <span style="color: #000000">ADC_NUMBER_SAMPLES</span>));
+    <span style="color: #000000">memset</span>(<span style="color: #000000">sample_buffer2</span>, <span style="color: #1C01CE">0</span>, <span style="color: #000000">adc_buf_size</span>(<span style="color: #000000">adc</span>, <span style="color: #000000">ADC_NUMBER_CHANNELS</span>, <span style="color: #000000">ADC_NUMBER_SAMPLES</span>));
+    <span style="color: #000000">adc_buf_set</span>(<span style="color: #000000">adc</span>, <span style="color: #000000">sample_buffer1</span>, <span style="color: #000000">sample_buffer2</span>,
+        <span style="color: #000000">adc_buf_size</span>(<span style="color: #000000">adc</span>, <span style="color: #000000">ADC_NUMBER_CHANNELS</span>, <span style="color: #000000">ADC_NUMBER_SAMPLES</span>));
+    <span style="color: #A90D91">return</span> <span style="color: #000000">adc</span>;
+}
+
+
+<span style="color: #A90D91">int</span>
+<span style="color: #000000">adc_read</span>(<span style="color: #A90D91">void</span> <span style="color: #000000">*buffer</span>, <span style="color: #A90D91">int</span> <span style="color: #000000">buffer_len</span>)
+{
+    <span style="color: #A90D91">int</span> <span style="color: #000000">i</span>;
+    <span style="color: #A90D91">int</span> <span style="color: #000000">adc_result</span>;
+    <span style="color: #A90D91">int</span> <span style="color: #000000">my_result_mv</span> <span style="color: #000000">=</span> <span style="color: #1C01CE">0</span>;
+    <span style="color: #A90D91">int</span> <span style="color: #000000">rc</span>;
+    <span style="color: #A90D91">for</span> (<span style="color: #000000">i</span> <span style="color: #000000">=</span> <span style="color: #1C01CE">0</span>; <span style="color: #000000">i</span> <span style="color: #000000">&lt;</span> <span style="color: #000000">ADC_NUMBER_SAMPLES</span>; <span style="color: #000000">i++</span>) {
+        <span style="color: #000000">rc</span> <span style="color: #000000">=</span> <span style="color: #000000">adc_buf_read</span>(<span style="color: #000000">adc</span>, <span style="color: #000000">buffer</span>, <span style="color: #000000">buffer_len</span>, <span style="color: #000000">i</span>, <span style="color: #000000">&amp;adc_result</span>);
+        <span style="color: #A90D91">if</span> (<span style="color: #000000">rc</span> <span style="color: #000000">!=</span> <span style="color: #1C01CE">0</span>) {
+            <span style="color: #A90D91">goto</span> <span style="color: #000000">err</span>;
+        }
+        <span style="color: #000000">my_result_mv</span> <span style="color: #000000">=</span> <span style="color: #000000">adc_result_mv</span>(<span style="color: #000000">adc</span>, <span style="color: #1C01CE">0</span>, <span style="color: #000000">adc_result</span>);
+    }        
+    <span style="color: #000000">adc_buf_release</span>(<span style="color: #000000">adc</span>, <span style="color: #000000">buffer</span>, <span style="color: #000000">buffer_len</span>);
+    <span style="color: #A90D91">return</span> <span style="color: #000000">my_result_mv</span>;
+<span style="color: #000000">err</span>:
+    <span style="color: #A90D91">return</span> (<span style="color: #000000">rc</span>);
+}
+</pre></div>
+
+
+<p>There's a lot going on in here, so let's walk through it step by step. </p>
+<p>First, we define a default configuration, with the resolution, oversample and interrupt priority. You'll see
+that these are <code>MYNEWT_VAL</code> values, which means that we'll define them shortly in
+a <code>syscfg.yml</code> file to be passed to the compiler at build time. </p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%"><span style="color: #A90D91">static</span> <span style="color: #A90D91">struct</span> <span style="color: #000000">adc_dev</span> <span style="color: #000000">os_bsp_adc0</span>;
+<span style="color: #A90D91">static</span> <span style="color: #A90D91">nrf_drv_saadc_config_t</span> <span style="color: #000000">os_bsp_adc0_config</span> <span style="color: #000000">=</span> {
+    .<span style="color: #000000">resolution</span>         <span style="color: #000000">=</span> <span style="color: #000000">MYNEWT_VAL</span>(<span style="color: #000000">ADC_0_RESOLUTION</span>),
+    .<span style="color: #000000">oversample</span>         <span style="color: #000000">=</span> <span style="color: #000000">MYNEWT_VAL</span>(<span style="color: #000000">ADC_0_OVERSAMPLE</span>),
+    .<span style="color: #000000">interrupt_priority</span> <span style="color: #000000">=</span> <span style="color: #000000">MYNEWT_VAL</span>(<span style="color: #000000">ADC_0_INTERRUPT_PRIORITY</span>),
+};
+</pre></div>
+
+
+<p>Next, in <code>adc_init()</code> , we need to tell the OS to create the device.</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%"><span style="color: #A90D91">void</span> <span style="color: #000000">*</span>
+<span style="color: #000000">adc_init</span>(<span style="color: #A90D91">void</span>)
+{
+    <span style="color: #A90D91">int</span> <span style="color: #000000">rc</span> <span style="color: #000000">=</span> <span style="color: #1C01CE">0</span>;
+
+    <span style="color: #000000">rc</span> <span style="color: #000000">=</span> <span style="color: #000000">os_dev_create</span>((<span style="color: #A90D91">struct</span> <span style="color: #000000">os_dev</span> <span style="color: #000000">*</span>) <span style="color: #000000">&amp;os_bsp_adc0</span>, <span style="color: #C41A16">&quot;adc0&quot;</span>,
+            <span style="color: #000000">OS_DEV_INIT_KERNEL</span>, <span style="color: #000000">OS_DEV_INIT_PRIO_DEFAULT</span>,
+            <span style="color: #000000">nrf52_adc_dev_init</span>, <span style="color: #000000">&amp;os_bsp_adc0_config</span>);
+    <span style="color: #000000">assert</span>(<span style="color: #000000">rc</span> <span style="color: #000000">==</span> <span style="color: #1C01CE">0</span>);
+    <span style="color: #A90D91">nrf_saadc_channel_config_t</span> <span style="color: #000000">cc</span> <span style="color: #000000">=</span> <span style="color: #000000">NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE</span>(<span style="color: #000000">NRF_SAADC_INPUT_AIN1</span>);
+    <span style="color: #000000">cc</span>.<span style="color: #000000">gain</span> <span style="color: #000000">=</span> <span style="color: #000000">NRF_SAADC_GAIN1_6</span>;
+    <span style="color: #000000">cc</span>.<span style="color: #000000">reference</span> <span style="color: #000000">=</span> <span style="color: #000000">NRF_SAADC_REFERENCE_INTERNAL</span>;
+    <span style="color: #000000">adc</span> <span style="color: #000000">=</span> (<span style="color: #A90D91">struct</span> <span style="color: #000000">adc_dev</span> <span style="color: #000000">*</span>) <span style="color: #000000">os_dev_open</span>(<span style="color: #C41A16">&quot;adc0&quot;</span>, <span style="color: #1C01CE">0</span>, <span style="color: #000000">&amp;adc_config</span>);
+    <span style="color: #000000">assert</span>(<span style="color: #000000">adc</span> <span style="color: #000000">!=</span> <span style="color: #A90D91">NULL</span>);
+    <span style="color: #000000">adc_chan_config</span>(<span style="color: #000000">adc</span>, <span style="color: #1C01CE">0</span>, <span style="color: #000000">&amp;cc</span>);
+    <span style="color: #000000">sample_buffer1</span> <span style="color: #000000">=</span> <span style="color: #000000">malloc</span>(<span style="color: #000000">adc_buf_size</span>(<span style="color: #000000">adc</span>, <span style="color: #000000">ADC_NUMBER_CHANNELS</span>, <span style="color: #000000">ADC_NUMBER_SAMPLES</span>));
+    <span style="color: #000000">sample_buffer2</span> <span style="color: #000000">=</span> <span style="color: #000000">malloc</span>(<span style="color: #000000">adc_buf_size</span>(<span style="color: #000000">adc</span>, <span style="color: #000000">ADC_NUMBER_CHANNELS</span>, <span style="color: #000000">ADC_NUMBER_SAMPLES</span>));
+    <span style="color: #000000">memset</span>(<span style="color: #000000">sample_buffer1</span>, <span style="color: #1C01CE">0</span>, <span style="color: #000000">adc_buf_size</span>(<span style="color: #000000">adc</span>, <span style="color: #000000">ADC_NUMBER_CHANNELS</span>, <span style="color: #000000">ADC_NUMBER_SAMPLES</span>));
+    <span style="color: #000000">memset</span>(<span style="color: #000000">sample_buffer2</span>, <span style="color: #1C01CE">0</span>, <span style="color: #000000">adc_buf_size</span>(<span style="color: #000000">adc</span>, <span style="color: #000000">ADC_NUMBER_CHANNELS</span>, <span style="color: #000000">ADC_NUMBER_SAMPLES</span>));
+    <span style="color: #000000">adc_buf_set</span>(<span style="color: #000000">adc</span>, <span style="color: #000000">sample_buffer1</span>, <span style="color: #000000">sample_buffer2</span>,
+        <span style="color: #000000">adc_buf_size</span>(<span style="color: #000000">adc</span>, <span style="color: #000000">ADC_NUMBER_CHANNELS</span>, <span style="color: #000000">ADC_NUMBER_SAMPLES</span>));
+    <span style="color: #A90D91">return</span> <span style="color: #000000">adc</span>;
+}
+</pre></div>
+
+
+<p>A few things need to be said about this part, as it is the most confusing. First, 
+we're using a <strong>default</strong> configuration for the ADC Channel via the <code>NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE</code>
+macro. The important part here is that we're actually using <code>AIN1</code>. I know what you're thinking, "But 
+we want ADC-0!" and that's true. The board is actually labelled 'A0, A1, A2' etc., and the actual pin 
+numbers are also listed on the board, which seems handy. At first. But it gets messy very quickly.</p>
+<p>If you try to use AIN0, and then go poke around in the registers while this is running, </p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%">(gdb) p/x {NRF_SAADC_Type}0x40007000
+...
+ CH = {{
+      PSELP = 0x1,
+      PSELN = 0x0,
+      CONFIG = 0x20000,
+      LIMIT = 0x7fff8000
+    }, 
+</pre></div>
+
+
+<p>You'll see that the pin for channel 0 is set to 1, which corresponds to AIN0, but that's <strong>NOT</strong>
+the same as A0 -- pin P0.03, the one we're using. For that, you use AIN1, which would set the
+pin value to 2. Messy. Someone, somewhere, thought this made sense. </p>
+<p>The only other thing to note here is that we're using the internal reference voltage, rather than
+setting our own. There's nothing wrong with that, but since we are, we'll have to crank up
+the gain a bit by using <code>NRF_SAADC_GAIN1_6</code>.</p>
+<p>Then, in <code>adc_read()</code> we will take readings, convert the raw readings to 
+a millivolt equivalent, and return the result. </p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%"><span style="color: #A90D91">int</span>
+<span style="color: #000000">adc_read</span>(<span style="color: #A90D91">void</span> <span style="color: #000000">*buffer</span>, <span style="color: #A90D91">int</span> <span style="color: #000000">buffer_len</span>)
+{
+    <span style="color: #A90D91">int</span> <span style="color: #000000">i</span>;
+    <span style="color: #A90D91">int</span> <span style="color: #000000">adc_result</span>;
+    <span style="color: #A90D91">int</span> <span style="color: #000000">my_result_mv</span> <span style="color: #000000">=</span> <span style="color: #1C01CE">0</span>;
+    <span style="color: #A90D91">int</span> <span style="color: #000000">rc</span>;
+    <span style="color: #A90D91">for</span> (<span style="color: #000000">i</span> <span style="color: #000000">=</span> <span style="color: #1C01CE">0</span>; <span style="color: #000000">i</span> <span style="color: #000000">&lt;</span> <span style="color: #000000">ADC_NUMBER_SAMPLES</span>; <span style="color: #000000">i++</span>) {
+        <span style="color: #000000">rc</span> <span style="color: #000000">=</span> <span style="color: #000000">adc_buf_read</span>(<span style="color: #000000">adc</span>, <span style="color: #000000">buffer</span>, <span style="color: #000000">buffer_len</span>, <span style="color: #000000">i</span>, <span style="color: #000000">&amp;adc_result</span>);
+        <span style="color: #A90D91">if</span> (<span style="color: #000000">rc</span> <span style="color: #000000">!=</span> <span style="color: #1C01CE">0</span>) {
+            <span style="color: #A90D91">goto</span> <span style="color: #000000">err</span>;
+        }
+        <span style="color: #000000">my_result_mv</span> <span style="color: #000000">=</span> <span style="color: #000000">adc_result_mv</span>(<span style="color: #000000">adc</span>, <span style="color: #1C01CE">0</span>, <span style="color: #000000">adc_result</span>);
+    }        
+    <span style="color: #000000">adc_buf_release</span>(<span style="color: #000000">adc</span>, <span style="color: #000000">buffer</span>, <span style="color: #000000">buffer_len</span>);
+    <span style="color: #A90D91">return</span> <span style="color: #000000">my_result_mv</span>;
+<span style="color: #000000">err</span>:
+    <span style="color: #A90D91">return</span> (<span style="color: #000000">rc</span>);
+}
+</pre></div>
+
+
+<p>Finally, we'll need some settings for our driver, as mentioned earlier. In the <code>myadc</code> directory
+you'll need to add a <code>syscfg.yml</code> file:</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%"># Package: libs/my_driver/myadc
+
+syscfg.defs:
+    ADC_0:
+        description: &#39;TBD&#39;
+        value:  1
+    ADC_0_RESOLUTION:
+        description: &#39;TBD&#39;
+        value: &#39;SAADC_CONFIG_RESOLUTION&#39;
+    ADC_0_OVERSAMPLE:
+        description: &#39;TBD&#39;
+        value: &#39;SAADC_CONFIG_OVERSAMPLE&#39;
+    ADC_0_INTERRUPT_PRIORITY:
+        description: &#39;TBD&#39;
+        value: &#39;SAADC_CONFIG_IRQ_PRIORITY&#39;
+</pre></div>
+
+
+<p>Once that's all done, you should have a working ADC Driver for your NRF52DK board. The last step in getting the driver set up is to include it in the package dependency defined by <code>pkg.deps</code> in the <code>pkg.yml</code> file of your app. Add it in <code>apps/nrf52_adc/pkg.yml</code> as shown by the highlighted line below.</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%"># Licensed to the Apache Software Foundation (ASF) under one
+# &lt;snip&gt;
+
+pkg.name: apps/nrf52_adc
+pkg.type: app
+pkg.description: Simple BLE peripheral application for ADC sensor.
+pkg.author: &quot;Apache Mynewt &lt;dev@mynewt.incubator.apache.org&gt;&quot;
+pkg.homepage: &quot;http://mynewt.apache.org/&quot;
+pkg.keywords:
+
+pkg.deps: 
+    - &quot;@apache-mynewt-core/boot/split&quot;
+    - &quot;@apache-mynewt-core/kernel/os&quot;
+    - &quot;@apache-mynewt-core/mgmt/imgmgr&quot;
+    - &quot;@apache-mynewt-core/mgmt/newtmgr&quot;
+    - &quot;@apache-mynewt-core/mgmt/newtmgr/transport/ble&quot;
+    - &quot;@apache-mynewt-core/net/nimble/controller&quot;
+    - &quot;@apache-mynewt-core/net/nimble/host&quot;
+    - &quot;@apache-mynewt-core/net/nimble/host/services/ans&quot;
+    - &quot;@apache-mynewt-core/net/nimble/host/services/gap&quot;
+    - &quot;@apache-mynewt-core/net/nimble/host/services/gatt&quot;
+    - &quot;@apache-mynewt-core/net/nimble/host/store/ram&quot;
+    - &quot;@apache-mynewt-core/net/nimble/transport/ram&quot;
+    - &quot;@apache-mynewt-core/sys/console/full&quot;
+    - &quot;@apache-mynewt-core/sys/log/full&quot;
+    - &quot;@apache-mynewt-core/sys/stats/full&quot;
+    - &quot;@apache-mynewt-core/sys/sysinit&quot;
+    - &quot;@apache-mynewt-core/sys/id&quot;
+<span style="background-color: #ffffcc">    - libs/my_drivers/myadc
+</span></pre></div>
+
+
+<p><br></p>
+<h3 id="creating-the-adc-task">Creating the ADC Task</h3>
+<p>Now that the driver is done, we'll need to add calls to the main app's <code>main.c</code> file, as well
+as a few other things. First, we'll need to update the includes, and add a task for our ADC
+sampling.</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%"><span style="color: #633820">#include &quot;myadc/myadc.h&quot;</span>
+...
+<span style="color: #177500">/* ADC Task settings */</span>
+<span style="color: #633820">#define ADC_TASK_PRIO           5</span>
+<span style="color: #633820">#define ADC_STACK_SIZE          (OS_STACK_ALIGN(336))</span>
+<span style="color: #A90D91">struct</span> <span style="color: #000000">os_eventq</span> <span style="color: #000000">adc_evq</span>;
+<span style="color: #A90D91">struct</span> <span style="color: #000000">os_task</span> <span style="color: #000000">adc_task</span>;
+<span style="color: #A90D91">bssnz_t</span> <span style="color: #A90D91">os_stack_t</span> <span style="color: #000000">adc_stack</span>[<span style="color: #000000">ADC_STACK_SIZE</span>];
+</pre></div>
+
+
+<p>Next we'll need  o initialize the task <code>event_q</code> so we'll add the highlighted code to <code>main()</code> as shown below:</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%">    <span style="color: #177500">/* Set the default device name. */</span>
+    <span style="color: #000000">rc</span> <span style="color: #000000">=</span> <span style="color: #000000">ble_svc_gap_device_name_set</span>(<span style="color: #C41A16">&quot;nimble-adc&quot;</span>);
+    <span style="color: #000000">assert</span>(<span style="color: #000000">rc</span> <span style="color: #000000">==</span> <span style="color: #1C01CE">0</span>);
+
+    <span style="color: #000000">conf_load</span>();
+
+<span style="background-color: #ffffcc">    <span style="color: #177500">/* Initialize adc sensor task eventq */</span>
+</span><span style="background-color: #ffffcc">    <span style="color: #000000">os_eventq_init</span>(<span style="color: #000000">&amp;adc_evq</span>);
+</span><span style="background-color: #ffffcc">
+</span><span style="background-color: #ffffcc">    <span style="color: #177500">/* Create the ADC reader task.  </span>
+</span><span style="background-color: #ffffcc"><span style="color: #177500">     * All sensor operations are performed in this task.</span>
+</span><span style="background-color: #ffffcc"><span style="color: #177500">     */</span>
+</span><span style="background-color: #ffffcc">    <span style="color: #000000">os_task_init</span>(<span style="color: #000000">&amp;adc_task</span>, <span style="color: #C41A16">&quot;sensor&quot;</span>, <span style="color: #000000">adc_task_handler</span>,
+</span><span style="background-color: #ffffcc">            <span style="color: #A90D91">NULL</span>, <span style="color: #000000">ADC_TASK_PRIO</span>, <span style="color: #000000">OS_WAIT_FOREVER</span>,
+</span><span style="background-color: #ffffcc">            <span style="color: #000000">adc_stack</span>, <span style="color: #000000">ADC_STACK_SIZE</span>);
+</span></pre></div>
+
+
+<p>We'll need that <code>adc_task_handler()</code> function to exist, and that's where we'll initialize the ADC Device
+and set the event handler. In the task's while() loop, we'll just make a call to <code>adc_sample()</code> to cause
+the ADC driver to sample the adc device.</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%"><span style="color: #177500">/**</span>
+<span style="color: #177500"> * Event loop for the sensor task.</span>
+<span style="color: #177500"> */</span>
+<span style="color: #A90D91">static</span> <span style="color: #A90D91">void</span>
+<span style="color: #000000">adc_task_handler</span>(<span style="color: #A90D91">void</span> <span style="color: #000000">*unused</span>)
+{
+    <span style="color: #A90D91">struct</span> <span style="color: #000000">adc_dev</span> <span style="color: #000000">*adc</span>;
+    <span style="color: #A90D91">int</span> <span style="color: #000000">rc</span>;
+    <span style="color: #177500">/* ADC init */</span>
+    <span style="color: #000000">adc</span> <span style="color: #000000">=</span> <span style="color: #000000">adc_init</span>();
+    <span style="color: #000000">rc</span> <span style="color: #000000">=</span> <span style="color: #000000">adc_event_handler_set</span>(<span style="color: #000000">adc</span>, <span style="color: #000000">adc_read_event</span>, (<span style="color: #A90D91">void</span> <span style="color: #000000">*</span>) <span style="color: #A90D91">NULL</span>);
+    <span style="color: #000000">assert</span>(<span style="color: #000000">rc</span> <span style="color: #000000">==</span> <span style="color: #1C01CE">0</span>);
+
+    <span style="color: #A90D91">while</span> (<span style="color: #1C01CE">1</span>) {
+        <span style="color: #000000">adc_sample</span>(<span style="color: #000000">adc</span>);
+        <span style="color: #177500">/* Wait 2 second */</span>
+        <span style="color: #000000">os_time_delay</span>(<span style="color: #000000">OS_TICKS_PER_SEC</span> <span style="color: #000000">*</span> <span style="color: #1C01CE">2</span>);
+    }
+}
+</pre></div>
+
+
+<p>Above the <code>adc_task_handler</code>, add code to handle the <code>adc_read_event()</code> calls:</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%"><span style="color: #A90D91">int</span>
+<span style="color: #000000">adc_read_event</span>(<span style="color: #A90D91">struct</span> <span style="color: #000000">adc_dev</span> <span style="color: #000000">*dev</span>, <span style="color: #A90D91">void</span> <span style="color: #000000">*arg</span>, <span style="color: #A90D91">uint8_t</span> <span style="color: #000000">etype</span>,
+        <span style="color: #A90D91">void</span> <span style="color: #000000">*buffer</span>, <span style="color: #A90D91">int</span> <span style="color: #000000">buffer_len</span>)
+{
+    <span style="color: #A90D91">int</span> <span style="color: #000000">value</span>;
+    <span style="color: #A90D91">uint16_t</span> <span style="color: #000000">chr_val_handle</span>;
+    <span style="color: #A90D91">int</span> <span style="color: #000000">rc</span>;
+
+    <span style="color: #000000">value</span> <span style="color: #000000">=</span> <span style="color: #000000">adc_read</span>(<span style="color: #000000">buffer</span>, <span style="color: #000000">buffer_len</span>);
+    <span style="color: #A90D91">if</span> (<span style="color: #000000">value</span> <span style="color: #000000">&gt;=</span> <span style="color: #1C01CE">0</span>) {
+        <span style="color: #000000">console_printf</span>(<span style="color: #C41A16">&quot;Got %d\n&quot;</span>, <span style="color: #000000">value</span>);
+    } <span style="color: #A90D91">else</span> {
+        <span style="color: #000000">console_printf</span>(<span style="color: #C41A16">&quot;Error while reading: %d\n&quot;</span>, <span style="color: #000000">value</span>);
+        <span style="color: #A90D91">goto</span> <span style="color: #000000">err</span>;
+    }
+    <span style="color: #000000">gatt_adc_val</span> <span style="color: #000000">=</span> <span style="color: #000000">value</span>;
+    <span style="color: #000000">rc</span> <span style="color: #000000">=</span> <span style="color: #000000">ble_gatts_find_chr</span>(<span style="color: #000000">&amp;gatt_svr_svc_adc_uuid</span>.<span style="color: #000000">u</span>, <span style="color: #000000">BLE_UUID16_DECLARE</span>(<span style="color: #000000">ADC_SNS_VAL</span>), <span style="color: #A90D91">NULL</span>, <span style="color: #000000">&amp;chr_val_handle</span>);
+    <span style="color: #000000">assert</span>(<span style="color: #000000">rc</span> <span style="color: #000000">==</span> <span style="color: #1C01CE">0</span>);
+    <span style="color: #000000">ble_gatts_chr_updated</span>(<span style="color: #000000">chr_val_handle</span>);
+    <span style="color: #A90D91">return</span> (<span style="color: #1C01CE">0</span>);
+<span style="color: #000000">err</span>:
+    <span style="color: #A90D91">return</span> (<span style="color: #000000">rc</span>);
+} 
+</pre></div>
+
+
+<p>This is where we actually read the ADC value and then update the BLE Characteristic for that value. </p>
+<p>But wait, we haven't defined those BLE services and characteristics yet! Right, so don't try to build and run this
+app just yet or it will surely fail. Instead, move on to the next section and get all of those services 
+defined.</p>
+<p><br></p>
+<h3 id="building-the-ble-services">Building the BLE Services</h3>
+<p>If the nrf52_adc app is going to be a Bluetooth-enabled sensor app that will allow you to read the value of the eTape Water Level Sensor
+via Bluetooth we'll need to actually define those Services and Characteristics.</p>
+<p>As with the <a href="../bleprph/bleprph-app/">ble peripheral</a> app, we will advertise a couple of values from our app. The first is
+not strictly necessary, but it will help us build an iOS app later. We've defined a service and the characteristics in
+that service in <code>bleadc.h</code> in the <code>apps/nrf52_adc/src/</code> directory as follows:</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%"><span style="color: #177500">/* Sensor Data */</span>
+<span style="color: #177500">/* e761d2af-1c15-4fa7-af80-b5729002b340 */</span>
+<span style="color: #A90D91">static</span> <span style="color: #A90D91">const</span> <span style="color: #A90D91">ble_uuid128_t</span> <span style="color: #000000">gatt_svr_svc_adc_uuid</span> <span style="color: #000000">=</span>
+        <span style="color: #000000">BLE_UUID128_INIT</span>(<span style="color: #1C01CE">0x40</span>, <span style="color: #1C01CE">0xb3</span>, <span style="color: #1C01CE">0x20</span>, <span style="color: #1C01CE">0x90</span>, <span style="color: #1C01CE">0x72</span>, <span style="color: #1C01CE">0xb5</span>, <span style="color: #1C01CE">0x80</span>, <span style="color: #1C01CE">0xaf</span>,
+                         <span style="color: #1C01CE">0xa7</span>, <span style="color: #1C01CE">0x4f</span>, <span style="color: #1C01CE">0x15</span>, <span style="color: #1C01CE">0x1c</span>, <span style="color: #1C01CE">0xaf</span>, <span style="color: #1C01CE">0xd2</span>, <span style="color: #1C01CE">0x61</span>, <span style="color: #1C01CE">0xe7</span>);
+<span style="color: #633820">#define ADC_SNS_TYPE          0xDEAD</span>
+<span style="color: #633820">#define ADC_SNS_STRING &quot;eTape Liquid Level Sensor&quot;</span>
+<span style="color: #633820">#define ADC_SNS_VAL           0xBEAD</span>
+<span style="color: #A90D91">extern</span> <span style="color: #A90D91">uint16_t</span> <span style="color: #000000">gatt_adc_val</span>; 
+</pre></div>
+
+
+<p>The first is the UUID of the service, followed by the 2 characteristics we are going to offer.
+The first characteristic is going to advertise the <em>type</em> of sensor we are advertising, and
+it will be a read-only characteristic. The second characteristic will be the sensor value
+itself, and we will allow connected devices to 'subscribe' to it in order to get 
+constantly-updated values.</p>
+<p><strong>Note:</strong> You can choose any valid Characteristic UUIDs to go here. We're using these values
+for illustrative purposes only.</p>
+<p>The value that we'll be updating is also defined here as <code>gatt_adc_val</code>.</p>
+<p>If we then go look at <code>gatt_srv.c</code> we can see the structure of the service and
+characteristic offering that we set up:</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%"><span style="color: #A90D91">static</span> <span style="color: #A90D91">const</span> <span style="color: #A90D91">struct</span> <span style="color: #000000">ble_gatt_svc_def</span> <span style="color: #000000">gatt_svr_svcs</span>[] <span style="color: #000000">=</span> {
+    {
+        <span style="color: #177500">/*** Service: Security test. */</span>
+        .<span style="color: #000000">type</span> <span style="color: #000000">=</span> <span style="color: #000000">BLE_GATT_SVC_TYPE_PRIMARY</span>,
+        .<span style="color: #000000">uuid</span> <span style="color: #000000">=</span> <span style="color: #000000">&amp;gatt_svr_svc_sec_test_uuid</span>.<span style="color: #000000">u</span>,
+        .<span style="color: #000000">characteristics</span> <span style="color: #000000">=</span> (<span style="color: #A90D91">struct</span> <span style="color: #000000">ble_gatt_chr_def</span>[]) { {
+            <span style="color: #177500">/*** Characteristic: Random number generator. */</span>
+            .<span style="color: #000000">uuid</span> <span style="color: #000000">=</span> <span style="color: #000000">&amp;gatt_svr_chr_sec_test_rand_uuid</span>.<span style="color: #000000">u</span>,
+            .<span style="color: #000000">access_cb</span> <span style="color: #000000">=</span> <span style="color: #000000">gatt_svr_chr_access_sec_test</span>,
+            .<span style="color: #000000">flags</span> <span style="color: #000000">=</span> <span style="color: #000000">BLE_GATT_CHR_F_READ</span> <span style="color: #000000">|</span> <span style="color: #000000">BLE_GATT_CHR_F_READ_ENC</span>,
+        }, {
+            <span style="color: #177500">/*** Characteristic: Static value. */</span>
+            .<span style="color: #000000">uuid</span> <span style="color: #000000">=</span> <span style="color: #000000">&amp;gatt_svr_chr_sec_test_static_uuid</span>.<span style="color: #000000">u</span>,
+            .<span style="color: #000000">access_cb</span> <span style="color: #000000">=</span> <span style="color: #000000">gatt_svr_chr_access_sec_test</span>,
+            .<span style="color: #000000">flags</span> <span style="color: #000000">=</span> <span style="color: #000000">BLE_GATT_CHR_F_READ</span> <span style="color: #000000">|</span>
+                     <span style="color: #000000">BLE_GATT_CHR_F_WRITE</span> <span style="color: #000000">|</span> <span style="color: #000000">BLE_GATT_CHR_F_WRITE_ENC</span>,
+        }, {
+            <span style="color: #1C01CE">0</span>, <span style="color: #177500">/* No more characteristics in this service. */</span>
+        } },
+    },
+<span style="background-color: #ffffcc">    {
+</span><span style="background-color: #ffffcc">        <span style="color: #177500">/*** ADC Level Notification Service. */</span>
+</span><span style="background-color: #ffffcc">        .<span style="color: #000000">type</span> <span style="color: #000000">=</span> <span style="color: #000000">BLE_GATT_SVC_TYPE_PRIMARY</span>,
+</span><span style="background-color: #ffffcc">        .<span style="color: #000000">uuid</span> <span style="color: #000000">=</span> <span style="color: #000000">&amp;gatt_svr_svc_adc_uuid</span>.<span style="color: #000000">u</span>,
+</span><span style="background-color: #ffffcc">        .<span style="color: #000000">characteristics</span> <span style="color: #000000">=</span> (<span style="color: #A90D91">struct</span> <span style="color: #000000">ble_gatt_chr_def</span>[]) { {
+</span><span style="background-color: #ffffcc">            .<span style="color: #000000">uuid</span> <span style="color: #000000">=</span> <span style="color: #000000">BLE_UUID16_DECLARE</span>(<span style="color: #000000">ADC_SNS_TYPE</span>),
+</span><span style="background-color: #ffffcc">            .<span style="color: #000000">access_cb</span> <span style="color: #000000">=</span> <span style="color: #000000">gatt_svr_sns_access</span>,
+</span><span style="background-color: #ffffcc">            .<span style="color: #000000">flags</span> <span style="color: #000000">=</span> <span style="color: #000000">BLE_GATT_CHR_F_READ</span>,
+</span><span style="background-color: #ffffcc">        }, {
+</span><span style="background-color: #ffffcc">            .<span style="color: #000000">uuid</span> <span style="color: #000000">=</span> <span style="color: #000000">BLE_UUID16_DECLARE</span>(<span style="color: #000000">ADC_SNS_VAL</span>),
+</span><span style="background-color: #ffffcc">            .<span style="color: #000000">access_cb</span> <span style="color: #000000">=</span> <span style="color: #000000">gatt_svr_sns_access</span>,
+</span><span style="background-color: #ffffcc">            .<span style="color: #000000">flags</span> <span style="color: #000000">=</span> <span style="color: #000000">BLE_GATT_CHR_F_NOTIFY</span>,
+</span><span style="background-color: #ffffcc">        }, {
+</span><span style="background-color: #ffffcc">            <span style="color: #1C01CE">0</span>, <span style="color: #177500">/* No more characteristics in this service. */</span>
+</span><span style="background-color: #ffffcc">        } },
+</span><span style="background-color: #ffffcc">    },
+</span><span style="background-color: #ffffcc">
+</span>    {
+        <span style="color: #1C01CE">0</span>, <span style="color: #177500">/* No more services. */</span>
+    },
+};
+</pre></div>
+
+
+<p>You should recognize the first services from the <a href="../bleprph/bleprph-intro/">BLE Peripheral</a>
+tutorial earlier. We're just adding another Service, with 2 new Characteristics, to 
+that application.</p>
+<p>We'll need to fill in the function that will be called for this service, <code>gatt_srv_sns_access</code>
+next so that the service knows what to do.</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%"><span style="color: #A90D91">static</span> <span style="color: #A90D91">int</span>
+<span style="color: #000000">gatt_svr_sns_access</span>(<span style="color: #A90D91">uint16_t</span> <span style="color: #000000">conn_handle</span>, <span style="color: #A90D91">uint16_t</span> <span style="color: #000000">attr_handle</span>,
+                          <span style="color: #A90D91">struct</span> <span style="color: #000000">ble_gatt_access_ctxt</span> <span style="color: #000000">*ctxt</span>,
+                          <span style="color: #A90D91">void</span> <span style="color: #000000">*arg</span>)
+{
+    <span style="color: #A90D91">uint16_t</span> <span style="color: #000000">uuid16</span>;
+    <span style="color: #A90D91">int</span> <span style="color: #000000">rc</span>;
+
+    <span style="color: #000000">uuid16</span> <span style="color: #000000">=</span> <span style="color: #000000">ble_uuid_u16</span>(<span style="color: #000000">ctxt-&gt;chr-&gt;uuid</span>);
+
+    <span style="color: #A90D91">switch</span> (<span style="color: #000000">uuid16</span>) {
+    <span style="color: #A90D91">case</span> <span style="color: #000000">ADC_SNS_TYPE</span>:
+        <span style="color: #000000">assert</span>(<span style="color: #000000">ctxt-&gt;op</span> <span style="color: #000000">==</span> <span style="color: #000000">BLE_GATT_ACCESS_OP_READ_CHR</span>);
+        <span style="color: #000000">rc</span> <span style="color: #000000">=</span> <span style="color: #000000">os_mbuf_append</span>(<span style="color: #000000">ctxt-&gt;om</span>, <span style="color: #000000">ADC_SNS_STRING</span>, <span style="color: #A90D91">sizeof</span> <span style="color: #000000">ADC_SNS_STRING</span>);
+        <span style="color: #000000">BLEPRPH_LOG</span>(<span style="color: #000000">INFO</span>, <span style="color: #C41A16">&quot;ADC SENSOR TYPE READ: %s\n&quot;</span>, <span style="color: #000000">ADC_SNS_STRING</span>);
+        <span style="color: #A90D91">return</span> <span style="color: #000000">rc</span> <span style="color: #000000">==</span> <span style="color: #1C01CE">0</span> <span style="color: #000000">?</span> <span style="color: #1C01CE">0</span> <span style="color: #000000">:</span> <span style="color: #000000">BLE_ATT_ERR_INSUFFICIENT_RES</span>;
+
+    <span style="color: #A90D91">case</span> <span style="color: #000000">ADC_SNS_VAL</span>:
+        <span style="color: #A90D91">if</span> (<span style="color: #000000">ctxt-&gt;op</span> <span style="color: #000000">==</span> <span style="color: #000000">BLE_GATT_ACCESS_OP_WRITE_CHR</span>) {
+            <span style="color: #000000">rc</span> <span style="color: #000000">=</span> <span style="color: #000000">gatt_svr_chr_write</span>(<span style="color: #000000">ctxt-&gt;om</span>, <span style="color: #1C01CE">0</span>,
+                                    <span style="color: #A90D91">sizeof</span> <span style="color: #000000">gatt_adc_val</span>,
+                                    <span style="color: #000000">&amp;gatt_adc_val</span>,
+                                    <span style="color: #A90D91">NULL</span>);
+            <span style="color: #A90D91">return</span> <span style="color: #000000">rc</span>;
+        } <span style="color: #A90D91">else</span> <span style="color: #A90D91">if</span> (<span style="color: #000000">ctxt-&gt;op</span> <span style="color: #000000">==</span> <span style="color: #000000">BLE_GATT_ACCESS_OP_READ_CHR</span>) {
+            <span style="color: #000000">rc</span> <span style="color: #000000">=</span> <span style="color: #000000">os_mbuf_append</span>(<span style="color: #000000">ctxt-&gt;om</span>, <span style="color: #000000">&amp;gatt_adc_val</span>,
+                                <span style="color: #A90D91">sizeof</span> <span style="color: #000000">gatt_adc_val</span>);
+            <span style="color: #A90D91">return</span> <span style="color: #000000">rc</span> <span style="color: #000000">==</span> <span style="color: #1C01CE">0</span> <span style="color: #000000">?</span> <span style="color: #1C01CE">0</span> <span style="color: #000000">:</span> <span style="color: #000000">BLE_ATT_ERR_INSUFFICIENT_RES</span>;
+        }
+
+    <span style="color: #A90D91">default</span><span style="color: #000000">:</span>
+        <span style="color: #000000">assert</span>(<span style="color: #1C01CE">0</span>);
+        <span style="color: #A90D91">return</span> <span style="color: #000000">BLE_ATT_ERR_UNLIKELY</span>;
+    }
+}
+</pre></div>
+
+
+<p>You can see that when request is for the <code>ADC_SNS_TYPE</code>, we return the
+Sensor Type we defined earlier. If the request if for <code>ADC_SNS_VAL</code> we'll return the
+<code>gatt_adc_val</code> value. </p>
+<p>Don't forget to include the <code>bleadc.h</code> include file at the top of the <code>gatt_svr.c</code> file!</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%">#include &lt;assert.h&gt;
+#include &lt;stdio.h&gt;
+#include &lt;string.h&gt;
+#include &quot;bsp/bsp.h&quot;
+#include &quot;host/ble_hs.h&quot;
+#include &quot;host/ble_uuid.h&quot;
+#include &quot;bleprph.h&quot;
+<span style="background-color: #ffffcc">#include &quot;bleadc.h&quot;
+</span></pre></div>
+
+
+<p>If you build, load and run this application now, you will see all those Services and Characteristics
+advertised, and you will even be able to read the "Sensor Type" String via the ADC_SNS_TYPE
+Characteristic.</p>
+<p><br></p>
+<h3 id="adding-the-etape-water-sensor">Adding the eTape Water Sensor</h3>
+<p>Now that we have a fully functioning BLE App that we can subscribe to sensor
+values from, it's time to actually wire up the sensor!</p>
+<p>As previously mentioned, we're going to be using an eTape Water Level Sensor. You can 
+get one from <a href="https://www.adafruit.com/products/1786">Adafruit</a>. </p>
+<p>We're going to use the sensor as a resistive sensor, and the setup is very simple. 
+I'll be using a 'breadboard` to put this all together for illustrative purposes. 
+First, attach a jumper-wire from Vdd on the board to the breadboard.
+Next, attach a jumper wire from pin P0.03 on the board to the breadboard. This will be
+our ADC-in. The sensor should have come with a 560 ohm resistor, so plug that
+into the board between Vdd and ADC-in holes. Finally, attach a jumper from
+GND on the board to your breadboard. At this point, your breadboard should look
+like this:</p>
+<p><img alt="Bread Board Setup" src="../pics/breadboard.png" /></p>
+<p>Now attach one of the middle 2 leads from the sensor to ground on the breadboard and 
+the other middle lead to the ADC-in on the breadboard. Your breadboard should now look
+like this:</p>
+<p><img alt="Bread Board Final" src="../pics/adc-demo-1.png" /></p>
+<p>And your eTape Sensor should look like this (at least if you have it mounted in a
+graduated cylinder as I do).</p>
+<p><img alt="eTape Sensor Setup" src="../pics/adc-demo-2.png" /></p>
+<p>That concludes the hardware portion. Easy!</p>
+<p>At this point you should be able to build, create-image and load your application and see it properly 
+sending readings. </p>
+<p><br></p>
+<h3 id="conclusion">Conclusion</h3>
+<p>Congratulations, you've now completed both a hardware project and a software project by connecting a
+sensor to your device and using Mynewt to read data from that sensor and send it via Bluetooth
+to a connected device. That's no small feat!</p>
+<p>If you see anything missing or want to send us feedback, please do so by signing up for 
+appropriate mailing lists on our <a href="../../../community/">Community Page</a>.</p>
+<p>Keep on hacking and sensing!</p>
+<p><br></p>
+<h3 id="note">Note</h3>
+<p>If you're wondering how to actually view these sensor readings via Bluetooth, you have a couple of
+options. On Mac OS or iOS you can download the <a href="https://itunes.apple.com/us/app/lightblue-explorer-bluetooth/id557428110?mt=8">LightBlue app</a>.
+This app lets you connect to, and interrogate, BLE devices like the one you just built. </p>
+<p>If you used the BLE Service and Characteristic UUIDs used in this tutorial, you can also download
+and use a Mac OS <a href="https://dragonflyiot.com/MyNewtSensorReader.zip">MyNewt Sensor Reader App</a> (Zip Archive) that allows 
+you to graph your data, etc. An iOS version is in Beta testing and should be available soon.</p>
+<p><img alt="My Newt Sensor Reader" src="../pics/MyNewtSensorReader006.jpg" /></p>
+<p>Enjoy!</p>
+                        
+                        <div class="row">
+                            
+
+
+
+<ul class="nav nav-pills" style="margin-bottom: 10px">
+    <li>
+    
+    <a href=../air_quality_ble/>
+        <span class="fa fa-arrow-left"></span>
+        Previous: BLE-enabled Air Quality Sensor
+    </a>
+    
+    </li>
+    <li class="pull-right">
+    
+    <a href=../../os_user_guide/>
+        Next: OS User Guide
+        <span class="fa fa-arrow-right"></span>
+    </a>
+    
+    </li>
+</ul>
+                        </div>
+                        <footer class="row">
+    <div class="col-xs-12">
+        
+            <p class="copyright">Apache Mynewt (incubating) is available under Apache License, version 2.0.</p>
+        
+    </div>
+    <div class="col-xs-12">
+        <div class="logos">
+            <img src="/img/asf_logo_wide_small.png" alt="Apache" title="Apache">
+            <small class="footnote">
+                MyNewt is an effort undergoing incubation at The Apache Software Foundation (ASF), sponsored by the Apache Incubator. Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects. While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF.
+            </small>
+            <img src="/img/egg-logo2.png" alt="Apache Incubator" title="Apache Incubator">
+        </div>
+    </div>
+</footer>
+                    </div>
+                </div>
+            
+            
+        </div>
+
+        <script src="../../../js/jquery-1.10.2.min.js"></script>
+        <script src="../../../js/bootstrap-3.0.3.min.js"></script>
+        <script src="../../../js/highlight.pack.js"></script>
+        <script src="../../../js/base.js"></script>
+        <script src="../../../js/custom.js"></script>
+
+    </body>
+</html>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/olimex/index.html
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/olimex/index.html b/latest/os/tutorials/olimex/index.html
index 4fa4ac8..474dc31 100644
--- a/latest/os/tutorials/olimex/index.html
+++ b/latest/os/tutorials/olimex/index.html
@@ -341,19 +341,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -432,6 +419,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/pics/MyNewtSensorReader006.jpg
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/pics/MyNewtSensorReader006.jpg b/latest/os/tutorials/pics/MyNewtSensorReader006.jpg
new file mode 100644
index 0000000..c15d69d
Binary files /dev/null and b/latest/os/tutorials/pics/MyNewtSensorReader006.jpg differ

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/pics/adc-demo-1.png
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/pics/adc-demo-1.png b/latest/os/tutorials/pics/adc-demo-1.png
new file mode 100644
index 0000000..6e5de58
Binary files /dev/null and b/latest/os/tutorials/pics/adc-demo-1.png differ

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/pics/adc-demo-2.png
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/pics/adc-demo-2.png b/latest/os/tutorials/pics/adc-demo-2.png
new file mode 100644
index 0000000..be2cce7
Binary files /dev/null and b/latest/os/tutorials/pics/adc-demo-2.png differ

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/pics/breadboard.png
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/pics/breadboard.png b/latest/os/tutorials/pics/breadboard.png
new file mode 100644
index 0000000..39a2b9d
Binary files /dev/null and b/latest/os/tutorials/pics/breadboard.png differ

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/pin-wheel-mods/index.html
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/pin-wheel-mods/index.html b/latest/os/tutorials/pin-wheel-mods/index.html
index 87305e6..478c69e 100644
--- a/latest/os/tutorials/pin-wheel-mods/index.html
+++ b/latest/os/tutorials/pin-wheel-mods/index.html
@@ -355,19 +355,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -446,6 +433,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/project-slinky/index.html
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/project-slinky/index.html b/latest/os/tutorials/project-slinky/index.html
index 84ad02c..29eb77c 100644
--- a/latest/os/tutorials/project-slinky/index.html
+++ b/latest/os/tutorials/project-slinky/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -389,6 +376,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/project-target-slinky/index.html
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/project-target-slinky/index.html b/latest/os/tutorials/project-target-slinky/index.html
index c358141..3053fdb 100644
--- a/latest/os/tutorials/project-target-slinky/index.html
+++ b/latest/os/tutorials/project-target-slinky/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -389,6 +376,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/repo/add_repos/index.html
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/repo/add_repos/index.html b/latest/os/tutorials/repo/add_repos/index.html
index d583da3..e82bad1 100644
--- a/latest/os/tutorials/repo/add_repos/index.html
+++ b/latest/os/tutorials/repo/add_repos/index.html
@@ -308,19 +308,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -399,6 +386,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/repo/create_repo/index.html
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/repo/create_repo/index.html b/latest/os/tutorials/repo/create_repo/index.html
index 772c160..71ad672 100644
--- a/latest/os/tutorials/repo/create_repo/index.html
+++ b/latest/os/tutorials/repo/create_repo/index.html
@@ -308,19 +308,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -399,6 +386,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/repo/private_repo/index.html
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/repo/private_repo/index.html b/latest/os/tutorials/repo/private_repo/index.html
index 269b7f1..07e3b10 100644
--- a/latest/os/tutorials/repo/private_repo/index.html
+++ b/latest/os/tutorials/repo/private_repo/index.html
@@ -308,19 +308,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -399,6 +386,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/repo/upgrade_repo/index.html
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/repo/upgrade_repo/index.html b/latest/os/tutorials/repo/upgrade_repo/index.html
index b549fd9..e1ae91c 100644
--- a/latest/os/tutorials/repo/upgrade_repo/index.html
+++ b/latest/os/tutorials/repo/upgrade_repo/index.html
@@ -308,19 +308,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -399,6 +386,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/tasks_lesson/index.html
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/tasks_lesson/index.html b/latest/os/tutorials/tasks_lesson/index.html
index 1f6e925..a2841e5 100644
--- a/latest/os/tutorials/tasks_lesson/index.html
+++ b/latest/os/tutorials/tasks_lesson/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -369,6 +356,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/tutorials/index.html
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/tutorials/index.html b/latest/os/tutorials/tutorials/index.html
index 5d8b7b3..b2ce3fa 100644
--- a/latest/os/tutorials/tutorials/index.html
+++ b/latest/os/tutorials/tutorials/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -369,6 +356,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>



[7/9] incubator-mynewt-site git commit: Added etape sensor tutorial. PR #152.

Posted by ad...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/os_user_guide/index.html
----------------------------------------------------------------------
diff --git a/develop/os/os_user_guide/index.html b/develop/os/os_user_guide/index.html
index 0cb36ff..7d9f54e 100644
--- a/develop/os/os_user_guide/index.html
+++ b/develop/os/os_user_guide/index.html
@@ -550,9 +550,9 @@
 <ul class="nav nav-pills" style="margin-bottom: 10px">
     <li>
     
-    <a href=../tutorials/blehci_project/>
+    <a href=../tutorials/nrf52_adc/>
         <span class="fa fa-arrow-left"></span>
-        Previous: BLE HCI interface
+        Previous: Add an Analog Sensor
     </a>
     
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/STM32F303/index.html
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/STM32F303/index.html b/develop/os/tutorials/STM32F303/index.html
index 07ea871..3733065 100644
--- a/develop/os/tutorials/STM32F303/index.html
+++ b/develop/os/tutorials/STM32F303/index.html
@@ -355,19 +355,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -446,6 +433,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/add_newtmgr/index.html
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/add_newtmgr/index.html b/develop/os/tutorials/add_newtmgr/index.html
index 22f7ca7..ebe6657 100644
--- a/develop/os/tutorials/add_newtmgr/index.html
+++ b/develop/os/tutorials/add_newtmgr/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -369,6 +356,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/add_shell/index.html
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/add_shell/index.html b/develop/os/tutorials/add_shell/index.html
index dbf6aaf..43428f6 100644
--- a/develop/os/tutorials/add_shell/index.html
+++ b/develop/os/tutorials/add_shell/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -369,6 +356,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/air_quality_ble/index.html
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/air_quality_ble/index.html b/develop/os/tutorials/air_quality_ble/index.html
index acc4133..da02e02 100644
--- a/develop/os/tutorials/air_quality_ble/index.html
+++ b/develop/os/tutorials/air_quality_ble/index.html
@@ -10,7 +10,7 @@
         <link rel="canonical" href="http://mynewt.apache.org/os/tutorials/air_quality_ble/"> -->
         <link rel="shortcut icon" href="../../../img/favicon.ico">
 
-	    <title>Bluetooth-enabled Air Quality Sensor - Apache Mynewt</title>
+	    <title>BLE-enabled Air Quality Sensor - Apache Mynewt</title>
 
         <link href="../../../css/bootstrap-3.0.3.min.css" rel="stylesheet">
         <link rel="stylesheet" href="../../../css/highlight.css">
@@ -41,7 +41,7 @@
     </head>
 
 
-    <body class="Bluetooth-enabled Air Quality Sensor">
+    <body class="BLE-enabled Air Quality Sensor">
 
 
         <div class="container">
@@ -278,33 +278,37 @@
           
               
                 
+    <li >
+      <a href="../event_queue/">Add task to manage multiple events</a>
+    </li>
+
+              
+          
+              
+                
   
   
     <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
+  ../project-slinky/
+">Project Slinky for remote comms</a>
   
   
-    <ul>
-          
-              
-                
-    <li >
-      <a href="../air_quality_sensor/">Basic Air Quality Sensor</a>
     </li>
 
               
           
               
                 
-    <li class="active">
-      <a href="./">Bluetooth-enabled Air Quality Sensor</a>
+    <li >
+      <a href="../add_newtmgr/">Enable Newt Manager in any app</a>
     </li>
 
               
           
-    </ul>
-  
+              
+                
+    <li >
+      <a href="../add_shell/">Enable the OS Shell and Console</a>
     </li>
 
               
@@ -312,7 +316,7 @@
               
                 
     <li >
-      <a href="../event_queue/">Add task to manage multiple events</a>
+      <a href="../bletiny_project/">BLE app to check stats via console</a>
     </li>
 
               
@@ -321,9 +325,7 @@
                 
   
   
-    <li><a href="
-  ../project-slinky/
-">Project Slinky for remote comms</a>
+    <li ><a href="../bleprph/bleprph-intro/">BLE peripheral project</a>
   
   
     </li>
@@ -333,7 +335,7 @@
               
                 
     <li >
-      <a href="../add_newtmgr/">Enable Newt Manager in any app</a>
+      <a href="../ibeacon/">BLE iBeacon</a>
     </li>
 
               
@@ -341,7 +343,7 @@
               
                 
     <li >
-      <a href="../add_shell/">Enable the OS Shell and Console</a>
+      <a href="../eddystone/">BLE Eddystone</a>
     </li>
 
               
@@ -349,7 +351,7 @@
               
                 
     <li >
-      <a href="../bletiny_project/">BLE app to check stats via console</a>
+      <a href="../blehci_project/">BLE HCI interface</a>
     </li>
 
               
@@ -358,25 +360,31 @@
                 
   
   
-    <li ><a href="../bleprph/bleprph-intro/">BLE peripheral project</a>
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
   
   
-    </li>
-
-              
+    <ul>
           
               
                 
     <li >
-      <a href="../ibeacon/">BLE iBeacon</a>
+      <a href="../air_quality_sensor/">Basic Air Quality Sensor</a>
     </li>
 
               
           
               
                 
-    <li >
-      <a href="../eddystone/">BLE Eddystone</a>
+    <li class="active">
+      <a href="./">BLE-enabled Air Quality Sensor</a>
+    </li>
+
+              
+          
+    </ul>
+  
     </li>
 
               
@@ -384,7 +392,7 @@
               
                 
     <li >
-      <a href="../blehci_project/">BLE HCI interface</a>
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
     </li>
 
               
@@ -479,7 +487,7 @@
         
       
       
-        <li>&raquo; Bluetooth-enabled Air Quality Sensor</li>
+        <li>&raquo; BLE-enabled Air Quality Sensor</li>
       
     
     
@@ -704,8 +712,8 @@ or any other application that can connect to, and read, Bluetooth data.</p>
     </li>
     <li class="pull-right">
     
-    <a href=../event_queue/>
-        Next: Add task to manage multiple events
+    <a href=../nrf52_adc/>
+        Next: Add an Analog Sensor
         <span class="fa fa-arrow-right"></span>
     </a>
     

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/air_quality_sensor/index.html
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/air_quality_sensor/index.html b/develop/os/tutorials/air_quality_sensor/index.html
index 5744c8d..aea6c7e 100644
--- a/develop/os/tutorials/air_quality_sensor/index.html
+++ b/develop/os/tutorials/air_quality_sensor/index.html
@@ -278,19 +278,21 @@
           
               
                 
+    <li >
+      <a href="../event_queue/">Add task to manage multiple events</a>
+    </li>
+
+              
+          
+              
+                
   
   
     <li><a href="
-  ./
-">Air-quality Sensor project</a>
+  ../project-slinky/
+">Project Slinky for remote comms</a>
   
   
-    <ul>
-          
-              
-                
-    <li class="active">
-      <a href="./">Basic Air Quality Sensor</a>
     </li>
 
               
@@ -298,13 +300,15 @@
               
                 
     <li >
-      <a href="../air_quality_ble/">Bluetooth-enabled Air Quality Sensor</a>
+      <a href="../add_newtmgr/">Enable Newt Manager in any app</a>
     </li>
 
               
           
-    </ul>
-  
+              
+                
+    <li >
+      <a href="../add_shell/">Enable the OS Shell and Console</a>
     </li>
 
               
@@ -312,7 +316,7 @@
               
                 
     <li >
-      <a href="../event_queue/">Add task to manage multiple events</a>
+      <a href="../bletiny_project/">BLE app to check stats via console</a>
     </li>
 
               
@@ -321,9 +325,7 @@
                 
   
   
-    <li><a href="
-  ../project-slinky/
-">Project Slinky for remote comms</a>
+    <li ><a href="../bleprph/bleprph-intro/">BLE peripheral project</a>
   
   
     </li>
@@ -333,7 +335,7 @@
               
                 
     <li >
-      <a href="../add_newtmgr/">Enable Newt Manager in any app</a>
+      <a href="../ibeacon/">BLE iBeacon</a>
     </li>
 
               
@@ -341,7 +343,7 @@
               
                 
     <li >
-      <a href="../add_shell/">Enable the OS Shell and Console</a>
+      <a href="../eddystone/">BLE Eddystone</a>
     </li>
 
               
@@ -349,7 +351,7 @@
               
                 
     <li >
-      <a href="../bletiny_project/">BLE app to check stats via console</a>
+      <a href="../blehci_project/">BLE HCI interface</a>
     </li>
 
               
@@ -358,9 +360,17 @@
                 
   
   
-    <li ><a href="../bleprph/bleprph-intro/">BLE peripheral project</a>
+    <li><a href="
+  ./
+">Air-quality Sensor project</a>
   
   
+    <ul>
+          
+              
+                
+    <li class="active">
+      <a href="./">Basic Air Quality Sensor</a>
     </li>
 
               
@@ -368,15 +378,13 @@
               
                 
     <li >
-      <a href="../ibeacon/">BLE iBeacon</a>
+      <a href="../air_quality_ble/">BLE-enabled Air Quality Sensor</a>
     </li>
 
               
           
-              
-                
-    <li >
-      <a href="../eddystone/">BLE Eddystone</a>
+    </ul>
+  
     </li>
 
               
@@ -384,7 +392,7 @@
               
                 
     <li >
-      <a href="../blehci_project/">BLE HCI interface</a>
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
     </li>
 
               
@@ -1301,16 +1309,16 @@ Loading app image into slot 1
 <ul class="nav nav-pills" style="margin-bottom: 10px">
     <li>
     
-    <a href=../unit_test/>
+    <a href=../blehci_project/>
         <span class="fa fa-arrow-left"></span>
-        Previous: Write a Test Suite for a Package
+        Previous: BLE HCI interface
     </a>
     
     </li>
     <li class="pull-right">
     
     <a href=../air_quality_ble/>
-        Next: Bluetooth-enabled Air Quality Sensor
+        Next: BLE-enabled Air Quality Sensor
         <span class="fa fa-arrow-right"></span>
     </a>
     

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/arduino_zero/index.html
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/arduino_zero/index.html b/develop/os/tutorials/arduino_zero/index.html
index 76b6d22..5a7ec42 100644
--- a/develop/os/tutorials/arduino_zero/index.html
+++ b/develop/os/tutorials/arduino_zero/index.html
@@ -341,19 +341,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -432,6 +419,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/blehci_project/index.html
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/blehci_project/index.html b/develop/os/tutorials/blehci_project/index.html
index 0305c17..e3bc630 100644
--- a/develop/os/tutorials/blehci_project/index.html
+++ b/develop/os/tutorials/blehci_project/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -369,6 +356,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>
@@ -635,8 +643,8 @@ eir_len 23
     </li>
     <li class="pull-right">
     
-    <a href=../../os_user_guide/>
-        Next: OS User Guide
+    <a href=../air_quality_sensor/>
+        Next: Basic Air Quality Sensor
         <span class="fa fa-arrow-right"></span>
     </a>
     

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/bleprph/bleprph-adv/index.html
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/bleprph/bleprph-adv/index.html b/develop/os/tutorials/bleprph/bleprph-adv/index.html
index e46264d..51f09ee 100644
--- a/develop/os/tutorials/bleprph/bleprph-adv/index.html
+++ b/develop/os/tutorials/bleprph/bleprph-adv/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -415,6 +402,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/bleprph/bleprph-app/index.html
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/bleprph/bleprph-app/index.html b/develop/os/tutorials/bleprph/bleprph-app/index.html
index fd63539..c418c9a 100644
--- a/develop/os/tutorials/bleprph/bleprph-app/index.html
+++ b/develop/os/tutorials/bleprph/bleprph-app/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -415,6 +402,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/bleprph/bleprph-chr-access/index.html
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/bleprph/bleprph-chr-access/index.html b/develop/os/tutorials/bleprph/bleprph-chr-access/index.html
index d4426bd..b811ac5 100644
--- a/develop/os/tutorials/bleprph/bleprph-chr-access/index.html
+++ b/develop/os/tutorials/bleprph/bleprph-chr-access/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -415,6 +402,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/bleprph/bleprph-gap-event/index.html
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/bleprph/bleprph-gap-event/index.html b/develop/os/tutorials/bleprph/bleprph-gap-event/index.html
index 2b3db93..4b8bb74 100644
--- a/develop/os/tutorials/bleprph/bleprph-gap-event/index.html
+++ b/develop/os/tutorials/bleprph/bleprph-gap-event/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -415,6 +402,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/bleprph/bleprph-intro/index.html
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/bleprph/bleprph-intro/index.html b/develop/os/tutorials/bleprph/bleprph-intro/index.html
index b531bc0..a12297e 100644
--- a/develop/os/tutorials/bleprph/bleprph-intro/index.html
+++ b/develop/os/tutorials/bleprph/bleprph-intro/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -415,6 +402,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/bleprph/bleprph-svc-reg/index.html
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/bleprph/bleprph-svc-reg/index.html b/develop/os/tutorials/bleprph/bleprph-svc-reg/index.html
index a83cac7..cbea8a4 100644
--- a/develop/os/tutorials/bleprph/bleprph-svc-reg/index.html
+++ b/develop/os/tutorials/bleprph/bleprph-svc-reg/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -415,6 +402,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/bletiny_project/index.html
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/bletiny_project/index.html b/develop/os/tutorials/bletiny_project/index.html
index 63b4787..ef8f4ce 100644
--- a/develop/os/tutorials/bletiny_project/index.html
+++ b/develop/os/tutorials/bletiny_project/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -369,6 +356,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/blinky_console/index.html
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/blinky_console/index.html b/develop/os/tutorials/blinky_console/index.html
index 7702a53..d55c683 100644
--- a/develop/os/tutorials/blinky_console/index.html
+++ b/develop/os/tutorials/blinky_console/index.html
@@ -341,19 +341,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -432,6 +419,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/blinky_primo/index.html
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/blinky_primo/index.html b/develop/os/tutorials/blinky_primo/index.html
index e8235a0..b673864 100644
--- a/develop/os/tutorials/blinky_primo/index.html
+++ b/develop/os/tutorials/blinky_primo/index.html
@@ -341,19 +341,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -432,6 +419,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/blinky_sram_olimex/index.html
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/blinky_sram_olimex/index.html b/develop/os/tutorials/blinky_sram_olimex/index.html
index 0787d90..7f147b2 100644
--- a/develop/os/tutorials/blinky_sram_olimex/index.html
+++ b/develop/os/tutorials/blinky_sram_olimex/index.html
@@ -341,19 +341,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -432,6 +419,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/eddystone/index.html
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/eddystone/index.html b/develop/os/tutorials/eddystone/index.html
index af9833c..46d6ce2 100644
--- a/develop/os/tutorials/eddystone/index.html
+++ b/develop/os/tutorials/eddystone/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -369,6 +356,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/event_queue/index.html
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/event_queue/index.html b/develop/os/tutorials/event_queue/index.html
index 84111cc..080e89e 100644
--- a/develop/os/tutorials/event_queue/index.html
+++ b/develop/os/tutorials/event_queue/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li class="active">
       <a href="./">Add task to manage multiple events</a>
     </li>
@@ -369,6 +356,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>
@@ -786,9 +794,9 @@ pkg.deps:
 <ul class="nav nav-pills" style="margin-bottom: 10px">
     <li>
     
-    <a href=../air_quality_ble/>
+    <a href=../unit_test/>
         <span class="fa fa-arrow-left"></span>
-        Previous: Bluetooth-enabled Air Quality Sensor
+        Previous: Write a Test Suite for a Package
     </a>
     
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/ibeacon/index.html
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/ibeacon/index.html b/develop/os/tutorials/ibeacon/index.html
index 9b2f17f..ed35cc6 100644
--- a/develop/os/tutorials/ibeacon/index.html
+++ b/develop/os/tutorials/ibeacon/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -369,6 +356,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/nRF52/index.html
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/nRF52/index.html b/develop/os/tutorials/nRF52/index.html
index 9812983..466e328 100644
--- a/develop/os/tutorials/nRF52/index.html
+++ b/develop/os/tutorials/nRF52/index.html
@@ -341,19 +341,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -432,6 +419,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>


[5/9] incubator-mynewt-site git commit: Added etape sensor tutorial. PR #152.

Posted by ad...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/unit_test/index.html
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/unit_test/index.html b/develop/os/tutorials/unit_test/index.html
index 6383ddd..6810ecd 100644
--- a/develop/os/tutorials/unit_test/index.html
+++ b/develop/os/tutorials/unit_test/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -369,6 +356,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>
@@ -653,8 +661,8 @@ the message shown below.</p>
     </li>
     <li class="pull-right">
     
-    <a href=../air_quality_sensor/>
-        Next: Basic Air Quality Sensor
+    <a href=../event_queue/>
+        Next: Add task to manage multiple events
         <span class="fa fa-arrow-right"></span>
     </a>
     

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/wi-fi_on_arduino/index.html
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/wi-fi_on_arduino/index.html b/develop/os/tutorials/wi-fi_on_arduino/index.html
index 7c6371f..f4e63ef 100644
--- a/develop/os/tutorials/wi-fi_on_arduino/index.html
+++ b/develop/os/tutorials/wi-fi_on_arduino/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -369,6 +356,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>


[6/9] incubator-mynewt-site git commit: Added etape sensor tutorial. PR #152.

Posted by ad...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/nrf52_adc/index.html
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/nrf52_adc/index.html b/develop/os/tutorials/nrf52_adc/index.html
new file mode 100644
index 0000000..37eb492
--- /dev/null
+++ b/develop/os/tutorials/nrf52_adc/index.html
@@ -0,0 +1,1305 @@
+<!DOCTYPE html>
+<html lang="en">
+    <head>
+        <meta charset="utf-8">
+        <meta http-equiv="X-UA-Compatible" content="IE=edge">
+        <meta name="viewport" content="width=device-width, initial-scale=1.0">
+        
+        
+        <!-- This is broken by doc revisioning.
+        <link rel="canonical" href="http://mynewt.apache.org/os/tutorials/nrf52_adc/"> -->
+        <link rel="shortcut icon" href="../../../img/favicon.ico">
+
+	    <title>Add an Analog Sensor - Apache Mynewt</title>
+
+        <link href="../../../css/bootstrap-3.0.3.min.css" rel="stylesheet">
+        <link rel="stylesheet" href="../../../css/highlight.css">
+        <link href="../../../css/base.css" rel="stylesheet">
+        <link href="../../../css/custom.css" rel="stylesheet">
+        <link href="../../../css/v2.css" rel="stylesheet">
+        <link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
+        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
+        <link href="../../../extra.css" rel="stylesheet">
+
+        <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
+        <!--[if lt IE 9]>
+            <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
+            <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
+        <![endif]-->
+
+        
+            <script>
+                (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
+                (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
+                m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
+                })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
+
+                ga('create', 'UA-72162311-1', 'auto');
+                ga('send', 'pageview');
+            </script>
+        
+    </head>
+
+
+    <body class="Add an Analog Sensor">
+
+
+        <div class="container">
+    <div class="row v2-main-banner">
+        <a class="logo-cell" href="/">
+            <img class="logo" src="/img/logo.png">
+        </a>
+        <div class="tagline-cell">
+            <h4 class="tagline">An OS to build, deploy and securely manage billions of devices</h4>
+        </div>
+        <div class="news-cell">
+            <div class="well">
+                <h4>Latest News:</h4> <a href="/download">Apache Mynewt 1.0.0-b1</a> released (Dec 13, 2016)
+            </div>
+        </div>
+    </div>
+</div>
+
+        
+
+
+
+
+
+
+<nav id="navbar" class="navbar navbar-inverse affix-top" data-spy="affix" data-offset-top="150" role="navigation">
+    <div class="container">
+        <!-- Collapsed navigation -->
+        <div class="navbar-header">
+            <!-- Expander button -->
+            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
+                <span class="sr-only">Toggle navigation</span>
+                <span class="icon-bar"></span>
+                <span class="icon-bar"></span>
+                <span class="icon-bar"></span>
+            </button>
+
+        </div>
+
+        <!-- Expanded navigation -->
+        <div class="navbar-collapse collapse">
+            <!-- Main navigation -->
+            <ul class="nav navbar-nav navbar-right">
+                <li 
+  class=""
+>
+                    <a href="/"><i class="fa fa-home" style="font-size: larger;"></i></a>
+                </li>
+                <li 
+  class="important"
+>
+                    <a href="/quick-start/">Quick Start</a>
+                </li>
+                <li 
+  class=""
+>
+                    <a href="/about/">About</a>
+                </li>
+                <li 
+  class=""
+>
+                    <a href="/talks/">Talks</a>
+                </li>
+                <li 
+  class="active"
+>
+                    <a href="/latest/os/introduction">Documentation</a>
+                </li>
+                <li 
+  class=""
+>
+                    <a href="/download/">Download</a>
+                </li>
+                <li 
+  class=""
+>
+                    <a href="/community/">Community</a>
+                </li>
+                <li 
+  class=""
+>
+                    <a href="/events/">Events</a>
+                </li>
+            </ul>
+
+            <!-- Search, Navigation and Repo links -->
+            <ul class="nav navbar-nav navbar-right">
+                
+            </ul>
+        </div>
+    </div>
+</nav>
+
+        
+
+        <div class="container">
+            
+                <div class="row">
+                    <div class="col-md-3 v2-sidebar sidebar-container"><div id="docSidebar" class="hidden-print" role="complementary">
+    <div class="top">
+        <div role="search">
+            <form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
+                <div class="form-group">
+                    <input type="text" name="q" class="form-control" placeholder="Search documentation" />
+                </div>
+            </form>
+        </div>
+    </div>
+    <ul class="toc-nav">
+      <li class="doc-version">
+<select class="form-control" onchange="if (this.value) window.location.href=this.value">
+    
+    <option
+      value="/develop/os/introduction"
+      selected="selected"
+    >
+      Version: develop (latest)
+    </option>
+    
+    <option
+      value="/v0_9_0/os/introduction"
+      
+    >
+      Version: 0.9.0
+    </option>
+    
+</select>
+</li>
+      
+        
+      
+        
+      
+        
+      
+        
+      
+        
+      
+        
+      
+        
+      
+        
+      
+        
+          
+  
+  
+    <li ><a href="../../introduction/">Mynewt Documentation</a>
+  
+  
+    <ul>
+          
+              
+          
+              
+                
+  
+  
+    <li ><a href="../../get_started/get_started/">Basic Setup</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../../get_started/vocabulary/">Concepts</a>
+    </li>
+
+              
+          
+              
+                
+  
+  
+    <li ><a href="../tutorials/">Tutorials</a>
+  
+  
+    <ul>
+          
+              
+          
+              
+                
+  
+  
+    <li><a href="
+  ../arduino_zero/
+">Project Blinky</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+  
+  
+    <li ><a href="../repo/add_repos/">Work with repositories</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../tasks_lesson/">Tasks and Priority Management</a>
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../wi-fi_on_arduino/">Enable Wi-Fi on Arduino Zero</a>
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../unit_test/">Write a Test Suite for a Package</a>
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../event_queue/">Add task to manage multiple events</a>
+    </li>
+
+              
+          
+              
+                
+  
+  
+    <li><a href="
+  ../project-slinky/
+">Project Slinky for remote comms</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../add_newtmgr/">Enable Newt Manager in any app</a>
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../add_shell/">Enable the OS Shell and Console</a>
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../bletiny_project/">BLE app to check stats via console</a>
+    </li>
+
+              
+          
+              
+                
+  
+  
+    <li ><a href="../bleprph/bleprph-intro/">BLE peripheral project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../ibeacon/">BLE iBeacon</a>
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../eddystone/">BLE Eddystone</a>
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../blehci_project/">BLE HCI interface</a>
+    </li>
+
+              
+          
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li class="active">
+      <a href="./">Add an Analog Sensor</a>
+    </li>
+
+              
+          
+    </ul>
+  
+    </li>
+
+              
+          
+              
+                
+  
+  
+    <li ><a href="../../os_user_guide/">OS User Guide</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+  
+  
+    <li><a href="
+  ../../../network/ble/ble_intro/
+">BLE User Guide</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+  
+  
+    <li ><a href="../../../newt/newt_intro/">Newt Tool Guide</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+  
+  
+    <li ><a href="../../../newtmgr/overview/">Newt Manager Guide</a>
+  
+  
+    </li>
+
+              
+          
+    </ul>
+  
+    </li>
+
+        
+      
+        
+          
+  
+  
+    <li><a href="
+  ../../../faq/how_to_edit_docs/
+">Appendix</a>
+  
+  
+    </li>
+
+        
+      
+    </ul>
+</div></div>
+
+                    <div class="col-md-9" role="main">
+                        <div class="doc-header">
+                            <div role="navigation" aria-label="breadcrumbs navigation">
+  <ul class="wy-breadcrumbs pull-right">
+    <li><a href="/develop/os/introduction">Docs</a></li>
+    
+    
+        
+          <li>&raquo; <a href="../../introduction/">Mynewt Documentation</a></li>
+        
+      
+        
+          <li>&raquo; <a href="../tutorials/">Tutorials</a></li>
+        
+      
+      
+        <li>&raquo; Add an Analog Sensor</li>
+      
+    
+    
+  </ul>
+</div>
+                        </div>
+                        
+                            <h2 id="adding-an-analog-sensor-on-nrf52">Adding an Analog Sensor on nRF52</h2>
+<p><br></p>
+<h3 id="objective">Objective</h3>
+<p>We will be adding an analog sensor to the NRF52DK development board and using the Analog to Digital Converter
+(ADC) to read the values from the sensor. It's also using Bluetooth to allow you to connect to the app and
+read the value of the sensor. Please see the following section for the required hardware
+in order to complete this tutorial.</p>
+<p><br></p>
+<h3 id="hardware-needed">Hardware needed</h3>
+<ul>
+<li>nRF52 Development Kit (one of the following)<ul>
+<li>Dev Kit from Nordic - PCA 10040</li>
+<li>Eval Kit from Rigado - BMD-300-EVAL-ES</li>
+</ul>
+</li>
+<li>eTape Liquid Sensor -- buy from <a href="https://www.adafruit.com/products/1786">Adafruit</a></li>
+<li>Laptop running Mac OS</li>
+<li>It is assumed you have already installed newt tool. </li>
+<li>It is assumed you already installed native tools as described <a href="../../get_started/native_tools/">here</a></li>
+</ul>
+<p><br></p>
+<h3 id="create-a-project">Create a project.</h3>
+<p>Create a new project to hold your work.  For a deeper understanding, you can read about project creation in 
+<a href="../../get_started/project_create/">Get Started -- Creating Your First Project</a>
+or just follow the commands below.</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%">    $ mkdir ~/dev
+    $ cd ~/dev
+    $ newt new myadc
+    Downloading project skeleton from apache/incubator-mynewt-blinky...
+    Installing skeleton in myadc...
+    Project myadc successfully created.
+    $ cd myadc
+</pre></div>
+
+
+<p><br></p>
+<h3 id="add-additional-repositories">Add Additional Repositories</h3>
+<p>The board-specific libraries for the NRF52dk board are in an external repository at present, so
+you'll need to include that remote repository and install it as well. If you're not familiar
+with using repositories, see the section on <a href="../repo/add_repos/">repositories</a> before
+continuing. Or just copy and paste the following.</p>
+<p>In your <code>project.yml</code> file, add <code>mynewt_nordic</code> to the <code>project.repositories</code> section, and 
+then add the proper repository definition. When you're done, your <code>project.yml</code> file
+should look like this:</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%">project.name: &quot;my_project&quot;
+
+project.repositories:
+    - apache-mynewt-core
+<span style="background-color: #ffffcc">    - mynewt_nordic
+</span>
+# Use github&#39;s distribution mechanism for core ASF libraries.
+# This provides mirroring automatically for us.
+#
+repository.apache-mynewt-core:
+    type: github
+    vers: 0-dev
+    user: apache
+    repo: incubator-mynewt-core
+<span style="background-color: #ffffcc">repository.mynewt_nordic:
+</span><span style="background-color: #ffffcc">    type: github
+</span><span style="background-color: #ffffcc">    vers: 0-latest
+</span><span style="background-color: #ffffcc">    user: runtimeinc
+</span><span style="background-color: #ffffcc">    repo: mynewt_nordic
+</span></pre></div>
+
+
+<p><br></p>
+<h3 id="install-everything">Install Everything</h3>
+<p>Now that you have defined the needed repositories, it's time to install everything so
+that you can get started.</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%">    $ newt install -v 
+    apache-mynewt-core
+    Downloading repository description for apache-mynewt-core... success!
+    ...
+    apache-mynewt-core successfully installed version 0.9.0-none
+    ...
+    mynewt_nordic
+    Downloading repository description for mynewt_nordic... success!
+    ...
+    mynewt_nordic successfully installed version 0.9.9-none
+</pre></div>
+
+
+<p><br></p>
+<h3 id="create-the-targets">Create the targets</h3>
+<p>Create two targets - one for the bootloader and one for the nrf52 board.  </p>
+<p><font color="#F2853F">
+Note: The correct bsp must be chosen for the board you are using. </font></p>
+<ul>
+<li>For the Nordic Dev Kit choose @apache-mynewt-core/hw/bsp/nrf52dk instead (in the highlighted lines)</li>
+<li>For the Rigado Eval Kit choose @apache-mynewt-core/hw/bsp/bmd300eval instead (in the highlighted lines)</li>
+</ul>
+<p>For the app itself we're going to extend the <a href="belpprph/bleprph-app.md">bleprph</a> app so that we
+get the Bluetooth communications built in, so the first thing we'll need to do is copy that app
+into our own app directory:</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%">$ mkdir -p apps/nrf52_adc
+$ cp -Rp repos/apache-mynewt-core/apps/bleprph/* apps/nrf52_adc
+</pre></div>
+
+
+<p>Next, you'll modify the <code>pkg.yml</code> file for your app. Note the change in <code>pkg.name</code> and <code>pkg.description</code>. Also make sure that you specify the full path of all the packages with the prefix <code>@apache-mynewt-core/</code> as shown in the third highlighted line.</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%">$ cat apps/nrf52_adc/pkg.yml
+...
+<span style="background-color: #ffffcc">pkg.name: apps/nrf52_adc
+</span>pkg.type: app
+<span style="background-color: #ffffcc">pkg.description: Simple BLE peripheral application for ADC Sensors.
+</span>pkg.author: &quot;Apache Mynewt &lt;dev@mynewt.incubator.apache.org&gt;&quot;
+pkg.homepage: &quot;http://mynewt.apache.org/&quot;
+pkg.keywords:
+
+pkg.deps: 
+<span style="background-color: #ffffcc">    - &quot;@apache-mynewt-core/boot/split&quot;
+</span>    - &quot;@apache-mynewt-core/kernel/os&quot;
+    - &quot;@apache-mynewt-core/mgmt/imgmgr&quot;
+    - &quot;@apache-mynewt-core/mgmt/newtmgr&quot;
+    - &quot;@apache-mynewt-core/mgmt/newtmgr/transport/ble&quot;
+    - &quot;@apache-mynewt-core/net/nimble/controller&quot;
+    - &quot;@apache-mynewt-core/net/nimble/host&quot;
+    - &quot;@apache-mynewt-core/net/nimble/host/services/ans&quot;
+    - &quot;@apache-mynewt-core/net/nimble/host/services/gap&quot;
+    - &quot;@apache-mynewt-core/net/nimble/host/services/gatt&quot;
+    - &quot;@apache-mynewt-core/net/nimble/host/store/ram&quot;
+    - &quot;@apache-mynewt-core/net/nimble/transport/ram&quot;
+    - &quot;@apache-mynewt-core/sys/console/full&quot;
+    - &quot;@apache-mynewt-core/sys/log/full&quot;
+    - &quot;@apache-mynewt-core/sys/stats/full&quot;
+    - &quot;@apache-mynewt-core/sys/sysinit&quot;
+    - &quot;@apache-mynewt-core/sys/id&quot;
+</pre></div>
+
+
+<p>Great! We have our very own app so let's make sure we have all of our targets set
+correctly:</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%">$ newt target create nrf52_adc
+$ newt target set nrf52_adc app=apps/nrf52_adc
+<span style="background-color: #ffffcc">Target targets/nrf52_adc successfully set target.app to apps/nrf52_adc
+</span>$ newt target set nrf52_adc bsp=@apache-mynewt-core/hw/bsp/nrf52dk
+$ newt target set nrf52_adc build_profile=debug
+
+$ newt target create nrf52_boot
+<span style="background-color: #ffffcc">$ newt target set nrf52_boot app=@apache-mynewt-core/apps/boot
+</span>$ newt target set nrf52_boot bsp=@apache-mynewt-core/hw/bsp/nrf52dk
+$ newt target set nrf52_boot build_profile=optimized
+
+$ newt target show 
+targets/nrf52_adc
+    app=apps/nrf52_adc
+    bsp=@apache-mynewt-core/hw/bsp/nrf52dk
+    build_profile=debug
+targets/nrf52_boot
+    app=@apache-mynewt-core/apps/boot
+    bsp=@apache-mynewt-core/hw/bsp/nrf52dk
+    build_profile=optimized
+</pre></div>
+
+
+<p><font color="#F2853F">
+Note: If you've already built and installed a bootloader for your NRF52dk then you do
+not need to create a target for it here, or build and load it as below. </font>
+<br></p>
+<h3 id="build-the-target-executables">Build the target executables</h3>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%">$ newt build nrf52_boot
+...
+Compiling boot.c
+Archiving boot.a
+Linking boot.elf
+App successfully built: ~/dev/myadc/bin/nrf52_boot/apps/boot/boot.elf
+</pre></div>
+
+
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%">$ newt build nrf52_adc
+...
+Compiling main.c
+Archiving nrf52_adc.a
+Linking nrf52_adc.elf
+App successfully built: ~/dev/myadc/bin/nrf52_adc/apps/nrf52_adc/nrf52_adc.elf
+</pre></div>
+
+
+<p><br></p>
+<h3 id="sign-and-create-the-nrf52_adc-application-image">Sign and create the nrf52_adc application image</h3>
+<p>You must sign and version your application image to download it using newt to the board. 
+Use the newt create-image command to perform this action. You may assign an arbitrary 
+version (e.g. 1.0.0) to the image.</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%">$ newt create-image nrf52_adc 1.0.0
+App image successfully generated: ~/dev/myadc/bin/nrf52_adc/apps/nrf52_adc/nrf52_adc.img
+Build manifest: ~/dev/myadc/bin/nrf52_adc/apps/nrf52_adc/manifest.json
+</pre></div>
+
+
+<p><br></p>
+<h3 id="connect-the-board">Connect the board</h3>
+<p>Connect the evaluation board via micro-USB to your PC via USB cable.</p>
+<p><br></p>
+<h3 id="download-to-the-target">Download to the target</h3>
+<p>Download the bootloader first and then the nrf52_adc executable to the target platform. 
+Don't forget to reset the board if you don't see the LED blinking right away!</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%">$ newt load nrf52_boot
+$ newt load nrf52_adc
+</pre></div>
+
+
+<p><br></p>
+<p><strong>Note:</strong> If you want to erase the flash and load the image again, you can use JLinkExe to issue an <code>erase</code> command.</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%">$ JLinkExe -device nRF52 -speed 4000 -if SWD
+SEGGER J-Link Commander V5.12c (Compiled Apr 21 2016 16:05:51)
+DLL version V5.12c, compiled Apr 21 2016 16:05:45
+
+Connecting to J-Link via USB...O.K.
+Firmware: J-Link OB-SAM3U128-V2-NordicSemi compiled Mar 15 2016 18:03:17
+Hardware version: V1.00
+S/N: 682863966
+VTref = 3.300V
+
+
+Type &quot;connect&quot; to establish a target connection, &#39;?&#39; for help
+J-Link&gt;erase
+Cortex-M4 identified.
+Erasing device (0;?i?)...
+Comparing flash   [100%] Done.
+Erasing flash     [100%] Done.
+Verifying flash   [100%] Done.
+J-Link: Flash download: Total time needed: 0.363s (Prepare: 0.093s, Compare: 0.000s, Erase: 0.262s, Program: 0.000s, Verify: 0.000s, Restore: 0.008s)
+Erasing done.
+J-Link&gt;exit
+$
+</pre></div>
+
+
+<p><br></p>
+<p>So you have a BLE app, but really all you've done is change the name of the <strong>bleprph</strong> app to <strong>nrf52_adc</strong> and load that.
+Not all that impressive, and it certainly won't read an Analog Sensor right now. So let's do that next. In order to 
+read an ADC sensor, and since the ADC package is in an external, licensed, repository, we'll create a driver for it
+here in our app that will leverage the existing driver in the external repository. It adds another layer of 
+indirection, but it will also give us a look at building our own driver, so we'll do it this way. </p>
+<p><br></p>
+<h3 id="building-a-driver">Building a Driver</h3>
+<p>The first thing to do is to create the directory structure for your driver:</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%">[user@IsMyLaptop:~/src/air_quality]$ mkdir -p libs/my_drivers/myadc/include/myadc
+[user@IsMyLaptop:~/src/air_quality]$ mkdir -p libs/my_drivers/myadc/src
+</pre></div>
+
+
+<p>Now you can add the files you need. You'll need a pkg.yml to describe the driver, and then header stub followed by source stub.</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%">[user@IsMyLaptop:~/src/air_quality]$ cat libs/my_drivers/myadc/pkg.yml
+</pre></div>
+
+
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%"><span style="color: #633820">#</span>
+<span style="color: #633820"># Licensed to the Apache Software Foundation (ASF) under one</span>
+<span style="color: #633820"># or more contributor license agreements.  See the NOTICE file</span>
+<span style="color: #633820"># distributed with this work for additional information</span>
+<span style="color: #633820"># regarding copyright ownership.  The ASF licenses this file</span>
+<span style="color: #633820"># to you under the Apache License, Version 2.0 (the</span>
+<span style="color: #633820"># &quot;License&quot;); you may not use this file except in compliance</span>
+<span style="color: #633820"># with the License.  You may obtain a copy of the License at</span>
+<span style="color: #633820"># </span>
+<span style="color: #633820">#  http:</span><span style="color: #177500">//www.apache.org/licenses/LICENSE-2.0</span>
+<span style="color: #633820">#</span>
+<span style="color: #633820"># Unless required by applicable law or agreed to in writing,</span>
+<span style="color: #633820"># software distributed under the License is distributed on an</span>
+<span style="color: #633820"># &quot;AS IS&quot; BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY</span>
+<span style="color: #633820"># KIND, either express or implied.  See the License for the</span>
+<span style="color: #633820"># specific language governing permissions and limitations</span>
+<span style="color: #633820"># under the License.</span>
+<span style="color: #633820">#</span>
+<span style="color: #000000">pkg</span>.<span style="color: #000000">name</span>: <span style="color: #000000">libs/my_drivers/myadc</span>
+<span style="color: #000000">pkg</span>.<span style="color: #000000">deps</span>:
+    <span style="color: #000000">-</span> <span style="color: #C41A16">&quot;@apache-mynewt-core/hw/hal&quot;</span>
+    <span style="color: #000000">-</span> <span style="color: #C41A16">&quot;@mynewt_nordic/hw/drivers/adc/adc_nrf52&quot;</span>
+</pre></div>
+
+
+<p>First, let's create the required header file <code>myadc.h</code> in the includes directory i.e. <code>libs/my_drivers/myadc/include/myadc/myadc.h</code>.
+It's a pretty straightforward header file, since we only need to do 2 things:</p>
+<ul>
+<li>Initialize the ADC device</li>
+<li>Read ADC Values</li>
+</ul>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%"><span style="color: #633820">#ifndef _NRF52_ADC_H_</span>
+<span style="color: #633820">#define _NRF52_ADC_H_</span>
+
+<span style="color: #A90D91">void</span> <span style="color: #000000">*</span> <span style="color: #000000">adc_init</span>(<span style="color: #A90D91">void</span>);
+<span style="color: #A90D91">int</span> <span style="color: #000000">adc_read</span>(<span style="color: #A90D91">void</span> <span style="color: #000000">*buffer</span>, <span style="color: #A90D91">int</span> <span style="color: #000000">buffer_len</span>);
+
+<span style="color: #633820">#endif </span><span style="color: #177500">/* _NRF52_ADC_H_ */</span><span style="color: #633820"></span>
+</pre></div>
+
+
+<p>Next we'll need a corresponding source file <code>myadc.c</code> in the src directory. This is where
+we'll implement the specifics of the driver:</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%"><span style="color: #633820">#include &lt;assert.h&gt;</span>
+<span style="color: #633820">#include &lt;os/os.h&gt;</span>
+<span style="color: #177500">/* ADC */</span>
+<span style="color: #633820">#include &quot;myadc/myadc.h&quot;</span>
+<span style="color: #633820">#include &quot;nrf.h&quot;</span>
+<span style="color: #633820">#include &quot;app_util_platform.h&quot;</span>
+<span style="color: #633820">#include &quot;app_error.h&quot;</span>
+<span style="color: #633820">#include &lt;adc/adc.h&gt;</span>
+<span style="color: #633820">#include &lt;adc_nrf52/adc_nrf52.h&gt;</span>
+<span style="color: #633820">#include &quot;nrf_drv_saadc.h&quot;</span>
+
+
+<span style="color: #633820">#define ADC_NUMBER_SAMPLES (2)</span>
+<span style="color: #633820">#define ADC_NUMBER_CHANNELS (1)</span>
+
+<span style="color: #A90D91">nrf_drv_saadc_config_t</span> <span style="color: #000000">adc_config</span> <span style="color: #000000">=</span> <span style="color: #000000">NRF_DRV_SAADC_DEFAULT_CONFIG</span>;
+
+<span style="color: #A90D91">struct</span> <span style="color: #000000">adc_dev</span> <span style="color: #000000">*adc</span>;
+<span style="color: #A90D91">uint8_t</span> <span style="color: #000000">*sample_buffer1</span>;
+<span style="color: #A90D91">uint8_t</span> <span style="color: #000000">*sample_buffer2</span>;
+
+<span style="color: #A90D91">static</span> <span style="color: #A90D91">struct</span> <span style="color: #000000">adc_dev</span> <span style="color: #000000">os_bsp_adc0</span>;
+<span style="color: #A90D91">static</span> <span style="color: #A90D91">nrf_drv_saadc_config_t</span> <span style="color: #000000">os_bsp_adc0_config</span> <span style="color: #000000">=</span> {
+    .<span style="color: #000000">resolution</span>         <span style="color: #000000">=</span> <span style="color: #000000">MYNEWT_VAL</span>(<span style="color: #000000">ADC_0_RESOLUTION</span>),
+    .<span style="color: #000000">oversample</span>         <span style="color: #000000">=</span> <span style="color: #000000">MYNEWT_VAL</span>(<span style="color: #000000">ADC_0_OVERSAMPLE</span>),
+    .<span style="color: #000000">interrupt_priority</span> <span style="color: #000000">=</span> <span style="color: #000000">MYNEWT_VAL</span>(<span style="color: #000000">ADC_0_INTERRUPT_PRIORITY</span>),
+};
+<span style="color: #A90D91">void</span> <span style="color: #000000">*</span>
+<span style="color: #000000">adc_init</span>(<span style="color: #A90D91">void</span>)
+{
+    <span style="color: #A90D91">int</span> <span style="color: #000000">rc</span> <span style="color: #000000">=</span> <span style="color: #1C01CE">0</span>;
+
+    <span style="color: #000000">rc</span> <span style="color: #000000">=</span> <span style="color: #000000">os_dev_create</span>((<span style="color: #A90D91">struct</span> <span style="color: #000000">os_dev</span> <span style="color: #000000">*</span>) <span style="color: #000000">&amp;os_bsp_adc0</span>, <span style="color: #C41A16">&quot;adc0&quot;</span>,
+            <span style="color: #000000">OS_DEV_INIT_KERNEL</span>, <span style="color: #000000">OS_DEV_INIT_PRIO_DEFAULT</span>,
+            <span style="color: #000000">nrf52_adc_dev_init</span>, <span style="color: #000000">&amp;os_bsp_adc0_config</span>);
+    <span style="color: #000000">assert</span>(<span style="color: #000000">rc</span> <span style="color: #000000">==</span> <span style="color: #1C01CE">0</span>);
+    <span style="color: #A90D91">nrf_saadc_channel_config_t</span> <span style="color: #000000">cc</span> <span style="color: #000000">=</span> <span style="color: #000000">NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE</span>(<span style="color: #000000">NRF_SAADC_INPUT_AIN1</span>);
+    <span style="color: #000000">cc</span>.<span style="color: #000000">gain</span> <span style="color: #000000">=</span> <span style="color: #000000">NRF_SAADC_GAIN1_6</span>;
+    <span style="color: #000000">cc</span>.<span style="color: #000000">reference</span> <span style="color: #000000">=</span> <span style="color: #000000">NRF_SAADC_REFERENCE_INTERNAL</span>;
+    <span style="color: #000000">adc</span> <span style="color: #000000">=</span> (<span style="color: #A90D91">struct</span> <span style="color: #000000">adc_dev</span> <span style="color: #000000">*</span>) <span style="color: #000000">os_dev_open</span>(<span style="color: #C41A16">&quot;adc0&quot;</span>, <span style="color: #1C01CE">0</span>, <span style="color: #000000">&amp;adc_config</span>);
+    <span style="color: #000000">assert</span>(<span style="color: #000000">adc</span> <span style="color: #000000">!=</span> <span style="color: #A90D91">NULL</span>);
+    <span style="color: #000000">adc_chan_config</span>(<span style="color: #000000">adc</span>, <span style="color: #1C01CE">0</span>, <span style="color: #000000">&amp;cc</span>);
+    <span style="color: #000000">sample_buffer1</span> <span style="color: #000000">=</span> <span style="color: #000000">malloc</span>(<span style="color: #000000">adc_buf_size</span>(<span style="color: #000000">adc</span>, <span style="color: #000000">ADC_NUMBER_CHANNELS</span>, <span style="color: #000000">ADC_NUMBER_SAMPLES</span>));
+    <span style="color: #000000">sample_buffer2</span> <span style="color: #000000">=</span> <span style="color: #000000">malloc</span>(<span style="color: #000000">adc_buf_size</span>(<span style="color: #000000">adc</span>, <span style="color: #000000">ADC_NUMBER_CHANNELS</span>, <span style="color: #000000">ADC_NUMBER_SAMPLES</span>));
+    <span style="color: #000000">memset</span>(<span style="color: #000000">sample_buffer1</span>, <span style="color: #1C01CE">0</span>, <span style="color: #000000">adc_buf_size</span>(<span style="color: #000000">adc</span>, <span style="color: #000000">ADC_NUMBER_CHANNELS</span>, <span style="color: #000000">ADC_NUMBER_SAMPLES</span>));
+    <span style="color: #000000">memset</span>(<span style="color: #000000">sample_buffer2</span>, <span style="color: #1C01CE">0</span>, <span style="color: #000000">adc_buf_size</span>(<span style="color: #000000">adc</span>, <span style="color: #000000">ADC_NUMBER_CHANNELS</span>, <span style="color: #000000">ADC_NUMBER_SAMPLES</span>));
+    <span style="color: #000000">adc_buf_set</span>(<span style="color: #000000">adc</span>, <span style="color: #000000">sample_buffer1</span>, <span style="color: #000000">sample_buffer2</span>,
+        <span style="color: #000000">adc_buf_size</span>(<span style="color: #000000">adc</span>, <span style="color: #000000">ADC_NUMBER_CHANNELS</span>, <span style="color: #000000">ADC_NUMBER_SAMPLES</span>));
+    <span style="color: #A90D91">return</span> <span style="color: #000000">adc</span>;
+}
+
+
+<span style="color: #A90D91">int</span>
+<span style="color: #000000">adc_read</span>(<span style="color: #A90D91">void</span> <span style="color: #000000">*buffer</span>, <span style="color: #A90D91">int</span> <span style="color: #000000">buffer_len</span>)
+{
+    <span style="color: #A90D91">int</span> <span style="color: #000000">i</span>;
+    <span style="color: #A90D91">int</span> <span style="color: #000000">adc_result</span>;
+    <span style="color: #A90D91">int</span> <span style="color: #000000">my_result_mv</span> <span style="color: #000000">=</span> <span style="color: #1C01CE">0</span>;
+    <span style="color: #A90D91">int</span> <span style="color: #000000">rc</span>;
+    <span style="color: #A90D91">for</span> (<span style="color: #000000">i</span> <span style="color: #000000">=</span> <span style="color: #1C01CE">0</span>; <span style="color: #000000">i</span> <span style="color: #000000">&lt;</span> <span style="color: #000000">ADC_NUMBER_SAMPLES</span>; <span style="color: #000000">i++</span>) {
+        <span style="color: #000000">rc</span> <span style="color: #000000">=</span> <span style="color: #000000">adc_buf_read</span>(<span style="color: #000000">adc</span>, <span style="color: #000000">buffer</span>, <span style="color: #000000">buffer_len</span>, <span style="color: #000000">i</span>, <span style="color: #000000">&amp;adc_result</span>);
+        <span style="color: #A90D91">if</span> (<span style="color: #000000">rc</span> <span style="color: #000000">!=</span> <span style="color: #1C01CE">0</span>) {
+            <span style="color: #A90D91">goto</span> <span style="color: #000000">err</span>;
+        }
+        <span style="color: #000000">my_result_mv</span> <span style="color: #000000">=</span> <span style="color: #000000">adc_result_mv</span>(<span style="color: #000000">adc</span>, <span style="color: #1C01CE">0</span>, <span style="color: #000000">adc_result</span>);
+    }        
+    <span style="color: #000000">adc_buf_release</span>(<span style="color: #000000">adc</span>, <span style="color: #000000">buffer</span>, <span style="color: #000000">buffer_len</span>);
+    <span style="color: #A90D91">return</span> <span style="color: #000000">my_result_mv</span>;
+<span style="color: #000000">err</span>:
+    <span style="color: #A90D91">return</span> (<span style="color: #000000">rc</span>);
+}
+</pre></div>
+
+
+<p>There's a lot going on in here, so let's walk through it step by step. </p>
+<p>First, we define a default configuration, with the resolution, oversample and interrupt priority. You'll see
+that these are <code>MYNEWT_VAL</code> values, which means that we'll define them shortly in
+a <code>syscfg.yml</code> file to be passed to the compiler at build time. </p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%"><span style="color: #A90D91">static</span> <span style="color: #A90D91">struct</span> <span style="color: #000000">adc_dev</span> <span style="color: #000000">os_bsp_adc0</span>;
+<span style="color: #A90D91">static</span> <span style="color: #A90D91">nrf_drv_saadc_config_t</span> <span style="color: #000000">os_bsp_adc0_config</span> <span style="color: #000000">=</span> {
+    .<span style="color: #000000">resolution</span>         <span style="color: #000000">=</span> <span style="color: #000000">MYNEWT_VAL</span>(<span style="color: #000000">ADC_0_RESOLUTION</span>),
+    .<span style="color: #000000">oversample</span>         <span style="color: #000000">=</span> <span style="color: #000000">MYNEWT_VAL</span>(<span style="color: #000000">ADC_0_OVERSAMPLE</span>),
+    .<span style="color: #000000">interrupt_priority</span> <span style="color: #000000">=</span> <span style="color: #000000">MYNEWT_VAL</span>(<span style="color: #000000">ADC_0_INTERRUPT_PRIORITY</span>),
+};
+</pre></div>
+
+
+<p>Next, in <code>adc_init()</code> , we need to tell the OS to create the device.</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%"><span style="color: #A90D91">void</span> <span style="color: #000000">*</span>
+<span style="color: #000000">adc_init</span>(<span style="color: #A90D91">void</span>)
+{
+    <span style="color: #A90D91">int</span> <span style="color: #000000">rc</span> <span style="color: #000000">=</span> <span style="color: #1C01CE">0</span>;
+
+    <span style="color: #000000">rc</span> <span style="color: #000000">=</span> <span style="color: #000000">os_dev_create</span>((<span style="color: #A90D91">struct</span> <span style="color: #000000">os_dev</span> <span style="color: #000000">*</span>) <span style="color: #000000">&amp;os_bsp_adc0</span>, <span style="color: #C41A16">&quot;adc0&quot;</span>,
+            <span style="color: #000000">OS_DEV_INIT_KERNEL</span>, <span style="color: #000000">OS_DEV_INIT_PRIO_DEFAULT</span>,
+            <span style="color: #000000">nrf52_adc_dev_init</span>, <span style="color: #000000">&amp;os_bsp_adc0_config</span>);
+    <span style="color: #000000">assert</span>(<span style="color: #000000">rc</span> <span style="color: #000000">==</span> <span style="color: #1C01CE">0</span>);
+    <span style="color: #A90D91">nrf_saadc_channel_config_t</span> <span style="color: #000000">cc</span> <span style="color: #000000">=</span> <span style="color: #000000">NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE</span>(<span style="color: #000000">NRF_SAADC_INPUT_AIN1</span>);
+    <span style="color: #000000">cc</span>.<span style="color: #000000">gain</span> <span style="color: #000000">=</span> <span style="color: #000000">NRF_SAADC_GAIN1_6</span>;
+    <span style="color: #000000">cc</span>.<span style="color: #000000">reference</span> <span style="color: #000000">=</span> <span style="color: #000000">NRF_SAADC_REFERENCE_INTERNAL</span>;
+    <span style="color: #000000">adc</span> <span style="color: #000000">=</span> (<span style="color: #A90D91">struct</span> <span style="color: #000000">adc_dev</span> <span style="color: #000000">*</span>) <span style="color: #000000">os_dev_open</span>(<span style="color: #C41A16">&quot;adc0&quot;</span>, <span style="color: #1C01CE">0</span>, <span style="color: #000000">&amp;adc_config</span>);
+    <span style="color: #000000">assert</span>(<span style="color: #000000">adc</span> <span style="color: #000000">!=</span> <span style="color: #A90D91">NULL</span>);
+    <span style="color: #000000">adc_chan_config</span>(<span style="color: #000000">adc</span>, <span style="color: #1C01CE">0</span>, <span style="color: #000000">&amp;cc</span>);
+    <span style="color: #000000">sample_buffer1</span> <span style="color: #000000">=</span> <span style="color: #000000">malloc</span>(<span style="color: #000000">adc_buf_size</span>(<span style="color: #000000">adc</span>, <span style="color: #000000">ADC_NUMBER_CHANNELS</span>, <span style="color: #000000">ADC_NUMBER_SAMPLES</span>));
+    <span style="color: #000000">sample_buffer2</span> <span style="color: #000000">=</span> <span style="color: #000000">malloc</span>(<span style="color: #000000">adc_buf_size</span>(<span style="color: #000000">adc</span>, <span style="color: #000000">ADC_NUMBER_CHANNELS</span>, <span style="color: #000000">ADC_NUMBER_SAMPLES</span>));
+    <span style="color: #000000">memset</span>(<span style="color: #000000">sample_buffer1</span>, <span style="color: #1C01CE">0</span>, <span style="color: #000000">adc_buf_size</span>(<span style="color: #000000">adc</span>, <span style="color: #000000">ADC_NUMBER_CHANNELS</span>, <span style="color: #000000">ADC_NUMBER_SAMPLES</span>));
+    <span style="color: #000000">memset</span>(<span style="color: #000000">sample_buffer2</span>, <span style="color: #1C01CE">0</span>, <span style="color: #000000">adc_buf_size</span>(<span style="color: #000000">adc</span>, <span style="color: #000000">ADC_NUMBER_CHANNELS</span>, <span style="color: #000000">ADC_NUMBER_SAMPLES</span>));
+    <span style="color: #000000">adc_buf_set</span>(<span style="color: #000000">adc</span>, <span style="color: #000000">sample_buffer1</span>, <span style="color: #000000">sample_buffer2</span>,
+        <span style="color: #000000">adc_buf_size</span>(<span style="color: #000000">adc</span>, <span style="color: #000000">ADC_NUMBER_CHANNELS</span>, <span style="color: #000000">ADC_NUMBER_SAMPLES</span>));
+    <span style="color: #A90D91">return</span> <span style="color: #000000">adc</span>;
+}
+</pre></div>
+
+
+<p>A few things need to be said about this part, as it is the most confusing. First, 
+we're using a <strong>default</strong> configuration for the ADC Channel via the <code>NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE</code>
+macro. The important part here is that we're actually using <code>AIN1</code>. I know what you're thinking, "But 
+we want ADC-0!" and that's true. The board is actually labelled 'A0, A1, A2' etc., and the actual pin 
+numbers are also listed on the board, which seems handy. At first. But it gets messy very quickly.</p>
+<p>If you try to use AIN0, and then go poke around in the registers while this is running, </p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%">(gdb) p/x {NRF_SAADC_Type}0x40007000
+...
+ CH = {{
+      PSELP = 0x1,
+      PSELN = 0x0,
+      CONFIG = 0x20000,
+      LIMIT = 0x7fff8000
+    }, 
+</pre></div>
+
+
+<p>You'll see that the pin for channel 0 is set to 1, which corresponds to AIN0, but that's <strong>NOT</strong>
+the same as A0 -- pin P0.03, the one we're using. For that, you use AIN1, which would set the
+pin value to 2. Messy. Someone, somewhere, thought this made sense. </p>
+<p>The only other thing to note here is that we're using the internal reference voltage, rather than
+setting our own. There's nothing wrong with that, but since we are, we'll have to crank up
+the gain a bit by using <code>NRF_SAADC_GAIN1_6</code>.</p>
+<p>Then, in <code>adc_read()</code> we will take readings, convert the raw readings to 
+a millivolt equivalent, and return the result. </p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%"><span style="color: #A90D91">int</span>
+<span style="color: #000000">adc_read</span>(<span style="color: #A90D91">void</span> <span style="color: #000000">*buffer</span>, <span style="color: #A90D91">int</span> <span style="color: #000000">buffer_len</span>)
+{
+    <span style="color: #A90D91">int</span> <span style="color: #000000">i</span>;
+    <span style="color: #A90D91">int</span> <span style="color: #000000">adc_result</span>;
+    <span style="color: #A90D91">int</span> <span style="color: #000000">my_result_mv</span> <span style="color: #000000">=</span> <span style="color: #1C01CE">0</span>;
+    <span style="color: #A90D91">int</span> <span style="color: #000000">rc</span>;
+    <span style="color: #A90D91">for</span> (<span style="color: #000000">i</span> <span style="color: #000000">=</span> <span style="color: #1C01CE">0</span>; <span style="color: #000000">i</span> <span style="color: #000000">&lt;</span> <span style="color: #000000">ADC_NUMBER_SAMPLES</span>; <span style="color: #000000">i++</span>) {
+        <span style="color: #000000">rc</span> <span style="color: #000000">=</span> <span style="color: #000000">adc_buf_read</span>(<span style="color: #000000">adc</span>, <span style="color: #000000">buffer</span>, <span style="color: #000000">buffer_len</span>, <span style="color: #000000">i</span>, <span style="color: #000000">&amp;adc_result</span>);
+        <span style="color: #A90D91">if</span> (<span style="color: #000000">rc</span> <span style="color: #000000">!=</span> <span style="color: #1C01CE">0</span>) {
+            <span style="color: #A90D91">goto</span> <span style="color: #000000">err</span>;
+        }
+        <span style="color: #000000">my_result_mv</span> <span style="color: #000000">=</span> <span style="color: #000000">adc_result_mv</span>(<span style="color: #000000">adc</span>, <span style="color: #1C01CE">0</span>, <span style="color: #000000">adc_result</span>);
+    }        
+    <span style="color: #000000">adc_buf_release</span>(<span style="color: #000000">adc</span>, <span style="color: #000000">buffer</span>, <span style="color: #000000">buffer_len</span>);
+    <span style="color: #A90D91">return</span> <span style="color: #000000">my_result_mv</span>;
+<span style="color: #000000">err</span>:
+    <span style="color: #A90D91">return</span> (<span style="color: #000000">rc</span>);
+}
+</pre></div>
+
+
+<p>Finally, we'll need some settings for our driver, as mentioned earlier. In the <code>myadc</code> directory
+you'll need to add a <code>syscfg.yml</code> file:</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%"># Package: libs/my_driver/myadc
+
+syscfg.defs:
+    ADC_0:
+        description: &#39;TBD&#39;
+        value:  1
+    ADC_0_RESOLUTION:
+        description: &#39;TBD&#39;
+        value: &#39;SAADC_CONFIG_RESOLUTION&#39;
+    ADC_0_OVERSAMPLE:
+        description: &#39;TBD&#39;
+        value: &#39;SAADC_CONFIG_OVERSAMPLE&#39;
+    ADC_0_INTERRUPT_PRIORITY:
+        description: &#39;TBD&#39;
+        value: &#39;SAADC_CONFIG_IRQ_PRIORITY&#39;
+</pre></div>
+
+
+<p>Once that's all done, you should have a working ADC Driver for your NRF52DK board. The last step in getting the driver set up is to include it in the package dependency defined by <code>pkg.deps</code> in the <code>pkg.yml</code> file of your app. Add it in <code>apps/nrf52_adc/pkg.yml</code> as shown by the highlighted line below.</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%"># Licensed to the Apache Software Foundation (ASF) under one
+# &lt;snip&gt;
+
+pkg.name: apps/nrf52_adc
+pkg.type: app
+pkg.description: Simple BLE peripheral application for ADC sensor.
+pkg.author: &quot;Apache Mynewt &lt;dev@mynewt.incubator.apache.org&gt;&quot;
+pkg.homepage: &quot;http://mynewt.apache.org/&quot;
+pkg.keywords:
+
+pkg.deps: 
+    - &quot;@apache-mynewt-core/boot/split&quot;
+    - &quot;@apache-mynewt-core/kernel/os&quot;
+    - &quot;@apache-mynewt-core/mgmt/imgmgr&quot;
+    - &quot;@apache-mynewt-core/mgmt/newtmgr&quot;
+    - &quot;@apache-mynewt-core/mgmt/newtmgr/transport/ble&quot;
+    - &quot;@apache-mynewt-core/net/nimble/controller&quot;
+    - &quot;@apache-mynewt-core/net/nimble/host&quot;
+    - &quot;@apache-mynewt-core/net/nimble/host/services/ans&quot;
+    - &quot;@apache-mynewt-core/net/nimble/host/services/gap&quot;
+    - &quot;@apache-mynewt-core/net/nimble/host/services/gatt&quot;
+    - &quot;@apache-mynewt-core/net/nimble/host/store/ram&quot;
+    - &quot;@apache-mynewt-core/net/nimble/transport/ram&quot;
+    - &quot;@apache-mynewt-core/sys/console/full&quot;
+    - &quot;@apache-mynewt-core/sys/log/full&quot;
+    - &quot;@apache-mynewt-core/sys/stats/full&quot;
+    - &quot;@apache-mynewt-core/sys/sysinit&quot;
+    - &quot;@apache-mynewt-core/sys/id&quot;
+<span style="background-color: #ffffcc">    - libs/my_drivers/myadc
+</span></pre></div>
+
+
+<p><br></p>
+<h3 id="creating-the-adc-task">Creating the ADC Task</h3>
+<p>Now that the driver is done, we'll need to add calls to the main app's <code>main.c</code> file, as well
+as a few other things. First, we'll need to update the includes, and add a task for our ADC
+sampling.</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%"><span style="color: #633820">#include &quot;myadc/myadc.h&quot;</span>
+...
+<span style="color: #177500">/* ADC Task settings */</span>
+<span style="color: #633820">#define ADC_TASK_PRIO           5</span>
+<span style="color: #633820">#define ADC_STACK_SIZE          (OS_STACK_ALIGN(336))</span>
+<span style="color: #A90D91">struct</span> <span style="color: #000000">os_eventq</span> <span style="color: #000000">adc_evq</span>;
+<span style="color: #A90D91">struct</span> <span style="color: #000000">os_task</span> <span style="color: #000000">adc_task</span>;
+<span style="color: #A90D91">bssnz_t</span> <span style="color: #A90D91">os_stack_t</span> <span style="color: #000000">adc_stack</span>[<span style="color: #000000">ADC_STACK_SIZE</span>];
+</pre></div>
+
+
+<p>Next we'll need  o initialize the task <code>event_q</code> so we'll add the highlighted code to <code>main()</code> as shown below:</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%">    <span style="color: #177500">/* Set the default device name. */</span>
+    <span style="color: #000000">rc</span> <span style="color: #000000">=</span> <span style="color: #000000">ble_svc_gap_device_name_set</span>(<span style="color: #C41A16">&quot;nimble-adc&quot;</span>);
+    <span style="color: #000000">assert</span>(<span style="color: #000000">rc</span> <span style="color: #000000">==</span> <span style="color: #1C01CE">0</span>);
+
+    <span style="color: #000000">conf_load</span>();
+
+<span style="background-color: #ffffcc">    <span style="color: #177500">/* Initialize adc sensor task eventq */</span>
+</span><span style="background-color: #ffffcc">    <span style="color: #000000">os_eventq_init</span>(<span style="color: #000000">&amp;adc_evq</span>);
+</span><span style="background-color: #ffffcc">
+</span><span style="background-color: #ffffcc">    <span style="color: #177500">/* Create the ADC reader task.  </span>
+</span><span style="background-color: #ffffcc"><span style="color: #177500">     * All sensor operations are performed in this task.</span>
+</span><span style="background-color: #ffffcc"><span style="color: #177500">     */</span>
+</span><span style="background-color: #ffffcc">    <span style="color: #000000">os_task_init</span>(<span style="color: #000000">&amp;adc_task</span>, <span style="color: #C41A16">&quot;sensor&quot;</span>, <span style="color: #000000">adc_task_handler</span>,
+</span><span style="background-color: #ffffcc">            <span style="color: #A90D91">NULL</span>, <span style="color: #000000">ADC_TASK_PRIO</span>, <span style="color: #000000">OS_WAIT_FOREVER</span>,
+</span><span style="background-color: #ffffcc">            <span style="color: #000000">adc_stack</span>, <span style="color: #000000">ADC_STACK_SIZE</span>);
+</span></pre></div>
+
+
+<p>We'll need that <code>adc_task_handler()</code> function to exist, and that's where we'll initialize the ADC Device
+and set the event handler. In the task's while() loop, we'll just make a call to <code>adc_sample()</code> to cause
+the ADC driver to sample the adc device.</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%"><span style="color: #177500">/**</span>
+<span style="color: #177500"> * Event loop for the sensor task.</span>
+<span style="color: #177500"> */</span>
+<span style="color: #A90D91">static</span> <span style="color: #A90D91">void</span>
+<span style="color: #000000">adc_task_handler</span>(<span style="color: #A90D91">void</span> <span style="color: #000000">*unused</span>)
+{
+    <span style="color: #A90D91">struct</span> <span style="color: #000000">adc_dev</span> <span style="color: #000000">*adc</span>;
+    <span style="color: #A90D91">int</span> <span style="color: #000000">rc</span>;
+    <span style="color: #177500">/* ADC init */</span>
+    <span style="color: #000000">adc</span> <span style="color: #000000">=</span> <span style="color: #000000">adc_init</span>();
+    <span style="color: #000000">rc</span> <span style="color: #000000">=</span> <span style="color: #000000">adc_event_handler_set</span>(<span style="color: #000000">adc</span>, <span style="color: #000000">adc_read_event</span>, (<span style="color: #A90D91">void</span> <span style="color: #000000">*</span>) <span style="color: #A90D91">NULL</span>);
+    <span style="color: #000000">assert</span>(<span style="color: #000000">rc</span> <span style="color: #000000">==</span> <span style="color: #1C01CE">0</span>);
+
+    <span style="color: #A90D91">while</span> (<span style="color: #1C01CE">1</span>) {
+        <span style="color: #000000">adc_sample</span>(<span style="color: #000000">adc</span>);
+        <span style="color: #177500">/* Wait 2 second */</span>
+        <span style="color: #000000">os_time_delay</span>(<span style="color: #000000">OS_TICKS_PER_SEC</span> <span style="color: #000000">*</span> <span style="color: #1C01CE">2</span>);
+    }
+}
+</pre></div>
+
+
+<p>Above the <code>adc_task_handler</code>, add code to handle the <code>adc_read_event()</code> calls:</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%"><span style="color: #A90D91">int</span>
+<span style="color: #000000">adc_read_event</span>(<span style="color: #A90D91">struct</span> <span style="color: #000000">adc_dev</span> <span style="color: #000000">*dev</span>, <span style="color: #A90D91">void</span> <span style="color: #000000">*arg</span>, <span style="color: #A90D91">uint8_t</span> <span style="color: #000000">etype</span>,
+        <span style="color: #A90D91">void</span> <span style="color: #000000">*buffer</span>, <span style="color: #A90D91">int</span> <span style="color: #000000">buffer_len</span>)
+{
+    <span style="color: #A90D91">int</span> <span style="color: #000000">value</span>;
+    <span style="color: #A90D91">uint16_t</span> <span style="color: #000000">chr_val_handle</span>;
+    <span style="color: #A90D91">int</span> <span style="color: #000000">rc</span>;
+
+    <span style="color: #000000">value</span> <span style="color: #000000">=</span> <span style="color: #000000">adc_read</span>(<span style="color: #000000">buffer</span>, <span style="color: #000000">buffer_len</span>);
+    <span style="color: #A90D91">if</span> (<span style="color: #000000">value</span> <span style="color: #000000">&gt;=</span> <span style="color: #1C01CE">0</span>) {
+        <span style="color: #000000">console_printf</span>(<span style="color: #C41A16">&quot;Got %d\n&quot;</span>, <span style="color: #000000">value</span>);
+    } <span style="color: #A90D91">else</span> {
+        <span style="color: #000000">console_printf</span>(<span style="color: #C41A16">&quot;Error while reading: %d\n&quot;</span>, <span style="color: #000000">value</span>);
+        <span style="color: #A90D91">goto</span> <span style="color: #000000">err</span>;
+    }
+    <span style="color: #000000">gatt_adc_val</span> <span style="color: #000000">=</span> <span style="color: #000000">value</span>;
+    <span style="color: #000000">rc</span> <span style="color: #000000">=</span> <span style="color: #000000">ble_gatts_find_chr</span>(<span style="color: #000000">&amp;gatt_svr_svc_adc_uuid</span>.<span style="color: #000000">u</span>, <span style="color: #000000">BLE_UUID16_DECLARE</span>(<span style="color: #000000">ADC_SNS_VAL</span>), <span style="color: #A90D91">NULL</span>, <span style="color: #000000">&amp;chr_val_handle</span>);
+    <span style="color: #000000">assert</span>(<span style="color: #000000">rc</span> <span style="color: #000000">==</span> <span style="color: #1C01CE">0</span>);
+    <span style="color: #000000">ble_gatts_chr_updated</span>(<span style="color: #000000">chr_val_handle</span>);
+    <span style="color: #A90D91">return</span> (<span style="color: #1C01CE">0</span>);
+<span style="color: #000000">err</span>:
+    <span style="color: #A90D91">return</span> (<span style="color: #000000">rc</span>);
+} 
+</pre></div>
+
+
+<p>This is where we actually read the ADC value and then update the BLE Characteristic for that value. </p>
+<p>But wait, we haven't defined those BLE services and characteristics yet! Right, so don't try to build and run this
+app just yet or it will surely fail. Instead, move on to the next section and get all of those services 
+defined.</p>
+<p><br></p>
+<h3 id="building-the-ble-services">Building the BLE Services</h3>
+<p>If the nrf52_adc app is going to be a Bluetooth-enabled sensor app that will allow you to read the value of the eTape Water Level Sensor
+via Bluetooth we'll need to actually define those Services and Characteristics.</p>
+<p>As with the <a href="../bleprph/bleprph-app/">ble peripheral</a> app, we will advertise a couple of values from our app. The first is
+not strictly necessary, but it will help us build an iOS app later. We've defined a service and the characteristics in
+that service in <code>bleadc.h</code> in the <code>apps/nrf52_adc/src/</code> directory as follows:</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%"><span style="color: #177500">/* Sensor Data */</span>
+<span style="color: #177500">/* e761d2af-1c15-4fa7-af80-b5729002b340 */</span>
+<span style="color: #A90D91">static</span> <span style="color: #A90D91">const</span> <span style="color: #A90D91">ble_uuid128_t</span> <span style="color: #000000">gatt_svr_svc_adc_uuid</span> <span style="color: #000000">=</span>
+        <span style="color: #000000">BLE_UUID128_INIT</span>(<span style="color: #1C01CE">0x40</span>, <span style="color: #1C01CE">0xb3</span>, <span style="color: #1C01CE">0x20</span>, <span style="color: #1C01CE">0x90</span>, <span style="color: #1C01CE">0x72</span>, <span style="color: #1C01CE">0xb5</span>, <span style="color: #1C01CE">0x80</span>, <span style="color: #1C01CE">0xaf</span>,
+                         <span style="color: #1C01CE">0xa7</span>, <span style="color: #1C01CE">0x4f</span>, <span style="color: #1C01CE">0x15</span>, <span style="color: #1C01CE">0x1c</span>, <span style="color: #1C01CE">0xaf</span>, <span style="color: #1C01CE">0xd2</span>, <span style="color: #1C01CE">0x61</span>, <span style="color: #1C01CE">0xe7</span>);
+<span style="color: #633820">#define ADC_SNS_TYPE          0xDEAD</span>
+<span style="color: #633820">#define ADC_SNS_STRING &quot;eTape Liquid Level Sensor&quot;</span>
+<span style="color: #633820">#define ADC_SNS_VAL           0xBEAD</span>
+<span style="color: #A90D91">extern</span> <span style="color: #A90D91">uint16_t</span> <span style="color: #000000">gatt_adc_val</span>; 
+</pre></div>
+
+
+<p>The first is the UUID of the service, followed by the 2 characteristics we are going to offer.
+The first characteristic is going to advertise the <em>type</em> of sensor we are advertising, and
+it will be a read-only characteristic. The second characteristic will be the sensor value
+itself, and we will allow connected devices to 'subscribe' to it in order to get 
+constantly-updated values.</p>
+<p><strong>Note:</strong> You can choose any valid Characteristic UUIDs to go here. We're using these values
+for illustrative purposes only.</p>
+<p>The value that we'll be updating is also defined here as <code>gatt_adc_val</code>.</p>
+<p>If we then go look at <code>gatt_srv.c</code> we can see the structure of the service and
+characteristic offering that we set up:</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%"><span style="color: #A90D91">static</span> <span style="color: #A90D91">const</span> <span style="color: #A90D91">struct</span> <span style="color: #000000">ble_gatt_svc_def</span> <span style="color: #000000">gatt_svr_svcs</span>[] <span style="color: #000000">=</span> {
+    {
+        <span style="color: #177500">/*** Service: Security test. */</span>
+        .<span style="color: #000000">type</span> <span style="color: #000000">=</span> <span style="color: #000000">BLE_GATT_SVC_TYPE_PRIMARY</span>,
+        .<span style="color: #000000">uuid</span> <span style="color: #000000">=</span> <span style="color: #000000">&amp;gatt_svr_svc_sec_test_uuid</span>.<span style="color: #000000">u</span>,
+        .<span style="color: #000000">characteristics</span> <span style="color: #000000">=</span> (<span style="color: #A90D91">struct</span> <span style="color: #000000">ble_gatt_chr_def</span>[]) { {
+            <span style="color: #177500">/*** Characteristic: Random number generator. */</span>
+            .<span style="color: #000000">uuid</span> <span style="color: #000000">=</span> <span style="color: #000000">&amp;gatt_svr_chr_sec_test_rand_uuid</span>.<span style="color: #000000">u</span>,
+            .<span style="color: #000000">access_cb</span> <span style="color: #000000">=</span> <span style="color: #000000">gatt_svr_chr_access_sec_test</span>,
+            .<span style="color: #000000">flags</span> <span style="color: #000000">=</span> <span style="color: #000000">BLE_GATT_CHR_F_READ</span> <span style="color: #000000">|</span> <span style="color: #000000">BLE_GATT_CHR_F_READ_ENC</span>,
+        }, {
+            <span style="color: #177500">/*** Characteristic: Static value. */</span>
+            .<span style="color: #000000">uuid</span> <span style="color: #000000">=</span> <span style="color: #000000">&amp;gatt_svr_chr_sec_test_static_uuid</span>.<span style="color: #000000">u</span>,
+            .<span style="color: #000000">access_cb</span> <span style="color: #000000">=</span> <span style="color: #000000">gatt_svr_chr_access_sec_test</span>,
+            .<span style="color: #000000">flags</span> <span style="color: #000000">=</span> <span style="color: #000000">BLE_GATT_CHR_F_READ</span> <span style="color: #000000">|</span>
+                     <span style="color: #000000">BLE_GATT_CHR_F_WRITE</span> <span style="color: #000000">|</span> <span style="color: #000000">BLE_GATT_CHR_F_WRITE_ENC</span>,
+        }, {
+            <span style="color: #1C01CE">0</span>, <span style="color: #177500">/* No more characteristics in this service. */</span>
+        } },
+    },
+<span style="background-color: #ffffcc">    {
+</span><span style="background-color: #ffffcc">        <span style="color: #177500">/*** ADC Level Notification Service. */</span>
+</span><span style="background-color: #ffffcc">        .<span style="color: #000000">type</span> <span style="color: #000000">=</span> <span style="color: #000000">BLE_GATT_SVC_TYPE_PRIMARY</span>,
+</span><span style="background-color: #ffffcc">        .<span style="color: #000000">uuid</span> <span style="color: #000000">=</span> <span style="color: #000000">&amp;gatt_svr_svc_adc_uuid</span>.<span style="color: #000000">u</span>,
+</span><span style="background-color: #ffffcc">        .<span style="color: #000000">characteristics</span> <span style="color: #000000">=</span> (<span style="color: #A90D91">struct</span> <span style="color: #000000">ble_gatt_chr_def</span>[]) { {
+</span><span style="background-color: #ffffcc">            .<span style="color: #000000">uuid</span> <span style="color: #000000">=</span> <span style="color: #000000">BLE_UUID16_DECLARE</span>(<span style="color: #000000">ADC_SNS_TYPE</span>),
+</span><span style="background-color: #ffffcc">            .<span style="color: #000000">access_cb</span> <span style="color: #000000">=</span> <span style="color: #000000">gatt_svr_sns_access</span>,
+</span><span style="background-color: #ffffcc">            .<span style="color: #000000">flags</span> <span style="color: #000000">=</span> <span style="color: #000000">BLE_GATT_CHR_F_READ</span>,
+</span><span style="background-color: #ffffcc">        }, {
+</span><span style="background-color: #ffffcc">            .<span style="color: #000000">uuid</span> <span style="color: #000000">=</span> <span style="color: #000000">BLE_UUID16_DECLARE</span>(<span style="color: #000000">ADC_SNS_VAL</span>),
+</span><span style="background-color: #ffffcc">            .<span style="color: #000000">access_cb</span> <span style="color: #000000">=</span> <span style="color: #000000">gatt_svr_sns_access</span>,
+</span><span style="background-color: #ffffcc">            .<span style="color: #000000">flags</span> <span style="color: #000000">=</span> <span style="color: #000000">BLE_GATT_CHR_F_NOTIFY</span>,
+</span><span style="background-color: #ffffcc">        }, {
+</span><span style="background-color: #ffffcc">            <span style="color: #1C01CE">0</span>, <span style="color: #177500">/* No more characteristics in this service. */</span>
+</span><span style="background-color: #ffffcc">        } },
+</span><span style="background-color: #ffffcc">    },
+</span><span style="background-color: #ffffcc">
+</span>    {
+        <span style="color: #1C01CE">0</span>, <span style="color: #177500">/* No more services. */</span>
+    },
+};
+</pre></div>
+
+
+<p>You should recognize the first services from the <a href="../bleprph/bleprph-intro/">BLE Peripheral</a>
+tutorial earlier. We're just adding another Service, with 2 new Characteristics, to 
+that application.</p>
+<p>We'll need to fill in the function that will be called for this service, <code>gatt_srv_sns_access</code>
+next so that the service knows what to do.</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%"><span style="color: #A90D91">static</span> <span style="color: #A90D91">int</span>
+<span style="color: #000000">gatt_svr_sns_access</span>(<span style="color: #A90D91">uint16_t</span> <span style="color: #000000">conn_handle</span>, <span style="color: #A90D91">uint16_t</span> <span style="color: #000000">attr_handle</span>,
+                          <span style="color: #A90D91">struct</span> <span style="color: #000000">ble_gatt_access_ctxt</span> <span style="color: #000000">*ctxt</span>,
+                          <span style="color: #A90D91">void</span> <span style="color: #000000">*arg</span>)
+{
+    <span style="color: #A90D91">uint16_t</span> <span style="color: #000000">uuid16</span>;
+    <span style="color: #A90D91">int</span> <span style="color: #000000">rc</span>;
+
+    <span style="color: #000000">uuid16</span> <span style="color: #000000">=</span> <span style="color: #000000">ble_uuid_u16</span>(<span style="color: #000000">ctxt-&gt;chr-&gt;uuid</span>);
+
+    <span style="color: #A90D91">switch</span> (<span style="color: #000000">uuid16</span>) {
+    <span style="color: #A90D91">case</span> <span style="color: #000000">ADC_SNS_TYPE</span>:
+        <span style="color: #000000">assert</span>(<span style="color: #000000">ctxt-&gt;op</span> <span style="color: #000000">==</span> <span style="color: #000000">BLE_GATT_ACCESS_OP_READ_CHR</span>);
+        <span style="color: #000000">rc</span> <span style="color: #000000">=</span> <span style="color: #000000">os_mbuf_append</span>(<span style="color: #000000">ctxt-&gt;om</span>, <span style="color: #000000">ADC_SNS_STRING</span>, <span style="color: #A90D91">sizeof</span> <span style="color: #000000">ADC_SNS_STRING</span>);
+        <span style="color: #000000">BLEPRPH_LOG</span>(<span style="color: #000000">INFO</span>, <span style="color: #C41A16">&quot;ADC SENSOR TYPE READ: %s\n&quot;</span>, <span style="color: #000000">ADC_SNS_STRING</span>);
+        <span style="color: #A90D91">return</span> <span style="color: #000000">rc</span> <span style="color: #000000">==</span> <span style="color: #1C01CE">0</span> <span style="color: #000000">?</span> <span style="color: #1C01CE">0</span> <span style="color: #000000">:</span> <span style="color: #000000">BLE_ATT_ERR_INSUFFICIENT_RES</span>;
+
+    <span style="color: #A90D91">case</span> <span style="color: #000000">ADC_SNS_VAL</span>:
+        <span style="color: #A90D91">if</span> (<span style="color: #000000">ctxt-&gt;op</span> <span style="color: #000000">==</span> <span style="color: #000000">BLE_GATT_ACCESS_OP_WRITE_CHR</span>) {
+            <span style="color: #000000">rc</span> <span style="color: #000000">=</span> <span style="color: #000000">gatt_svr_chr_write</span>(<span style="color: #000000">ctxt-&gt;om</span>, <span style="color: #1C01CE">0</span>,
+                                    <span style="color: #A90D91">sizeof</span> <span style="color: #000000">gatt_adc_val</span>,
+                                    <span style="color: #000000">&amp;gatt_adc_val</span>,
+                                    <span style="color: #A90D91">NULL</span>);
+            <span style="color: #A90D91">return</span> <span style="color: #000000">rc</span>;
+        } <span style="color: #A90D91">else</span> <span style="color: #A90D91">if</span> (<span style="color: #000000">ctxt-&gt;op</span> <span style="color: #000000">==</span> <span style="color: #000000">BLE_GATT_ACCESS_OP_READ_CHR</span>) {
+            <span style="color: #000000">rc</span> <span style="color: #000000">=</span> <span style="color: #000000">os_mbuf_append</span>(<span style="color: #000000">ctxt-&gt;om</span>, <span style="color: #000000">&amp;gatt_adc_val</span>,
+                                <span style="color: #A90D91">sizeof</span> <span style="color: #000000">gatt_adc_val</span>);
+            <span style="color: #A90D91">return</span> <span style="color: #000000">rc</span> <span style="color: #000000">==</span> <span style="color: #1C01CE">0</span> <span style="color: #000000">?</span> <span style="color: #1C01CE">0</span> <span style="color: #000000">:</span> <span style="color: #000000">BLE_ATT_ERR_INSUFFICIENT_RES</span>;
+        }
+
+    <span style="color: #A90D91">default</span><span style="color: #000000">:</span>
+        <span style="color: #000000">assert</span>(<span style="color: #1C01CE">0</span>);
+        <span style="color: #A90D91">return</span> <span style="color: #000000">BLE_ATT_ERR_UNLIKELY</span>;
+    }
+}
+</pre></div>
+
+
+<p>You can see that when request is for the <code>ADC_SNS_TYPE</code>, we return the
+Sensor Type we defined earlier. If the request if for <code>ADC_SNS_VAL</code> we'll return the
+<code>gatt_adc_val</code> value. </p>
+<p>Don't forget to include the <code>bleadc.h</code> include file at the top of the <code>gatt_svr.c</code> file!</p>
+<div class="codehilite" style="background: #ffffff"><pre style="line-height: 125%">#include &lt;assert.h&gt;
+#include &lt;stdio.h&gt;
+#include &lt;string.h&gt;
+#include &quot;bsp/bsp.h&quot;
+#include &quot;host/ble_hs.h&quot;
+#include &quot;host/ble_uuid.h&quot;
+#include &quot;bleprph.h&quot;
+<span style="background-color: #ffffcc">#include &quot;bleadc.h&quot;
+</span></pre></div>
+
+
+<p>If you build, load and run this application now, you will see all those Services and Characteristics
+advertised, and you will even be able to read the "Sensor Type" String via the ADC_SNS_TYPE
+Characteristic.</p>
+<p><br></p>
+<h3 id="adding-the-etape-water-sensor">Adding the eTape Water Sensor</h3>
+<p>Now that we have a fully functioning BLE App that we can subscribe to sensor
+values from, it's time to actually wire up the sensor!</p>
+<p>As previously mentioned, we're going to be using an eTape Water Level Sensor. You can 
+get one from <a href="https://www.adafruit.com/products/1786">Adafruit</a>. </p>
+<p>We're going to use the sensor as a resistive sensor, and the setup is very simple. 
+I'll be using a 'breadboard` to put this all together for illustrative purposes. 
+First, attach a jumper-wire from Vdd on the board to the breadboard.
+Next, attach a jumper wire from pin P0.03 on the board to the breadboard. This will be
+our ADC-in. The sensor should have come with a 560 ohm resistor, so plug that
+into the board between Vdd and ADC-in holes. Finally, attach a jumper from
+GND on the board to your breadboard. At this point, your breadboard should look
+like this:</p>
+<p><img alt="Bread Board Setup" src="../pics/breadboard.png" /></p>
+<p>Now attach one of the middle 2 leads from the sensor to ground on the breadboard and 
+the other middle lead to the ADC-in on the breadboard. Your breadboard should now look
+like this:</p>
+<p><img alt="Bread Board Final" src="../pics/adc-demo-1.png" /></p>
+<p>And your eTape Sensor should look like this (at least if you have it mounted in a
+graduated cylinder as I do).</p>
+<p><img alt="eTape Sensor Setup" src="../pics/adc-demo-2.png" /></p>
+<p>That concludes the hardware portion. Easy!</p>
+<p>At this point you should be able to build, create-image and load your application and see it properly 
+sending readings. </p>
+<p><br></p>
+<h3 id="conclusion">Conclusion</h3>
+<p>Congratulations, you've now completed both a hardware project and a software project by connecting a
+sensor to your device and using Mynewt to read data from that sensor and send it via Bluetooth
+to a connected device. That's no small feat!</p>
+<p>If you see anything missing or want to send us feedback, please do so by signing up for 
+appropriate mailing lists on our <a href="../../../community/">Community Page</a>.</p>
+<p>Keep on hacking and sensing!</p>
+<p><br></p>
+<h3 id="note">Note</h3>
+<p>If you're wondering how to actually view these sensor readings via Bluetooth, you have a couple of
+options. On Mac OS or iOS you can download the <a href="https://itunes.apple.com/us/app/lightblue-explorer-bluetooth/id557428110?mt=8">LightBlue app</a>.
+This app lets you connect to, and interrogate, BLE devices like the one you just built. </p>
+<p>If you used the BLE Service and Characteristic UUIDs used in this tutorial, you can also download
+and use a Mac OS <a href="https://dragonflyiot.com/MyNewtSensorReader.zip">MyNewt Sensor Reader App</a> (Zip Archive) that allows 
+you to graph your data, etc. An iOS version is in Beta testing and should be available soon.</p>
+<p><img alt="My Newt Sensor Reader" src="../pics/MyNewtSensorReader006.jpg" /></p>
+<p>Enjoy!</p>
+                        
+                        <div class="row">
+                            
+
+
+
+<ul class="nav nav-pills" style="margin-bottom: 10px">
+    <li>
+    
+    <a href=../air_quality_ble/>
+        <span class="fa fa-arrow-left"></span>
+        Previous: BLE-enabled Air Quality Sensor
+    </a>
+    
+    </li>
+    <li class="pull-right">
+    
+    <a href=../../os_user_guide/>
+        Next: OS User Guide
+        <span class="fa fa-arrow-right"></span>
+    </a>
+    
+    </li>
+</ul>
+                        </div>
+                        <footer class="row">
+    <div class="col-xs-12">
+        
+            <p class="copyright">Apache Mynewt (incubating) is available under Apache License, version 2.0.</p>
+        
+    </div>
+    <div class="col-xs-12">
+        <div class="logos">
+            <img src="/img/asf_logo_wide_small.png" alt="Apache" title="Apache">
+            <small class="footnote">
+                MyNewt is an effort undergoing incubation at The Apache Software Foundation (ASF), sponsored by the Apache Incubator. Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects. While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF.
+            </small>
+            <img src="/img/egg-logo2.png" alt="Apache Incubator" title="Apache Incubator">
+        </div>
+    </div>
+</footer>
+                    </div>
+                </div>
+            
+            
+        </div>
+
+        <script src="../../../js/jquery-1.10.2.min.js"></script>
+        <script src="../../../js/bootstrap-3.0.3.min.js"></script>
+        <script src="../../../js/highlight.pack.js"></script>
+        <script src="../../../js/base.js"></script>
+        <script src="../../../js/custom.js"></script>
+
+    </body>
+</html>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/olimex/index.html
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/olimex/index.html b/develop/os/tutorials/olimex/index.html
index 3ed37f4..b808aac 100644
--- a/develop/os/tutorials/olimex/index.html
+++ b/develop/os/tutorials/olimex/index.html
@@ -341,19 +341,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -432,6 +419,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/pics/MyNewtSensorReader006.jpg
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/pics/MyNewtSensorReader006.jpg b/develop/os/tutorials/pics/MyNewtSensorReader006.jpg
new file mode 100644
index 0000000..c15d69d
Binary files /dev/null and b/develop/os/tutorials/pics/MyNewtSensorReader006.jpg differ

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/pics/adc-demo-1.png
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/pics/adc-demo-1.png b/develop/os/tutorials/pics/adc-demo-1.png
new file mode 100644
index 0000000..6e5de58
Binary files /dev/null and b/develop/os/tutorials/pics/adc-demo-1.png differ

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/pics/adc-demo-2.png
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/pics/adc-demo-2.png b/develop/os/tutorials/pics/adc-demo-2.png
new file mode 100644
index 0000000..be2cce7
Binary files /dev/null and b/develop/os/tutorials/pics/adc-demo-2.png differ

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/pics/breadboard.png
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/pics/breadboard.png b/develop/os/tutorials/pics/breadboard.png
new file mode 100644
index 0000000..39a2b9d
Binary files /dev/null and b/develop/os/tutorials/pics/breadboard.png differ

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/pin-wheel-mods/index.html
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/pin-wheel-mods/index.html b/develop/os/tutorials/pin-wheel-mods/index.html
index 20501d4..5e5a581 100644
--- a/develop/os/tutorials/pin-wheel-mods/index.html
+++ b/develop/os/tutorials/pin-wheel-mods/index.html
@@ -355,19 +355,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -446,6 +433,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/project-slinky/index.html
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/project-slinky/index.html b/develop/os/tutorials/project-slinky/index.html
index 0ba2375..349d998 100644
--- a/develop/os/tutorials/project-slinky/index.html
+++ b/develop/os/tutorials/project-slinky/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -389,6 +376,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/project-target-slinky/index.html
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/project-target-slinky/index.html b/develop/os/tutorials/project-target-slinky/index.html
index 5449457..c9b1c99 100644
--- a/develop/os/tutorials/project-target-slinky/index.html
+++ b/develop/os/tutorials/project-target-slinky/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -389,6 +376,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/repo/add_repos/index.html
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/repo/add_repos/index.html b/develop/os/tutorials/repo/add_repos/index.html
index 93a5887..2bc41d6 100644
--- a/develop/os/tutorials/repo/add_repos/index.html
+++ b/develop/os/tutorials/repo/add_repos/index.html
@@ -308,19 +308,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -399,6 +386,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/repo/create_repo/index.html
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/repo/create_repo/index.html b/develop/os/tutorials/repo/create_repo/index.html
index b5f2abb..60fc0dc 100644
--- a/develop/os/tutorials/repo/create_repo/index.html
+++ b/develop/os/tutorials/repo/create_repo/index.html
@@ -308,19 +308,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -399,6 +386,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/repo/private_repo/index.html
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/repo/private_repo/index.html b/develop/os/tutorials/repo/private_repo/index.html
index 9ad0df0..637762c 100644
--- a/develop/os/tutorials/repo/private_repo/index.html
+++ b/develop/os/tutorials/repo/private_repo/index.html
@@ -308,19 +308,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -399,6 +386,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/repo/upgrade_repo/index.html
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/repo/upgrade_repo/index.html b/develop/os/tutorials/repo/upgrade_repo/index.html
index ea177d9..e57f1e4 100644
--- a/develop/os/tutorials/repo/upgrade_repo/index.html
+++ b/develop/os/tutorials/repo/upgrade_repo/index.html
@@ -308,19 +308,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -399,6 +386,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/tasks_lesson/index.html
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/tasks_lesson/index.html b/develop/os/tutorials/tasks_lesson/index.html
index f11eae2..df7064c 100644
--- a/develop/os/tutorials/tasks_lesson/index.html
+++ b/develop/os/tutorials/tasks_lesson/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -369,6 +356,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/develop/os/tutorials/tutorials/index.html
----------------------------------------------------------------------
diff --git a/develop/os/tutorials/tutorials/index.html b/develop/os/tutorials/tutorials/index.html
index 0820cf6..5336b0e 100644
--- a/develop/os/tutorials/tutorials/index.html
+++ b/develop/os/tutorials/tutorials/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -369,6 +356,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>



[3/9] incubator-mynewt-site git commit: Added etape sensor tutorial. PR #152.

Posted by ad...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/os_user_guide/index.html
----------------------------------------------------------------------
diff --git a/latest/os/os_user_guide/index.html b/latest/os/os_user_guide/index.html
index 66cec26..bc93455 100644
--- a/latest/os/os_user_guide/index.html
+++ b/latest/os/os_user_guide/index.html
@@ -550,9 +550,9 @@
 <ul class="nav nav-pills" style="margin-bottom: 10px">
     <li>
     
-    <a href=../tutorials/blehci_project/>
+    <a href=../tutorials/nrf52_adc/>
         <span class="fa fa-arrow-left"></span>
-        Previous: BLE HCI interface
+        Previous: Add an Analog Sensor
     </a>
     
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/STM32F303/index.html
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/STM32F303/index.html b/latest/os/tutorials/STM32F303/index.html
index 44f57cb..a5a0b60 100644
--- a/latest/os/tutorials/STM32F303/index.html
+++ b/latest/os/tutorials/STM32F303/index.html
@@ -355,19 +355,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -446,6 +433,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/add_newtmgr/index.html
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/add_newtmgr/index.html b/latest/os/tutorials/add_newtmgr/index.html
index 4ed9583..e71832a 100644
--- a/latest/os/tutorials/add_newtmgr/index.html
+++ b/latest/os/tutorials/add_newtmgr/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -369,6 +356,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/add_shell/index.html
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/add_shell/index.html b/latest/os/tutorials/add_shell/index.html
index 2c6ad11..a9bf018 100644
--- a/latest/os/tutorials/add_shell/index.html
+++ b/latest/os/tutorials/add_shell/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -369,6 +356,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/air_quality_ble/index.html
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/air_quality_ble/index.html b/latest/os/tutorials/air_quality_ble/index.html
index 5de7e09..f4c8a90 100644
--- a/latest/os/tutorials/air_quality_ble/index.html
+++ b/latest/os/tutorials/air_quality_ble/index.html
@@ -10,7 +10,7 @@
         <link rel="canonical" href="http://mynewt.apache.org/os/tutorials/air_quality_ble/"> -->
         <link rel="shortcut icon" href="../../../img/favicon.ico">
 
-	    <title>Bluetooth-enabled Air Quality Sensor - Apache Mynewt</title>
+	    <title>BLE-enabled Air Quality Sensor - Apache Mynewt</title>
 
         <link href="../../../css/bootstrap-3.0.3.min.css" rel="stylesheet">
         <link rel="stylesheet" href="../../../css/highlight.css">
@@ -41,7 +41,7 @@
     </head>
 
 
-    <body class="Bluetooth-enabled Air Quality Sensor">
+    <body class="BLE-enabled Air Quality Sensor">
 
 
         <div class="container">
@@ -278,33 +278,37 @@
           
               
                 
+    <li >
+      <a href="../event_queue/">Add task to manage multiple events</a>
+    </li>
+
+              
+          
+              
+                
   
   
     <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
+  ../project-slinky/
+">Project Slinky for remote comms</a>
   
   
-    <ul>
-          
-              
-                
-    <li >
-      <a href="../air_quality_sensor/">Basic Air Quality Sensor</a>
     </li>
 
               
           
               
                 
-    <li class="active">
-      <a href="./">Bluetooth-enabled Air Quality Sensor</a>
+    <li >
+      <a href="../add_newtmgr/">Enable Newt Manager in any app</a>
     </li>
 
               
           
-    </ul>
-  
+              
+                
+    <li >
+      <a href="../add_shell/">Enable the OS Shell and Console</a>
     </li>
 
               
@@ -312,7 +316,7 @@
               
                 
     <li >
-      <a href="../event_queue/">Add task to manage multiple events</a>
+      <a href="../bletiny_project/">BLE app to check stats via console</a>
     </li>
 
               
@@ -321,9 +325,7 @@
                 
   
   
-    <li><a href="
-  ../project-slinky/
-">Project Slinky for remote comms</a>
+    <li ><a href="../bleprph/bleprph-intro/">BLE peripheral project</a>
   
   
     </li>
@@ -333,7 +335,7 @@
               
                 
     <li >
-      <a href="../add_newtmgr/">Enable Newt Manager in any app</a>
+      <a href="../ibeacon/">BLE iBeacon</a>
     </li>
 
               
@@ -341,7 +343,7 @@
               
                 
     <li >
-      <a href="../add_shell/">Enable the OS Shell and Console</a>
+      <a href="../eddystone/">BLE Eddystone</a>
     </li>
 
               
@@ -349,7 +351,7 @@
               
                 
     <li >
-      <a href="../bletiny_project/">BLE app to check stats via console</a>
+      <a href="../blehci_project/">BLE HCI interface</a>
     </li>
 
               
@@ -358,25 +360,31 @@
                 
   
   
-    <li ><a href="../bleprph/bleprph-intro/">BLE peripheral project</a>
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
   
   
-    </li>
-
-              
+    <ul>
           
               
                 
     <li >
-      <a href="../ibeacon/">BLE iBeacon</a>
+      <a href="../air_quality_sensor/">Basic Air Quality Sensor</a>
     </li>
 
               
           
               
                 
-    <li >
-      <a href="../eddystone/">BLE Eddystone</a>
+    <li class="active">
+      <a href="./">BLE-enabled Air Quality Sensor</a>
+    </li>
+
+              
+          
+    </ul>
+  
     </li>
 
               
@@ -384,7 +392,7 @@
               
                 
     <li >
-      <a href="../blehci_project/">BLE HCI interface</a>
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
     </li>
 
               
@@ -479,7 +487,7 @@
         
       
       
-        <li>&raquo; Bluetooth-enabled Air Quality Sensor</li>
+        <li>&raquo; BLE-enabled Air Quality Sensor</li>
       
     
     
@@ -704,8 +712,8 @@ or any other application that can connect to, and read, Bluetooth data.</p>
     </li>
     <li class="pull-right">
     
-    <a href=../event_queue/>
-        Next: Add task to manage multiple events
+    <a href=../nrf52_adc/>
+        Next: Add an Analog Sensor
         <span class="fa fa-arrow-right"></span>
     </a>
     

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/air_quality_sensor/index.html
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/air_quality_sensor/index.html b/latest/os/tutorials/air_quality_sensor/index.html
index ab46cf1..eea6eaa 100644
--- a/latest/os/tutorials/air_quality_sensor/index.html
+++ b/latest/os/tutorials/air_quality_sensor/index.html
@@ -278,19 +278,21 @@
           
               
                 
+    <li >
+      <a href="../event_queue/">Add task to manage multiple events</a>
+    </li>
+
+              
+          
+              
+                
   
   
     <li><a href="
-  ./
-">Air-quality Sensor project</a>
+  ../project-slinky/
+">Project Slinky for remote comms</a>
   
   
-    <ul>
-          
-              
-                
-    <li class="active">
-      <a href="./">Basic Air Quality Sensor</a>
     </li>
 
               
@@ -298,13 +300,15 @@
               
                 
     <li >
-      <a href="../air_quality_ble/">Bluetooth-enabled Air Quality Sensor</a>
+      <a href="../add_newtmgr/">Enable Newt Manager in any app</a>
     </li>
 
               
           
-    </ul>
-  
+              
+                
+    <li >
+      <a href="../add_shell/">Enable the OS Shell and Console</a>
     </li>
 
               
@@ -312,7 +316,7 @@
               
                 
     <li >
-      <a href="../event_queue/">Add task to manage multiple events</a>
+      <a href="../bletiny_project/">BLE app to check stats via console</a>
     </li>
 
               
@@ -321,9 +325,7 @@
                 
   
   
-    <li><a href="
-  ../project-slinky/
-">Project Slinky for remote comms</a>
+    <li ><a href="../bleprph/bleprph-intro/">BLE peripheral project</a>
   
   
     </li>
@@ -333,7 +335,7 @@
               
                 
     <li >
-      <a href="../add_newtmgr/">Enable Newt Manager in any app</a>
+      <a href="../ibeacon/">BLE iBeacon</a>
     </li>
 
               
@@ -341,7 +343,7 @@
               
                 
     <li >
-      <a href="../add_shell/">Enable the OS Shell and Console</a>
+      <a href="../eddystone/">BLE Eddystone</a>
     </li>
 
               
@@ -349,7 +351,7 @@
               
                 
     <li >
-      <a href="../bletiny_project/">BLE app to check stats via console</a>
+      <a href="../blehci_project/">BLE HCI interface</a>
     </li>
 
               
@@ -358,9 +360,17 @@
                 
   
   
-    <li ><a href="../bleprph/bleprph-intro/">BLE peripheral project</a>
+    <li><a href="
+  ./
+">Air-quality Sensor project</a>
   
   
+    <ul>
+          
+              
+                
+    <li class="active">
+      <a href="./">Basic Air Quality Sensor</a>
     </li>
 
               
@@ -368,15 +378,13 @@
               
                 
     <li >
-      <a href="../ibeacon/">BLE iBeacon</a>
+      <a href="../air_quality_ble/">BLE-enabled Air Quality Sensor</a>
     </li>
 
               
           
-              
-                
-    <li >
-      <a href="../eddystone/">BLE Eddystone</a>
+    </ul>
+  
     </li>
 
               
@@ -384,7 +392,7 @@
               
                 
     <li >
-      <a href="../blehci_project/">BLE HCI interface</a>
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
     </li>
 
               
@@ -1301,16 +1309,16 @@ Loading app image into slot 1
 <ul class="nav nav-pills" style="margin-bottom: 10px">
     <li>
     
-    <a href=../unit_test/>
+    <a href=../blehci_project/>
         <span class="fa fa-arrow-left"></span>
-        Previous: Write a Test Suite for a Package
+        Previous: BLE HCI interface
     </a>
     
     </li>
     <li class="pull-right">
     
     <a href=../air_quality_ble/>
-        Next: Bluetooth-enabled Air Quality Sensor
+        Next: BLE-enabled Air Quality Sensor
         <span class="fa fa-arrow-right"></span>
     </a>
     

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/arduino_zero/index.html
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/arduino_zero/index.html b/latest/os/tutorials/arduino_zero/index.html
index d5a1e79..77ba88d 100644
--- a/latest/os/tutorials/arduino_zero/index.html
+++ b/latest/os/tutorials/arduino_zero/index.html
@@ -341,19 +341,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -432,6 +419,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/blehci_project/index.html
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/blehci_project/index.html b/latest/os/tutorials/blehci_project/index.html
index 1fb93c7..84d1f95 100644
--- a/latest/os/tutorials/blehci_project/index.html
+++ b/latest/os/tutorials/blehci_project/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -369,6 +356,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>
@@ -635,8 +643,8 @@ eir_len 23
     </li>
     <li class="pull-right">
     
-    <a href=../../os_user_guide/>
-        Next: OS User Guide
+    <a href=../air_quality_sensor/>
+        Next: Basic Air Quality Sensor
         <span class="fa fa-arrow-right"></span>
     </a>
     

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/bleprph/bleprph-adv/index.html
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/bleprph/bleprph-adv/index.html b/latest/os/tutorials/bleprph/bleprph-adv/index.html
index 1dbe9c1..3c973bc 100644
--- a/latest/os/tutorials/bleprph/bleprph-adv/index.html
+++ b/latest/os/tutorials/bleprph/bleprph-adv/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -415,6 +402,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/bleprph/bleprph-app/index.html
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/bleprph/bleprph-app/index.html b/latest/os/tutorials/bleprph/bleprph-app/index.html
index 0b8fc20..b178a49 100644
--- a/latest/os/tutorials/bleprph/bleprph-app/index.html
+++ b/latest/os/tutorials/bleprph/bleprph-app/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -415,6 +402,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/bleprph/bleprph-chr-access/index.html
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/bleprph/bleprph-chr-access/index.html b/latest/os/tutorials/bleprph/bleprph-chr-access/index.html
index 42cc68a..c90db21 100644
--- a/latest/os/tutorials/bleprph/bleprph-chr-access/index.html
+++ b/latest/os/tutorials/bleprph/bleprph-chr-access/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -415,6 +402,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/bleprph/bleprph-gap-event/index.html
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/bleprph/bleprph-gap-event/index.html b/latest/os/tutorials/bleprph/bleprph-gap-event/index.html
index 8b3b63b..fead055 100644
--- a/latest/os/tutorials/bleprph/bleprph-gap-event/index.html
+++ b/latest/os/tutorials/bleprph/bleprph-gap-event/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -415,6 +402,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/bleprph/bleprph-intro/index.html
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/bleprph/bleprph-intro/index.html b/latest/os/tutorials/bleprph/bleprph-intro/index.html
index eaa2890..1eead55 100644
--- a/latest/os/tutorials/bleprph/bleprph-intro/index.html
+++ b/latest/os/tutorials/bleprph/bleprph-intro/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -415,6 +402,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/bleprph/bleprph-svc-reg/index.html
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/bleprph/bleprph-svc-reg/index.html b/latest/os/tutorials/bleprph/bleprph-svc-reg/index.html
index a02acf7..44fd0e8 100644
--- a/latest/os/tutorials/bleprph/bleprph-svc-reg/index.html
+++ b/latest/os/tutorials/bleprph/bleprph-svc-reg/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -415,6 +402,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/bletiny_project/index.html
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/bletiny_project/index.html b/latest/os/tutorials/bletiny_project/index.html
index d382bec..b05811d 100644
--- a/latest/os/tutorials/bletiny_project/index.html
+++ b/latest/os/tutorials/bletiny_project/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -369,6 +356,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/blinky_console/index.html
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/blinky_console/index.html b/latest/os/tutorials/blinky_console/index.html
index a07b038..88476ef 100644
--- a/latest/os/tutorials/blinky_console/index.html
+++ b/latest/os/tutorials/blinky_console/index.html
@@ -341,19 +341,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -432,6 +419,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/blinky_primo/index.html
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/blinky_primo/index.html b/latest/os/tutorials/blinky_primo/index.html
index 0e5528c..edde0a4 100644
--- a/latest/os/tutorials/blinky_primo/index.html
+++ b/latest/os/tutorials/blinky_primo/index.html
@@ -341,19 +341,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -432,6 +419,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/blinky_sram_olimex/index.html
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/blinky_sram_olimex/index.html b/latest/os/tutorials/blinky_sram_olimex/index.html
index 5ecf85a..e5c2def 100644
--- a/latest/os/tutorials/blinky_sram_olimex/index.html
+++ b/latest/os/tutorials/blinky_sram_olimex/index.html
@@ -341,19 +341,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -432,6 +419,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/eddystone/index.html
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/eddystone/index.html b/latest/os/tutorials/eddystone/index.html
index 74531b6..bf259a8 100644
--- a/latest/os/tutorials/eddystone/index.html
+++ b/latest/os/tutorials/eddystone/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -369,6 +356,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/event_queue/index.html
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/event_queue/index.html b/latest/os/tutorials/event_queue/index.html
index 2548aec..5528261 100644
--- a/latest/os/tutorials/event_queue/index.html
+++ b/latest/os/tutorials/event_queue/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li class="active">
       <a href="./">Add task to manage multiple events</a>
     </li>
@@ -369,6 +356,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>
@@ -786,9 +794,9 @@ pkg.deps:
 <ul class="nav nav-pills" style="margin-bottom: 10px">
     <li>
     
-    <a href=../air_quality_ble/>
+    <a href=../unit_test/>
         <span class="fa fa-arrow-left"></span>
-        Previous: Bluetooth-enabled Air Quality Sensor
+        Previous: Write a Test Suite for a Package
     </a>
     
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/ibeacon/index.html
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/ibeacon/index.html b/latest/os/tutorials/ibeacon/index.html
index 5b7099e..9364cc8 100644
--- a/latest/os/tutorials/ibeacon/index.html
+++ b/latest/os/tutorials/ibeacon/index.html
@@ -278,19 +278,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -369,6 +356,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/os/tutorials/nRF52/index.html
----------------------------------------------------------------------
diff --git a/latest/os/tutorials/nRF52/index.html b/latest/os/tutorials/nRF52/index.html
index f785404..bcc94b0 100644
--- a/latest/os/tutorials/nRF52/index.html
+++ b/latest/os/tutorials/nRF52/index.html
@@ -341,19 +341,6 @@
           
               
                 
-  
-  
-    <li><a href="
-  ../air_quality_sensor/
-">Air-quality Sensor project</a>
-  
-  
-    </li>
-
-              
-          
-              
-                
     <li >
       <a href="../event_queue/">Add task to manage multiple events</a>
     </li>
@@ -432,6 +419,27 @@
 
               
           
+              
+                
+  
+  
+    <li><a href="
+  ../air_quality_sensor/
+">Air-quality Sensor project</a>
+  
+  
+    </li>
+
+              
+          
+              
+                
+    <li >
+      <a href="../nrf52_adc/">Add an Analog Sensor</a>
+    </li>
+
+              
+          
     </ul>
   
     </li>


[4/9] incubator-mynewt-site git commit: Added etape sensor tutorial. PR #152.

Posted by ad...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-site/blob/a4d946d9/latest/mkdocs/search_index.json
----------------------------------------------------------------------
diff --git a/latest/mkdocs/search_index.json b/latest/mkdocs/search_index.json
index 245f7c7..5613d59 100644
--- a/latest/mkdocs/search_index.json
+++ b/latest/mkdocs/search_index.json
@@ -1276,56 +1276,6 @@
             "title": "Testing on your target"
         }, 
         {
-            "location": "/os/tutorials/air_quality_sensor/", 
-            "text": "Air quality sensor project\n\n\nSetting up source tree for stuff you need\n\n\nTo start with, you need to create a new project under which you will do this development. So you type in:\n\n\n    $ mkdir $HOME/src\n    $ cd $HOME/src\n    $ newt new air_quality\n\n\n\n\n\nLet's say you are using Arduino Primo -- which is based on the Nordic Semi NRF52 chip -- as the platform. \nYou know you need the board support package for that hardware. You can look up its location, add it your \nproject, and fetch that along with the core OS components. Luckily, the Arduino Primo is supported in the \nMynewt Core, so there's nothing much to do here. \n\n\nYour project.yml file should look like this:\n\n\n    [user@IsMyLaptop:~/src/air_quality]$ emacs project.yml \n\n    [user@IsMyLaptop:~/src/air_quality]$ cat project.yml\n    project.name: \nair_quality\n\n\n    project.repositories:\n        - apache-mynewt-core\n\n    # Use github\ns distribution mechanism for core ASF libr
 aries.\n    # This provides mirroring automatically for us.\n    #\n    repository.apache-mynewt-core:\n        type: github\n        vers: 0-latest\n        user: apache\n        repo: incubator-mynewt-core\n\n    [user@IsMyLaptop:~/src/air_quality]$ newt install\n    apache-mynewt-core\n    [user@IsMyLaptop:~/src/air_quality]$ ls repos/\n    apache-mynewt-core\n\n\n\n\n\nGood. You want to make sure you have all the needed bits for supporting your board; \nso you decide to build the blinky project for the platform first.\n\n\nNow create a target for it and build it. Easiest way to proceed is to copy the existing target for blinky, and modify it to build for Arduino Primo board.\n\n\n[user@IsMyLaptop:~/src/air_quality]$ newt target copy my_blinky_sim blink_primo\nTarget successfully copied; targets/my_blinky_sim --\n targets/blink_primo\n[user@IsMyLaptop:~/src/air_quality]$ newt target set blink_primo bsp=@apache-mynewt-core/hw/bsp/arduino_primo_nrf52\nTarget targets/blink_nrf succe
 ssfully set target.bsp to @apache-mynewt-core/hw/bsp/arduino_primo_nrf52\n[user@IsMyLaptop:~/src/air_quality]$ newt build blink_primo\nCompiling hal_bsp.c\n...\nLinking blinky.elf\nApp successfully built: /Users/user/src/air_quality/bin/blink_primo/apps/blinky/blinky.elf\n\n\n\n\n\nGood.\n\n\nYou know that this platform uses bootloader, which means you have to create a target for that too.\n\n\n[user@IsMyLaptop:~/src/air_quality]$ newt target create boot_primo\nTarget targets/boot_nrf successfully created\n[user@IsMyLaptop:~/src/air_quality]$ newt target show\n@apache-mynewt-core/targets/unittest\n    bsp=hw/bsp/native\n    build_profile=debug\n    compiler=compiler/sim\ntargets/blink_primo\n    app=apps/blinky\n    bsp=@apache-mynewt-core/hw/bsp/arduino_primo_nrf52\n    build_profile=debug\ntargets/boot_primo\ntargets/my_blinky_sim\n    app=apps/blinky\n    bsp=@apache-mynewt-core/hw/bsp/native\n    build_profile=debug\n[user@IsMyLaptop:~/src/air_quality]$ newt target set boot_nrf 
 bsp=@apache-mynewt-core/hw/bsp/arduino_primo_nrf52\nTarget targets/boot_nrf successfully set target.bsp to @apache-mynewt-core/hw/bsp/arduino_primo_nrf52\n[user@IsMyLaptop:~/src/air_quality]$ newt target set boot_nrf app=@apache-mynewt-core/apps/boot\nTarget targets/boot_nrf successfully set target.app to @apache-mynewt-core/apps/boot\n[user@IsMyLaptop:~/src/air_quality]$ newt target set boot_nrf build_profile=optimized\nTarget targets/boot_nrf successfully set target.build_profile to optimized\n\n\n\n\n\nAnd then build it, and load it onto the board.\n\n\nnewt build boot_primo\n....\nLinking boot.elf\nApp successfully built: /Users/user/src/air_quality/bin/boot_primo/apps/boot/boot.elf\n[user@IsMyLaptop:~/src/air_quality]\n$ newt load boot_primo\n\n\n\n\n\nAt this point, you may (or may not) see a bunch of error messages about not being able to connect to\nyour board, not being able to load the image, etc. If that's the case, and you haven't already, you\nshould most definitely go 
 worth through the \nblinky_primo\n tutorial so that you\ncan properly communicate with your board.\n\n\nNext you must download the targets to board, and see that the LED actually blinks. You plug in the \nArduino Primo board to your laptop, and say:\n\n\n[user@IsMyLaptop:~/src/air_quality]$ newt load blink_primo\nLoading app image into slot 1\nError: couldn\nt open /Users/user/src/air_quality/bin/blink_primo/apps/blinky/blinky.img\n\nError: exit status 1\n\nload - Load app image to target for \ntarget-name\n.\n\nUsage:\n  newt load [flags]\n\nExamples:\n  newt load \ntarget-name\n\n\n\nGlobal Flags:\n  -l, --loglevel string   Log level, defaults to WARN. (default \nWARN\n)\n  -o, --outfile string    Filename to tee log output to\n  -q, --quiet             Be quiet; only display error output.\n  -s, --silent            Be silent; don\nt output anything.\n  -v, --verbose           Enable verbose output when executing commands.\nexit status 1\n\n\n\n\n\nAh. Forgot to create an image ou
 t of the blinky binary. Note that every time you want to build and \nload a new firmware image to a target board, you need to run 'create-image' on it.\n\n\n[user@IsMyLaptop:~/src/air_quality]$ newt create-image blink_primo 0.0.1\nApp image successfully generated: /Users/user/src/air_quality/bin/blink_primo/apps/blinky/blinky.img\nBuild manifest: /Users/user/src/air_quality/bin/blink_nrf/apps/blinky/manifest.json\n[user@IsMyLaptop:~/src/air_quality]$ newt load blink_primo\n\n\n\n\n\nAnd it's blinking.\n\n\nShortcut for doing build/create-image/load/debug steps all in one is 'newt run' command. Check \nout the usage from command line help.\n\n\nCreate test project\n\n\nNow that you have your system setup, you can start creating your own stuff.\nFirst you want to create a project for yourself - you could start by using blinky as a project \ntemplate, but since we're going to want to be able to access the data via Bluetooth, let's \nuse the \nbleprph\n Bluetooth Peripheral project inst
 ead.\n\n\n    [user@IsMyLaptop:~/src/air_quality]$ mkdir apps/air_quality\n    [user@IsMyLaptop:~/src/air_quality]$ cp repos/apache-mynewt-core/apps/bleprph/pkg.yml apps/air_quality/\n    [user@IsMyLaptop:~/src/air_quality]$ cp -Rp repos/apache-mynewt-core/apps/bleprph/src apps/air_quality/\n\n\n\n\n\nThen you modify the apps/air_quality/pkg.yml for air_quality in order to change the \npkg.name\n to be \napps/air_quality\n.\nYou'll need to add the \n@apache-mynewt-core/\n path to all the package dependencies, since the app no longer\nresides within the apache-mynewt-core repository.\n\n\n[user@IsMyLaptop:~/src/air_quality]$ cat apps/air_quality/pkg.yml\npkg.name: apps/air_quality\npkg.type: app\npkg.description: BLE Air Quality application.\npkg.author: \nApache Mynewt \ndev@mynewt.incubator.apache.org\n\npkg.homepage: \nhttp://mynewt.apache.org/\n\npkg.keywords:\n\npkg.deps: \n    - \n@apache-mynewt-core/kernel/os\n\n    - \n@apache-mynewt-core/sys/shell\n\n    - \n@apache-mynewt-c
 ore/sys/stats/full\n\n    - \n@apache-mynewt-core/sys/log/full\n\n    - \n@apache-mynewt-core/mgmt/newtmgr\n\n    - \n@apache-mynewt-core/mgmt/newtmgr/transport/ble\n\n    - \n@apache-mynewt-core/net/nimble/controller\n\n    - \n@apache-mynewt-core/net/nimble/host\n\n    - \n@apache-mynewt-core/net/nimble/host/services/ans\n\n    - \n@apache-mynewt-core/net/nimble/host/services/gap\n\n    - \n@apache-mynewt-core/net/nimble/host/services/gatt\n\n    - \n@apache-mynewt-core/net/nimble/host/store/ram\n\n    - \n@apache-mynewt-core/net/nimble/transport/ram\n\n    - \n@apache-mynewt-core/sys/console/full\n\n    - \n@apache-mynewt-core/sys/sysinit\n\n    - \n@apache-mynewt-core/sys/id\n\n\n\n\n\n\nAnd create a target for it:\n\n\n[user@IsMyLaptop:~/src/air_quality]$ newt target create air_q\nTarget targets/air_q successfully created\n[user@IsMyLaptop:~/src/air_quality]$ newt target set air_q bsp=@apache-mynewt-core/hw/bsp/arduino_primo_nrf52\nTarget targets/air_q successfully set target.b
 sp to @apache-mynewt-core/hw/bsp/arduino_primo_nrf52\n[user@IsMyLaptop:~/src/air_quality]$ newt target set air_q app=apps/air_quality \nTarget targets/air_q successfully set target.app to apps/air_quality\n[user@IsMyLaptop:~/src/air_quality]$ newt target set air_q build_profile=debug\nTarget targets/air_q successfully set target.build_profile to debug\n[user@IsMyLaptop:~/src/air_quality]$ newt build air_q\n ....\nLinking /Users/dsimmons/dev/myproj/bin/targets/air_q/app/apps/air_quality/air_quality.elf\nTarget successfully built: targets/air_q\n\n\n\n\n\nCreate packages for drivers\n\n\nOne of the sensors you want to enable is SenseAir K30, which will connect to the board over a serial port.\nTo start development of the driver, you first need to create a package description for it, and add stubs for sources.\n\n\nThe first thing to do is to create the directory structure for your driver:\n\n\n[user@IsMyLaptop:~/src/air_quality]$ mkdir -p libs/my_drivers/senseair/include/senseair\n[us
 er@IsMyLaptop:~/src/air_quality]$ mkdir -p libs/my_drivers/senseair/src\n\n\n\n\n\nNow you can add the files you need. You'll need a pkg.yml to describe the driver, and then header stub followed by source stub.\n\n\n[user@IsMyLaptop:~/src/air_quality]$ cat libs/my_drivers/senseair/pkg.yml\n\n\n\n\n\n#\n\n\n# Licensed to the Apache Software Foundation (ASF) under one\n\n\n# or more contributor license agreements.  See the NOTICE file\n\n\n# distributed with this work for additional information\n\n\n# regarding copyright ownership.  The ASF licenses this file\n\n\n# to you under the Apache License, Version 2.0 (the\n\n\n# \nLicense\n); you may not use this file except in compliance\n\n\n# with the License.  You may obtain a copy of the License at\n\n\n# \n\n\n#  http:\n//www.apache.org/licenses/LICENSE-2.0\n\n\n#\n\n\n# Unless required by applicable law or agreed to in writing,\n\n\n# software distributed under the License is distributed on an\n\n\n# \nAS IS\n BASIS, WITHOUT WARRANTIE
 S OR CONDITIONS OF ANY\n\n\n# KIND, either express or implied.  See the License for the\n\n\n# specific language governing permissions and limitations\n\n\n# under the License.\n\n\n#\n\n\npkg\n.\nname\n: \nlibs/my_drivers/senseair\n\n\npkg\n.\ndescription\n: \nHost\n \nside\n \nof\n \nthe\n \nnimble\n \nBluetooth\n \nSmart\n \nstack\n.\n\npkg\n.\nauthor\n: \nApache Mynewt \ndev@mynewt.incubator.apache.org\n\n\npkg\n.\nhomepage\n: \nhttp://mynewt.apache.org/\n\n\npkg\n.\nkeywords\n:\n    \n-\n \nble\n\n    \n-\n \nbluetooth\n\n\n\npkg\n.\ndeps\n:\n    \n-\n \n@apache-mynewt-core/kernel/os\n\n\n\n\n\n\n[user@IsMyLaptop:~/src/air_quality]$ cat libs/my_drivers/senseair/include/senseair/senseair.h\n\n\n\n\n\n/*\n\n\n * Licensed to the Apache Software Foundation (ASF) under one\n\n\n * or more contributor license agreements.  See the NOTICE file\n\n\n * distributed with this work for additional information\n\n\n * regarding copyright ownership.  The ASF licenses this file\n\n\n * to you 
 under the Apache License, Version 2.0 (the\n\n\n * \nLicense\n); you may not use this file except in compliance\n\n\n * with the License.  You may obtain a copy of the License at\n\n\n * \n\n\n *  http://www.apache.org/licenses/LICENSE-2.0\n\n\n *\n\n\n * Unless required by applicable law or agreed to in writing,\n\n\n * software distributed under the License is distributed on an\n\n\n * \nAS IS\n BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n\n\n * KIND, either express or implied.  See the License for the\n\n\n * specific language governing permissions and limitations\n\n\n * under the License.\n\n\n*/\n\n\n#ifndef _SENSEAIR_H_\n\n\n#define _SENSEAIR_H_\n\n\n\nvoid\n \nsenseair_init\n(\nvoid\n);\n\n\n#endif \n/* _SENSEAIR_H_ */\n\n\n\n\n\n\n[user@IsMyLaptop:~/src/air_quality]$ cat libs/my_drivers/senseair/src/senseair.c\n\n\n\n\n\n/**\n\n\n * Licensed to the Apache Software Foundation (ASF) under one\n\n\n * or more contributor license agreements.  See the NOTICE file\n\n\n * dis
 tributed with this work for additional information\n\n\n * regarding copyright ownership.  The ASF licenses this file\n\n\n * to you under the Apache License, Version 2.0 (the\n\n\n * \nLicense\n); you may not use this file except in compliance\n\n\n * with the License.  You may obtain a copy of the License at\n\n\n * \n\n\n *  http://www.apache.org/licenses/LICENSE-2.0\n\n\n *\n\n\n * Unless required by applicable law or agreed to in writing,\n\n\n * software distributed under the License is distributed on an\n\n\n * \nAS IS\n BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n\n\n * KIND, either express or implied.  See the License for the\n\n\n * specific language governing permissions and limitations\n\n\n * under the License.\n\n\n */\n\n\n\nvoid\n\n\nsenseair_init\n(\nvoid\n)\n{\n}\n\n\n\n\n\nAnd add dependency to this package in your project yml file.\n\n\nHere's the listing from apps/air_quality/pkg.yml\n\n\npkg.name: apps/air_quality\npkg.type: app\npkg.description: Air qualit
 y sensor test\npkg.keywords:\n\npkg.deps:\n    - \n@apache-mynewt-core/libs/console/full\n\n    - \n@apache-mynewt-core/libs/newtmgr\n\n    - \n@apache-mynewt-core/libs/os\n\n    - \n@apache-mynewt-core/libs/shell\n\n    - \n@apache-mynewt-core/sys/config\n\n    - \n@apache-mynewt-core/sys/log/full\n\n    - \n@apache-mynewt-core/sys/stats/full\n\n    - libs/my_drivers/senseair\n\n\n\n\n\nAnd add a call to your main() to initialize this driver.\n\n\n    [user@IsMyLaptop:~/src/air_quality]$ diff project/blinky/src/main.c project/air_quality/src/main.c\n    28a29\n    \n #include \nsenseair/senseair.h\n\n    190a192\n    \n senseair_init();\n    [user@IsMyLaptop:~/src/air_quality\n\n\n\n\n\nThe ble_prph app runs everything in one task handler. For this project, we're going to add a second\ntask handler to respond to the shell, and then handle communicating with the senseair sensor for us.\n\n\n/** shell task settings. */\n\n\n#define SHELL_TASK_PRIO           2\n\n\n#define SHELL_STACK
 _SIZE          (OS_STACK_ALIGN(336))\n\n\n\nstruct\n \nos_eventq\n \nshell_evq\n;\n\nstruct\n \nos_task\n \nshell_task\n;\n\nbssnz_t\n \nos_stack_t\n \nshell_stack\n[\nSHELL_STACK_SIZE\n];\n\n\n\n\n\nThat defines the task, now we need to initialize it, add a task handler, and we're going to \nuse this task as our default task handler.\n\n\n/**\n\n\n * Event loop for the main shell task.\n\n\n */\n\n\nstatic\n \nvoid\n\n\nshell_task_handler\n(\nvoid\n \n*unused\n)\n{\n    \nwhile\n (\n1\n) {\n        \nos_eventq_run\n(\nshell_evq\n);\n    }\n}\n\n\n\n\n\nAnd in your \nmain()\n add:\n\n\n    \n/* Initialize shell eventq */\n\n    \nos_eventq_init\n(\nshell_evq\n);\n\n    \n/* Create the shell task.  \n\n\n     * All shell operations are performed in this task.\n\n\n     */\n\n    \nos_task_init\n(\nshell_task\n, \nshell\n, \nshell_task_handler\n,\n                              \nNULL\n, \nSHELL_TASK_PRIO\n, \nOS_WAIT_FOREVER\n,\n                              \nshell_stack\n, \nSHELL_S
 TACK_SIZE\n);\n\n\n\n\n\nDon't forget to change your default task handler!\n\n\n    \nos_eventq_dflt_set\n(\nshell_evq\n);\n\n\n\n\n\nAnd then build it to make sure all goes well.\n\n\n[user@IsMyLaptop:~/src/air_quality]$ newt build air_q\nCompiling senseair.c\nArchiving senseair.a\nLinking air_quality.elf\nApp successfully built: /Users/user/src/air_quality/bin/air_q/apps/air_quality/air_quality.elf\n\n\n\n\n\nAll looks good.\n\n\nAdd CLI commands for testing drivers\n\n\nWhile developing the driver, you want to issue operations from console asking it to do stuff. We'll assume that you've already worked through the tutorial \non how to \nenable the CLI\n, so all we'll need to do is add the propper values to the project's \nsyscfg.yml\n file:\n\n\n[user@IsMyLaptop:~/src/air_quality]$ cat targets/air_q/syscfg.yml\nsyscfg.vals:\n    # Set as per blinky_primo\n    OPENOCD_DEBUG: 1\n    # Enable the shell task.\n    SHELL_TASK: 1\n    STATS_CLI: 1\n    CONSOLE_TICKS: 1\n    CONSOLE_PROM
 PT: 1\n\n\n\n\n\nThen register your senseair command with the shell by adding the following to \nlibs/my_drivers/senseair/src/senseair.c\n\n\n#include \nshell/shell.h\n\n\n#include \nconsole/console.h\n\n\n#include \nassert.h\n\n\n\n\nstatic\n \nint\n \nsenseair_shell_func\n(\nint\n \nargc\n, \nchar\n \n**argv\n);\n\nstatic\n \nstruct\n \nshell_cmd\n \nsenseair_cmd\n \n=\n {\n    .\nsc_cmd\n \n=\n \nsenseair\n,\n    .\nsc_cmd_func\n \n=\n \nsenseair_shell_func\n,\n};\n\n\nvoid\n\n\nsenseair_init\n(\nvoid\n)\n{\n    \nint\n \nrc\n;\n\n    \nrc\n \n=\n \nshell_cmd_register\n(\nsenseair_cmd\n);\n    \nassert\n(\nrc\n \n==\n \n0\n);\n}\n\n\nstatic\n \nint\n\n\nsenseair_shell_func\n(\nint\n \nargc\n, \nchar\n \n**argv\n)\n{\n    \nconsole_printf\n(\nYay! Somebody called!\\n\n);\n    \nreturn\n \n0\n;\n\n}\n\n\n\n\n\nNow you can you build this, download to target, and start minicom on your console port. If you haven't already, familiarize yourself with\nthe tutorial on how to connect a se
 rial port to your board \nhere\n.\n\n\nYou'll need to wire up your Board to a Serial converter first. On the Arduino Primo Board pin 1 is TX and pin 0 is RX so wire 1 to RX on your serial board, and 0 to TX on your serial board.\n\n\n    [user@IsMyLaptop:~]$ minicom -D /dev/tty.usbserial-AH02MIE2\n\n\n    Welcome to minicom 2.7\n\n    OPTIONS: \n    Compiled on Oct 12 2015, 07:48:30.\n    Port /dev/tty.usbserial-AH02MIE2, 13:44:40\n\n    Press CTRL-X Z for help on special keys\n\n    ?\n    419: \n ?\n    Commands:\n    641:     stat      echo         ?    prompt     ticks     tasks\n    643: mempools      date  senseair\n    644: \n senseair\n    Yay! Somebody called!\n    1125: \n\n    53611: \n tasks\n    Tasks:\n    54047:    task pri tid  runtime      csw    stksz   stkuse   lcheck   ncheck flg\n    54057:    idle 255   0    54048    66890       64       30        0        0   0\n    54068:  ble_ll   0   1        9    64986       80       58        0        0   0\n    54079: bl
 eprph   1   2        0        1      336       32        0        0   0\n    54090:   shell   2   3        0     2077      336      262        0        0   0\n    54101: \n\n\n\n\n\n\nThat's great. Your shell task is running, and is responding appropriately!\nYou can connect the hardware to your board and start developing code for the driver itself.\n\n\nUse of HAL for drivers\n\n\nThe sensor has a serial port connection, and that's how you are going to connect to it. Your original BSP, hw/bsp/arduino_primo_nrf52, has two UARTs set up.\nWe're using one for our shell/console. It also has a second UART set up as a 'bit-bang' UART but since the SenseAir only needs to\ncommunicate at 9600 baud, this bit-banged uart is plenty fast enough.\n\n\nYou'll have to make a small change to the \nsyscfg.yml\n file in your project's target directory to change  the pin definitions \nfor this second UART. Those changes are as follows:\n\n\n    UART_0_PIN_TX: 23\n    UART_0_PIN_RX: 24\n\n\n\n\n\nWith 
 this in place, you can refer to serial port where your SenseAir sensor by a logical number. This makes the code more platform independent - you could connect this sensor to another board, like Olimex. You will also use the HAL UART abstraction to do the UART port setup and data transfer. That way you don't need to have any platform dependent pieces within your little driver.\n\n\nYou will now see what the driver code ends up looking like. Here's the header file, filled in from the stub you created earlier.\n\n\n/*\n\n\n * Licensed to the Apache Software Foundation (ASF) under one\n\n\n * or more contributor license agreements.  See the NOTICE file\n\n\n * distributed with this work for additional information\n\n\n * regarding copyright ownership.  The ASF licenses this file\n\n\n * to you under the Apache License, Version 2.0 (the\n\n\n * \nLicense\n); you may not use this file except in compliance\n\n\n * with the License.  You may obtain a copy of the License at\n\n\n * \n\n\n *  
 http://www.apache.org/licenses/LICENSE-2.0\n\n\n *\n\n\n * Unless required by applicable law or agreed to in writing,\n\n\n * software distributed under the License is distributed on an\n\n\n * \nAS IS\n BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n\n\n * KIND, either express or implied.  See the License for the\n\n\n * specific language governing permissions and limitations\n\n\n * under the License.\n\n\n*/\n\n\n#ifndef _SENSEAIR_H_\n\n\n#define _SENSEAIR_H_\n\n\n\nenum\n \nsenseair_read_type\n {\n        \nSENSEAIR_CO2\n,\n};\n\n\nint\n \nsenseair_init\n(\nint\n \nuartno\n);\n\n\nint\n \nsenseair_read\n(\nenum\n \nsenseair_read_type\n);\n\n\n#endif \n/* _SENSEAIR_H_ */\n\n\n\n\n\n\nAs you can see, logical UART number has been added to the init routine. A 'read' function has been added, \nwhich is a blocking read. If you were making a commercial product, you would probably have a callback for reporting the results.\n\n\nAnd here is the source for the driver.\n\n\n/**\n\n\n * Li
 censed to the Apache Software Foundation (ASF) under one\n\n\n * or more contributor license agreements.  See the NOTICE file\n\n\n * distributed with this work for additional information\n\n\n * regarding copyright ownership.  The ASF licenses this file\n\n\n * to you under the Apache License, Version 2.0 (the\n\n\n * \nLicense\n); you may not use this file except in compliance\n\n\n * with the License.  You may obtain a copy of the License at\n\n\n *\n\n\n *  http://www.apache.org/licenses/LICENSE-2.0\n\n\n *\n\n\n * Unless required by applicable law or agreed to in writing,\n\n\n * software distributed under the License is distributed on an\n\n\n * \nAS IS\n BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n\n\n * KIND, either express or implied.  See the License for the\n\n\n * specific language governing permissions and limitations\n\n\n * under the License.\n\n\n */\n\n\n#include \nstring.h\n\n\n\n#include \nshell/shell.h\n\n\n#include \nconsole/console.h\n\n\n#include \nos/os.h
 \n\n\n\n#include \nhal/hal_uart.h\n\n\n\n#include \nsenseair/senseair.h\n\n\n\nstatic\n \nconst\n \nuint8_t\n \ncmd_read_co2\n[] \n=\n {\n    \n0xFE\n, \n0\nX44\n, \n0\nX00\n, \n0\nX08\n, \n0\nX02\n, \n0\nX9F\n, \n0\nX25\n\n};\n\n\nstatic\n \nint\n \nsenseair_shell_func\n(\nint\n \nargc\n, \nchar\n \n**argv\n);\n\nstatic\n \nstruct\n \nshell_cmd\n \nsenseair_cmd\n \n=\n {\n    .\nsc_cmd\n \n=\n \nsenseair\n,\n    .\nsc_cmd_func\n \n=\n \nsenseair_shell_func\n,\n};\n\n\nstruct\n \nsenseair\n { \n    \nint\n \nuart\n;\n    \nstruct\n \nos_sem\n \nsema\n;\n    \nconst\n \nuint8_t\n \n*tx_data\n;\n    \nint\n \ntx_off\n;\n    \nint\n \ntx_len\n;\n    \nuint8_t\n \nrx_data\n[\n32\n]; \n    \nint\n \nrx_off\n;\n    \nint\n \nvalue\n;\n} \nsenseair\n;\n\n\nstatic\n \nint\n\n\nsenseair_tx_char\n(\nvoid\n \n*arg\n)\n{\n    \nstruct\n \nsenseair\n \n*s\n \n=\n \nsenseair\n;\n    \nint\n \nrc\n;\n\n    \nif\n (\ns-\ntx_off\n \n=\n \ns-\ntx_len\n) {\n    \n/*\n\n\n         * Command tx finished
 .\n\n\n         */\n\n        \ns-\ntx_data\n \n=\n \nNULL\n;\n        \nreturn\n \n-\n1\n;\n    }\n\n    \nrc\n \n=\n \ns-\ntx_data\n[\ns-\ntx_off\n];\n    \ns-\ntx_off++\n;\n    \nreturn\n \nrc\n;\n}\n\n\n/*\n\n\n * CRC for modbus over serial port.\n\n\n */\n\n\nstatic\n \nconst\n \nuint16_t\n \nmb_crc_tbl\n[] \n=\n {\n    \n0x0000\n, \n0xcc01\n, \n0xd801\n, \n0x1400\n, \n0xf001\n, \n0x3c00\n, \n0x2800\n, \n0xe401\n,\n    \n0xa001\n, \n0x6c00\n, \n0x7800\n, \n0xb401\n, \n0x5000\n, \n0x9c01\n, \n0x8801\n, \n0x4400\n\n};\n\n\nstatic\n \nuint16_t\n\n\nmb_crc\n(\nconst\n \nuint8_t\n \n*data\n, \nint\n \nlen\n, \nuint16_t\n \ncrc\n)\n{\n    \nwhile\n (\nlen--\n \n \n0\n) {\n        \ncrc\n \n^=\n \n*data++\n;\n        \ncrc\n \n=\n (\ncrc\n \n \n4\n) \n^\n \nmb_crc_tbl\n[\ncrc\n \n \n0xf\n];\n        \ncrc\n \n=\n (\ncrc\n \n \n4\n) \n^\n \nmb_crc_tbl\n[\ncrc\n \n \n0xf\n];\n    }\n    \nreturn\n \ncrc\n;\n}\n\n\nstatic\n \nint\n\n\nmb_crc_check\n(\nconst\n \nvoid\n \n*pkt\n, \nint\n \
 nlen\n)\n{\n    \nuint16_t\n \ncrc\n, \ncmp\n;\n    \nuint8_t\n \n*bp\n \n=\n (\nuint8_t\n \n*\n)\npkt\n;\n\n    \nif\n (\nlen\n \n \nsizeof\n(\ncrc\n) \n+\n \n1\n) {\n        \nreturn\n \n-\n1\n;\n    }\n    \ncrc\n \n=\n \nmb_crc\n(\npkt\n, \nlen\n \n-\n \n2\n, \n0xffff\n);\n    \ncmp\n \n=\n \nbp\n[\nlen\n \n-\n \n2\n] \n|\n (\nbp\n[\nlen\n \n-\n \n1\n] \n \n8\n);\n    \nif\n (\ncrc\n \n!=\n \ncmp\n) {\n        \nreturn\n \n-\n1\n;\n    } \nelse\n {\n        \nreturn\n \n0\n;\n    }\n}\n\n\nstatic\n \nint\n\n\nsenseair_rx_char\n(\nvoid\n \n*arg\n, \nuint8_t\n \ndata\n)\n{\n    \nstruct\n \nsenseair\n \n*s\n \n=\n (\nstruct\n \nsenseair\n \n*\n)\narg\n;\n    \nint\n \nrc\n;\n\n    \nif\n (\ns-\nrx_off\n \n=\n \nsizeof\n(\ns-\nrx_data\n)) {\n        \ns-\nrx_off\n \n=\n \n0\n;\n    }\n    \ns-\nrx_data\n[\ns-\nrx_off\n] \n=\n \ndata\n;\n    \ns-\nrx_off++\n;\n\n    \nif\n (\ns-\nrx_off\n \n==\n \n7\n) {\n        \nrc\n \n=\n \nmb_crc_check\n(\ns-\nrx_data\n, \ns-\nrx_off\n);\n     
    \nif\n (\nrc\n \n==\n \n0\n) {\n            \ns-\nvalue\n \n=\n \ns-\nrx_data\n[\n3\n] \n*\n \n256\n \n+\n \ns-\nrx_data\n[\n4\n];\n            \nos_sem_release\n(\ns-\nsema\n);\n        }\n    }\n    \nreturn\n \n0\n;\n}\n\n\nvoid\n\n\nsenseair_tx\n(\nstruct\n \nsenseair\n \n*s\n, \nconst\n \nuint8_t\n \n*tx_data\n, \nint\n \ndata_len\n)\n{\n    \ns-\ntx_data\n \n=\n \ntx_data\n;\n    \ns-\ntx_len\n \n=\n \ndata_len\n;\n    \ns-\ntx_off\n \n=\n \n0\n;\n    \ns-\nrx_off\n \n=\n \n0\n;\n\n    \nhal_uart_start_tx\n(\ns-\nuart\n);\n}\n\n\nint\n\n\nsenseair_read\n(\nenum\n \nsenseair_read_type\n \ntype\n)\n{\n    \nstruct\n \nsenseair\n \n*s\n \n=\n \nsenseair\n;\n    \nconst\n \nuint8_t\n \n*cmd\n;\n    \nint\n \ncmd_len\n;\n    \nint\n \nrc\n;\n\n    \nif\n (\ns-\ntx_data\n) {\n        \n/*\n\n\n         * busy\n\n\n         */\n\n        \nreturn\n \n-\n1\n;\n    }\n    \nswitch\n (\ntype\n) {\n    \ncase\n \nSENSEAIR_CO2\n:\n        \ncmd\n \n=\n \ncmd_read_co2\n;\n        \ncmd_
 len\n \n=\n \nsizeof\n(\ncmd_read_co2\n);\n        \nbreak\n;\n    \ndefault\n:\n\n        \nreturn\n \n-\n1\n;\n    }\n    \nsenseair_tx\n(\ns\n, \ncmd\n, \ncmd_len\n);\n    \nrc\n \n=\n \nos_sem_pend\n(\ns-\nsema\n, \nOS_TICKS_PER_SEC\n \n/\n \n2\n);\n    \nif\n (\nrc\n \n==\n \nOS_TIMEOUT\n) {\n        \n/*\n\n\n         * timeout\n\n\n         */\n\n        \nreturn\n \n-\n2\n;\n    }\n    \nreturn\n \ns-\nvalue\n;\n}\n\n\nstatic\n \nint\n\n\nsenseair_shell_func\n(\nint\n \nargc\n, \nchar\n \n**argv\n)\n{\n    \nint\n \nvalue\n;\n    \nenum\n \nsenseair_read_type\n \ntype\n;\n\n    \nif\n (\nargc\n \n \n2\n) {\n\nusage\n:\n        \nconsole_printf\n(\n%s co2\\n\n, \nargv\n[\n0\n]);\n        \nreturn\n \n0\n;\n    }\n    \nif\n (\n!strcmp\n(\nargv\n[\n1\n], \nco2\n)) {\n        \ntype\n \n=\n \nSENSEAIR_CO2\n;\n    } \nelse\n {\n        \ngoto\n \nusage\n;\n    }\n    \nvalue\n \n=\n \nsenseair_read\n(\ntype\n);\n    \nif\n (\nvalue\n \n=\n \n0\n) {\n        \nconsole_printf\n(\n
 Got %d\\n\n, \nvalue\n);\n    } \nelse\n {\n        \nconsole_printf\n(\nError while reading: %d\\n\n, \nvalue\n);\n    }\n    \nreturn\n \n0\n;\n}\n\n\nint\n\n\nsenseair_init\n(\nint\n \nuartno\n)\n{\n    \nint\n \nrc\n;\n    \nstruct\n \nsenseair\n \n*s\n \n=\n \nsenseair\n;\n\n    \nrc\n \n=\n \nshell_cmd_register\n(\nsenseair_cmd\n);\n    \nif\n (\nrc\n) {\n        \nreturn\n \nrc\n;\n    }\n\n    \nrc\n \n=\n \nos_sem_init\n(\ns-\nsema\n, \n1\n);\n    \nif\n (\nrc\n) {\n        \nreturn\n \nrc\n;\n    }\n    \nrc\n \n=\n \nhal_uart_init_cbs\n(\nuartno\n, \nsenseair_tx_char\n, \nNULL\n,\n      \nsenseair_rx_char\n, \nsenseair\n);\n    \nif\n (\nrc\n) {\n        \nreturn\n \nrc\n;\n    }\n    \nrc\n \n=\n \nhal_uart_config\n(\nuartno\n, \n9600\n, \n8\n, \n1\n, \nHAL_UART_PARITY_NONE\n,\n      \nHAL_UART_FLOW_CTL_NONE\n);\n    \nif\n (\nrc\n) {\n        \nreturn\n \nrc\n;\n    }\n    \ns-\nuart\n \n=\n \nuartno\n;\n\n    \nreturn\n \n0\n;\n}\n\n\n\n\n\nAnd your modified main() for
  senseair driver init.\n\n\nint\n\n\nmain\n(\nint\n \nargc\n, \nchar\n \n**argv\n)\n{\n    ....\n    \nsenseair_init\n(\n0\n);\n    ....\n    }\n\n\n\n\n\nYou can see from the code that you are using the HAL interface to open a UART port, and using OS \nsemaphore as a way of blocking the task when waiting for read response to come back from the sensor.\n\n\nNow comes the fun part: Hooking up the sensor! It's fun because a) hooking up a sensor is always \nfun and b) the SenseAir sensor's PCB is entirely unlabeled, so you'll have to trust us on how to hook it up. \n\n\nSo here we go. \n\n\nYou'll have to do a little soldering. I soldered some header pins to the SenseAir K30 board to\nmake connecting wires easier using standard jumper wires, but you can also just solder wires\nstraight to the board if you prefer.\n\n\nHere's what your SenseAir board should look like once it's wired up:\n\n\n\n\nNow that you have that wired up, let's get the Arduino Primo wired up. A couple of things to
  note:\n\n\n\n\nThe Arduino Primo's 'console' UART is actually UART1. \n\n\nThe secondary (bit-banged) UART is UART0, so that's where we'll have to hook up the SenseAir.\n\n\n\n\nHere's what your Arduino Primo should now look like with everything wired in:\n\n\n\n\nEverything is wired and you're ready to go! Build and load your new app:\n\n\n$ newt build air_q\nBuilding target targets/air_q\nCompiling apps/air_quality/src/main.c\nArchiving apps_air_quality.a\nLinking myproj/bin/targets/air_q/app/apps/air_quality/air_quality.elf\nTarget successfully built: targets/air_q\n$ newt create-image air_q 1.0.0\nApp image succesfully generated: myproj/bin/targets/air_q/app/apps/air_quality/air_quality.img\n$ newt load air_q\nLoading app image into slot 1\n\n\n\n\n\nNow, you should be able to connect to your serial port and read values:\n\n\nuser@IsMyLaptop:~]$ minicom -D /dev/tty.usbserial-AH02MIE2\n\n\n    Welcome to minicom 2.7\n\n    OPTIONS: \n    Compiled on Oct 12 2015, 07:48:30.\n    P
 ort /dev/tty.usbserial-AH02MIE2, 13:44:40\n\n    Press CTRL-X Z for help on special keys\n\n    1185: \n ?\n    Commands:\n    1382:     stat      echo         ?    prompt     ticks     tasks\n    1390: mempools      date  senseair\n    1395: \n senseair\n    senseair co2\n    2143: \n senseair co2\n    Got 973\n\n\n\n\n\nAnd you're getting valid readings! Congratulations!\n\n\nNext we'll hook this all up via Bluetooth so that you can read those values remotely.", 
-            "title": "Basic Air Quality Sensor"
-        }, 
-        {
-            "location": "/os/tutorials/air_quality_sensor/#air-quality-sensor-project", 
-            "text": "", 
-            "title": "Air quality sensor project"
-        }, 
-        {
-            "location": "/os/tutorials/air_quality_sensor/#setting-up-source-tree-for-stuff-you-need", 
-            "text": "To start with, you need to create a new project under which you will do this development. So you type in:      $ mkdir $HOME/src\n    $ cd $HOME/src\n    $ newt new air_quality  Let's say you are using Arduino Primo -- which is based on the Nordic Semi NRF52 chip -- as the platform. \nYou know you need the board support package for that hardware. You can look up its location, add it your \nproject, and fetch that along with the core OS components. Luckily, the Arduino Primo is supported in the \nMynewt Core, so there's nothing much to do here.   Your project.yml file should look like this:      [user@IsMyLaptop:~/src/air_quality]$ emacs project.yml  \n    [user@IsMyLaptop:~/src/air_quality]$ cat project.yml\n    project.name:  air_quality \n\n    project.repositories:\n        - apache-mynewt-core\n\n    # Use github s distribution mechanism for core ASF libraries.\n    # This provides mirroring automatically for us.\n    #\n    repository.apache-mynewt-core:\n 
        type: github\n        vers: 0-latest\n        user: apache\n        repo: incubator-mynewt-core\n\n    [user@IsMyLaptop:~/src/air_quality]$ newt install\n    apache-mynewt-core\n    [user@IsMyLaptop:~/src/air_quality]$ ls repos/\n    apache-mynewt-core  Good. You want to make sure you have all the needed bits for supporting your board; \nso you decide to build the blinky project for the platform first.  Now create a target for it and build it. Easiest way to proceed is to copy the existing target for blinky, and modify it to build for Arduino Primo board.  [user@IsMyLaptop:~/src/air_quality]$ newt target copy my_blinky_sim blink_primo\nTarget successfully copied; targets/my_blinky_sim --  targets/blink_primo\n[user@IsMyLaptop:~/src/air_quality]$ newt target set blink_primo bsp=@apache-mynewt-core/hw/bsp/arduino_primo_nrf52\nTarget targets/blink_nrf successfully set target.bsp to @apache-mynewt-core/hw/bsp/arduino_primo_nrf52\n[user@IsMyLaptop:~/src/air_quality]$ newt build bl
 ink_primo\nCompiling hal_bsp.c\n...\nLinking blinky.elf\nApp successfully built: /Users/user/src/air_quality/bin/blink_primo/apps/blinky/blinky.elf  Good.  You know that this platform uses bootloader, which means you have to create a target for that too.  [user@IsMyLaptop:~/src/air_quality]$ newt target create boot_primo\nTarget targets/boot_nrf successfully created\n[user@IsMyLaptop:~/src/air_quality]$ newt target show\n@apache-mynewt-core/targets/unittest\n    bsp=hw/bsp/native\n    build_profile=debug\n    compiler=compiler/sim\ntargets/blink_primo\n    app=apps/blinky\n    bsp=@apache-mynewt-core/hw/bsp/arduino_primo_nrf52\n    build_profile=debug\ntargets/boot_primo\ntargets/my_blinky_sim\n    app=apps/blinky\n    bsp=@apache-mynewt-core/hw/bsp/native\n    build_profile=debug\n[user@IsMyLaptop:~/src/air_quality]$ newt target set boot_nrf bsp=@apache-mynewt-core/hw/bsp/arduino_primo_nrf52\nTarget targets/boot_nrf successfully set target.bsp to @apache-mynewt-core/hw/bsp/arduino_
 primo_nrf52\n[user@IsMyLaptop:~/src/air_quality]$ newt target set boot_nrf app=@apache-mynewt-core/apps/boot\nTarget targets/boot_nrf successfully set target.app to @apache-mynewt-core/apps/boot\n[user@IsMyLaptop:~/src/air_quality]$ newt target set boot_nrf build_profile=optimized\nTarget targets/boot_nrf successfully set target.build_profile to optimized  And then build it, and load it onto the board.  newt build boot_primo\n....\nLinking boot.elf\nApp successfully built: /Users/user/src/air_quality/bin/boot_primo/apps/boot/boot.elf\n[user@IsMyLaptop:~/src/air_quality]\n$ newt load boot_primo  At this point, you may (or may not) see a bunch of error messages about not being able to connect to\nyour board, not being able to load the image, etc. If that's the case, and you haven't already, you\nshould most definitely go worth through the  blinky_primo  tutorial so that you\ncan properly communicate with your board.  Next you must download the targets to board, and see that the LED ac
 tually blinks. You plug in the \nArduino Primo board to your laptop, and say:  [user@IsMyLaptop:~/src/air_quality]$ newt load blink_primo\nLoading app image into slot 1\nError: couldn t open /Users/user/src/air_quality/bin/blink_primo/apps/blinky/blinky.img\n\nError: exit status 1\n\nload - Load app image to target for  target-name .\n\nUsage:\n  newt load [flags]\n\nExamples:\n  newt load  target-name \n\n\nGlobal Flags:\n  -l, --loglevel string   Log level, defaults to WARN. (default  WARN )\n  -o, --outfile string    Filename to tee log output to\n  -q, --quiet             Be quiet; only display error output.\n  -s, --silent            Be silent; don t output anything.\n  -v, --verbose           Enable verbose output when executing commands.\nexit status 1  Ah. Forgot to create an image out of the blinky binary. Note that every time you want to build and \nload a new firmware image to a target board, you need to run 'create-image' on it.  [user@IsMyLaptop:~/src/air_quality]$ newt
  create-image blink_primo 0.0.1\nApp image successfully generated: /Users/user/src/air_quality/bin/blink_primo/apps/blinky/blinky.img\nBuild manifest: /Users/user/src/air_quality/bin/blink_nrf/apps/blinky/manifest.json\n[user@IsMyLaptop:~/src/air_quality]$ newt load blink_primo  And it's blinking.  Shortcut for doing build/create-image/load/debug steps all in one is 'newt run' command. Check \nout the usage from command line help.", 
-            "title": "Setting up source tree for stuff you need"
-        }, 
-        {
-            "location": "/os/tutorials/air_quality_sensor/#create-test-project", 
-            "text": "Now that you have your system setup, you can start creating your own stuff.\nFirst you want to create a project for yourself - you could start by using blinky as a project \ntemplate, but since we're going to want to be able to access the data via Bluetooth, let's \nuse the  bleprph  Bluetooth Peripheral project instead.      [user@IsMyLaptop:~/src/air_quality]$ mkdir apps/air_quality\n    [user@IsMyLaptop:~/src/air_quality]$ cp repos/apache-mynewt-core/apps/bleprph/pkg.yml apps/air_quality/\n    [user@IsMyLaptop:~/src/air_quality]$ cp -Rp repos/apache-mynewt-core/apps/bleprph/src apps/air_quality/  Then you modify the apps/air_quality/pkg.yml for air_quality in order to change the  pkg.name  to be  apps/air_quality .\nYou'll need to add the  @apache-mynewt-core/  path to all the package dependencies, since the app no longer\nresides within the apache-mynewt-core repository.  [user@IsMyLaptop:~/src/air_quality]$ cat apps/air_quality/pkg.yml\npkg.name: apps/air_q
 uality\npkg.type: app\npkg.description: BLE Air Quality application.\npkg.author:  Apache Mynewt  dev@mynewt.incubator.apache.org \npkg.homepage:  http://mynewt.apache.org/ \npkg.keywords:\n\npkg.deps: \n    -  @apache-mynewt-core/kernel/os \n    -  @apache-mynewt-core/sys/shell \n    -  @apache-mynewt-core/sys/stats/full \n    -  @apache-mynewt-core/sys/log/full \n    -  @apache-mynewt-core/mgmt/newtmgr \n    -  @apache-mynewt-core/mgmt/newtmgr/transport/ble \n    -  @apache-mynewt-core/net/nimble/controller \n    -  @apache-mynewt-core/net/nimble/host \n    -  @apache-mynewt-core/net/nimble/host/services/ans \n    -  @apache-mynewt-core/net/nimble/host/services/gap \n    -  @apache-mynewt-core/net/nimble/host/services/gatt \n    -  @apache-mynewt-core/net/nimble/host/store/ram \n    -  @apache-mynewt-core/net/nimble/transport/ram \n    -  @apache-mynewt-core/sys/console/full \n    -  @apache-mynewt-core/sys/sysinit \n    -  @apache-mynewt-core/sys/id   And create a target for it: 
  [user@IsMyLaptop:~/src/air_quality]$ newt target create air_q\nTarget targets/air_q successfully created\n[user@IsMyLaptop:~/src/air_quality]$ newt target set air_q bsp=@apache-mynewt-core/hw/bsp/arduino_primo_nrf52\nTarget targets/air_q successfully set target.bsp to @apache-mynewt-core/hw/bsp/arduino_primo_nrf52\n[user@IsMyLaptop:~/src/air_quality]$ newt target set air_q app=apps/air_quality \nTarget targets/air_q successfully set target.app to apps/air_quality\n[user@IsMyLaptop:~/src/air_quality]$ newt target set air_q build_profile=debug\nTarget targets/air_q successfully set target.build_profile to debug\n[user@IsMyLaptop:~/src/air_quality]$ newt build air_q\n ....\nLinking /Users/dsimmons/dev/myproj/bin/targets/air_q/app/apps/air_quality/air_quality.elf\nTarget successfully built: targets/air_q", 
-            "title": "Create test project"
-        }, 
-        {
-            "location": "/os/tutorials/air_quality_sensor/#create-packages-for-drivers", 
-            "text": "One of the sensors you want to enable is SenseAir K30, which will connect to the board over a serial port.\nTo start development of the driver, you first need to create a package description for it, and add stubs for sources.  The first thing to do is to create the directory structure for your driver:  [user@IsMyLaptop:~/src/air_quality]$ mkdir -p libs/my_drivers/senseair/include/senseair\n[user@IsMyLaptop:~/src/air_quality]$ mkdir -p libs/my_drivers/senseair/src  Now you can add the files you need. You'll need a pkg.yml to describe the driver, and then header stub followed by source stub.  [user@IsMyLaptop:~/src/air_quality]$ cat libs/my_drivers/senseair/pkg.yml  #  # Licensed to the Apache Software Foundation (ASF) under one  # or more contributor license agreements.  See the NOTICE file  # distributed with this work for additional information  # regarding copyright ownership.  The ASF licenses this file  # to you under the Apache License, Version 2.0 (the  # 
  License ); you may not use this file except in compliance  # with the License.  You may obtain a copy of the License at  #   #  http: //www.apache.org/licenses/LICENSE-2.0  #  # Unless required by applicable law or agreed to in writing,  # software distributed under the License is distributed on an  #  AS IS  BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY  # KIND, either express or implied.  See the License for the  # specific language governing permissions and limitations  # under the License.  #  pkg . name :  libs/my_drivers/senseair  pkg . description :  Host   side   of   the   nimble   Bluetooth   Smart   stack . pkg . author :  Apache Mynewt  dev@mynewt.incubator.apache.org  pkg . homepage :  http://mynewt.apache.org/  pkg . keywords :\n     -   ble \n     -   bluetooth  pkg . deps :\n     -   @apache-mynewt-core/kernel/os   [user@IsMyLaptop:~/src/air_quality]$ cat libs/my_drivers/senseair/include/senseair/senseair.h  /*   * Licensed to the Apache Software Foundation (ASF) u
 nder one   * or more contributor license agreements.  See the NOTICE file   * distributed with this work for additional information   * regarding copyright ownership.  The ASF licenses this file   * to you under the Apache License, Version 2.0 (the   *  License ); you may not use this file except in compliance   * with the License.  You may obtain a copy of the License at   *    *  http://www.apache.org/licenses/LICENSE-2.0   *   * Unless required by applicable law or agreed to in writing,   * software distributed under the License is distributed on an   *  AS IS  BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY   * KIND, either express or implied.  See the License for the   * specific language governing permissions and limitations   * under the License.  */  #ifndef _SENSEAIR_H_  #define _SENSEAIR_H_  void   senseair_init ( void ); #endif  /* _SENSEAIR_H_ */   [user@IsMyLaptop:~/src/air_quality]$ cat libs/my_drivers/senseair/src/senseair.c  /**   * Licensed to the Apache Software Fou
 ndation (ASF) under one   * or more contributor license agreements.  See the NOTICE file   * distributed with this work for additional information   * regarding copyright ownership.  The ASF licenses this file   * to you under the Apache License, Version 2.0 (the   *  License ); you may not use this file except in compliance   * with the License.  You may obtain a copy of the License at   *    *  http://www.apache.org/licenses/LICENSE-2.0   *   * Unless required by applicable law or agreed to in writing,   * software distributed under the License is distributed on an   *  AS IS  BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY   * KIND, either express or implied.  See the License for the   * specific language governing permissions and limitations   * under the License.   */  void  senseair_init ( void )\n{\n}  And add dependency to this package in your project yml file.  Here's the listing from apps/air_quality/pkg.yml  pkg.name: apps/air_quality\npkg.type: app\npkg.description: Air q
 uality sensor test\npkg.keywords:\n\npkg.deps:\n    -  @apache-mynewt-core/libs/console/full \n    -  @apache-mynewt-core/libs/newtmgr \n    -  @apache-mynewt-core/libs/os \n    -  @apache-mynewt-core/libs/shell \n    -  @apache-mynewt-core/sys/config \n    -  @apache-mynewt-core/sys/log/full \n    -  @apache-mynewt-core/sys/stats/full \n    - libs/my_drivers/senseair  And add a call to your main() to initialize this driver.      [user@IsMyLaptop:~/src/air_quality]$ diff project/blinky/src/main.c project/air_quality/src/main.c\n    28a29\n      #include  senseair/senseair.h \n    190a192\n      senseair_init();\n    [user@IsMyLaptop:~/src/air_quality  The ble_prph app runs everything in one task handler. For this project, we're going to add a second\ntask handler to respond to the shell, and then handle communicating with the senseair sensor for us.  /** shell task settings. */  #define SHELL_TASK_PRIO           2  #define SHELL_STACK_SIZE          (OS_STACK_ALIGN(336))  struct   os
 _eventq   shell_evq ; struct   os_task   shell_task ; bssnz_t   os_stack_t   shell_stack [ SHELL_STACK_SIZE ];  That defines the task, now we need to initialize it, add a task handler, and we're going to \nuse this task as our default task handler.  /**   * Event loop for the main shell task.   */  static   void  shell_task_handler ( void   *unused )\n{\n     while  ( 1 ) {\n         os_eventq_run ( shell_evq );\n    }\n}  And in your  main()  add:       /* Initialize shell eventq */ \n     os_eventq_init ( shell_evq );\n\n     /* Create the shell task.         * All shell operations are performed in this task.       */ \n     os_task_init ( shell_task ,  shell ,  shell_task_handler ,\n                               NULL ,  SHELL_TASK_PRIO ,  OS_WAIT_FOREVER ,\n                               shell_stack ,  SHELL_STACK_SIZE );  Don't forget to change your default task handler!       os_eventq_dflt_set ( shell_evq );  And then build it to make sure all goes well.  [user@IsMyLaptop:~/s
 rc/air_quality]$ newt build air_q\nCompiling senseair.c\nArchiving senseair.a\nLinking air_quality.elf\nApp successfully built: /Users/user/src/air_quality/bin/air_q/apps/air_quality/air_quality.elf  All looks good.", 
-            "title": "Create packages for drivers"
-        }, 
-        {
-            "location": "/os/tutorials/air_quality_sensor/#add-cli-commands-for-testing-drivers", 
-            "text": "While developing the driver, you want to issue operations from console asking it to do stuff. We'll assume that you've already worked through the tutorial \non how to  enable the CLI , so all we'll need to do is add the propper values to the project's  syscfg.yml  file:  [user@IsMyLaptop:~/src/air_quality]$ cat targets/air_q/syscfg.yml\nsyscfg.vals:\n    # Set as per blinky_primo\n    OPENOCD_DEBUG: 1\n    # Enable the shell task.\n    SHELL_TASK: 1\n    STATS_CLI: 1\n    CONSOLE_TICKS: 1\n    CONSOLE_PROMPT: 1  Then register your senseair command with the shell by adding the following to  libs/my_drivers/senseair/src/senseair.c  #include  shell/shell.h  #include  console/console.h  #include  assert.h  static   int   senseair_shell_func ( int   argc ,  char   **argv ); static   struct   shell_cmd   senseair_cmd   =  {\n    . sc_cmd   =   senseair ,\n    . sc_cmd_func   =   senseair_shell_func ,\n}; void  senseair_init ( void )\n{\n     int   rc ;\n\n     rc   = 
   shell_cmd_register ( senseair_cmd );\n     assert ( rc   ==   0 );\n} static   int  senseair_shell_func ( int   argc ,  char   **argv )\n{\n     console_printf ( Yay! Somebody called!\\n );\n     return   0 ;\n\n}  Now you can you build this, download to target, and start minicom on your console port. If you haven't already, familiarize yourself with\nthe tutorial on how to connect a serial port to your board  here .  You'll need to wire up your Board to a Serial converter first. On the Arduino Primo Board pin 1 is TX and pin 0 is RX so wire 1 to RX on your serial board, and 0 to TX on your serial board.      [user@IsMyLaptop:~]$ minicom -D /dev/tty.usbserial-AH02MIE2\n\n\n    Welcome to minicom 2.7\n\n    OPTIONS: \n    Compiled on Oct 12 2015, 07:48:30.\n    Port /dev/tty.usbserial-AH02MIE2, 13:44:40\n\n    Press CTRL-X Z for help on special keys\n\n    ?\n    419:   ?\n    Commands:\n    641:     stat      echo         ?    prompt     ticks     tasks\n    643: mempools      dat
 e  senseair\n    644:   senseair\n    Yay! Somebody called!\n    1125:  \n    53611:   tasks\n    Tasks:\n    54047:    task pri tid  runtime      csw    stksz   stkuse   lcheck   ncheck flg\n    54057:    idle 255   0    54048    66890       64       30        0        0   0\n    54068:  ble_ll   0   1        9    64986       80       58        0        0   0\n    54079: bleprph   1   2        0        1      336       32        0        0   0\n    54090:   shell   2   3        0     2077      336      262        0        0   0\n    54101:    That's great. Your shell task is running, and is responding appropriately!\nYou can connect the hardware to your board and start developing code for the driver itself.", 
-            "title": "Add CLI commands for testing drivers"
-        }, 
-        {
-            "location": "/os/tutorials/air_quality_sensor/#use-of-hal-for-drivers", 
-            "text": "The sensor has a serial port connection, and that's how you are going to connect to it. Your original BSP, hw/bsp/arduino_primo_nrf52, has two UARTs set up.\nWe're using one for our shell/console. It also has a second UART set up as a 'bit-bang' UART but since the SenseAir only needs to\ncommunicate at 9600 baud, this bit-banged uart is plenty fast enough.  You'll have to make a small change to the  syscfg.yml  file in your project's target directory to change  the pin definitions \nfor this second UART. Those changes are as follows:      UART_0_PIN_TX: 23\n    UART_0_PIN_RX: 24  With this in place, you can refer to serial port where your SenseAir sensor by a logical number. This makes the code more platform independent - you could connect this sensor to another board, like Olimex. You will also use the HAL UART abstraction to do the UART port setup and data transfer. That way you don't need to have any platform dependent pieces within your little driver.  You w
 ill now see what the driver code ends up looking like. Here's the header file, filled in from the stub you created earlier.  /*   * Licensed to the Apache Software Foundation (ASF) under one   * or more contributor license agreements.  See the NOTICE file   * distributed with this work for additional information   * regarding copyright ownership.  The ASF licenses this file   * to you under the Apache License, Version 2.0 (the   *  License ); you may not use this file except in compliance   * with the License.  You may obtain a copy of the License at   *    *  http://www.apache.org/licenses/LICENSE-2.0   *   * Unless required by applicable law or agreed to in writing,   * software distributed under the License is distributed on an   *  AS IS  BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY   * KIND, either express or implied.  See the License for the   * specific language governing permissions and limitations   * under the License.  */  #ifndef _SENSEAIR_H_  #define _SENSEAIR_H_  enu
 m   senseair_read_type  {\n         SENSEAIR_CO2 ,\n}; int   senseair_init ( int   uartno ); int   senseair_read ( enum   senseair_read_type ); #endif  /* _SENSEAIR_H_ */   As you can see, logical UART number has been added to the init routine. A 'read' function has been added, \nwhich is a blocking read. If you were making a commercial product, you would probably have a callback for reporting the results.  And here is the source for the driver.  /**   * Licensed to the Apache Software Foundation (ASF) under one   * or more contributor license agreements.  See the NOTICE file   * distributed with this work for additional information   * regarding copyright ownership.  The ASF licenses this file   * to you under the Apache License, Version 2.0 (the   *  License ); you may not use this file except in compliance   * with the License.  You may obtain a copy of the License at   *   *  http://www.apache.org/licenses/LICENSE-2.0   *   * Unless required by applicable law or agreed to in wri
 ting,   * software distributed under the License is distributed on an   *  AS IS  BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY   * KIND, either express or implied.  See the License for the   * specific language governing permissions and limitations   * under the License.   */  #include  string.h  #include  shell/shell.h  #include  console/console.h  #include  os/os.h  #include  hal/hal_uart.h  #include  senseair/senseair.h  static   const   uint8_t   cmd_read_co2 []  =  {\n     0xFE ,  0 X44 ,  0 X00 ,  0 X08 ,  0 X02 ,  0 X9F ,  0 X25 \n}; static   int   senseair_shell_func ( int   argc ,  char   **argv ); static   struct   shell_cmd   senseair_cmd   =  {\n    . sc_cmd   =   senseair ,\n    . sc_cmd_func   =   senseair_shell_func ,\n}; struct   senseair  { \n     int   uart ;\n     struct   os_sem   sema ;\n     const   uint8_t   *tx_data ;\n     int   tx_off ;\n     int   tx_len ;\n     uint8_t   rx_data [ 32 ]; \n     int   rx_off ;\n     int   value ;\n}  senseair ; static   i
 nt  senseair_tx_char ( void   *arg )\n{\n     struct   senseair   *s   =   senseair ;\n     int   rc ;\n\n     if  ( s- tx_off   =   s- tx_len ) {\n     /*           * Command tx finished.           */ \n         s- tx_data   =   NULL ;\n         return   - 1 ;\n    }\n\n     rc   =   s- tx_data [ s- tx_off ];\n     s- tx_off++ ;\n     return   rc ;\n} /*   * CRC for modbus over serial port.   */  static   const   uint16_t   mb_crc_tbl []  =  {\n     0x0000 ,  0xcc01 ,  0xd801 ,  0x1400 ,  0xf001 ,  0x3c00 ,  0x2800 ,  0xe401 ,\n     0xa001 ,  0x6c00 ,  0x7800 ,  0xb401 ,  0x5000 ,  0x9c01 ,  0x8801 ,  0x4400 \n}; static   uint16_t  mb_crc ( const   uint8_t   *data ,  int   len ,  uint16_t   crc )\n{\n     while  ( len--     0 ) {\n         crc   ^=   *data++ ;\n         crc   =  ( crc     4 )  ^   mb_crc_tbl [ crc     0xf ];\n         crc   =  ( crc     4 )  ^   mb_crc_tbl [ crc     0xf ];\n    }\n     return   crc ;\n} static   int  mb_crc_check ( const   void   *pkt ,  int   len 
 )\n{\n     uint16_t   crc ,  cmp ;\n     uint8_t   *bp   =  ( uint8_t   * ) pkt ;\n\n     if  ( len     sizeof ( crc )  +   1 ) {\n         return   - 1 ;\n    }\n     crc   =   mb_crc ( pkt ,  len   -   2 ,  0xffff );\n     cmp   =   bp [ len   -   2 ]  |  ( bp [ len   -   1 ]    8 );\n     if  ( crc   !=   cmp ) {\n         return   - 1 ;\n    }  else  {\n         return   0 ;\n    }\n} static   int  senseair_rx_char ( void   *arg ,  uint8_t   data )\n{\n     struct   senseair   *s   =  ( struct   senseair   * ) arg ;\n     int   rc ;\n\n     if  ( s- rx_off   =   sizeof ( s- rx_data )) {\n         s- rx_off   =   0 ;\n    }\n     s- rx_data [ s- rx_off ]  =   data ;\n     s- rx_off++ ;\n\n     if  ( s- rx_off   ==   7 ) {\n         rc   =   mb_crc_check ( s- rx_data ,  s- rx_off );\n         if  ( rc   ==   0 ) {\n             s- value   =   s- rx_data [ 3 ]  *   256   +   s- rx_data [ 4 ];\n             os_sem_release ( s- sema );\n        }\n    }\n     return   0 ;\n} void  se
 nseair_tx ( struct   senseair   *s ,  const   uint8_t   *tx_data ,  int   data_len )\n{\n     s- tx_data   =   tx_data ;\n     s- tx_len   =   data_len ;\n     s- tx_off   =   0 ;\n     s- rx_off   =   0 ;\n\n     hal_uart_start_tx ( s- uart );\n} int  senseair_read ( enum   senseair_read_type   type )\n{\n     struct   senseair   *s   =   senseair ;\n     const   uint8_t   *cmd ;\n     int   cmd_len ;\n     int   rc ;\n\n     if  ( s- tx_data ) {\n         /*           * busy           */ \n         return   - 1 ;\n    }\n     switch  ( type ) {\n     case   SENSEAIR_CO2 :\n         cmd   =   cmd_read_co2 ;\n         cmd_len   =   sizeof ( cmd_read_co2 );\n         break ;\n     default : \n         return   - 1 ;\n    }\n     senseair_tx ( s ,  cmd ,  cmd_len );\n     rc   =   os_sem_pend ( s- sema ,  OS_TICKS_PER_SEC   /   2 );\n     if  ( rc   ==   OS_TIMEOUT ) {\n         /*           * timeout           */ \n         return   - 2 ;\n    }\n     return   s- value ;\n} static   
 int  senseair_shell_func ( int   argc ,  char   **argv )\n{\n     int   value ;\n     enum   senseair_read_type   type ;\n\n     if  ( argc     2 ) { usage :\n         console_printf ( %s co2\\n ,  argv [ 0 ]);\n         return   0 ;\n    }\n     if  ( !strcmp ( argv [ 1 ],  co2 )) {\n         type   =   SENSEAIR_CO2 ;\n    }  else  {\n         goto   usage ;\n    }\n     value   =   senseair_read ( type );\n     if  ( value   =   0 ) {\n         console_printf ( Got %d\\n ,  value );\n    }  else  {\n         console_printf ( Error while reading: %d\\n ,  value );\n    }\n     return   0 ;\n} int  senseair_init ( int   uartno )\n{\n     int   rc ;\n     struct   senseair   *s   =   senseair ;\n\n     rc   =   shell_cmd_register ( senseair_cmd );\n     if  ( rc ) {\n         return   rc ;\n    }\n\n     rc   =   os_sem_init ( s- sema ,  1 );\n     if  ( rc ) {\n         return   rc ;\n    }\n     rc   =   hal_uart_init_cbs ( uartno ,  senseair_tx_char ,  NULL ,\n       senseair_rx_c
 har ,  senseair );\n     if  ( rc ) {\n         return   rc ;\n    }\n     rc   =   hal_uart_config ( uartno ,  9600 ,  8 ,  1 ,  HAL_UART_PARITY_NONE ,\n       HAL_UART_FLOW_CTL_NONE );\n     if  ( rc ) {\n         return   rc ;\n    }\n     s- uart   =   uartno ;\n\n     return   0 ;\n}  And your modified main() for senseair driver init.  int  main ( int   argc ,  char   **argv )\n{\n    ....\n     senseair_init ( 0 );\n    ....\n    }  You can see from the code that you are using the HAL interface to open a UART port, and using OS \nsemaphore as a way of blocking the task when waiting for read response to come back from the sensor.  Now comes the fun part: Hooking up the sensor! It's fun because a) hooking up a sensor is always \nfun and b) the SenseAir sensor's PCB is entirely unlabeled, so you'll have to trust us on how to hook it up.   So here we go.   You'll have to do a little soldering. I soldered some header pins to the SenseAir K30 board to\nmake connecting wires easier u
 sing standard jumper wires, but you can also just solder wires\nstraight to the board if you prefer.  Here's what your SenseAir board should look like once it's wired up:   Now that you have that wired up, let's get the Arduino Primo wired up. A couple of things to note:   The Arduino Primo's 'console' UART is actually UART1.   The secondary (bit-banged) UART is UART0, so that's where we'll have to hook up the SenseAir.   Here's what your Arduino Primo should now look like with everything wired in:   Everything is wired and you're ready to go! Build and load your new app:  $ newt build air_q\nBuilding target targets/air_q\nCompiling apps/air_quality/src/main.c\nArchiving apps_air_quality.a\nLinking myproj/bin/targets/air_q/app/apps/air_quality/air_quality.elf\nTarget successfully built: targets/air_q\n$ newt create-image air_q 1.0.0\nApp image succesfully generated: myproj/bin/targets/air_q/app/apps/air_quality/air_quality.img\n$ newt load air_q\nLoading app image into slot 1  Now, 
 you should be able to connect to your serial port and read values:  user@IsMyLaptop:~]$ minicom -D /dev/tty.usbserial-AH02MIE2\n\n\n    Welcome to minicom 2.7\n\n    OPTIONS: \n    Compiled on Oct 12 2015, 07:48:30.\n    Port /dev/tty.usbserial-AH02MIE2, 13:44:40\n\n    Press CTRL-X Z for help on special keys\n\n    1185:   ?\n    Commands:\n    1382:     stat      echo         ?    prompt     ticks     tasks\n    1390: mempools      date  senseair\n    1395:   senseair\n    senseair co2\n    2143:   senseair co2\n    Got 973  And you're getting valid readings! Congratulations!  Next we'll hook this all up via Bluetooth so that you can read those values remotely.", 
-            "title": "Use of HAL for drivers"
-        }, 
-        {
-            "location": "/os/tutorials/air_quality_ble/", 
-            "text": "Air quality sensor project via Bluetooth\n\n\nThis is a follow-on project to the \nBasic Air Quality Sensor\n project; so it is\nassumed that you have worked through that project and have your CO\n2\n sensor working properly with\nyour Arduino Primo board. \n\n\nSo let's get started making this thing Bluetooth enabled!\n\n\nAdd Bluetooth GATT Services\n\n\nSince we already built the previous demo on the \nbluetooth peripheral\n basic\napp most of the bluetooth plumbing has already been taken care of for us. What's left is for us\nto add the required GATT services for advertising the Carbon Dioxide sensor so that\nother devices can get those values.\n\n\nFirst, we'll define the GATT Services in \napps/air_quality/src/bleprph.h\n.\n\n\n/* Sensor Data */\n\n\n/* e761d2af-1c15-4fa7-af80-b5729002b340 */\n\n\nstatic\n \nconst\n \nble_uuid128_t\n \ngatt_svr_svc_co2_uuid\n \n=\n\n    \nBLE_UUID128_INIT\n(\n0x40\n, \n0xb3\n, \n0x20\n, \n0x90\n, \n0x72\n, \n0xb5\n, \n0x80
 \n, \n0xaf\n,\n                     \n0xa7\n, \n0x4f\n, \n0x15\n, \n0x1c\n, \n0xaf\n, \n0xd2\n, \n0x61\n, \n0xe7\n);\n\n#define CO2_SNS_TYPE          0xDEAD\n\n\n#define CO2_SNS_STRING \nSenseAir K30 CO2 Sensor\n\n\n#define CO2_SNS_VAL           0xBEAD\n\n\n\nuint16_t\n \ngatt_co2_val\n; \n\n\n\n\n\nYou can use any hex values you choose for the sensor type and sensor values, and you can \neven forget the sensor type and sensor string definitions altogether but they make\nthe results look nice in our Bluetooth App for Mac OS X and iOS.\n\n\nNext we'll add those services to \napps/air_quality/src/gatt_svr.c\n.\n\n\nstatic\n \nint\n\n\ngatt_svr_sns_access\n(\nuint16_t\n \nconn_handle\n, \nuint16_t\n \nattr_handle\n,\n    \nstruct\n \nble_gatt_access_ctxt\n \n*ctxt\n,\n    \nvoid\n \n*arg\n);\n\n\nstatic\n \nuint16_t\n \ngatt_co2_val_len\n;\n\n\n\n\n\nMake sure it is added as \nprimary\n service.\n\n\nstatic\n \nconst\n \nstruct\n \nble_gatt_svc_def\n \ngatt_svr_svcs\n[] \n=\n {\n    {\
 n        \n/*** Service: Security test. */\n\n        .\ntype\n \n=\n \nBLE_GATT_SVC_TYPE_PRIMARY\n,\n        .\nuuid\n \n=\n \ngatt_svr_svc_sec_test_uuid\n.\nu\n,\n        .\ncharacteristics\n \n=\n (\nstruct\n \nble_gatt_chr_def\n[]) { {\n            \n/*** Characteristic: Random number generator. */\n\n            .\nuuid\n \n=\n \ngatt_svr_chr_sec_test_rand_uuid\n.\nu\n,\n            .\naccess_cb\n \n=\n \ngatt_svr_chr_access_sec_test\n,\n            .\nflags\n \n=\n \nBLE_GATT_CHR_F_READ\n \n|\n \nBLE_GATT_CHR_F_READ_ENC\n,\n        }, {\n            \n/*** Characteristic: Static value. */\n\n            .\nuuid\n \n=\n \ngatt_svr_chr_sec_test_static_uuid\n,.\nu\n\n            .\naccess_cb\n \n=\n \ngatt_svr_chr_access_sec_test\n,\n            .\nflags\n \n=\n \nBLE_GATT_CHR_F_READ\n \n|\n\n                     \nBLE_GATT_CHR_F_WRITE\n \n|\n \nBLE_GATT_CHR_F_WRITE_ENC\n,\n        }, {\n            \n0\n, \n/* No more characteristics in this service. */\n\n        } },\n    },\n
         {\n            \n/*** CO2 Level Notification Service. */\n\n            .\ntype\n \n=\n \nBLE_GATT_SVC_TYPE_PRIMARY\n,\n            .\nuuid\n \n=\n \ngatt_svr_svc_co2_uuid\n.\nu\n,\n            .\ncharacteristics\n \n=\n (\nstruct\n \nble_gatt_chr_def\n[]) { {\n                .\nuuid\n \n=\n \nBLE_UUID16_DECLARE\n(\nCO2_SNS_TYPE\n),\n                .\naccess_cb\n \n=\n \ngatt_svr_sns_access\n,\n                .\nflags\n \n=\n \nBLE_GATT_CHR_F_READ\n,\n            }, {\n                .\nuuid\n \n=\n \nBLE_UUID16_DECLARE\n(\nCO2_SNS_VAL\n),\n                .\naccess_cb\n \n=\n \ngatt_svr_sns_access\n,\n                .\nflags\n \n=\n \nBLE_GATT_CHR_F_NOTIFY\n,\n            }, {\n                \n0\n, \n/* No more characteristics in this service. */\n\n            } },\n        },\n\n        {\n            \n0\n, \n/* No more services. */\n\n        },\n    };\n\n\n\n\n\nNext we need to tell the GATT Server how to handle requests for CO\n2\n readings :\n\n\nsstatic\n \n
 int\n\n\ngatt_svr_sns_access\n(\nuint16_t\n \nconn_handle\n, \nuint16_t\n \nattr_handle\n,\n                          \nstruct\n \nble_gatt_access_ctxt\n \n*ctxt\n,\n                          \nvoid\n \n*arg\n)\n{\n    \nuint16_t\n \nuuid16\n;\n    \nint\n \nrc\n;\n\n    \nuuid16\n \n=\n \nble_uuid_u16\n(\nctxt-\nchr-\nuuid\n);\n\n    \nswitch\n (\nuuid16\n) {\n    \ncase\n \nCO2_SNS_TYPE\n:\n        \nassert\n(\nctxt-\nop\n \n==\n \nBLE_GATT_ACCESS_OP_READ_CHR\n);\n        \nrc\n \n=\n \nos_mbuf_append\n(\nctxt-\nom\n, \nCO2_SNS_STRING\n, \nsizeof\n \nCO2_SNS_STRING\n);\n        \nBLEPRPH_LOG\n(\nINFO\n, \nCO2 SENSOR TYPE READ: %s\\n\n, \nCO2_SNS_STRING\n);\n        \nreturn\n \nrc\n \n==\n \n0\n \n?\n \n0\n \n:\n \nBLE_ATT_ERR_INSUFFICIENT_RES\n;\n\n    \ncase\n \nCO2_SNS_VAL\n:\n        \nif\n (\nctxt-\nop\n \n==\n \nBLE_GATT_ACCESS_OP_WRITE_CHR\n) {\n            \nrc\n \n=\n \ngatt_svr_chr_write\n(\nctxt-\nom\n, \n0\n,\n                                    \nsizeof\n \ngatt_co2_v
 al\n,\n                                    \ngatt_co2_val\n,\n                                    \ngatt_co2_val_len\n);\n            \nreturn\n \nrc\n;\n        } \nelse\n \nif\n (\nctxt-\nop\n \n==\n \nBLE_GATT_ACCESS_OP_READ_CHR\n) {\n            \nrc\n \n=\n \nos_mbuf_append\n(\nctxt-\nom\n, \ngatt_co2_val\n,\n                                \nsizeof\n \ngatt_co2_val\n);\n            \nreturn\n \nrc\n \n==\n \n0\n \n?\n \n0\n \n:\n \nBLE_ATT_ERR_INSUFFICIENT_RES\n;\n        }\n\n    \ndefault\n:\n\n        \nassert\n(\n0\n);\n        \nreturn\n \nBLE_ATT_ERR_UNLIKELY\n;\n    }\n}\n\n\n\n\n\nNow it's time to go into our \napps/air_quality/src/main.c\n and change how we read CO\n2\n readings and \nrespond to requests. \n\n\nWe'll need a task handler with an event queue for the CO\n2\n readings -- they were handled by the shell task in the previous tutorial but now it needs to be replaced by a different handler as shown below.\n\n\n/* CO2 Task settings */\n\n\n#define CO2_TASK_PRIO
            5\n\n\n#define CO2_STACK_SIZE          (OS_STACK_ALIGN(336))\n\n\nstruct\n \nos_eventq\n \nco2_evq\n;\n\nstruct\n \nos_task\n \nco2_task\n;\n\nbssnz_t\n \nos_stack_t\n \nco2_stack\n[\nCO2_STACK_SIZE\n];\n\n\n\n\n\nAnd of course we'll need to go to our \nmain()\n and do all the standard task and event setup we\nnormally do by adding the following. Again, remember to delete all the shell event queues and tasks.\n\n\n/* Initialize sensor eventq */\n\n\nos_eventq_init\n(\nco2_evq\n);\n\n\n/* Create the CO2 reader task.  \n\n\n * All sensor reading operations are performed in this task.\n\n\n */\n\n\nos_task_init\n(\nco2_task\n, \nsensor\n, \nco2_task_handler\n,\n            \nNULL\n, \nCO2_TASK_PRIO\n, \nOS_WAIT_FOREVER\n,\n            \nco2_stack\n, \nCO2_STACK_SIZE\n);\n\n\n\n\n\nWe'll also need to add a task handler -- since we initialized it above:\n\n\n/**\n\n\n * Event loop for the sensor task.\n\n\n */\n\n\nstatic\n \nvoid\n\n\nco2_task_handler\n(\nvoid\n \n*unused\n)\
 n{    \n    \nwhile\n (\n1\n) {\n        \nco2_read_event\n();\n        \n/* Wait 2 second */\n\n        \nos_time_delay\n(\nOS_TICKS_PER_SEC\n \n*\n \n2\n);\n\n    }\n}\n\n\n\n\n\nAnd finally, we'll take care of that \nco2_read_event()\n function:\n\n\nint\n\n\nco2_read_event\n(\nvoid\n)\n{\n    \nint\n \nvalue\n;\n    \nenum\n \nsenseair_read_type\n \ntype\n \n=\n \nSENSEAIR_CO2\n;\n    \nuint16_t\n \nchr_val_handle\n;\n    \nint\n \nrc\n;\n\n    \nvalue\n \n=\n \nsenseair_read\n(\ntype\n);\n    \nif\n (\nvalue\n \n=\n \n0\n) {\n        \nconsole_printf\n(\nGot %d\\n\n, \nvalue\n);\n    } \nelse\n {\n        \nconsole_printf\n(\nError while reading: %d\\n\n, \nvalue\n);\n        \ngoto\n \nerr\n;\n    }\n    \ngatt_co2_val\n \n=\n \nvalue\n;\n    \nrc\n \n=\n \nble_gatts_find_chr\n(\ngatt_svr_svc_co2_uuid\n.\nu\n, \nBLE_UUID16_DECLARE\n(\nCO2_SNS_VAL\n), \nNULL\n, \nchr_val_handle\n);\n    \nassert\n(\nrc\n \n==\n \n0\n);\n    \nble_gatts_chr_updated\n(\nchr_val_handle\n);\n    \n
 return\n (\n0\n);\n\nerr\n:\n    \nreturn\n (\nrc\n);\n}\n\n\n\n\n\nYou'll notice that it looks eeirily similar to a portion of the shell event we created \nearlier. This one simply reads and updates the CO\n2\n value and sends that over BLE to any\nconnected clients instead. \n\n\nWe can now build, create-image and load the app onto our Arduino Primo board, and then \nconnect and see the updated values! The image below shows the results using MyNewt Sensor Reader,\na Mac OS X app developed for connecting to MyNewt devices over Bluetooth but you can also use LightBlue\nor any other application that can connect to, and read, Bluetooth data.\n\n\n\n\nCongratulations!!", 
-            "title": "Bluetooth-enabled Air Quality Sensor"
-        }, 
-        {
-            "location": "/os/tutorials/air_quality_ble/#air-quality-sensor-project-via-bluetooth", 
-            "text": "This is a follow-on project to the  Basic Air Quality Sensor  project; so it is\nassumed that you have worked through that project and have your CO 2  sensor working properly with\nyour Arduino Primo board.   So let's get started making this thing Bluetooth enabled!", 
-            "title": "Air quality sensor project via Bluetooth"
-        }, 
-        {
-            "location": "/os/tutorials/air_quality_ble/#add-bluetooth-gatt-services", 
-            "text": "Since we already built the previous demo on the  bluetooth peripheral  basic\napp most of the bluetooth plumbing has already been taken care of for us. What's left is for us\nto add the required GATT services for advertising the Carbon Dioxide sensor so that\nother devices can get those values.  First, we'll define the GATT Services in  apps/air_quality/src/bleprph.h .  /* Sensor Data */  /* e761d2af-1c15-4fa7-af80-b5729002b340 */  static   const   ble_uuid128_t   gatt_svr_svc_co2_uuid   = \n     BLE_UUID128_INIT ( 0x40 ,  0xb3 ,  0x20 ,  0x90 ,  0x72 ,  0xb5 ,  0x80 ,  0xaf ,\n                      0xa7 ,  0x4f ,  0x15 ,  0x1c ,  0xaf ,  0xd2 ,  0x61 ,  0xe7 ); #define CO2_SNS_TYPE          0xDEAD  #define CO2_SNS_STRING  SenseAir K30 CO2 Sensor  #define CO2_SNS_VAL           0xBEAD  uint16_t   gatt_co2_val ;   You can use any hex values you choose for the sensor type and sensor values, and you can \neven forget the sensor type and sensor string definitions alt
 ogether but they make\nthe results look nice in our Bluetooth App for Mac OS X and iOS.  Next we'll add those services to  apps/air_quality/src/gatt_svr.c .  static   int  gatt_svr_sns_access ( uint16_t   conn_handle ,  uint16_t   attr_handle ,\n     struct   ble_gatt_access_ctxt   *ctxt ,\n     void   *arg ); static   uint16_t   gatt_co2_val_len ;  Make sure it is added as  primary  service.  static   const   struct   ble_gatt_svc_def   gatt_svr_svcs []  =  {\n    {\n         /*** Service: Security test. */ \n        . type   =   BLE_GATT_SVC_TYPE_PRIMARY ,\n        . uuid   =   gatt_svr_svc_sec_test_uuid . u ,\n        . characteristics   =  ( struct   ble_gatt_chr_def []) { {\n             /*** Characteristic: Random number generator. */ \n            . uuid   =   gatt_svr_chr_sec_test_rand_uuid . u ,\n            . access_cb   =   gatt_svr_chr_access_sec_test ,\n            . flags   =   BLE_GATT_CHR_F_READ   |   BLE_GATT_CHR_F_READ_ENC ,\n        }, {\n             /*** Charact
 eristic: Static value. */ \n            . uuid   =   gatt_svr_chr_sec_test_static_uuid ,. u \n            . access_cb   =   gatt_svr_chr_access_sec_test ,\n            . flags   =   BLE_GATT_CHR_F_READ   | \n                      BLE_GATT_CHR_F_WRITE   |   BLE_GATT_CHR_F_WRITE_ENC ,\n        }, {\n             0 ,  /* No more characteristics in this service. */ \n        } },\n    },\n        {\n             /*** CO2 Level Notification Service. */ \n            . type   =   BLE_GATT_SVC_TYPE_PRIMARY ,\n            . uuid   =   gatt_svr_svc_co2_uuid . u ,\n            . characteristics   =  ( struct   ble_gatt_chr_def []) { {\n                . uuid   =   BLE_UUID16_DECLARE ( CO2_SNS_TYPE ),\n                . access_cb   =   gatt_svr_sns_access ,\n                . flags   =   BLE_GATT_CHR_F_READ ,\n            }, {\n                . uuid   =   BLE_UUID16_DECLARE ( CO2_SNS_VAL ),\n                . access_cb   =   gatt_svr_sns_access ,\n                . flags   =   BLE_GATT_CHR_F_
 NOTIFY ,\n            }, {\n                 0 ,  /* No more characteristics in this service. */ \n            } },\n        },\n\n        {\n             0 ,  /* No more services. */ \n        },\n    };  Next we need to tell the GATT Server how to handle requests for CO 2  readings :  sstatic   int  gatt_svr_sns_access ( uint16_t   conn_handle ,  uint16_t   attr_handle ,\n                           struct   ble_gatt_access_ctxt   *ctxt ,\n                           void   *arg )\n{\n     uint16_t   uuid16 ;\n     int   rc ;\n\n     uuid16   =   ble_uuid_u16 ( ctxt- chr- uuid );\n\n     switch  ( uuid16 ) {\n     case   CO2_SNS_TYPE :\n         assert ( ctxt- op   ==   BLE_GATT_ACCESS_OP_READ_CHR );\n         rc   =   os_mbuf_append ( ctxt- om ,  CO2_SNS_STRING ,  sizeof   CO2_SNS_STRING );\n         BLEPRPH_LOG ( INFO ,  CO2 SENSOR TYPE READ: %s\\n ,  CO2_SNS_STRING );\n         return   rc   ==   0   ?   0   :   BLE_ATT_ERR_INSUFFICIENT_RES ;\n\n     case   CO2_SNS_VAL :\n       
   if  ( ctxt- op   ==   BLE_GATT_ACCESS_OP_WRITE_CHR ) {\n             rc   =   gatt_svr_chr_write ( ctxt- om ,  0 ,\n                                     sizeof   gatt_co2_val ,\n                                     gatt_co2_val ,\n                                     gatt_co2_val_len );\n             return   rc ;\n        }  else   if  ( ctxt- op   ==   BLE_GATT_ACCESS_OP_READ_CHR ) {\n             rc   =   os_mbuf_append ( ctxt- om ,  gatt_co2_val ,\n                                 sizeof   gatt_co2_val );\n             return   rc   ==   0   ?   0   :   BLE_ATT_ERR_INSUFFICIENT_RES ;\n        }\n\n     default : \n         assert ( 0 );\n         return   BLE_ATT_ERR_UNLIKELY ;\n    }\n}  Now it's time to go into our  apps/air_quality/src/main.c  and change how we read CO 2  readings and \nrespond to requests.   We'll need a task handler with an event queue for the CO 2  readings -- they were handled by the shell task in the previous tutorial but now it needs to be replaced by
  a different handler as shown below.  /* CO2 Task settings */  #define CO2_TASK_PRIO           5  #define CO2_STACK_SIZE          (OS_STACK_ALIGN(336))  struct   os_eventq   co2_evq ; struct   os_task   co2_task ; bssnz_t   os_stack_t   co2_stack [ CO2_STACK_SIZE ];  And of course we'll need to go to our  main()  and do all the standard task and event setup we\nnormally do by adding the following. Again, remember to delete all the shell event queues and tasks.  /* Initialize sensor eventq */  os_eventq_init ( co2_evq ); /* Create the CO2 reader task.     * All sensor reading operations are performed in this task.   */  os_task_init ( co2_task ,  sensor ,  co2_task_handler ,\n             NULL ,  CO2_TASK_PRIO ,  OS_WAIT_FOREVER ,\n             co2_stack ,  CO2_STACK_SIZE );  We'll also need to add a task handler -- since we initialized it above:  /**   * Event loop for the sensor task.   */  static   void  co2_task_handler ( void   *unused )\n{    \n     while  ( 1 ) {\n         co2
 _read_event ();\n         /* Wait 2 second */ \n         os_time_delay ( OS_TICKS_PER_SEC   *   2 );\n\n    }\n}  And finally, we'll take care of that  co2_read_event()  function:  int  co2_read_event ( void )\n{\n     int   value ;\n     enum   senseair_read_type   type   =   SENSEAIR_CO2 ;\n     uint16_t   chr_val_handle ;\n     int   rc ;\n\n     value   =   senseair_read ( type );\n     if  ( value   =   0 ) {\n         console_printf ( Got %d\\n ,  value );\n    }  else  {\n         console_printf ( Error while reading: %d\\n ,  value );\n         goto   err ;\n    }\n     gatt_co2_val   =   value ;\n     rc   =   ble_gatts_find_chr ( gatt_svr_svc_co2_uuid . u ,  BLE_UUID16_DECLARE ( CO2_SNS_VAL ),  NULL ,  chr_val_handle );\n     assert ( rc   ==   0 );\n     ble_gatts_chr_updated ( chr_val_handle );\n     return  ( 0 ); err :\n     return  ( rc );\n}  You'll notice that it looks eeirily similar to a portion of the shell event we created \nearlier. This one simply reads and up
 dates the CO 2  value and sends that over BLE to any\nconnected clients instead.   We can now build, create-image and load the app onto our Arduino Primo board, and then \nconnect and see the updated values! The image below shows the results using MyNewt Sensor Reader,\na Mac OS X app developed for connecting to MyNewt devices over Bluetooth but you can also use LightBlue\nor any other application that can connect to, and read, Bluetooth data.   Congratulations!!", 
-            "title": "Add Bluetooth GATT Services"
-        }, 
-        {
             "location": "/os/tutorials/event_queue/", 
             "text": "How to define a task which uses event queues to manage multiple events\n\n\nIntroduction\n\n\nEvent queue is a mechanism by which you can serialize incoming events for your task. You can use it to get info about arrived hardware interrupts, callout expirations and messages from other tasks.\n\n\nThe benefit of doing inter-task communication this way is that there should be less resources that need to be locked.\n\n\nThe benefit of doing interrupt processing in a task context instead of inside an interrupt context is that you are not blocking other HW interrupts when doing the work. The same goes for high priority tasks in the system; they're blocked until the interrupt handler returns. From the task context you'll also be able to access other OS facilities; you can sleep while waiting for a lock, for example.\n\n\n\n\nExample app\n\n\nHere you are going to write an app which demonstrates the use of event queues for communication between tasks. You will  also use
  OS callouts for timer expiration and another event from a GPIO interrupt.\n\n\nYou will  use inputs from 3 sources to toggle 3 GPIO outputs on my STM32F3discovery board.\n\n\n\n\nCreate project\n\n\nYou start by creating a project and populating it with repositories incubator-mynewt-core and mynewt_stm32f3. See \nSTM32F3 tutorial\n if you need help with this. You can also read the tutorial on \nAdditional Repositories\n for a more thorough understanding. \n\n\n \n\n\nCreate application\n\n\nHere's what the pkg.yml looks for the application.\n\n\n[marko@IsMyLaptop:~/src/events]$ cat apps/event_sample/pkg.yml\npkg.name: apps/event_sample\npkg.type: app\n\npkg.deps:\n    - \n@apache-mynewt-core/libs/os\n\n    - \n@apache-mynewt-core/hw/hal\n\n    - \n@apache-mynewt-core/libs/console/stub\n\n\n\n\n\n\n\n\nInitialize the event queue structure\n\n\nThis must be done before anyone tries to place events to the queue. Here it's done before any task gets created. Initialization is done by ca
 lling \nos_eventq_init()\n.\n\n\n#define MY_TASK_PRIO        4\n\n\n#define MY_TASK_STACK_SZ    512\n\n\n\nstatic\n \nstruct\n \nos_eventq\n \nmy_eventq\n;\n\nstatic\n \nos_stack_t\n \nmy_task_stack\n[\nMY_TASK_STACK_SZ\n];\n\nstatic\n \nstruct\n \nos_task\n \nmy_task_str\n;\n\n\nvoid\n\n\ninit_tasks\n(\nvoid\n)\n{\n    \nstruct\n \nos_task\n \ntaskid\n;\n\n    \nos_eventq_init\n(\nmy_eventq\n);\n    \nos_task_init\n(\nmy_task_str\n, \ntask\n, \nmy_task\n, \nNULL\n, \nMY_TASK_PRIO\n,\n        \nOS_WAIT_FOREVER\n, \nmy_task_stack\n, \nMY_TASK_STACK_SZ\n);\n\n\n\n\n\n\n\nProcessing events\n\n\nHere event processing is done inside \nmy_task\n. The main loop of the task is pulling events from the queue, and then taking action. We look at the type of the event to figure out what to do.\n\n\nThe code snippet shows what the main loop of the event handler looks like. Events are removed from the head of the queue using os_eventq_get\n\n\nvoid\n\n\nmy_task\n(\nvoid\n \n*arg\n)\n{\n    \nstruc
 t\n \nos_event\n \n*ev\n;\n\n    \nwhile\n (\n1\n) {\n        \nev\n \n=\n \nos_eventq_get\n(\nmy_eventq\n);\n        \nswitch\n (\nev-\nev_type\n) {\n        \n/* more event types here */\n\n        \ndefault\n:\n\n            \nassert\n(\n0\n);\n        }\n    }\n}\n\n\n\n\n\n\n\nEvent types\n\n\nYou can define your own event types. Some numbers are already reserved by the OS, so you should not use those as your own types.\n\n\nReserved event types are defined in \nlibs/os/include/os/os_eventq.h\n. One example of a reserved type is OS_EVENT_T_TIMER, which is used as type in OS callouts.\n\n\nYou should start your event numbers from \nOS_EVENT_T_PERUSER\n, and go higher.\n\n\nYou are going to generate events from GPIO interrupt handler, from another task as well as from a callout. OS callout already has a type, but you'll need to define types for the other uses.\n\n\n#define MY_TASK_GPIO_EVENT  (OS_EVENT_T_PERUSER)\n\n\n#define MY_TASK_TASK_EVENT  (OS_EVENT_T_PERUSER + 1)\n\n\n\n\n
 \n\n\n\nPosting events from another task\n\n\nEvents are posted to a queue by calling \nos_eventq_put()\n. You need to preallocate memory for the event structure. Here it's done by declaring the event structure as a global variable.\n\n\nNote that you can call \nos_eventq_put()\n with an event which has already been queued. In that case, the call has no effect; the position of the event is not changed within the queue.\n\n\nIn the code snippet we declare the os_event structure, and initialize it. We also create the event generating task, and periodically post event to the event queue.\n\n\n#define GEN_TASK_PRIO       3\n\n\n#define GEN_TASK_STACK_SZ   512\n\n\n\nstatic\n \nstruct\n \nos_event\n \ngen_task_ev\n;\n\nstatic\n \nos_stack_t\n \ngen_task_stack\n[\nGEN_TASK_STACK_SZ\n];\n\nstatic\n \nstruct\n \nos_task\n \ngen_task_str\n;\n\n\nvoid\n\n\ngen_task\n(\nvoid\n \n*arg\n)\n{\n    \nwhile\n (\n1\n) {\n        \nos_time_delay\n(\nOS_TICKS_PER_SEC\n \n/\n \n4\n);\n        \nos_even
 tq_put\n(\nmy_eventq\n, \ngen_task_ev\n);\n    }\n}\n\n\nvoid\n\n\ninit_tasks\n(\nvoid\n)\n{\n    \n/* .... */\n\n    \ngen_task_ev\n.\nev_type\n \n=\n \nMY_TASK_TASK_EVENT\n;\n    \nos_task_init\n(\ngen_task_str\n, \ngen_task\n, \ngen_task\n, \nNULL\n, \nGEN_TASK_PRIO\n,\n        \nOS_WAIT_FOREVER\n, \ngen_task_stack\n, \nGEN_TASK_STACK_SZ\n);\n}\n\n\n\n\n\n\n\nCallout events\n\n\nYou can get timer events delivered to your task's event queue with OS callout. Check \ncallout documentation\n for description on how to use the API.\n\n\nFor this example, you'll use only one type of callout; so you can use the simpler structure.\n\n\nIn the code snippet we declare the os_callout structure and initialize it. Then we arm the timer.\n\n\nstatic\n \nstruct\n \nos_callout\n \nmy_callout\n;\n\n\nvoid\n\n\ninit_tasks\n(\nvoid\n)\n{\n    \n/* .... */\n\n\n    \nos_callout_init\n(\nmy_callout\n, \nmy_eventq\n, \nNULL\n);\n    \nos_callout_reset\n(\nmy_callout\n, \nOS_TICKS_PER_SEC\n);\n}\n\n\n\n
 \n\n\n\nPosting events from interrupt handler\n\n\nAnother place where posting events makes sense is from an interrupt handler. In this tutorial you will do it when GPIO changes state.\n\n\nYou'll use HAL GPIO interface to register a routine which is getting called from the interrupt handler context. This routine will then post event to your queue.\n\n\nOn STM32F3Discovery board, there is a button connected to PA0. The identifier for this GPIO pin is 0.\n\n\nstatic\n \nstruct\n \nos_event\n \ngpio_ev\n;\n\n\nvoid\n\n\ninit_tasks\n(\nvoid\n)\n{\n    \n/* .... */\n\n\n    \ngpio_ev\n.\nev_type\n \n=\n \nMY_TASK_GPIO_EVENT\n;\n    \nhal_gpio_irq_init\n(\n0\n, \nmy_gpio_irq\n, \nNULL\n, \nGPIO_TRIG_RISING\n,\n        \nGPIO_PULL_NONE\n);\n    \nhal_gpio_irq_enable\n(\n0\n);\n}\n\n\nstatic\n \nvoid\n\n\nmy_gpio_irq\n(\nvoid\n \n*arg\n)\n{\n    \nos_eventq_put\n(\nmy_eventq\n, \ngpio_ev\n);\n}\n\n\n\n\n\n\n\nEvent processing finalized\n\n\nNow that you are posting events from different so
 urces, you will fill in the parts in the task main loop to trigger different behaviors depending on event type.\n\n\nYou'll drive different LEDs depending on what type of event arrived. LEDs on this board are connected to PE8, PE9, PE10 and so on. These have GPIO identifiers starting from 72 onwards.\n\n\n#define TASK_LED        72\n\n\n#define CALLOUT_LED     73\n\n\n#define GPIO_LED        74\n\n\n\nvoid\n\n\ninit_tasks\n(\nvoid\n)\n{\n    \n/* .... */\n\n    \nhal_gpio_init_out\n(\nTASK_LED\n, \n1\n);\n    \nhal_gpio_init_out\n(\nCALLOUT_LED\n, \n1\n);\n    \nhal_gpio_init_out\n(\nGPIO_LED\n, \n1\n);\n}\n\n\n\n\n\nAnd here is the new main loop for your task. Note that when callout event arrives, we re-arm the callout.\n\n\nvoid\n\n\nmy_task\n(\nvoid\n \n*arg\n)\n{\n    \nstruct\n \nos_event\n \n*ev\n;\n\n    \nwhile\n (\n1\n) {\n        \nev\n \n=\n \nos_eventq_get\n(\nmy_eventq\n);\n        \nswitch\n (\nev-\nev_type\n) {\n        \ncase\n \nMY_TASK_TASK_EVENT\n:\n            \n
 hal_gpio_toggle\n(\nTASK_LED\n);\n            \nbreak\n;\n        \ncase\n \nOS_EVENT_T_TIMER\n:\n            \nhal_gpio_toggle\n(\nCALLOUT_LED\n);\n            \nos_callout_reset\n(\nmy_callout\n, \nOS_TICKS_PER_SEC\n \n/\n \n2\n);\n            \nbreak\n;\n        \ncase\n \nMY_TASK_GPIO_EVENT\n:\n            \nhal_gpio_toggle\n(\nGPIO_LED\n);\n            \nbreak\n;\n        \ndefault\n:\n\n            \nassert\n(\n0\n);\n        }\n    }\n}\n\n\n\n\n\n\n\nNow you're done. Once you load this to your board, the task LED will blink at an interval of 250ms, the callout LED with an interval of 500ms, and the GPIO LED every time you press the button.\n\n\n\n\nCode for the example\n\n\n#include \nos/os.h\n\n\n#include \nbsp/bsp.h\n\n\n#include \nhal/hal_gpio.h\n\n\n#include \nassert.h\n\n\n\n\n#define MY_TASK_PRIO        4\n\n\n#define MY_TASK_STACK_SZ    512\n\n\n\n#define GEN_TASK_PRIO       3\n\n\n#define GEN_TASK_STACK_SZ   512\n\n\n\n#define MY_TASK_GPIO_EVENT  (OS_EVENT_T_PERUSER)
 \n\n\n#define MY_TASK_TASK_EVENT  (OS_EVENT_T_PERUSER + 1)\n\n\n\n#define TASK_LED        72\n\n\n#define CALLOUT_LED     73\n\n\n#define GPIO_LED        74\n\n\n\nstatic\n \nstruct\n \nos_eventq\n \nmy_eventq\n;\n\nstatic\n \nos_stack_t\n \nmy_task_stack\n[\nMY_TASK_STACK_SZ\n];\n\nstatic\n \nstruct\n \nos_task\n \nmy_task_str\n;\n\n\nstatic\n \nstruct\n \nos_event\n \ngen_task_ev\n;\n\nstatic\n \nos_stack_t\n \ngen_task_stack\n[\nGEN_TASK_STACK_SZ\n];\n\nstatic\n \nstruct\n \nos_task\n \ngen_task_str\n;\n\n\nstatic\n \nstruct\n \nos_callout\n \nmy_callout\n;\n\n\nstatic\n \nstruct\n \nos_event\n \ngpio_ev\n;\n\n\nvoid\n\n\nmy_task\n(\nvoid\n \n*arg\n)\n{\n    \nstruct\n \nos_event\n \n*ev\n;\n\n    \nwhile\n (\n1\n) {\n        \nev\n \n=\n \nos_eventq_get\n(\nmy_eventq\n);\n        \nswitch\n (\nev-\nev_type\n) {\n        \ncase\n \nMY_TASK_TASK_EVENT\n:\n            \nhal_gpio_toggle\n(\nTASK_LED\n);\n            \nbreak\n;\n        \ncase\n \nOS_EVENT_T_TIMER\n:\n            \nh
 al_gpio_toggle\n(\nCALLOUT_LED\n);\n            \nos_callout_reset\n(\nmy_callout\n, \nOS_TICKS_PER_SEC\n \n/\n \n2\n);\n            \nbreak\n;\n        \ncase\n \nMY_TASK_GPIO_EVENT\n:\n            \nhal_gpio_toggle\n(\nGPIO_LED\n);\n            \nbreak\n;\n        \ndefault\n:\n\n            \nassert\n(\n0\n);\n        }\n    }\n}\n\n\nstatic\n \nvoid\n\n\nmy_gpio_irq\n(\nvoid\n \n*arg\n)\n{\n    \nos_eventq_put\n(\nmy_eventq\n, \ngpio_ev\n);\n}\n\n\nvoid\n\n\ngen_task\n(\nvoid\n \n*arg\n)\n{\n    \nwhile\n (\n1\n) {\n        \nos_time_delay\n(\nOS_TICKS_PER_SEC\n \n/\n \n4\n);\n        \nos_eventq_put\n(\nmy_eventq\n, \ngen_task_ev\n);\n    }\n}\n\n\nvoid\n\n\ninit_tasks\n(\nvoid\n)\n{\n    \nos_eventq_init\n(\nmy_eventq\n);\n    \nos_task_init\n(\nmy_task_str\n, \ntask\n, \nmy_task\n, \nNULL\n, \nMY_TASK_PRIO\n,\n        \nOS_WAIT_FOREVER\n, \nmy_task_stack\n, \nMY_TASK_STACK_SZ\n);\n\n    \ngen_task_ev\n.\nev_type\n \n=\n \nMY_TASK_TASK_EVENT\n;\n    \nos_task_init\n(\ngen_task
 _str\n, \ngen_task\n, \ngen_task\n, \nNULL\n, \nGEN_TASK_PRIO\n,\n        \nOS_WAIT_FOREVER\n, \ngen_task_stack\n, \nGEN_TASK_STACK_SZ\n);\n\n    \nos_callout_init\n(\nmy_callout\n, \nmy_eventq\n, \nNULL\n);\n    \nos_callout_reset\n(\nmy_callout\n, \nOS_TICKS_PER_SEC\n);\n\n    \ngpio_ev\n.\nev_type\n \n=\n \nMY_TASK_GPIO_EVENT\n;\n    \nhal_gpio_irq_init\n(\n0\n, \nmy_gpio_irq\n, \nNULL\n, \nGPIO_TRIG_RISING\n,\n        \nGPIO_PULL_NONE\n);\n    \nhal_gpio_irq_enable\n(\n0\n);\n\n    \nhal_gpio_init_out\n(\nTASK_LED\n, \n1\n);\n    \nhal_gpio_init_out\n(\nCALLOUT_LED\n, \n1\n);\n    \nhal_gpio_init_out\n(\nGPIO_LED\n, \n1\n);\n}\n\n\nint\n\n\nmain\n(\nint\n \nargc\n, \nchar\n \n**argv\n)\n{\n    \nos_init\n();\n\n    \ninit_tasks\n();\n    \nos_start\n();\n    \nassert\n(\n0\n);\n    \nreturn\n \n0\n;\n}", 
             "title": "Add task to manage multiple events"
@@ -1966,6 +1916,146 @@
             "title": "Start btmgmt to send commands"
         }, 
         {
+            "location": "/os/tutorials/air_quality_sensor/", 
+            "text": "Air quality sensor project\n\n\nSetting up source tree for stuff you need\n\n\nTo start with, you need to create a new project under which you will do this development. So you type in:\n\n\n    $ mkdir $HOME/src\n    $ cd $HOME/src\n    $ newt new air_quality\n\n\n\n\n\nLet's say you are using Arduino Primo -- which is based on the Nordic Semi NRF52 chip -- as the platform. \nYou know you need the board support package for that hardware. You can look up its location, add it your \nproject, and fetch that along with the core OS components. Luckily, the Arduino Primo is supported in the \nMynewt Core, so there's nothing much to do here. \n\n\nYour project.yml file should loo

<TRUNCATED>