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> |
| 25 | 1. The command line tool setprop via {{{setprop my.property}}} value |
| 26 | 2. 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 |
| 27 | 3. With native C function {{{property_get}}} from system/core/include/cutils/properties.h |
| 28 | 4. 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 | |
| 31 | For 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 == |
| 35 | While 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 | |
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 | {{{ |
| 41 | import com.gateworks.gateworksutil.*; |
| 43 | * Hardware monitor values: |
| 44 | - to see available hwmon values: |
| 45 | {{{#!bash |
| 46 | adb 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 | {{{ |
| 66 | int vin = HardwareMonitor.getHwmonValue("gsc_vin")); |
| 67 | }}} |
| 68 | - to get value of the IMX6 provided 'cpu_temp' (CPU temperature): |
| 69 | {{{ |
| 70 | int vin = HardwareMonitor.getHwmonValue("imx_cpu_temp")); |
| 71 | }}} |
| 72 | * GPIO values: |
| 73 | - to see available exported/registered GPIOs: |
| 74 | {{{#!bash |
| 75 | adb 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 | {{{ |
| 83 | setGpioDirection("dio0", IN); |
| 84 | int getGpioValue("dio0"); |
| 85 | }}} |
| 86 | - to set DIO1 as an output level high: |
| 87 | {{{ |
| 88 | setGpioDirection("dio1", OUT); |
| 89 | setGpioValue("dio1", 1); |
| 90 | }}} |
| 91 | * LED values: |
| 92 | - to see available exported/registered LEDs: |
| 93 | {{{ |
| 94 | adb 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 | {{{ |
| 101 | setLedtrigger("none", 0); |
| 102 | setLedValue("frontgreen", 0); |
| 103 | }}} |
| 104 | - to set the front panel green LED to an automatic 'heartbeat' trigger: |
| 105 | {{{ |
| 106 | setLedTrigger("frontgreen", "heartbeat"); |
| 107 | }}} |
| 108 | * PWM values: |
| 109 | - to see available exported/registered PWMs: |
| 110 | {{{ |
| 111 | adb 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 | {{{ |
| 116 | setPeriod("pwm2", 1000); |
| 117 | setDutyCycle("pwm2", 50); |
| 118 | setPolarity("pwm2", NORMAL); |
| 119 | setEnabled("pwm2", 1); |
| 120 | }}} |