| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -89,14 +89,9 @@ public static void analogWrite(int pin, int value) { | |||
| 89 | 89 | ||
| 90 | 90 | ||
| 91 | 91 | /** | |
| 92 | - * Calls a function when the value of an INPUT pin changes | ||
| 93 | - * | ||
| 94 | - * Don't use enableInterrupt() and waitForInterrupt() in combination with | ||
| 95 | - * this function, as they are orthogonal. The sketch method provided must | ||
| 96 | - * accept a single integer (int) parameter, which is the number of the GPIO | ||
| 97 | - * pin that the interrupt occured on. | ||
| 92 | + * Calls a function when the value of an input pin changes | ||
| 98 | 93 | * @param pin GPIO pin | |
| 99 | - * @param parent this | ||
| 94 | + * @param parent typically use "this" | ||
| 100 | 95 | * @param method name of sketch method to call | |
| 101 | 96 | * @param mode when to call: GPIO.CHANGE, GPIO.FALLING or GPIO.RISING | |
| 102 | 97 | * @see noInterrupts | |
@@ -163,7 +158,6 @@ public void run() { | |||
| 163 | 158 | * Board-specific classes, such as RPI, assign -1 to pins that carry power, | |
| 164 | 159 | * ground and the like. | |
| 165 | 160 | * @param pin GPIO pin | |
| 166 | - * @webref | ||
| 167 | 161 | */ | |
| 168 | 162 | protected static void checkValidPin(int pin) { | |
| 169 | 163 | if (pin < 0) { | |
@@ -174,9 +168,6 @@ protected static void checkValidPin(int pin) { | |||
| 174 | 168 | ||
| 175 | 169 | /** | |
| 176 | 170 | * Returns the value of an input pin | |
| 177 | - * | ||
| 178 | - * You need to set the pin to INPUT by calling pinMode before calling | ||
| 179 | - * this function. | ||
| 180 | 171 | * @param pin GPIO pin | |
| 181 | 172 | * @return GPIO.HIGH (1) or GPIO.LOW (0) | |
| 182 | 173 | * @see pinMode | |
@@ -207,14 +198,9 @@ public static int digitalRead(int pin) { | |||
| 207 | 198 | ||
| 208 | 199 | ||
| 209 | 200 | /** | |
| 210 | - * Sets an output pin to HIGH or LOW | ||
| 211 | - * | ||
| 212 | - * You need set the pin to OUTPUT by calling pinMode before calling this | ||
| 213 | - * function. It is not possible to enable or disable internal pull-up | ||
| 214 | - * resistors for inputs using this function, which is something that's | ||
| 215 | - * supported on Arduino. | ||
| 201 | + * Sets an output pin to be either high or low | ||
| 216 | 202 | * @param pin GPIO pin | |
| 217 | - * @param value GPIO.HIGH or GPIO.LOW | ||
| 203 | + * @param value GPIO.HIGH (1) or GPIO.LOW (0) | ||
| 218 | 204 | * @see pinMode | |
| 219 | 205 | * @see digitalRead | |
| 220 | 206 | * @webref | |
@@ -247,17 +233,7 @@ public static void digitalWrite(int pin, int value) { | |||
| 247 | 233 | ||
| 248 | 234 | ||
| 249 | 235 | /** | |
| 250 | - * Sets an output pin to HIGH or LOW | ||
| 251 | - * | ||
| 252 | - * You need set the pin to OUTPUT by calling pinMode before calling this | ||
| 253 | - * function. It is not possible to enable or disable internal pull-up | ||
| 254 | - * resistors for inputs using this function, which is something that's | ||
| 255 | - * supported on Arduino. | ||
| 256 | - * @param pin GPIO pin | ||
| 257 | 236 | * @param value true or false | |
| 258 | - * @see pinMode | ||
| 259 | - * @see digitalRead | ||
| 260 | - * @webref | ||
| 261 | 237 | */ | |
| 262 | 238 | public static void digitalWrite(int pin, boolean value) { | |
| 263 | 239 | if (value) { | |
@@ -269,33 +245,24 @@ public static void digitalWrite(int pin, boolean value) { | |||
| 269 | 245 | ||
| 270 | 246 | ||
| 271 | 247 | /** | |
| 272 | - * Disables an interrupt for an INPUT pin | ||
| 273 | - * | ||
| 274 | - * Use this function only in combination with enableInterrupt() and | ||
| 275 | - * waitForInterrupt(). This should not be called when attachInterrupt() | ||
| 276 | - * is being used. | ||
| 248 | + * Disables an interrupt for an input pin | ||
| 277 | 249 | * @param pin GPIO pin | |
| 278 | 250 | * @see enableInterrupt | |
| 279 | 251 | * @see waitForInterrupt | |
| 280 | - * @webref | ||
| 281 | 252 | */ | |
| 282 | - public static void disableInterrupt(int pin) { | ||
| 253 | + protected static void disableInterrupt(int pin) { | ||
| 283 | 254 | enableInterrupt(pin, NONE); | |
| 284 | 255 | } | |
| 285 | 256 | ||
| 286 | 257 | ||
| 287 | 258 | /** | |
| 288 | - * Enables an interrupt for an INPUT pin | ||
| 289 | - * | ||
| 290 | - * Use this function only when calling waitForInterrupt(). This should not | ||
| 291 | - * be called when attachInterrupt() is being used. | ||
| 259 | + * Enables an interrupt for an input pin | ||
| 292 | 260 | * @param pin GPIO pin | |
| 293 | 261 | * @param mode what to wait for: GPIO.CHANGE, GPIO.FALLING or GPIO.RISING | |
| 294 | 262 | * @see waitForInterrupt | |
| 295 | 263 | * @see disableInterrupt | |
| 296 | - * @webref | ||
| 297 | 264 | */ | |
| 298 | - public static void enableInterrupt(int pin, int mode) { | ||
| 265 | + protected static void enableInterrupt(int pin, int mode) { | ||
| 299 | 266 | checkValidPin(pin); | |
| 300 | 267 | ||
| 301 | 268 | String out; | |
@@ -324,11 +291,6 @@ public static void enableInterrupt(int pin, int mode) { | |||
| 324 | 291 | ||
| 325 | 292 | /** | |
| 326 | 293 | * Allows interrupts to happen | |
| 327 | - * | ||
| 328 | - * You can use noInterrupts() and interrupts() in tandem to make sure no interrupts | ||
| 329 | - * are occuring while your sketch is doing a particular task. This is only relevant | ||
| 330 | - * when using attachInterrupt(), not for waitForInterrupt(). By default, interrupts | ||
| 331 | - * are enabled. | ||
| 332 | 294 | * @see attachInterrupt | |
| 333 | 295 | * @see noInterrupts | |
| 334 | 296 | * @see releaseInterrupt | |
@@ -341,11 +303,6 @@ public static void interrupts() { | |||
| 341 | 303 | ||
| 342 | 304 | /** | |
| 343 | 305 | * Prevents interrupts from happpening | |
| 344 | - * | ||
| 345 | - * You can use noInterrupts() and interrupts() in tandem to make sure no interrupts | ||
| 346 | - * are occuring while your sketch is doing a particular task. This is only relevant | ||
| 347 | - * when using attachInterrupt(), not for waitForInterrupt(). By default, interrupts | ||
| 348 | - * are enabled. | ||
| 349 | 306 | * @see attachInterrupt | |
| 350 | 307 | * @see interrupts | |
| 351 | 308 | * @see releaseInterrupt | |
@@ -357,11 +314,7 @@ public static void noInterrupts() { | |||
| 357 | 314 | ||
| 358 | 315 | ||
| 359 | 316 | /** | |
| 360 | - * Sets a pin to INPUT or OUTPUT | ||
| 361 | - * | ||
| 362 | - * While pins are implicitly set to input by default on Arduino, it is | ||
| 363 | - * necessary to call this function for any pin you want to access later, | ||
| 364 | - * including input pins. | ||
| 317 | + * Configures a pin to act either as input or output | ||
| 365 | 318 | * @param pin GPIO pin | |
| 366 | 319 | * @param mode GPIO.INPUT or GPIO.OUTPUT | |
| 367 | 320 | * @see digitalRead | |
@@ -421,10 +374,7 @@ public static void pinMode(int pin, int mode) { | |||
| 421 | 374 | ||
| 422 | 375 | ||
| 423 | 376 | /** | |
| 424 | - * Stops listening for interrupts on an INPUT pin | ||
| 425 | - * | ||
| 426 | - * Use this function only in combination with attachInterrupt(). This should | ||
| 427 | - * not be called when enableInterrupt() and waitForInterrupt() are being used. | ||
| 377 | + * Stops listening for interrupts on an input pin | ||
| 428 | 378 | * @param pin GPIO pin | |
| 429 | 379 | * @see attachInterrupt | |
| 430 | 380 | * @see noInterrupts | |
@@ -452,9 +402,6 @@ public static void releaseInterrupt(int pin) { | |||
| 452 | 402 | ||
| 453 | 403 | /** | |
| 454 | 404 | * Gives ownership of a pin back to the operating system | |
| 455 | - * | ||
| 456 | - * Without calling this function the pin will remain in the current | ||
| 457 | - * state even after the sketch has been closed. | ||
| 458 | 405 | * @param pin GPIO pin | |
| 459 | 406 | * @see pinMode | |
| 460 | 407 | * @webref | |
@@ -477,7 +424,21 @@ public static void releasePin(int pin) { | |||
| 477 | 424 | ||
| 478 | 425 | ||
| 479 | 426 | /** | |
| 480 | - * Waits for the value of an INPUT pin to change | ||
| 427 | + * Waits for the value of an input pin to change | ||
| 428 | + * @param pin GPIO pin | ||
| 429 | + * @param mode what to wait for: GPIO.CHANGE, GPIO.FALLING or GPIO.RISING | ||
| 430 | + * @param timeout don't wait more than timeout milliseconds (-1 waits indefinitely) | ||
| 431 | + * @return true if the interrupt occured, false if the timeout occured | ||
| 432 | + * @webref | ||
| 433 | + */ | ||
| 434 | + public static boolean waitForInterrupt(int pin, int mode, int timeout) { | ||
| 435 | + enableInterrupt(pin, mode); | ||
| 436 | + return waitForInterrupt(pin, timeout); | ||
| 437 | + } | ||
| 438 | + | ||
| 439 | + | ||
| 440 | + /** | ||
| 441 | + * Waits for the value of an input pin to change | ||
| 481 | 442 | * | |
| 482 | 443 | * Make sure to setup the interrupt with enableInterrupt() before calling | |
| 483 | 444 | * this function. A timeout value of -1 waits indefinitely. | |
@@ -486,9 +447,8 @@ public static void releasePin(int pin) { | |||
| 486 | 447 | * @return true if the interrupt occured, false if the timeout occured | |
| 487 | 448 | * @see enableInterrupt | |
| 488 | 449 | * @see disableInterrupt | |
| 489 | - * @webref | ||
| 490 | 450 | */ | |
| 491 | - public static boolean waitForInterrupt(int pin, int timeout) { | ||
| 451 | + protected static boolean waitForInterrupt(int pin, int timeout) { | ||
| 492 | 452 | checkValidPin(pin); | |
| 493 | 453 | ||
| 494 | 454 | String fn = String.format("/sys/class/gpio/gpio%d/value", pin); | |
@@ -509,17 +469,16 @@ public static boolean waitForInterrupt(int pin, int timeout) { | |||
| 509 | 469 | ||
| 510 | 470 | ||
| 511 | 471 | /** | |
| 512 | - * Waits for the value of an INPUT pin to change | ||
| 472 | + * Waits for the value of an input pin to change | ||
| 513 | 473 | * | |
| 514 | 474 | * Make sure to setup the interrupt with enableInterrupt() before calling | |
| 515 | 475 | * this function. This function will wait indefinitely for an interrupt | |
| 516 | 476 | * to occur. | |
| 517 | 477 | * @parm pin GPIO pin | |
| 518 | 478 | * @see enableInterrupt | |
| 519 | 479 | * @see disableInterrupt | |
| 520 | - * @webref | ||
| 521 | 480 | */ | |
| 522 | - public static void waitForInterrupt(int pin) { | ||
| 481 | + protected static void waitForInterrupt(int pin) { | ||
| 523 | 482 | waitForInterrupt(pin, -1); | |
| 524 | 483 | } | |
| 525 | 484 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -42,9 +42,8 @@ public class I2C { | |||
| 42 | 42 | ||
| 43 | 43 | ||
| 44 | 44 | /** | |
| 45 | - * Opens an I2C device as master | ||
| 46 | - * | ||
| 47 | - * @param dev device name | ||
| 45 | + * Opens an I2C interface as master | ||
| 46 | + * @param dev interface name | ||
| 48 | 47 | * @see list | |
| 49 | 48 | * @webref | |
| 50 | 49 | */ | |
@@ -60,19 +59,6 @@ public I2C(String dev) { | |||
| 60 | 59 | ||
| 61 | 60 | /** | |
| 62 | 61 | * Begins a transmission to an attached device | |
| 63 | - * | ||
| 64 | - * I2C addresses consist of 7 bits plus one bit that indicates whether | ||
| 65 | - * the device is being read from or written to. Some datasheets list | ||
| 66 | - * the address in an 8 bit form (7 address bits + R/W bit), while others | ||
| 67 | - * provide the address in a 7 bit form, with the address in the lower | ||
| 68 | - * 7 bits. This function expects the address in the lower 7 bits, the | ||
| 69 | - * same way as in Arduino's Wire library, and as shown in the output | ||
| 70 | - * of the i2cdetect tool. | ||
| 71 | - * If the address provided in a datasheet is greater than 127 (hex 0x7f) | ||
| 72 | - * or there are separate addresses for read and write operations listed, | ||
| 73 | - * which vary exactly by one, then you want to shift the this number by | ||
| 74 | - * one bit to the right before passing it as an argument to this function. | ||
| 75 | - * @param slave 7 bit address of slave device | ||
| 76 | 62 | * @see write | |
| 77 | 63 | * @see read | |
| 78 | 64 | * @see endTransmission | |
@@ -111,8 +97,6 @@ protected void finalize() throws Throwable { | |||
| 111 | 97 | ||
| 112 | 98 | /** | |
| 113 | 99 | * Ends the current transmissions | |
| 114 | - * | ||
| 115 | - * This executes any queued writes. | ||
| 116 | 100 | * @see beginTransmission | |
| 117 | 101 | * @see write | |
| 118 | 102 | * @webref | |
@@ -137,7 +121,7 @@ public void endTransmission() { | |||
| 137 | 121 | ||
| 138 | 122 | ||
| 139 | 123 | /** | |
| 140 | - * Lists all available I2C devices | ||
| 124 | + * Lists all available I2C interfaces | ||
| 141 | 125 | * @return String array | |
| 142 | 126 | * @webref | |
| 143 | 127 | */ | |
@@ -161,10 +145,6 @@ public static String[] list() { | |||
| 161 | 145 | ||
| 162 | 146 | /** | |
| 163 | 147 | * Reads bytes from the attached device | |
| 164 | - * | ||
| 165 | - * You must call beginTransmission() before calling this function. This function | ||
| 166 | - * also ends the current transmisison and sends any data that was queued using | ||
| 167 | - * write() before. | ||
| 168 | 148 | * @param len number of bytes to read | |
| 169 | 149 | * @return bytes read from device | |
| 170 | 150 | * @see beginTransmission | |
@@ -195,10 +175,6 @@ public byte[] read(int len) { | |||
| 195 | 175 | ||
| 196 | 176 | /** | |
| 197 | 177 | * Adds bytes to be written to the device | |
| 198 | - * | ||
| 199 | - * You must call beginTransmission() before calling this function. | ||
| 200 | - * The actual writing takes part when read() or endTransmission() is being | ||
| 201 | - * called. | ||
| 202 | 178 | * @param out bytes to be written | |
| 203 | 179 | * @see beginTransmission | |
| 204 | 180 | * @see read | |
@@ -222,33 +198,23 @@ public void write(byte[] out) { | |||
| 222 | 198 | ||
| 223 | 199 | ||
| 224 | 200 | /** | |
| 225 | - * Adds bytes to be written to the device | ||
| 226 | - * | ||
| 227 | - * You must call beginTransmission() before calling this function. | ||
| 228 | - * The actual writing takes part when read() or endTransmission() is being | ||
| 229 | - * called. | ||
| 201 | + * Adds bytes to be written to the attached device | ||
| 230 | 202 | * @param out string to be written | |
| 231 | 203 | * @see beginTransmission | |
| 232 | 204 | * @see read | |
| 233 | 205 | * @see endTransmission | |
| 234 | - * @webref | ||
| 235 | 206 | */ | |
| 236 | 207 | public void write(String out) { | |
| 237 | 208 | write(out.getBytes()); | |
| 238 | 209 | } | |
| 239 | 210 | ||
| 240 | 211 | ||
| 241 | 212 | /** | |
| 242 | - * Adds a byte to be written to the device | ||
| 243 | - * | ||
| 244 | - * You must call beginTransmission() before calling this function. | ||
| 245 | - * The actual writing takes part when read() or endTransmission() is being | ||
| 246 | - * called. | ||
| 213 | + * Adds a byte to be written to the attached device | ||
| 247 | 214 | * @param out single byte to be written (0-255) | |
| 248 | 215 | * @see beginTransmission | |
| 249 | 216 | * @see read | |
| 250 | 217 | * @see endTransmission | |
| 251 | - * @webref | ||
| 252 | 218 | */ | |
| 253 | 219 | public void write(int out) { | |
| 254 | 220 | if (out < 0 || 255 < out) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -119,9 +119,6 @@ public void brightness(float bright) { | |||
| 119 | 119 | ||
| 120 | 120 | /** | |
| 121 | 121 | * Restores the previous state | |
| 122 | - * | ||
| 123 | - * Without calling this function the LED will remain in the current | ||
| 124 | - * state even after the sketch has been closed. | ||
| 125 | 122 | * @webref | |
| 126 | 123 | */ | |
| 127 | 124 | public void close() { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -99,9 +99,6 @@ public void clear() { | |||
| 99 | 99 | ||
| 100 | 100 | /** | |
| 101 | 101 | * Gives ownership of a channel back to the operating system | |
| 102 | - * | ||
| 103 | - * Without calling this function the channel will remain in the current | ||
| 104 | - * state even after the sketch has been closed. | ||
| 105 | 102 | * @webref | |
| 106 | 103 | */ | |
| 107 | 104 | public void close() { | |
@@ -187,10 +184,6 @@ public void set(int period, float duty) { | |||
| 187 | 184 | ||
| 188 | 185 | /** | |
| 189 | 186 | * Enables the PWM output with a preset period of 1 kHz | |
| 190 | - * | ||
| 191 | - * This period approximately matches the dedicated PWM pins on | ||
| 192 | - * the Arduino Uno, which have a frequency of 980 Hz. | ||
| 193 | - * It is recommended to use set(period, duty) instead. | ||
| 194 | 187 | * @param duty duty cycle, 0.0 (always off) to 1.0 (always on) | |
| 195 | 188 | * @webref | |
| 196 | 189 | */ | |
| Back | FazBrowse Home | New Git URL |
0 commit comments