Changes between Version 1 and Version 2 of Android/GateworksUtil


Ignore:
Timestamp:
10/30/2017 11:20:23 PM (7 years ago)
Author:
Tim Harvey
Comment:

convert restored html to wiki markup

Legend:

Unmodified
Added
Removed
Modified
  • Android/GateworksUtil

    v1 v2  
    1 {{{#!html
    2           <div id="wikipage" class="trac-content"><p>
    3 </p><div class="wiki-toc">
    4 <ol>
    5   <li>
    6     <a href="#GateworksUtilityLibrary">Gateworks Utility Library</a>
    7     <ol>
    8       <li>
    9         <a href="#Overview">Overview</a>
    10       </li>
    11       <li>
    12         <a href="#Requirements">Requirements</a>
    13         <ol>
    14           <li>
    15             <a href="#Exporting">Exporting</a>
    16           </li>
    17           <li>
    18             <a href="#Registering">Registering</a>
    19           </li>
    20         </ol>
    21       </li>
    22       <li>
    23         <a href="#CodeExamples">Code Examples</a>
    24       </li>
    25       <li>
    26         <a href="#Attachments">Attachments</a>
    27       </li>
    28     </ol>
    29   </li>
    30 </ol>
    31 </div><p>
    32 </p>
    33 <h1 id="GateworksUtilityLibrary">Gateworks Utility Library</h1>
    34 <p>
    35 <span class="wikianchor" id="overview"></span>
    36 </p>
    37 <h2 id="Overview">Overview</h2>
    38 <p>
     1[[PageOutline]]
     2
     3= Gateworks Utility Library =
     4
     5== Overview ==
    396In order to provide users with easy access to the ventana family's low level linux functionality, Gateworks has composed a java library that exposes some simple methods for interacting with LEDs, GPIOs, PWMs, and hardware monitors that have been exported and registered in the android property system.
    40 </p>
    41 <p>
    42 The source for the library is available on Github at <a class="ext-link" href="https://github.com/Gateworks/android_packages_apps_gateworksutil"><span class="icon">​</span>Gateworks/android_packatges_apps_gateworksutil</a> and the javadoc created api documentation can be found <a class="ext-link" href="http://dev.gateworks.com/docs/android/GateworksUtil/"><span class="icon">​</span>here</a>.
    43 </p>
    44 <p>
    45 <span class="wikianchor" id="requirements"></span>
    46 </p>
    47 <h2 id="Requirements">Requirements</h2>
    48 <p>
    49 In order for the library to function as intended, all low level controllers must be both <strong>exported</strong> and <strong>registered</strong> prior to runtime.
    50 </p>
    51 <p>
    52 Note that this is done by the Gateworks Android init script  <a class="ext-link" href="https://github.com/Gateworks/android_device_gateworks/blob/imx_kk4.4.3_2.0.0-beta/ventana/init.sh"><span class="icon">​</span>/device/gateworks/ventana/init.sh</a> which is installed to /system/bin/init.sh and run as root on bootup for the standard resources on the various Ventana boards.
    53 </p>
    54 <p>
    55 <span class="wikianchor" id="exporting"></span>
    56 </p>
    57 <h3 id="Exporting">Exporting</h3>
    58 <p>
     7
     8The source for the library is available on Github at [https://github.com/Gateworks/android_packages_apps_gateworksutil ​Gateworks/android_packatges_apps_gateworksutil] and the javadoc created api documentation can be found [http://dev.gateworks.com/docs/android/GateworksUtil/ here].
     9
     10
     11== Requirements ==
     12In order for the library to function as intended, all low level controllers must be both '''exported''' and '''registered''' prior to runtime.
     13
     14Note that this is done by the Gateworks Android init script ​/device/gateworks/ventana/init.sh which is installed to /system/bin/init.sh and run as root on bootup for the standard resources on the various Ventana boards.
     15
     16=== Exporting ===
    5917Since the GateworksUtil library depends on access to the controller's associated sysfs structure, all GPIOs, PWMs, and LEDs must first be exported to userspace before they can be used. For further information on exporting see the following pages:
    60 </p>
    61 <ul><li><a class="wiki" href="/wiki/gpio#gpiolib_sysfs">GPIO</a>
    62 </li><li><a class="wiki" href="/wiki/linux/pwm">PWM</a>
    63 </li><li><a class="wiki" href="/wiki/gpio#led">LED</a>
    64 </li></ul><p>
    65 <span class="wikianchor" id="registering"></span>
    66 </p>
    67 <h3 id="Registering">Registering</h3>
    68 <p>
     18 * [wiki:gpio#gpiolib_sysfs GPIO]
     19 * [wiki:linux/pwm PWM]
     20 * [wiki:gpio#led LED]
     21
     22
     23=== Registering ===
    6924In addition, the low level controllers being used must also be registered in the Android System Property list. This can be done a number of ways:
    70 </p>
    71 <ol><li>The command line tool setprop via <tt>setprop my.property value</tt>
    72 </li><li>Modifying the <a class="ext-link" href="https://github.com/Gateworks/android_device_gateworks/blob/imx_kk4.4.3_2.0.0-beta/ventana/init.sh"><span class="icon">​</span>/device/gateworks/ventana/init.sh</a> script of the device to register a new controller
    73 </li><li>With native C function <tt>property_get</tt> from system/core/include/cutils/properties.h
    74 </li><li>With the java class <tt>android.os.SystemProperties</tt> (see <a class="ext-link" href="https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/os/SystemProperties.java"><span class="icon">​</span>Android Google Source</a>)
    75 </li></ol><p>
    76 *Note: the android.os.SystemProperties class is only accessible to the internal android source SDK.
    77 </p>
    78 <p>
    79 For further information on registering see the <a class="wiki" href="/wiki/Android/OSDevelopment#AndroidProperties">Android Properties</a> section of the <a class="wiki" href="/wiki/Android/OSDevelopment">Android OS Development</a> page.
    80 </p>
    81 <h2 id="CodeExamples">Code Examples</h2>
    82 <p>
    83 While the full source for the library is available on Github at <a class="ext-link" href="https://github.com/Gateworks/android_packages_apps_gateworksutil"><span class="icon">​</span>Gateworks/android_packatges_apps_gateworksutil</a> and the javadoc created api documentation can be found <a class="ext-link" href="http://dev.gateworks.com/docs/android/GateworksUtil/"><span class="icon">​</span>here</a> sometimes a few simple examples can be extremely helpful.
    84 </p>
    85 <p>
     251. The command line tool setprop via {{{setprop my.property}}} value
     262. Modifying the ​[https://github.com/Gateworks/android_device_gateworks/blob/imx_kk4.4.3_2.0.0-beta/ventana/init.sh /device/gateworks/ventana/init.sh] script of the device to register a new controller
     273. With native C function {{{property_get}}} from system/core/include/cutils/properties.h
     284. With the java class {{{android.os.SystemProperties}}} (see ​[https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/os/SystemProperties.java Android Google Source])
     29 * Note: the {{{android.os.SystemProperties}}} class is only accessible to the internal android source SDK.
     30
     31For further information on registering see the [wiki:Android/OSDevelopment#AndroidProperties Android Properties] section of the [wiki:Android/OSDevelopment Android OS Development] page.
     32
     33
     34== Code Examples ==
     35While the full source for the library is available on Github at [https://github.com/Gateworks/android_packages_apps_gateworksutil ​Gateworks/android_packatges_apps_gateworksutil] and the javadoc created api documentation can be found ​[http://dev.gateworks.com/docs/android/GateworksUtil/ here] sometimes a few simple examples can be extremely helpful.
     36
    8637Code snippets and notes:
    87 </p>
    88 <ul><li>be sure add the <a class="wiki" href="/wiki/Android/GateworksUtil">GateworksUtil</a>.jar library to your project (copy it to the <tt>libs</tt> directory and tell Android Studio to add it as a library)
    89 </li><li>be sure to import it's classes so that your code has access to them:
    90 <div class="code"><pre><span class="kn">import</span> <span class="nn">com.gateworks.gateworksutil.*</span><span class="o">;</span>
    91 </pre></div></li><li>Hardware monitor values:
    92 <ul><li>to see available hwmon values:
    93 <div class="code"><pre> adb shell getprop | grep hw.hwmon
    94 <span class="o">[</span>hw.hwmon.gsc_3p3<span class="o">]</span>: <span class="o">[</span>/sys/class/hwmon/hwmon1/device/in1_input<span class="o">]</span>
    95 <span class="o">[</span>hw.hwmon.gsc_5p0<span class="o">]</span>: <span class="o">[</span>/sys/class/hwmon/hwmon1/device/in3_input<span class="o">]</span>
    96 <span class="o">[</span>hw.hwmon.gsc_bat<span class="o">]</span>: <span class="o">[</span>/sys/class/hwmon/hwmon1/device/in2_input<span class="o">]</span>
    97 <span class="o">[</span>hw.hwmon.gsc_core<span class="o">]</span>: <span class="o">[</span>/sys/class/hwmon/hwmon1/device/in4_input<span class="o">]</span>
    98 <span class="o">[</span>hw.hwmon.gsc_cpu1<span class="o">]</span>: <span class="o">[</span>/sys/class/hwmon/hwmon1/device/in5_input<span class="o">]</span>
    99 <span class="o">[</span>hw.hwmon.gsc_cpu2<span class="o">]</span>: <span class="o">[</span>/sys/class/hwmon/hwmon1/device/in6_input<span class="o">]</span>
    100 <span class="o">[</span>hw.hwmon.gsc_current<span class="o">]</span>: <span class="o">[</span>/sys/class/hwmon/hwmon1/device/in12_input<span class="o">]</span>
    101 <span class="o">[</span>hw.hwmon.gsc_dram<span class="o">]</span>: <span class="o">[</span>/sys/class/hwmon/hwmon1/device/in7_input<span class="o">]</span>
    102 <span class="o">[</span>hw.hwmon.gsc_ext_bat<span class="o">]</span>: <span class="o">[</span>/sys/class/hwmon/hwmon1/device/in8_input<span class="o">]</span>
    103 <span class="o">[</span>hw.hwmon.gsc_io1<span class="o">]</span>: <span class="o">[</span>/sys/class/hwmon/hwmon1/device/in9_input<span class="o">]</span>
    104 <span class="o">[</span>hw.hwmon.gsc_io2<span class="o">]</span>: <span class="o">[</span>/sys/class/hwmon/hwmon1/device/in10_input<span class="o">]</span>
    105 <span class="o">[</span>hw.hwmon.gsc_pci2<span class="o">]</span>: <span class="o">[</span>/sys/class/hwmon/hwmon1/device/in11_input<span class="o">]</span>
    106 <span class="o">[</span>hw.hwmon.gsc_temp<span class="o">]</span>: <span class="o">[</span>/sys/class/hwmon/hwmon1/device/temp0_input<span class="o">]</span>
    107 <span class="o">[</span>hw.hwmon.gsc_vin<span class="o">]</span>: <span class="o">[</span>/sys/class/hwmon/hwmon1/device/in0_input<span class="o">]</span>
    108 <span class="o">[</span>hw.hwmon.imx_cpu_crit_temp<span class="o">]</span>: <span class="o">[</span>/sys/class/hwmon/hwmon2/temp1_crit<span class="o">]</span>
    109 <span class="o">[</span>hw.hwmon.imx_cpu_temp<span class="o">]</span>: <span class="o">[</span>/sys/class/hwmon/hwmon2/temp1_input<span class="o">]</span>
    110 </pre></div></li><li>to get value of the Gateworks System Controller provided 'vin' (Voltage Input):
    111 <div class="code"><pre><span class="kt">int</span> vin <span class="o">=</span> HardwareMonitor<span class="o">.</span><span class="na">getHwmonValue</span><span class="o">(</span><span class="s">"gsc_vin"</span><span class="o">));</span>
    112 </pre></div></li><li>to get value of the IMX6 provided 'cpu_temp' (CPU temperature):
    113 <div class="code"><pre><span class="kt">int</span> vin <span class="o">=</span> HardwareMonitor<span class="o">.</span><span class="na">getHwmonValue</span><span class="o">(</span><span class="s">"imx_cpu_temp"</span><span class="o">));</span>
    114 </pre></div></li></ul></li><li>GPIO values:
    115 <ul><li>to see available exported/registered GPIOs:
    116 <div class="code"><pre>adb shell getprop | grep hw.gpio
    117 <span class="o">[</span>hw.gpio.can_stby<span class="o">]</span>: <span class="o">[</span>/sys/class/gpio/gpio2/<span class="o">]</span>
    118 <span class="o">[</span>hw.gpio.dio0<span class="o">]</span>: <span class="o">[</span>/sys/class/gpio/gpio9/<span class="o">]</span>
    119 <span class="o">[</span>hw.gpio.dio1<span class="o">]</span>: <span class="o">[</span>/sys/class/gpio/gpio19/<span class="o">]</span>
    120 <span class="o">[</span>hw.gpio.dio2<span class="o">]</span>: <span class="o">[</span>/sys/class/gpio/gpio41/<span class="o">]</span>
    121 </pre></div></li><li>to set DIO0 direction and read its value:
    122 <div class="code"><pre>setGpioDirection<span class="o">(</span><span class="s">"dio0"</span><span class="o">,</span> IN<span class="o">);</span>
    123 <span class="kt">int</span> <span class="nf">getGpioValue</span><span class="o">(</span><span class="s">"dio0"</span><span class="o">);</span>
    124 </pre></div></li><li>to set DIO1 as an output level high:
    125 <div class="code"><pre>setGpioDirection<span class="o">(</span><span class="s">"dio1"</span><span class="o">,</span> OUT<span class="o">);</span>
    126 setGpioValue<span class="o">(</span><span class="s">"dio1"</span><span class="o">,</span> <span class="mi">1</span><span class="o">);</span>
    127 </pre></div></li></ul></li><li>LED values:
    128 <ul><li>to see available exported/registered LEDs:
    129 <div class="code"><pre>adb shell getprop | grep hw.led
    130 <span class="o">[</span>hw.led.frontgreen<span class="o">]</span>: <span class="o">[</span>/sys/class/leds/user1/<span class="o">]</span>
    131 <span class="o">[</span>hw.led.frontred<span class="o">]</span>: <span class="o">[</span>/sys/class/leds/user2/<span class="o">]</span>
    132 <span class="o">[</span>hw.led.local<span class="o">]</span>: <span class="o">[</span>/sys/class/leds/user3/<span class="o">]</span>
    133 </pre></div></li><li>to set the front panel green LED to no automatic trigger and off state:
    134 <div class="code"><pre>setLedtrigger<span class="o">(</span><span class="s">"none"</span><span class="o">,</span> <span class="mi">0</span><span class="o">);</span>
    135 setLedValue<span class="o">(</span><span class="s">"frontgreen"</span><span class="o">,</span> <span class="mi">0</span><span class="o">);</span>
    136 </pre></div></li><li>to set the front panel green LED to an automatic 'heartbeat' trigger
    137 <div class="code"><pre>setLedTrigger<span class="o">(</span><span class="s">"frontgreen"</span><span class="o">,</span> <span class="s">"heartbeat"</span><span class="o">);</span>
    138 </pre></div></li></ul></li><li>PWM values:
    139 <ul><li>to see available exported/registered PWMs:
    140 <div class="code"><pre>adb shell getprop | grep hw.pwm
    141 <span class="o">[</span>hw.pwm.pwm2<span class="o">]</span>: <span class="o">[</span>/sys/class/pwm/pwmchip0/pwm0/<span class="o">]</span>
    142 </pre></div></li><li>to set pwm2 for a 1000ns period and 50% duty cycle and enable it:
    143 <div class="code"><pre>setPeriod<span class="o">(</span><span class="s">"pwm2"</span><span class="o">,</span> <span class="mi">1000</span><span class="o">);</span>
    144 setDutyCycle<span class="o">(</span><span class="s">"pwm2"</span><span class="o">,</span> <span class="mi">50</span><span class="o">);</span>
    145 setPolarity<span class="o">(</span><span class="s">"pwm2"</span><span class="o">,</span> NORMAL<span class="o">);</span>
    146 setEnabled<span class="o">(</span><span class="s">"pwm2"</span><span class="o">,</span> <span class="mi">1</span><span class="o">);</span>
    147 </pre></div></li></ul></li></ul><p>
    148 <span class="wikianchor" id="attachments"></span>
    149 </p>
    150 <h2 id="Attachments">Attachments</h2>
    151 <p>
    152 The file links below include the following:
    153 </p>
    154 <ul><li><a class="attachment" href="/attachment/wiki/Android/GateworksUtil/GateworksUtil.jar" title="Attachment 'GateworksUtil.jar' in Android/GateworksUtil">GateworksUtil.jar</a><a class="trac-rawlink" href="/raw-attachment/wiki/Android/GateworksUtil/GateworksUtil.jar" title="Download">​</a> - The precompiled binary for importing into an android project
    155 </li></ul
     38 * be sure add the GateworksUtil.jar library to your project (copy it to the libs directory and tell Android Studio to add it as a library)
     39 * be sure to import it's classes so that your code has access to them:
     40{{{
     41import com.gateworks.gateworksutil.*;
    15642}}}
     43 * Hardware monitor values:
     44  - to see available hwmon values:
     45{{{#!bash
     46adb shell getprop | grep hw.hwmon
     47[hw.hwmon.gsc_3p3]: [/sys/class/hwmon/hwmon1/device/in1_input]
     48[hw.hwmon.gsc_5p0]: [/sys/class/hwmon/hwmon1/device/in3_input]
     49[hw.hwmon.gsc_bat]: [/sys/class/hwmon/hwmon1/device/in2_input]
     50[hw.hwmon.gsc_core]: [/sys/class/hwmon/hwmon1/device/in4_input]
     51[hw.hwmon.gsc_cpu1]: [/sys/class/hwmon/hwmon1/device/in5_input]
     52[hw.hwmon.gsc_cpu2]: [/sys/class/hwmon/hwmon1/device/in6_input]
     53[hw.hwmon.gsc_current]: [/sys/class/hwmon/hwmon1/device/in12_input]
     54[hw.hwmon.gsc_dram]: [/sys/class/hwmon/hwmon1/device/in7_input]
     55[hw.hwmon.gsc_ext_bat]: [/sys/class/hwmon/hwmon1/device/in8_input]
     56[hw.hwmon.gsc_io1]: [/sys/class/hwmon/hwmon1/device/in9_input]
     57[hw.hwmon.gsc_io2]: [/sys/class/hwmon/hwmon1/device/in10_input]
     58[hw.hwmon.gsc_pci2]: [/sys/class/hwmon/hwmon1/device/in11_input]
     59[hw.hwmon.gsc_temp]: [/sys/class/hwmon/hwmon1/device/temp0_input]
     60[hw.hwmon.gsc_vin]: [/sys/class/hwmon/hwmon1/device/in0_input]
     61[hw.hwmon.imx_cpu_crit_temp]: [/sys/class/hwmon/hwmon2/temp1_crit]
     62[hw.hwmon.imx_cpu_temp]: [/sys/class/hwmon/hwmon2/temp1_input]
     63}}}
     64  - to get value of the Gateworks System Controller provided 'vin' (Voltage Input):
     65{{{
     66int vin = HardwareMonitor.getHwmonValue("gsc_vin"));
     67}}}
     68  - to get value of the IMX6 provided 'cpu_temp' (CPU temperature):
     69{{{
     70int vin = HardwareMonitor.getHwmonValue("imx_cpu_temp"));
     71}}}
     72 * GPIO values:
     73  - to see available exported/registered GPIOs:
     74{{{#!bash
     75adb shell getprop | grep hw.gpio
     76[hw.gpio.can_stby]: [/sys/class/gpio/gpio2/]
     77[hw.gpio.dio0]: [/sys/class/gpio/gpio9/]
     78[hw.gpio.dio1]: [/sys/class/gpio/gpio19/]
     79[hw.gpio.dio2]: [/sys/class/gpio/gpio41/]
     80}}}
     81  - to set DIO0 direction and read its value:
     82{{{
     83setGpioDirection("dio0", IN);
     84int getGpioValue("dio0");
     85}}}
     86  - to set DIO1 as an output level high:
     87{{{
     88setGpioDirection("dio1", OUT);
     89setGpioValue("dio1", 1);
     90}}}
     91 * LED values:
     92  - to see available exported/registered LEDs:
     93{{{
     94adb shell getprop | grep hw.led
     95[hw.led.frontgreen]: [/sys/class/leds/user1/]
     96[hw.led.frontred]: [/sys/class/leds/user2/]
     97[hw.led.local]: [/sys/class/leds/user3/]
     98}}}
     99  - to set the front panel green LED to no automatic trigger and off state:
     100{{{
     101setLedtrigger("none", 0);
     102setLedValue("frontgreen", 0);
     103}}}
     104  - to set the front panel green LED to an automatic 'heartbeat' trigger:
     105{{{
     106setLedTrigger("frontgreen", "heartbeat");
     107}}}
     108 * PWM values:
     109  - to see available exported/registered PWMs:
     110{{{
     111adb shell getprop | grep hw.pwm
     112[hw.pwm.pwm2]: [/sys/class/pwm/pwmchip0/pwm0/]
     113}}}
     114  - to set pwm2 for a 1000ns period and 50% duty cycle and enable it:
     115{{{
     116setPeriod("pwm2", 1000);
     117setDutyCycle("pwm2", 50);
     118setPolarity("pwm2", NORMAL);
     119setEnabled("pwm2", 1);
     120}}}