Fix ledc, otaupgrade, pulsecnt, sdmmc, sjson, touch docs (#3436)

ledc.md - formatting, add object name
otaupgrade.md - formatting, add 'Syntax' section
pulsecnt.md - formatting, fix syntax pulsecnt.create, add object name
sdmmc.md - fix typos
sjson.md - formatting, add `Parameters` section
touch.md - formatting, add object name, fix Returns in tp:read()
This commit is contained in:
serg3295 2021-05-23 17:29:01 +03:00 committed by GitHub
parent 39dc2e050f
commit 8e0e0cb31c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 165 additions and 158 deletions

View File

@ -49,7 +49,7 @@ List of configuration tables:
- `duty` Channel duty, the duty range is [0, (2**bit_num) - 1]. Example: if ledc.TIMER_13_BIT is used maximum value is 4096 x 2 -1 = 8091
#### Returns
`ledc.channel`
`channel` ledc.channel
#### Example
```lua
@ -79,7 +79,7 @@ Disable LEDC output, and set idle level.
- `ledc.IDLE_HIGH`
#### Returns
nil
`nil`
#### Example
```lua
@ -96,7 +96,7 @@ Set channel frequency (Hz)
- `frequency` What frequency should be set
#### Returns
nil
`nil`
#### Example
```lua
@ -133,7 +133,7 @@ Set channel duty
- `duty` What duty should be set
#### Returns
nil
`nil`
#### Example
```lua
@ -170,7 +170,7 @@ Resets the timer
None
#### Returns
nil
`nil`
#### Example
@ -189,7 +189,7 @@ Pauses the timer
None
#### Returns
nil
`nil`
#### Example
```lua
@ -207,7 +207,7 @@ Resumes a paused timer
None
#### Returns
nil
`nil`
#### Example
```lua
@ -229,7 +229,7 @@ Set LEDC fade function, with a limited time.
- `ledc.FADE_WAIT_DONE`
#### Returns
nil
`nil`
#### Example
```lua
@ -252,7 +252,7 @@ Set LEDC fade function, with step.
- `ledc.FADE_WAIT_DONE`
#### Returns
nil
`nil`
#### Example
```lua
@ -269,8 +269,8 @@ Set LEDC fade function.
#### Parameters
- `duty` Set the start of the gradient duty.
- `direction` Set the direction of the gradient.
- `ledc.FADE_DECREASE`
- `ledc.FADE_INCREASE`
- `ledc.FADE_DECREASE`
- `ledc.FADE_INCREASE`
- `scale` Set gradient change amplitude.
- `cycleNum` Set how many LEDC tick each time the gradient lasts.
- `stepNum` Set the number of the gradient.
@ -279,7 +279,7 @@ Set LEDC fade function.
- `ledc.FADE_WAIT_DONE`
#### Returns
nil
`nil`
#### Example
```lua

View File

@ -54,36 +54,40 @@ marking a new firmware as valid is to ensure the upgrade server can be
reached, on the basis that as long as the firmware can be remotely
upgraded, it's "good enough" to accept.
# otaupgrade.info()
## otaupgrade.info()
The boot info and application state and version info can be queried with
this function. Typically it will be used to check the version of the
running application, to compare against a "desired" version in order
to decide whether an upgrade is required.
#### Syntax
`otaupgrade.info()`
#### Parameters
None.
#### Returns
A list of three values:
- the name of the partition of the running application
- the name of the partition currently marked for boot next (typically the
same as the running application, but after `otaupgrade.complete()` it
may point to a new application partition.
- a table whose keys are the names of OTA partitions and corresponding
values are tables containing:
- `state` one of `new`, `testing`, `valid`, `invalid`, `aborted` or
- `state` one of `new`, `testing`, `valid`, `invalid`, `aborted` or
possibly `undefined`. The values `invalid` and `aborted` largely
mean the same things. See the IDF documentation for specifics.
A partition in `testing` state needs to call `otaupgrade.accept()`
if it wishes to become `valid`.
- `name` the application name, typically "NodeMCU"
- `date` the build date
- `time` the build time
- `version` the build version, as set by the *PROJECT_VER* variable
- `name` the application name, typically "NodeMCU"
- `date` the build date
- `time` the build time
- `version` the build version, as set by the *PROJECT_VER* variable
during build
- `secure_version` the secure version number, if secure boot is enabled
- `idf_version` the IDF version
- `secure_version` the secure version number, if secure boot is enabled
- `idf_version` the IDF version
#### Example
```lua
@ -99,7 +103,7 @@ end
print("Running version: "..info[boot_part].version)
```
# otaupgrade.commence()
## otaupgrade.commence()
Wipes the spare application partition and prepares to receive the new
application firmware.
@ -121,7 +125,7 @@ A Lua error may be raised if the OTA upgrade cannot be commenced for some
reason (such as due to incorrect partition setup).
# otaupgrade.write(data)
## otaupgrade.write(data)
Write a chunk of application firmware data to the correct partition and
location. Data must be streamed sequentially, the IDF does not support
@ -141,7 +145,7 @@ data not being a valid OTA image (the IDF performs some checks in this
regard).
# otaupgrade.complete(reboot)
## otaupgrade.complete(reboot)
Finalises the upgrade, and optionally reboots into the new application
firmware right away.
@ -192,7 +196,7 @@ end)
```
# otaupgrade.accept()
## otaupgrade.accept()
When the installed boot loader is built with rollback support, a new
application image is by default only booted once. During this "test run"
@ -211,7 +215,7 @@ None.
`nil`
# otaupgrade.rollback()
## otaupgrade.rollback()
A new firmware may decide that it is not performing as expected, and
request an explicit rollback to the previous version. If the call to this

View File

@ -14,18 +14,18 @@ a control GPIO for ignoring or decrementing pulses when the control signal is hi
Create the pulse counter object.
### Syntax
`pulsecnt.create(unit, callbackOnEvents)`
#### Syntax
`pulsecnt.create(unit, callbackOnEvents [, isDebug])`
### Parameters
#### Parameters
- `unit` Required. ESP32 has 0 thru 7 units to count pulses on.
- `callbackOnEvents` Optional. Your Lua method to call on event. myfunction(unit, isThr0, isThr1, isLLim, isHLim, isZero) will be called. Event will be PCNT_EVT_THRES_0 (Threshold 0 hit), PCNT_EVT_THRES_1 (Threshold 1 hit), PCNT_EVT_L_LIM (Minimum counter value), PCNT_EVT_H_LIM (Maximum counter value), or PCNT_EVT_ZERO (counter value zero event)
- `isDebug` Optional. Turn on extra logging by passing in true.
### Returns
`pulsecnt` object
#### Returns
`pulsecntObj` pulsecnt object
### Example
#### Example
```lua
-- Example Pulse Counter for 1 channel with polling of pulse count
@ -54,7 +54,7 @@ pcnt:clear()
print("Current pulse counter val:" .. pcnt:getCnt())
```
### Example
#### Example
```lua
-- Example Pulse Counter for 1 channel with callback
@ -104,7 +104,7 @@ pcnt:setThres(thr0, thr1)
print("Current pulse counter val:" .. pcnt:getCnt())
```
### Example
#### Example
```lua
-- Example Pulse Counter for 2 push buttons
-- Button 1 increments the counter (chan0)
@ -184,67 +184,67 @@ pcnt:setThres(thr0, thr1)
Configure channel 0 of the pulse counter object you created from the create() method.
### Syntax
#### Syntax
`pulsecntObj:chan0Config(pulse_gpio_num, ctrl_gpio_num, pos_mode, neg_mode, lctrl_mode, hctrl_mode, counter_l_lim, counter_h_lim)`
### Parameters
#### Parameters
- `pulse_gpio_num` Required. Any GPIO pin can be used.
- `ctrl_gpio_num` Required (although you can specify pulsecnt.PIN_NOT_USED to ignore). Any GPIO pin can be used. If you are trying to use a pin you use as gpio.OUT in other parts of your code, you can instead configure the pin as gpio.IN_OUT and write high or low to it to achieve your gpio.OUT task while still enabling the pulse counter to successfully read the pin state.
- `pos_mode` Required. Positive rising edge count mode, i.e. count the pulse when the rising edge occurs.
- pulsecnt.PCNT_COUNT_DIS = 0 Counter mode: Inhibit counter (counter value will not change in this condition).
- pulsecnt.PCNT_COUNT_INC = 1 Counter mode: Increase counter value.
- pulsecnt.PCNT_COUNT_DEC = 2 Counter mode: Decrease counter value.
- pulsecnt.PCNT_COUNT_DIS = 0 Counter mode: Inhibit counter (counter value will not change in this condition).
- pulsecnt.PCNT_COUNT_INC = 1 Counter mode: Increase counter value.
- pulsecnt.PCNT_COUNT_DEC = 2 Counter mode: Decrease counter value.
- `neg_mode` Required. Negative falling edge count mode, i.e. count the pulse when the falling edge occurs.
- pulsecnt.PCNT_COUNT_DIS = 0 Counter mode: Inhibit counter (counter value will not change in this condition).
- pulsecnt.PCNT_COUNT_INC = 1 Counter mode: Increase counter value.
- pulsecnt.PCNT_COUNT_DEC = 2 Counter mode: Decrease counter value.
- pulsecnt.PCNT_COUNT_DIS = 0 Counter mode: Inhibit counter (counter value will not change in this condition).
- pulsecnt.PCNT_COUNT_INC = 1 Counter mode: Increase counter value.
- pulsecnt.PCNT_COUNT_DEC = 2 Counter mode: Decrease counter value.
- `lctrl_mode` Required. When `ctrl_gpio_num` is low how should the counter be influenced.
- pulsecnt.PCNT_MODE_KEEP = 0 Control mode: will not change counter mode.
- pulsecnt.PCNT_MODE_REVERSE = 1 Control mode: invert counter mode (increase -> decrease, decrease -> increase).
- pulsecnt.PCNT_MODE_DISABLE = 2 Control mode: Inhibit counter (counter value will not change in this condition).
- pulsecnt.PCNT_MODE_KEEP = 0 Control mode: will not change counter mode.
- pulsecnt.PCNT_MODE_REVERSE = 1 Control mode: invert counter mode (increase -> decrease, decrease -> increase).
- pulsecnt.PCNT_MODE_DISABLE = 2 Control mode: Inhibit counter (counter value will not change in this condition).
- `hctrl_mode` Required. When `ctrl_gpio_num` is high how should the counter be influenced.
- pulsecnt.PCNT_MODE_KEEP = 0 Control mode: will not change counter mode.
- pulsecnt.PCNT_MODE_REVERSE = 1 Control mode: invert counter mode (increase -> decrease, decrease -> increase).
- pulsecnt.PCNT_MODE_DISABLE = 2 Control mode: Inhibit counter (counter value will not change in this condition).
- pulsecnt.PCNT_MODE_KEEP = 0 Control mode: will not change counter mode.
- pulsecnt.PCNT_MODE_REVERSE = 1 Control mode: invert counter mode (increase -> decrease, decrease -> increase).
- pulsecnt.PCNT_MODE_DISABLE = 2 Control mode: Inhibit counter (counter value will not change in this condition).
- `counter_l_lim` Required. Range -32768 to 32767. The lower limit counter. You get a callback at this count and the counter is reset to zero after this lower limit is hit.
- `counter_h_lim` Required. Range -32768 to 32767. The high limit counter. You get a callback at this count and the counter is reset to zero after this high limit is hit.
### Returns
#### Returns
`nil`
## pulsecntObj:chan1Config()
Configure channel 1 of the pulse counter object you created from the create() method.
### Syntax
#### Syntax
`pulsecntObj:chan1Config(pulse_gpio_num, ctrl_gpio_num, pos_mode, neg_mode, lctrl_mode, hctrl_mode, counter_l_lim, counter_h_lim)`
### Parameters
#### Parameters
- `pulse_gpio_num` Required. Any GPIO pin can be used.
- `ctrl_gpio_num` Required (although you can specify pulsecnt.PIN_NOT_USED to ignore). Any GPIO pin can be used. If you are trying to use a pin you use as gpio.OUT in other parts of your code, you can instead configure the pin as gpio.IN and toggle gpio.PULL_UP or gpio.PULL_DOWN to achieve your gpio.OUT task while still enabling the pulse counter to successfully read the pin state.
- `pos_mode` Required. Positive rising edge count mode, i.e. count the pulse when the rising edge occurs.
- pulsecnt.PCNT_COUNT_DIS = 0 Counter mode: Inhibit counter (counter value will not change in this condition).
- pulsecnt.PCNT_COUNT_INC = 1 Counter mode: Increase counter value.
- pulsecnt.PCNT_COUNT_DEC = 2 Counter mode: Decrease counter value.
- pulsecnt.PCNT_COUNT_DIS = 0 Counter mode: Inhibit counter (counter value will not change in this condition).
- pulsecnt.PCNT_COUNT_INC = 1 Counter mode: Increase counter value.
- pulsecnt.PCNT_COUNT_DEC = 2 Counter mode: Decrease counter value.
- `neg_mode` Required. Negative falling edge count mode, i.e. count the pulse when the falling edge occurs.
- pulsecnt.PCNT_COUNT_DIS = 0 Counter mode: Inhibit counter (counter value will not change in this condition).
- pulsecnt.PCNT_COUNT_INC = 1 Counter mode: Increase counter value.
- pulsecnt.PCNT_COUNT_DEC = 2 Counter mode: Decrease counter value.
- pulsecnt.PCNT_COUNT_DIS = 0 Counter mode: Inhibit counter (counter value will not change in this condition).
- pulsecnt.PCNT_COUNT_INC = 1 Counter mode: Increase counter value.
- pulsecnt.PCNT_COUNT_DEC = 2 Counter mode: Decrease counter value.
- `lctrl_mode` Required. When `ctrl_gpio_num` is low how should the counter be influenced.
- pulsecnt.PCNT_MODE_KEEP = 0 Control mode: will not change counter mode.
- pulsecnt.PCNT_MODE_REVERSE = 1 Control mode: invert counter mode (increase -> decrease, decrease -> increase).
- pulsecnt.PCNT_MODE_DISABLE = 2 Control mode: Inhibit counter (counter value will not change in this condition).
- pulsecnt.PCNT_MODE_KEEP = 0 Control mode: will not change counter mode.
- pulsecnt.PCNT_MODE_REVERSE = 1 Control mode: invert counter mode (increase -> decrease, decrease -> increase).
- pulsecnt.PCNT_MODE_DISABLE = 2 Control mode: Inhibit counter (counter value will not change in this condition).
- `hctrl_mode` Required. When `ctrl_gpio_num` is high how should the counter be influenced.
- pulsecnt.PCNT_MODE_KEEP = 0 Control mode: will not change counter mode.
- pulsecnt.PCNT_MODE_REVERSE = 1 Control mode: invert counter mode (increase -> decrease, decrease -> increase).
- pulsecnt.PCNT_MODE_DISABLE = 2 Control mode: Inhibit counter (counter value will not change in this condition).
- pulsecnt.PCNT_MODE_KEEP = 0 Control mode: will not change counter mode.
- pulsecnt.PCNT_MODE_REVERSE = 1 Control mode: invert counter mode (increase -> decrease, decrease -> increase).
- pulsecnt.PCNT_MODE_DISABLE = 2 Control mode: Inhibit counter (counter value will not change in this condition).
- `counter_l_lim` Required. Range -32768 to 32767. The lower limit counter. You get a callback at this count and the counter is reset to zero after this lower limit is hit.
- `counter_h_lim` Required. Range -32768 to 32767. The high limit counter. You get a callback at this count and the counter is reset to zero after this high limit is hit.
### Returns
#### Returns
`nil`
### Example
#### Example
```lua
-- Button 1 increment counter
pcnt:chan0Config(
@ -275,17 +275,17 @@ pcnt:chan1Config(
Set the threshold values to establish watchpoints for getting callbacks on.
### Syntax
#### Syntax
`pulsecntObj:setThres(thr0, thr1)`
### Parameters
#### Parameters
- `thr0` Required. Threshold 0 value. Range -32768 to 32767. This is a watchpoint value to get a callback with isThr0 set to true on this count being reached.
- `thr1` Required. Threshold 1 value. Range -32768 to 32767. This is a watchpoint value to get a callback with isThr1 set to true on this count being reached.
### Returns
#### Returns
`nil`
### Example
#### Example
```lua
pcnt:setThres(-2000, 2000) -- get callbacks when counter is -2000 or 2000
```
@ -297,16 +297,16 @@ pcnt:setThres(500, 10000) -- get callbacks when counter is 500 or 10000
Set a filter to ignore pulses on the `pulse_gpio_num` pin and the `ctrl_gpio_num` to avoid short glitches. Any pulses lasting shorter than this will be ignored.
### Syntax
#### Syntax
`pulsecntObj:setFilter(clkCycleCnt)`
### Parameters
#### Parameters
- `clkCycleCnt` Required. 0 to 1023 allowd. Any pulses lasting shorter than this will be ignored. A pulse needs to be high or low for longer than this filter clock cycle. Clock is 80Mhz APB clock, so one cycle is 1000/80,000,000 = 0.0000125 ms. The longest value of 1023 cycles = 0.0127875 ms.
### Returns
#### Returns
`nil`
### Example
#### Example
```lua
pcnt:setFilter(1023) -- set max filter clock cylce count to ignore pulses shorter than 12.7us
```
@ -315,16 +315,16 @@ pcnt:setFilter(1023) -- set max filter clock cylce count to ignore pulses shorte
Clear the counter. Sets it back to zero.
### Syntax
#### Syntax
`pulsecntObj:clear()`
### Parameters
#### Parameters
None
### Returns
#### Returns
`nil`
### Example
#### Example
```lua
pcnt:clear() -- set counter back to zero
```
@ -333,16 +333,16 @@ pcnt:clear() -- set counter back to zero
Get the current pulse counter.
### Syntax
#### Syntax
`pulsecntObj:getCnt()`
### Parameters
#### Parameters
None
### Returns
#### Returns
`integer`
### Example
#### Example
```lua
val = pcnt:getCnt() -- get counter
print("Pulse counter:", val)

View File

@ -69,7 +69,7 @@ Initialize the SDMMC and probe the attached SD card.
- `slot` SDMMC slot, one of `sdmmc.HS1` or `sdmmc.HS2`
- `cfg` optional table containing slot configuration:
- `cd_pin` card detect pin, none if omitted
- `wp_pin` write-protcet pin, none if omitted
- `wp_pin` write-protect pin, none if omitted
- `fmax` maximum communication frequency, defaults to 20  if omitted
- `width` bis width, defaults to `sdmmc.W1BIT` if omitted, one of:
- `sdmmc.W1BIT`
@ -84,7 +84,7 @@ Initialize the SDMMC and probe the attached SD card.
- `miso_pin`, SPI MISO pin, mandatory
- `cs_pin`, SPI CS pin, mandatory
- `cd_pin` card detect pin, none if omitted
- `wp_pin` write-protcet pin, none if omitted
- `wp_pin` write-protect pin, none if omitted
- `fmax` maximum communication frequency, defaults to 20  if omitted
#### Returns

View File

@ -29,29 +29,29 @@ When encoding a Lua object, if a function is found, then it is invoked (with no
This creates an encoder object that can convert a Lua object into a JSON encoded string.
####Syntax
#### Syntax
`sjson.encoder(table [, opts])`
####Parameters
#### Parameters
- `table` data to encode
- `opts` an optional table of options. The possible entries are:
- `depth` the maximum encoding depth needed to encode the table. The default is 20 which should be enough for nearly all situations.
- `null` the string value to treat as null.
####Returns
#### Returns
A `sjson.encoder` object.
## sjson.encoder:read
## sjson.encoder:read()
This gets a chunk of JSON encoded data.
####Syntax
#### Syntax
`encoder:read([size])`
####Parameters
#### Parameters
- `size` an optional value for the number of bytes to return. The default is 1024.
####Returns
#### Returns
A string of up to `size` bytes, or `nil` if the encoding is complete and all data has been returned.
#### Example
@ -82,19 +82,19 @@ end
Encode a Lua table to a JSON string. This is a convenience method provided for backwards compatibility with `cjson`.
####Syntax
#### Syntax
`sjson.encode(table [, opts])`
####Parameters
#### Parameters
- `table` data to encode
- `opts` an optional table of options. The possible entries are:
- `depth` the maximum encoding depth needed to encode the table. The default is 20 which should be enough for nearly all situations.
- `null` the string value to treat as null.
####Returns
#### Returns
JSON string
####Example
#### Example
```lua
ok, json = pcall(sjson.encode, {key="value"})
if ok then
@ -109,7 +109,7 @@ end
This makes a decoder object that can parse a JSON encoded string into a Lua object. A metatable can be specified for all the newly created Lua tables. This allows
you to handle each value as it is inserted into each table (by implementing the `__newindex` method).
####Syntax
#### Syntax
`sjson.decoder([opts])`
#### Parameters
@ -121,7 +121,7 @@ you to handle each value as it is inserted into each table (by implementing the
#### Returns
A `sjson.decoder` object
####Metatable
#### Metatable
There are two principal methods that are invoked in the metatable (if it is present).
@ -152,36 +152,39 @@ The reason for being able to filter is that it enables processing of very large
which would exceed the memory budget of the platform. For example, `https://api.github.com/repos/nodemcu/nodemcu-firmware/contents` is over 13kB, and yet, if
you only need the `download_url` keys, then the total size is around 600B. This can be handled with a simple `__newindex` method.
## sjson.decoder:write
## sjson.decoder:write()
This provides more data to be parsed into the Lua object.
####Syntax
#### Syntax
`decoder:write(string)`
####Parameters
#### Parameters
- `string` the next piece of JSON encoded data
####Returns
#### Returns
The constructed Lua object or `nil` if the decode is not yet complete.
####Errors
#### Errors
If a parse error occurrs during this decode, then an error is thrown and the parse is aborted. The object cannot be used again.
## sjson.decoder:result
## sjson.decoder:result()
This gets the decoded Lua object, or raises an error if the decode is not yet complete. This can be called multiple times and will return the
same object each time.
####Syntax
#### Syntax
`decoder:result()`
####Errors
#### Parameters
none
#### Errors
If the decode is not complete, then an error is thrown.
####Example
#### Example
```
local decoder = sjson.decoder()
@ -211,29 +214,29 @@ decoder:write('[1, 2, {"foo":"bar"}]')
Decode a JSON string to a Lua table. This is a convenience method provided for backwards compatibility with `cjson`.
####Syntax
#### Syntax
`sjson.decode(str[, opts])`
####Parameters
#### Parameters
- `str` JSON string to decode
- `opts` an optional table of options. The possible entries are:
- `depth` the maximum encoding depth needed to encode the table. The default is 20 which should be enough for nearly all situations.
- `null` the string value to treat as null.
- `metatable` a table to use as the metatable for all the new tables in the returned object. See the metatable section in the description of `sjson.decoder()` above.
####Returns
#### Returns
Lua table representation of the JSON data
####Errors
#### Errors
If the string is not valid JSON, then an error is thrown.
####Example
#### Example
```lua
t = sjson.decode('{"key":"value"}')
for k,v in pairs(t) do print(k,v) end
```
##Constants
## Constants
There is one constant, `sjson.NULL`, which is used in Lua structures to represent the presence of a JSON null.

View File

@ -22,7 +22,7 @@ The touch sensors are on the following GPIO pins
| 3 | GPIO15 | | 8 | GPIO33 |
| 4 | GPIO13 | | 9 | GPIO32 |
### Example Lua Code
#### Example Lua Code
Example code showing how to configure 8 pads.
- Main run file [touch_8pads_showlist_test.lua](../../lua_examples/touch/touch_8pads_showlist_test.lua)
@ -38,7 +38,7 @@ Example code showing how to use 5 touch pads to jog a stepper motor at different
Create the touch sensor object. You must call this method first. Only one touch object may be created since most settings on the touch driver are global in nature such as threshold trigger mode, interrupt callbacks, and reference voltages.
### Syntax
#### Syntax
```lua
tp = touch.create({
pad = 0 || {0,1,2,3,4,5,6,7,8,9}, -- 0=GPIO4, 1=GPIO0, 2=GPIO2, 3=GPIO15, 4=GPIO13, 5=GPIO12, 6=GPIO14, 7=GPIO27, 8=GPIO33, 9=GPIO32
@ -54,7 +54,7 @@ tp = touch.create({
})
```
### Parameters
#### Parameters
List of values for configuration table:
- `pad` Required. padNum || {table of padNums}. Specify one pad like `pad = 4`, or provide a table list of pads. For example use `pad = {0,1,2,3,4,5,6,7,8,9}` to specify all pads. Pads allowed are 0=GPIO4, 1=GPIO0, 2=GPIO2, 3=GPIO15, 4=GPIO13, 5=GPIO12, 6=GPIO14, 7=GPIO27, 8=GPIO33, 9=GPIO32.
@ -62,30 +62,30 @@ List of values for configuration table:
- `intrInitAtStart` Optional. Defaults to true. Turn on interrupt at start. Set to false to if you want to configure the touch sensors first and then manually turn on interrupts later with `tp:intrEnable()`.
- `thres` Optional. Defaults to 0. Range is 0 to 65536. Provide a threshold value to be set on all pads specified in the `pad` parameter. Typically you will set thresholds per pad since pad size/shape/wire legnth influences the counter value per pad and thus your threshold is usually differnt per pad. You can set thres later per pad with `tp:setThres(padNum, thres)`.
- `thresTrigger` Optional. Defaults to touch.TOUCH_TRIGGER_BELOW.
- touch.TOUCH_TRIGGER_BELOW
- touch.TOUCH_TRIGGER_ABOVE
- touch.TOUCH_TRIGGER_BELOW
- touch.TOUCH_TRIGGER_ABOVE
- `filterMs` Optional. Range is 0 to 4294967295 milliseconds. Used in polling mode only (if you provide a callback polling mode is disabled). Will filter noise for this many ms to give more consistent counter results. When filterMs is specified you will receive a 2nd return value in the `raw, filter = tp:read()` call with the filtered values in a Lua table.
- `lvolt` Optional. Low reference voltage
- touch.TOUCH_LVOLT_0V4
- touch.TOUCH_LVOLT_0V5
- touch.TOUCH_LVOLT_0V6
- touch.TOUCH_LVOLT_0V7
- touch.TOUCH_LVOLT_0V4
- touch.TOUCH_LVOLT_0V5
- touch.TOUCH_LVOLT_0V6
- touch.TOUCH_LVOLT_0V7
- `hvolt` Optional. High reference voltage
- touch.TOUCH_HVOLT_2V4
- touch.TOUCH_HVOLT_2V5
- touch.TOUCH_HVOLT_2V6
- touch.TOUCH_HVOLT_2V7
- touch.TOUCH_HVOLT_2V4
- touch.TOUCH_HVOLT_2V5
- touch.TOUCH_HVOLT_2V6
- touch.TOUCH_HVOLT_2V7
- `atten` Optional. High reference voltage attenuation
- touch.TOUCH_HVOLT_ATTEN_0V
- touch.TOUCH_HVOLT_ATTEN_0V5
- touch.TOUCH_HVOLT_ATTEN_1V
- touch.TOUCH_HVOLT_ATTEN_1V5
- touch.TOUCH_HVOLT_ATTEN_0V
- touch.TOUCH_HVOLT_ATTEN_0V5
- touch.TOUCH_HVOLT_ATTEN_1V
- touch.TOUCH_HVOLT_ATTEN_1V5
- `isDebug` Optional. Defaults to false. Set to true to get debug information during development. The info returned while debug is on can be very helpful in understanding polling vs interrupts, configuration, and threshold settings. Set to false during production.
### Returns
`touch` object
#### Returns
`tp` touch object
### Example 1 - Polling
#### Example 1 - Polling
```lua
-- Touch sensor with 5 touch pads for polling counter state
@ -108,7 +108,7 @@ end
read()
```
### Example 2 - Polling with Filtering
#### Example 2 - Polling with Filtering
```lua
-- Touch sensor with 3 touch pads for polling with filtering
@ -135,7 +135,7 @@ read()
tmr.create():alarm(1000, tmr.ALARM_SINGLE, read)
```
### Example 3 - Interrupt Touch / Untouch
#### Example 3 - Interrupt Touch / Untouch
```lua
-- Touch sensor with 1 pad for touch / untouch using threshold trigger mode
-- Swap TOUCH_TRIGGER_BELOW / TOUCH_TRIGGER_ABOVE on each callback
@ -204,7 +204,7 @@ read()
config()
```
### Example 4 - Interrupt Touch / Untouch with Timer
#### Example 4 - Interrupt Touch / Untouch with Timer
```lua
-- Touch sensor with 1 pad for touch / untouch using timer
-- Shows how to detect a touch and then an untouch
@ -290,17 +290,17 @@ m.config()
Read the touch sensor counter values for all pads configured in `touch.create()` method.
### Syntax
#### Syntax
`raw, filter = tp:read()`
### Parameters
#### Parameters
None
### Returns
#### Returns
- `raw` Lua table of touch sensor counter values per pad
- `raw, filter` A 2nd Lua table of touch sensor filtered counter values per pad is returned if `filterMs` is specified during the touch.create() method.
- `filter` A 2nd Lua table of touch sensor filtered counter values per pad is returned if `filterMs` is specified during the touch.create() method.
### Example 1 - Raw
#### Example 1 - Raw
```lua
raw = tp:read()
print("Pad", "Val")
@ -309,7 +309,7 @@ for key,value in pairs(raw) do
end
```
### Example 2 - Raw / Filter
#### Example 2 - Raw / Filter
```lua
-- You get a filter Lua table if you specified filterMs in touch.create()
raw, filter = tp:read()
@ -324,23 +324,23 @@ end
Set touch sensor interrupt threshold per pad. The threshold only matters if you are in interrupt mode, which only activates if you specify a callback in the `touch.create()` configuration.
### Syntax
#### Syntax
`tp:setThres(padNum, thresVal)`
### Parameters
#### Parameters
- `padNum` Required. One pad number can be specified here. If you did multiple pads you must call this per pad.
- `thresVal` Required. The threshold value to set for the pad interrupt trigger. If you set touch.TOUCH_TRIGGER_BELOW then the interrupt occurs when the touch counter goes below this threshold value, or vice versa for touch.TOUCH_TRIGGER_ABOVE.
### Returns
#### Returns
`nil`
### Example 1
#### Example 1
```lua
-- Set threshold for pad 2 where baseline counter is around 800 and
-- when touched is around 200, so trigger at mid-point around 500
tp:setThres(2, 500)
```
### Example 2
#### Example 2
```lua
-- Configure by reading baseline, then setting threshold to 30% below base
local raw = tp:read()
@ -361,16 +361,16 @@ tp:intrEnable()
Set the trigger mode globally for all touch pads. The trigger mode only matters in interrupt mode where you can tell the hardware to give you an interrupt if the counter on the pad falls above or below the threshold you specify.
### Syntax
#### Syntax
`tp:setTriggerMode(mode)`
### Parameters
#### Parameters
- `mode` Required. touch.TOUCH_TRIGGER_BELOW or touch.TOUCH_TRIGGER_ABOVE can be specified. If your pad's baseline counter value is around 600 when not touched, and sits around 300 when touched, then you would set your threshold around 450. If you set touch.TOUCH_TRIGGER_BELOW then when the counter drops to 300 it would fall BELOW the threshold of 450, thus triggering the interrupt. This process works in the reverse for touch.TOUCH_TRIGGER_ABOVE.
### Returns
#### Returns
`nil`
### Example 1
#### Example 1
```lua
-- Trigger callback when pad counter goes above threshold value
tp:setTriggerMode(touch.TOUCH_TRIGGER_ABOVE)
@ -378,7 +378,7 @@ tp:setTriggerMode(touch.TOUCH_TRIGGER_ABOVE)
tp:setTriggerMode(touch.TOUCH_TRIGGER_BELOW)
```
### Example 2
#### Example 2
```lua
-- Configure touch hardware to callback on TOUCH_TRIGGER_BELOW during touch.create()
-- Then on first callback swap to TOUCH_TRIGGER_ABOVE when detecting touch
@ -414,16 +414,16 @@ end
Enable interrupt on the touch sensor hardware. You can specify `intrInitAtStart=false` during `touch.create()` and thus you would want to call this method later on after configuring your pad thresholds.
### Syntax
#### Syntax
`tp:intrEnable()`
### Parameters
#### Parameters
None
### Returns
#### Returns
`nil`
### Example
#### Example
```lua
tp:intrEnable() -- Enable interrupt
```
@ -432,16 +432,16 @@ tp:intrEnable() -- Enable interrupt
Disable interrupt on the touch sensor hardware.
### Syntax
#### Syntax
`tp:intrDisable()`
### Parameters
#### Parameters
None
### Returns
#### Returns
`nil`
### Example
#### Example
```lua
tp:intrDisable() -- Disable interrupt
```
```