diff --git a/docs/_images/esp32_hardware.jpg b/docs/_images/esp32_hardware.jpg new file mode 100644 index 0000000..56d50eb Binary files /dev/null and b/docs/_images/esp32_hardware.jpg differ diff --git a/docs/_images/esp32_res.jpg b/docs/_images/esp32_res.jpg new file mode 100644 index 0000000..95353ca Binary files /dev/null and b/docs/_images/esp32_res.jpg differ diff --git a/docs/_images/ispindel_esp32.jpg b/docs/_images/ispindel_esp32.jpg new file mode 100644 index 0000000..660af86 Binary files /dev/null and b/docs/_images/ispindel_esp32.jpg differ diff --git a/docs/_images/ispindel_esp32c3.jpg b/docs/_images/ispindel_esp32c3.jpg new file mode 100644 index 0000000..0cdde25 Binary files /dev/null and b/docs/_images/ispindel_esp32c3.jpg differ diff --git a/docs/_images/ispindel_esp8266.jpg b/docs/_images/ispindel_esp8266.jpg new file mode 100644 index 0000000..34a4c4d Binary files /dev/null and b/docs/_images/ispindel_esp8266.jpg differ diff --git a/docs/_images/serial_esp32c3.jpg b/docs/_images/serial_esp32c3.jpg new file mode 100644 index 0000000..b895e8e Binary files /dev/null and b/docs/_images/serial_esp32c3.jpg differ diff --git a/docs/_images/usb-ttl.jpg b/docs/_images/usb-ttl.jpg new file mode 100644 index 0000000..5b27fa0 Binary files /dev/null and b/docs/_images/usb-ttl.jpg differ diff --git a/docs/_sources/api.rst.txt b/docs/_sources/api.rst.txt index a8dcc40..695e34d 100644 --- a/docs/_sources/api.rst.txt +++ b/docs/_sources/api.rst.txt @@ -84,7 +84,7 @@ GET: /api/status Retrieve the current device status via an HTTP GET command. Payload is in JSON format. * ``temp-format`` can be either ``C`` or ``F`` -* ``platform`` can be either ``esp8266`` or ``esp32`` +* ``platform`` can be either ``esp8266``, ``esp32c3``, ``esp32s2`` or ``esp32`` * ``temp-c`` will be set to -273 C if there is no temp sensor * ``angle`` will be set to 0 if no valid angle is found and -1 if there is no gyro diff --git a/docs/_sources/compiling.rst.txt b/docs/_sources/compiling.rst.txt index fe824a9..2f3c243 100644 --- a/docs/_sources/compiling.rst.txt +++ b/docs/_sources/compiling.rst.txt @@ -29,14 +29,9 @@ In the platformio config there are 3 targets defined * gravity-debug; Maximum logging for trouble shooting, deep sleep is disabled. * gravity-release; Standard release -* gravity-perf; Standard release but contains code for measuring performance. -* gravity32-release: Version for ESP32. -* gravity32-perf: Version for ESP32 but contains code for measuring performance. - -.. note:: - There is an experimental ESP32 target but since platformio only supports SDK 1.0.6 and the WIFI connection is really slow compared to ESP8266, - so the recommendation is to wait for support on 2.0.x branch. With the tested version an wifi connection takes 3-8s on a ESP32 compared - to 0.5s on an ESP8266. There is also a bug in OneWire connected to ESP32 that has not been fixed in the main repository yet. +* gravity32-release: Version for ESP32 mini. +* gravity32-c3-release: Version for ESP32 C3 mini. +* gravity32-s2-release: Version for ESP32 S2 mini. .. warning:: The debug target can be unstable and crash the device under certain circumstanses. Excessive logging to the serial port can cause corruption and crashes. @@ -91,8 +86,6 @@ This is a list of C++ defines that is used to enable/disable functions in the co - Done include verbose logging in the corresponding class. Excessive logging may crash device. * - USE_LITTLEFS - Use the new filesystem in Ardurino - * - EMBED_HTML - - Html files are included in code, if not defined they are served from the file system. * - USER_SSID - If defined the device will always use this SSID * - USER_SSID_PWD diff --git a/docs/_sources/hardware.rst.txt b/docs/_sources/hardware.rst.txt index 102c6e7..b2e1900 100644 --- a/docs/_sources/hardware.rst.txt +++ b/docs/_sources/hardware.rst.txt @@ -3,49 +3,89 @@ Hardware ######## -There are lots of resources out there on how to build the hardware for an iSpindle so I will not go into details on that part. Here are two of my builds using the iSpindle PCB v4. +iSpindle based on esp8266 +========================= -.. image:: images/ispindel.jpg +There are lots of resouces out there on how to build the hardware for an iSpindle so I will not go into details on that part. I typically use one of the +excellent pcb boards that, for example the iSpindel PCB v4.0 from Cherry Philip. Here is one of my standard builds using an esp8266. + +.. image:: images/ispindel_esp8266.jpg :width: 500 - :alt: Builds of iSpindel - -It's possible to use this PCB and mount an ESP32 on top of that. It must be an pin compatible ESP32 and the one I used was called *ESP32 d1 mini*. Since this is the same width as the PCB you need to -mount it really close to the PCB in order for it to fit in the PET tube/container. I also had to smooth the edge of the ESP32 in order for it to fit. - -I would suggest that you try how it fits into the PET tube before soldering it to the PCB. Make sure that the battery is attached since this will be a really tight fit. - -You also need to desolder (remove) the RED ON LED from the ESP32 or the battery power will be reduced a lot. - -Final thing is to add a resistor between A0 (Analog PIN) and ground of 470k. The reason is that the esp8266 has a build in resistor which -the esp32 does not have. So in order to get a valid voltage (less than 3.2V) on the A0 pin this is needed. Once the modification is done you might -need to adjust the voltage factor so the battery reading is correct. - -.. image:: images/esp32.jpg - :width: 500 - :alt: Mounting esp32 + :alt: iSpindle esp8266 Schema for esp8266 build ------------------------- +++++++++++++++++++++++++ .. image:: images/schema_esp8266.png :width: 700 :alt: Schema esp8266 +iSpindle based on esp32 +======================= + +I've experimented with porting my software version to esp32 and this is a selection of options i have been testing. + +.. warning:: + Work to support esp32s2 is still ongoing, ESP32-mini and ESP32c3-mini is confirmed to be working. However I would recommend the C3 variant. + +.. image:: images/esp32_hardware.jpg + :width: 500 + :alt: iSpindle esp32 hardware options + +* esp32 mini, this was the first board i tried which is a smaller form factor of the first generetion esp32 with 2 cores. Slow on connecting to wifi is the main downside. +* esp32c3 mini, a newer version based on the latest risc v7 architecture, is seen as the replacement for the esp8266 with bluetooth support. +* esp32s2 mini, similar to the c3 board but without bluetooth support. + +It's possible to use this PCB and mount an ESP32 mini on top of that (c3 and s2 are prefered). The esp32 mini is a larger formfactor and can be hard to fit into the tube. + +.. note:: + You need to add a resistor between A0 (Analog PIN) and ground of 470k. The reason is that the esp8266 has a build in resistor for a voltage divider + which the esp32 does not have. So in order to get a valid voltage (less than 3.2V) on the A0 pin this is needed. Once the modification is done you might + need to adjust the voltage factor so the battery reading is correct. + +ESP32c3 mini +++++++++++++ + +This is model is now fully supported by gravitymon. + +.. image:: images/ispindel_esp32c3.jpg + :width: 500 + :alt: Esp32c3 mini build + +Here is an image of where I added the resistor for the voltage divider. + +.. image:: images/esp32_res.jpg + :width: 500 + :alt: Esp32c3 adding resistor as voltage dividier. + +ESP32s2 mini +++++++++++++ + +Work in progress... + +ESP32 d1 mini ++++++++++++++ + +I would suggest that you try how it fits into the PET tube before soldering it to the PCB. Make sure that the battery is attached since this will be a really tight fit. + +.. image:: images/ispindel_esp32.jpg + :width: 500 + :alt: Esp32 mini build + Schema for esp32 build ----------------------- +++++++++++++++++++++++ .. note:: - This schema assumes that an ESP32 D1 Mini (pin compatible with ESP8266 D1 Mini is used) - The ESP32 has two rows of pins but only the inner row is used. The main difference is the added resistor R3 so we - get a voltage divider for measuring battery. The ESP8266 has a built in resistor thats not visible on the schema. - + This schema assumes that an ESP32 D1 Mini (pin compatible with ESP8266 D1 Mini is used). The ESP32 has two rows of pins but + only the inner row is used. The main difference is the added resistor R3 so we get a voltage divider for measuring battery. + The ESP8266 has a built in resistor thats not visible on the schema and this acts as a voltage divider. .. image:: images/schema_esp32.png :width: 700 :alt: Schema esp32 -Modifying with reed switch --------------------------- +Adding a reed (magnetic) reset switch +===================================== A reed switch is a switch that reacts to magnetic fields. The ones I have tested are normally open and close in proximity to a magnet. diff --git a/docs/_sources/index.rst.txt b/docs/_sources/index.rst.txt index d2ae85b..563328e 100644 --- a/docs/_sources/index.rst.txt +++ b/docs/_sources/index.rst.txt @@ -7,7 +7,7 @@ Welcome to GravityMon's documentation! ###################################### .. note:: - This documentation reflects **v1.1**. Last updated 2022-08-14 + This documentation reflects **v1.2 - beta 1**. Last updated 2022-10-15 User interface overview ----------------------- @@ -23,6 +23,7 @@ This animation shows how the user interface is structured, it reflects an older Main features ------------- +* Support either an ESP8266-d1-mini, ESP32-mini or ESP32C3-mini board (see :ref:`hardware`) * Operates in two modes gravity monitoring and configuration mode * Gravity mode is comparable to how the iSpindle works when collecting data * Configuration mode has a modern HTML5 based web UI. No need to start the access point to change settings diff --git a/docs/_sources/installation.rst.txt b/docs/_sources/installation.rst.txt index 21731d9..7cad484 100644 --- a/docs/_sources/installation.rst.txt +++ b/docs/_sources/installation.rst.txt @@ -23,30 +23,30 @@ available here `Brewflasher WEB `_. Binaries ******** -In the /bin directory you will find 3 different firmware builds; +In the /bin directory you will find 4 different firmware builds; * **firmware.bin** This is the standard release build (preferred version) -* **firmware-perf.bin** - - This version also submits performance data to an influx database with detailed execution times. - * **firmware32.bin** - This is the standard release build for an ESP32 variant. When flashing an ESP32 you also need the **partition32.bin** file that outlines the flash memory structure. Due to + This is the release build for an ESP32-d1-mini variant. When flashing an ESP32 you also need the *partition32.bin* file that outlines the flash memory structure. Due to the size of the firmware we are using a custom partition setup. -In these versions all the html files are embedded in the binaries. The file system is currently only used for storing -the configuration file. +* **firmware32c3.bin** -If the software becomes so large the html files can be moved to the file system, but this is not enabled by -default (see compiling for details). This approach makes installation much easier and ensure that html files -and code is in sync. + This is the release build for an ESP32c3-mini variant. When flashing an ESP32 you also need the *partition32c3.bin* file that outlines the flash memory structure. Due to + the size of the firmware we are using a custom partition setup. -Esptool -======= +* **firmware32s2.bin** + + This is the release build for an ESP32s2-mini variant. When flashing an ESP32 you also need the *partition32s2.bin* file that outlines the flash memory structure. Due to + the size of the firmware we are using a custom partition setup. + + +Esptool (esp8266) +================= The other option for flashing esp8266 device is via the official esptool. Documentation can be found here; `esptool home page `_ @@ -61,8 +61,8 @@ If there are issues you can try do erase the flash first using this command; ``esptool.py --port COM4 erase_flash`` -iSpindel -======== +iSpindel (esp8266) +================== If you already have the device flashed with iSpindel firmware you can go into the configuration mode where you will find an option for updating firmware. The option is under the maintenance menu. @@ -101,9 +101,21 @@ To check output from the device (logs) there are several tools out there. I foun Just select a baud rate of 115200, 8N1. .. image:: images/serial.png - :width: 800 + :width: 600 :alt: Serial output +On the build for esp32c3 the serial output is written to UART0 which is connected to the RX/TX pins on the chip. This way the serial output can be viewed +without a connection to the USB port, convinient when running the device on battery power. + +You need a USB to TTL cable that you connect the TX, RX and GND pins. **Dont connect the power pin** if you are powering the device from USB or Battery. + +.. image:: images/usb-ttl.jpg + :width: 300 + :alt: USB to TTL cable + +.. image:: images/serial_esp32c3.jpg + :width: 300 + :alt: Serial output ESP32c3 .. _setup_wifi: @@ -130,7 +142,7 @@ successful then it will be used as primary. *The second wifi setting is optional .. image:: images/wifi.png - :width: 200 + :width: 300 :alt: Wifi page diff --git a/docs/_sources/releases.rst.txt b/docs/_sources/releases.rst.txt index 27f51d3..ab600a5 100644 --- a/docs/_sources/releases.rst.txt +++ b/docs/_sources/releases.rst.txt @@ -3,6 +3,23 @@ Releases ######## +v1.2.0 - beta1 +============== + +Features +++++++++ +* Added support for the ESP32 C3 mini board +* Serial output is written to TX/RX pins instead of the USB connection for the ESP32c3. This way the serial console can be viewed when running on battery power. + +Issues adressed +++++++++++++++++ +* BUG: The first portion of a format template was lost when doing conversion. + +Documentation ++++++++++++++ +* Updated hardware section with options for ESP32 boards +* Updated installation instructions. + v1.1.1 ====== * BUG: The text before the first variable was missed in the conversion of a format template. diff --git a/docs/_static/check-solid.svg b/docs/_static/check-solid.svg new file mode 100644 index 0000000..92fad4b --- /dev/null +++ b/docs/_static/check-solid.svg @@ -0,0 +1,4 @@ + + + + diff --git a/docs/_static/clipboard.min.js b/docs/_static/clipboard.min.js new file mode 100644 index 0000000..54b3c46 --- /dev/null +++ b/docs/_static/clipboard.min.js @@ -0,0 +1,7 @@ +/*! + * clipboard.js v2.0.8 + * https://clipboardjs.com/ + * + * Licensed MIT © Zeno Rocha + */ +!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ClipboardJS=e():t.ClipboardJS=e()}(this,function(){return n={686:function(t,e,n){"use strict";n.d(e,{default:function(){return o}});var e=n(279),i=n.n(e),e=n(370),u=n.n(e),e=n(817),c=n.n(e);function a(t){try{return document.execCommand(t)}catch(t){return}}var f=function(t){t=c()(t);return a("cut"),t};var l=function(t){var e,n,o,r=1 + + + + diff --git a/docs/_static/copybutton.css b/docs/_static/copybutton.css new file mode 100644 index 0000000..40eafe5 --- /dev/null +++ b/docs/_static/copybutton.css @@ -0,0 +1,93 @@ +/* Copy buttons */ +button.copybtn { + position: absolute; + display: flex; + top: .3em; + right: .3em; + width: 1.7em; + height: 1.7em; + opacity: 0; + transition: opacity 0.3s, border .3s, background-color .3s; + user-select: none; + padding: 0; + border: none; + outline: none; + border-radius: 0.4em; + /* The colors that GitHub uses */ + border: #1b1f2426 1px solid; + background-color: #f6f8fa; + color: #57606a; +} + +button.copybtn.success { + border-color: #22863a; + color: #22863a; +} + +button.copybtn svg { + stroke: currentColor; + width: 1.5em; + height: 1.5em; + padding: 0.1em; +} + +div.highlight { + position: relative; +} + +.highlight:hover button.copybtn { + opacity: 1; +} + +.highlight button.copybtn:hover { + background-color: rgb(235, 235, 235); +} + +.highlight button.copybtn:active { + background-color: rgb(187, 187, 187); +} + +/** + * A minimal CSS-only tooltip copied from: + * https://codepen.io/mildrenben/pen/rVBrpK + * + * To use, write HTML like the following: + * + *

Short

+ */ + .o-tooltip--left { + position: relative; + } + + .o-tooltip--left:after { + opacity: 0; + visibility: hidden; + position: absolute; + content: attr(data-tooltip); + padding: .2em; + font-size: .8em; + left: -.2em; + background: grey; + color: white; + white-space: nowrap; + z-index: 2; + border-radius: 2px; + transform: translateX(-102%) translateY(0); + transition: opacity 0.2s cubic-bezier(0.64, 0.09, 0.08, 1), transform 0.2s cubic-bezier(0.64, 0.09, 0.08, 1); +} + +.o-tooltip--left:hover:after { + display: block; + opacity: 1; + visibility: visible; + transform: translateX(-100%) translateY(0); + transition: opacity 0.2s cubic-bezier(0.64, 0.09, 0.08, 1), transform 0.2s cubic-bezier(0.64, 0.09, 0.08, 1); + transition-delay: .5s; +} + +/* By default the copy button shouldn't show up when printing a page */ +@media print { + button.copybtn { + display: none; + } +} diff --git a/docs/_static/copybutton.js b/docs/_static/copybutton.js new file mode 100644 index 0000000..40ac331 --- /dev/null +++ b/docs/_static/copybutton.js @@ -0,0 +1,220 @@ +// Localization support +const messages = { + 'en': { + 'copy': 'Copy', + 'copy_to_clipboard': 'Copy to clipboard', + 'copy_success': 'Copied!', + 'copy_failure': 'Failed to copy', + }, + 'es' : { + 'copy': 'Copiar', + 'copy_to_clipboard': 'Copiar al portapapeles', + 'copy_success': '¡Copiado!', + 'copy_failure': 'Error al copiar', + }, + 'de' : { + 'copy': 'Kopieren', + 'copy_to_clipboard': 'In die Zwischenablage kopieren', + 'copy_success': 'Kopiert!', + 'copy_failure': 'Fehler beim Kopieren', + }, + 'fr' : { + 'copy': 'Copier', + 'copy_to_clipboard': 'Copié dans le presse-papier', + 'copy_success': 'Copié !', + 'copy_failure': 'Échec de la copie', + }, + 'ru': { + 'copy': 'Скопировать', + 'copy_to_clipboard': 'Скопировать в буфер', + 'copy_success': 'Скопировано!', + 'copy_failure': 'Не удалось скопировать', + }, + 'zh-CN': { + 'copy': '复制', + 'copy_to_clipboard': '复制到剪贴板', + 'copy_success': '复制成功!', + 'copy_failure': '复制失败', + }, + 'it' : { + 'copy': 'Copiare', + 'copy_to_clipboard': 'Copiato negli appunti', + 'copy_success': 'Copiato!', + 'copy_failure': 'Errore durante la copia', + } +} + +let locale = 'en' +if( document.documentElement.lang !== undefined + && messages[document.documentElement.lang] !== undefined ) { + locale = document.documentElement.lang +} + +let doc_url_root = DOCUMENTATION_OPTIONS.URL_ROOT; +if (doc_url_root == '#') { + doc_url_root = ''; +} + +/** + * SVG files for our copy buttons + */ +let iconCheck = ` + ${messages[locale]['copy_success']} + + +` + +// If the user specified their own SVG use that, otherwise use the default +let iconCopy = ``; +if (!iconCopy) { + iconCopy = ` + ${messages[locale]['copy_to_clipboard']} + + + +` +} + +/** + * Set up copy/paste for code blocks + */ + +const runWhenDOMLoaded = cb => { + if (document.readyState != 'loading') { + cb() + } else if (document.addEventListener) { + document.addEventListener('DOMContentLoaded', cb) + } else { + document.attachEvent('onreadystatechange', function() { + if (document.readyState == 'complete') cb() + }) + } +} + +const codeCellId = index => `codecell${index}` + +// Clears selected text since ClipboardJS will select the text when copying +const clearSelection = () => { + if (window.getSelection) { + window.getSelection().removeAllRanges() + } else if (document.selection) { + document.selection.empty() + } +} + +// Changes tooltip text for two seconds, then changes it back +const temporarilyChangeTooltip = (el, oldText, newText) => { + el.setAttribute('data-tooltip', newText) + el.classList.add('success') + setTimeout(() => el.setAttribute('data-tooltip', oldText), 2000) + setTimeout(() => el.classList.remove('success'), 2000) +} + +// Changes the copy button icon for two seconds, then changes it back +const temporarilyChangeIcon = (el) => { + el.innerHTML = iconCheck; + setTimeout(() => {el.innerHTML = iconCopy}, 2000) +} + +const addCopyButtonToCodeCells = () => { + // If ClipboardJS hasn't loaded, wait a bit and try again. This + // happens because we load ClipboardJS asynchronously. + if (window.ClipboardJS === undefined) { + setTimeout(addCopyButtonToCodeCells, 250) + return + } + + // Add copybuttons to all of our code cells + const codeCells = document.querySelectorAll('div.highlight pre') + codeCells.forEach((codeCell, index) => { + const id = codeCellId(index) + codeCell.setAttribute('id', id) + + const clipboardButton = id => + `` + codeCell.insertAdjacentHTML('afterend', clipboardButton(id)) + }) + +function escapeRegExp(string) { + return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string +} + +// Callback when a copy button is clicked. Will be passed the node that was clicked +// should then grab the text and replace pieces of text that shouldn't be used in output +function formatCopyText(textContent, copybuttonPromptText, isRegexp = false, onlyCopyPromptLines = true, removePrompts = true, copyEmptyLines = true, lineContinuationChar = "", hereDocDelim = "") { + + var regexp; + var match; + + // Do we check for line continuation characters and "HERE-documents"? + var useLineCont = !!lineContinuationChar + var useHereDoc = !!hereDocDelim + + // create regexp to capture prompt and remaining line + if (isRegexp) { + regexp = new RegExp('^(' + copybuttonPromptText + ')(.*)') + } else { + regexp = new RegExp('^(' + escapeRegExp(copybuttonPromptText) + ')(.*)') + } + + const outputLines = []; + var promptFound = false; + var gotLineCont = false; + var gotHereDoc = false; + const lineGotPrompt = []; + for (const line of textContent.split('\n')) { + match = line.match(regexp) + if (match || gotLineCont || gotHereDoc) { + promptFound = regexp.test(line) + lineGotPrompt.push(promptFound) + if (removePrompts && promptFound) { + outputLines.push(match[2]) + } else { + outputLines.push(line) + } + gotLineCont = line.endsWith(lineContinuationChar) & useLineCont + if (line.includes(hereDocDelim) & useHereDoc) + gotHereDoc = !gotHereDoc + } else if (!onlyCopyPromptLines) { + outputLines.push(line) + } else if (copyEmptyLines && line.trim() === '') { + outputLines.push(line) + } + } + + // If no lines with the prompt were found then just use original lines + if (lineGotPrompt.some(v => v === true)) { + textContent = outputLines.join('\n'); + } + + // Remove a trailing newline to avoid auto-running when pasting + if (textContent.endsWith("\n")) { + textContent = textContent.slice(0, -1) + } + return textContent +} + + +var copyTargetText = (trigger) => { + var target = document.querySelector(trigger.attributes['data-clipboard-target'].value); + return formatCopyText(target.innerText, '', false, true, true, true, '', '') +} + + // Initialize with a callback so we can modify the text before copy + const clipboard = new ClipboardJS('.copybtn', {text: copyTargetText}) + + // Update UI with error/success messages + clipboard.on('success', event => { + clearSelection() + temporarilyChangeTooltip(event.trigger, messages[locale]['copy'], messages[locale]['copy_success']) + temporarilyChangeIcon(event.trigger) + }) + + clipboard.on('error', event => { + temporarilyChangeTooltip(event.trigger, messages[locale]['copy'], messages[locale]['copy_failure']) + }) +} + +runWhenDOMLoaded(addCopyButtonToCodeCells) \ No newline at end of file diff --git a/docs/_static/copybutton_funcs.js b/docs/_static/copybutton_funcs.js new file mode 100644 index 0000000..b9168c5 --- /dev/null +++ b/docs/_static/copybutton_funcs.js @@ -0,0 +1,58 @@ +function escapeRegExp(string) { + return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string +} + +// Callback when a copy button is clicked. Will be passed the node that was clicked +// should then grab the text and replace pieces of text that shouldn't be used in output +export function formatCopyText(textContent, copybuttonPromptText, isRegexp = false, onlyCopyPromptLines = true, removePrompts = true, copyEmptyLines = true, lineContinuationChar = "", hereDocDelim = "") { + + var regexp; + var match; + + // Do we check for line continuation characters and "HERE-documents"? + var useLineCont = !!lineContinuationChar + var useHereDoc = !!hereDocDelim + + // create regexp to capture prompt and remaining line + if (isRegexp) { + regexp = new RegExp('^(' + copybuttonPromptText + ')(.*)') + } else { + regexp = new RegExp('^(' + escapeRegExp(copybuttonPromptText) + ')(.*)') + } + + const outputLines = []; + var promptFound = false; + var gotLineCont = false; + var gotHereDoc = false; + const lineGotPrompt = []; + for (const line of textContent.split('\n')) { + match = line.match(regexp) + if (match || gotLineCont || gotHereDoc) { + promptFound = regexp.test(line) + lineGotPrompt.push(promptFound) + if (removePrompts && promptFound) { + outputLines.push(match[2]) + } else { + outputLines.push(line) + } + gotLineCont = line.endsWith(lineContinuationChar) & useLineCont + if (line.includes(hereDocDelim) & useHereDoc) + gotHereDoc = !gotHereDoc + } else if (!onlyCopyPromptLines) { + outputLines.push(line) + } else if (copyEmptyLines && line.trim() === '') { + outputLines.push(line) + } + } + + // If no lines with the prompt were found then just use original lines + if (lineGotPrompt.some(v => v === true)) { + textContent = outputLines.join('\n'); + } + + // Remove a trailing newline to avoid auto-running when pasting + if (textContent.endsWith("\n")) { + textContent = textContent.slice(0, -1) + } + return textContent +} diff --git a/docs/_static/documentation_options.js b/docs/_static/documentation_options.js index 584dfc5..5be98c4 100644 --- a/docs/_static/documentation_options.js +++ b/docs/_static/documentation_options.js @@ -1,6 +1,6 @@ var DOCUMENTATION_OPTIONS = { URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'), - VERSION: '1.1.0', + VERSION: '1.2.0', LANGUAGE: 'None', COLLAPSE_INDEX: false, BUILDER: 'html', diff --git a/docs/advanced.html b/docs/advanced.html index a3604d4..8c1123d 100644 --- a/docs/advanced.html +++ b/docs/advanced.html @@ -5,9 +5,10 @@ - Advanced Configuration - GravityMon 1.1.0 documentation + Advanced Configuration - GravityMon 1.2.0 documentation + @@ -122,7 +123,7 @@
@@ -145,7 +146,7 @@
@@ -145,7 +146,7 @@
@@ -145,7 +146,7 @@