{"id":13548236,"url":"https://github.com/Bee-Mar/MMM-Simple-Swiper","last_synced_at":"2025-04-02T21:31:05.667Z","repository":{"id":101693525,"uuid":"165588650","full_name":"Bee-Mar/MMM-Simple-Swiper","owner":"Bee-Mar","description":"A simple, multi-threaded interface for the HC-SR04 sensors and the MagicMirror","archived":true,"fork":false,"pushed_at":"2022-01-16T14:43:22.000Z","size":13779,"stargazers_count":19,"open_issues_count":2,"forks_count":9,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-11-03T17:38:29.899Z","etag":null,"topics":["c","javascript","magic-mirror-modules","magicmirror2","nodejs","raspberry-pi-3","rasperrypi"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Bee-Mar.png","metadata":{"files":{"readme":"README.org","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-01-14T03:22:36.000Z","updated_at":"2024-07-07T20:43:35.000Z","dependencies_parsed_at":"2024-01-16T18:23:26.903Z","dependency_job_id":null,"html_url":"https://github.com/Bee-Mar/MMM-Simple-Swiper","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bee-Mar%2FMMM-Simple-Swiper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bee-Mar%2FMMM-Simple-Swiper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bee-Mar%2FMMM-Simple-Swiper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bee-Mar%2FMMM-Simple-Swiper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Bee-Mar","download_url":"https://codeload.github.com/Bee-Mar/MMM-Simple-Swiper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246895683,"owners_count":20851312,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","javascript","magic-mirror-modules","magicmirror2","nodejs","raspberry-pi-3","rasperrypi"],"created_at":"2024-08-01T12:01:07.686Z","updated_at":"2025-04-02T21:31:05.367Z","avatar_url":"https://github.com/Bee-Mar.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"#+AUTHOR: Brandon Marlowe \u0026 Otto Juba\n#+EMAIL: bpmarlowe@gmail.com;ottojuba@gmail.com\n#+STARTUP: showall\n#+OPTIONS: toc:nil\n\n* MMM-Simple-Swiper\n| Author          | Contact                           |\n|-----------------+-----------------------------------|\n| Brandon Marlowe | bpmarlowe-software@protonmail.com |\n| Otto Juba       | ottojuba@gmail.com                |\n\n** What is this, and why did we make this module?\n   This module attempts to determine distance/motion based on the output\n   from the sensors in a simple, efficient manner. When the\n   =MMM-Simple-Swiper= modules loads, it sends a socket notification to\n   =node_helper.js=. The =node_helper= then creates a child process,\n   which calls a C executable, and supplies the JSON config as a command\n   line argument in string format. The JSON string is parsed, the values\n   are stored in structs, and an infinite loop is entered. Within the\n   inifinte loop, two threads are created to collect the distance\n   measurements, remove the outliers, and calculate the average\n   distance. The two threads are joined, and the averages are printed to\n   =stdout= in a =[FLOAT]:[FLOAT]= format, which is read by the child\n   process created in =node_helper.js=. From here, the values are checked\n   to see if both are within a certain threshold. If the values meet this\n   criteria and there is a large enough difference between the two\n   values, a socket nofication is sent to the =MMM-Simple-Swiper= module,\n   which sends a notification to the =MMM-pages= module.\n\n** Dependencies\n   This module has three dependencies, all of which are listed in the\n   table below. When you clone this repo, install the =wiringPi= library using the instructions from the table below, and run and =npm install= inside repo's directory.\n\n   | Library Dependencies | Link/Installation                            |\n   |----------------------+----------------------------------------------|\n   | WiringPi             | =sudo apt-get install wiringpi -y=           |\n   | child_process        | https://nodejs.org/api/child_process.html    |\n   | electron-rebuild     | https://github.com/electron/electron-rebuild |\n\n   | Recommended MagicMirror Modules | Link                                              |\n   |---------------------------------+---------------------------------------------------|\n   | MMM-pages                       | https://github.com/edward-shen/MMM-pages          |\n   | MMM-page-indicator              | https://github.com/edward-shen/MMM-page-indicator |\n\n** Installation\nYou can either follow the manual instructions for installation below, or you can make use of the =MMPM (Magic Mirror Package Manager)= found here: https://github.com/Bee-Mar/mmpm\n\n#+BEGIN_SRC sh\n# assuming mmpm is already installed\n\n$ sudo apt-get install wiringpi -y\n$ mmpm -i MMM-Simple-Swiper\n$ cd ~/MagicMirror/modules/MMM-Simple-Swiper \u0026\u0026 make\n\n#+END_SRC\n\n#+BEGIN_SRC sh\n   # manual installation\n   $ cd ~/MagicMirror/modules/\n   $ https://github.com/Bee-Mar/MMM-Simple-Swiper.git\n   $ cd MMM-Simple-Swiper\n   $ sudo apt-get install wiringpi -y\n   $ npm install\n   $ make\n#+END_SRC\n\nBe sure to add the snippet for your =config.js= file below.\n\n** SuDON'T\n\n   When running this module, there is absolutely no need to execute\n   =sudo= with =npm start=. This is due to the small hack (I guess it can\n   be considered a hack??) used when launching the child process within\n   =node_helper.js=. The code snippet where this occurs is shown below:\n\n\n#+BEGIN_SRC js\n  // other code above ...\n\n  var child = require(\"child_process\").spawn(\"sudo\", [\n     __dirname + \"/swiper\",\n     JSON.stringify(payload),\n  ]);\n\n  // other code below ...\n#+END_SRC\n\nNotice the first argument of the =spawn= function being =sudo=, which\ntakes care of the permissions required for the GPIO pins. We show you\nthis in an attempt to be transparent, and asure you no funny business\nis taking place.\n\n** Raspberry Pi Pin Layout Reference\n   [[./images/raspberry_pi_circuit_note_fig2a.jpg]]\n   * Source: https://www.jameco.com/Jameco/workshop/circuitnotes/raspberry_pi_circuit_note_fig2a.jpg\n\n** Wiring the Sensors\n   [[./images/hcsr04.png]]\n   * Source: https://github.com/mochman/MMM-Swipe (shamelessly lifted)\n\n** How we wired ours\n   [[./images/MMM-Simple-Swiper-Pin-Layout.jpg]]\n   * _IMPORTANT:_ Do not forget to add a resistor to the Echo wire. Refer to the diagram above.\n\n** Config\n   The default config is shown below, and the order in which the values\n   are listed are not important.  Feel free to tweak the values to your\n   needs. Also, please read the =Tested Conditions/Warning= section\n   below.\n\n#+BEGIN_SRC js\n// other module configs ...\n\n   module: \"MMM-Simple-Swiper\",\n   disabled: false,\n   config: {\n       echoLeftPin: 24, // GPIO #\n       triggerLeftPin: 23, // GPIO #\n       echoRightPin: 26, // GPIO #\n       triggerRightPin: 25, // GPIO #\n       threshold: 175, // in centimeters\n       distanceDiff: 1.25, // difference between both sensors\n       debug: false, // if true, the raw data is printed to stdout while MagicMirror is running\n       magicMirrorDelay: 1000, // number of milliseconds between passing data from C executable to the node_helper for MagicMirror to act upon\n       sensorDelay: 10, // the number of microseconds each sensor waits to check for changes in voltage (fine tune this for CPU performance)\n   }\n\n// other module configs ...\n#+END_SRC\n\n** MMM-pages\n   When using with =MMM-pages=, place =MMM-Simple-Swiper= within the\n   =fixed= property. The =fixed= property contains the list of modules\n   which are fixed in place (as the name would suggest).\n\n   Just so it's more clear, here's the example config taken from the\n   =MMM-pages= Github, with our module tucked nicely inside the\n   =fixed= section.\n\n#+BEGIN_SRC js\n  modules: [\n    {\n      module: 'MMM-pages',\n      config: {\n        modules: [\n          [ \"weatherforecast\", \"newsfeed\"],\n          [ \"calendar\", \"compliments\" ]\n        ],\n\n        fixed: [\n          \"clock\",\n          \"currentweather\",\n          \"MMM-page-indicator\",\n          \"MMM-Simple-Swiper\"\n        ],\n\n      }\n    }\n  ]\n#+END_SRC\n\n\n** Tested Conditions/Warning\n   This has only been tested on the RaspberryPi 3 B using Raspbian (based\n   on Debian Stretch), using two HC-SR04 ultra sonic sensors. This module\n   was intended to be run along side =MMM-pages= and\n   =MMM-page-indicator=, and has done so very well in our testing. Also,\n   since the C executable outputs raw values from the sensors, if you\n   wanted to take the code and utilize it in another project, please,\n   feel free. In fact, you're encouraged to do so.\n\n   While messing around with the =delay= parameter of the config in the\n   =MMM-Simple-Swiper= file, we did notice that anything less than 600\n   milliseconds can cause the entire module to hang after running for\n   approximately 30 seconds. We haven't figured out exactly why, but we\n   suspect it has to do with too much throughput, and the child process\n   not being able to read the data from stdout fast enough. Additionally,\n   attempting to cover the sensors or swiping across the sensors rapidly\n   can cause the module to lock up. We are actively looking into\n   this issue, but, if you can exercise patience, and swipe through your\n   pages at a moderate pace, you will not experience this issue.\n\n   If you notice any bugs, please let us know, and we'll do our best to\n   correct them.\n\n   Side note, I'm sure you noticed we abused the use of the special\n   =tags=... =Well, we like how it looks=.\n\n* Future Work\n  We intend to add more options that can be tweaked from the\n  =config.js=, such as:\\\\\n  * being able to change the direction in which pages slide\n    (ie. left-to-right or right-to-left)\n  * adjusting the number of samples the sensors use for determining\n    motion\n\n  If you have any suggestions that would be cool, or useful, feel free\n  to email us!\n\n* Performance Demonstration\n[[./videos/MMM-Simple-Swiper-Demo.mp4]]\n\n* Step-By-Step Instructions\n** Screencasted Video of Installation\n   [[./videos/MMM-Simple-Swiper-Installation.mp4]]\n** Before getting started...\n\n   1) The demo installation was done on a _Raspberry Pi 3 B_ running\n      Raspbian\n      * The board was _BRAND NEW_ and the OS was _FRESHLY_ installed\n      * The installation occurred after the initial boot and initial\n        update\n        + =Remote GPIO= and =SSH= were enabled under =raspi-config=\n        + (You can enable them as well, if you would like to by\n          following below)\n          1) Open a terminal window\n          2) run =sudo raspi-config=\n          3) select =Interfacing Options=, select =SSH=; select =\u003cYES\u003e=\n             to enable\n          4) Also within =Interfacing Options=; select =Remote GPIO=;\n             select =\u003cYES\u003e= to enable\n\n        + I created SSH keys \u0026 copied them to my laptop (for easier\n          SSHing)\n          * For information on how to do this, see:\n            https://www.ssh.com/ssh/keygen/\n        + Otherwise, nothing else beyond what is shown was installed or\n          removed\n\n   2) I used my laptop to SSH into the Pi and record the installation\n      * The Pi cannot handle screen recording + installation of\n        MagicMirror very well\n\n   3) All of these steps can be replicated directly from the Raspberry\n      Pi 3 B in a terminal\n\n   4) There were no steps skipped throughout the video\n\n   5) Instructions for the =Required Packages= are from the relevant\n      Github pages\n\n   6) The Required Packages are the _BARE MINIMUM_ to get this working\n\n   7) _NOTE_: Within the =Basic config.js containing required modules=\n      * There are default modules, which can be removed, if desired\n        (see comments within file)\n\n\n** Required Magic Mirror Modules\n*** NodeJS (10.15 or higher)\n   #+BEGIN_SRC sh\n\n     # taken from: https://github.com/MichMich/MagicMirror\n\n     curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -\n\n     sudo apt install nodejs -y\n\n   #+END_SRC\n\n*** MagicMirror\n   #+BEGIN_SRC sh\n\n     cd ~/\n\n     git clone https://github.com/MichMich/MagicMirror\n\n     cd ~/MagicMirror\n\n     npm install\n\n     # for the moment, don’t start the MagicMirror\n\n   #+END_SRC\n\n*** MMM-pages\n   #+BEGIN_SRC sh\n\n     cd ~/MagicMirror/modules/\n\n     git clone https://github.com/edward-shen/MMM-pages.git\n\n     cd ~/MagicMirror/modules/MMM-pages\n\n     npm install\n\n   #+END_SRC\n\n*** MMM-page-indicator\n   #+BEGIN_SRC sh\n\n     cd ~/MagicMirror/modules/\n\n     git clone https://github.com/edward-shen/MMM-page-indicator.git\n\n     # this module has no package.json, so \"npm install\" is not needed\n\n   #+END_SRC\n\n*** MMM-Simple-Swiper\n   #+BEGIN_SRC sh\n\n     cd ~/MagicMirror/modules\n\n     git clone https://github.com/Bee-Mar/MMM-Simple-Swiper.git\n\n     cd ~/MagicMirror/modules/MMM-Simple-Swiper\n\n     # ONLY DO THIS IF YOU DON’T ALREADY HAVE A CONFIG SETUP\n     cp sample-config-file/SAMPLE_CONFIG.js ~/MagicMirror/config/config.js\n     # otherwise, simply examine the file, and see what is required\n\n     # installing dependencies and compile executable\n     make build_depends \u0026\u0026 make\n\n     # OPTIONAL: To test the module, follow below\n     cd ~/MagicMirror/modules/MMM-Simple-Swiper/\n\n     make clean \u0026\u0026 make debug\n\n     sudo ./swiper \"{echoLeftPin: 24, triggerLeftPin: 23, echoRightPin: 26, triggerRightPin: 25, threshold: 175, distanceDiff: 1.25, debug: false, delay: 750, }\"\n\n     # if the executable compiled correctly, then you should see values being output to the screen\n\n     # after running \"make debug\", recompile to build normal executable\n     make clean \u0026\u0026 make\n\n\n\n\n\n   #+END_SRC\n\n\n** Basic config.js containing required modules\n  #+BEGIN_SRC js\n    /* Magic Mirror Config Sample\n     ,*\n     ,* By Michael Teeuw http://michaelteeuw.nl\n     ,* MIT Licensed.\n     ,*\n     ,* For more information how you can configurate this file\n     ,* See https://github.com/MichMich/MagicMirror#configuration\n     ,*\n     ,*/\n\n    var config = {\n      address: \"localhost\", // Address to listen on, can be:\n      // - \"localhost\", \"127.0.0.1\", \"::1\" to listen on loopback interface\n      // - another specific IPv4/6 to listen on a specific interface\n      // - \"\", \"0.0.0.0\", \"::\" to listen on any interface\n      // Default, when address config is left out, is \"localhost\"\n      port: 8080,\n      ipWhitelist: [\"127.0.0.1\", \"::ffff:127.0.0.1\", \"::1\"], // Set [] to allow all IP addresses\n      // or add a specific IPv4 of 192.168.1.5 :\n      // [\"127.0.0.1\", \"::ffff:127.0.0.1\", \"::1\", \"::ffff:192.168.1.5\"],\n      // or IPv4 range of 192.168.3.0 --\u003e 192.168.3.15 use CIDR format :\n      // [\"127.0.0.1\", \"::ffff:127.0.0.1\", \"::1\", \"::ffff:192.168.3.0/28\"],\n\n      language: \"en\",\n      timeFormat: 24,\n      units: \"metric\",\n\n      modules: [\n        {\n          module: \"MMM-pages\", // REQUIRED\n          config: {\n            modules: [\n              [\n                \"weatherforecast\", // feel free to remove or swap out\n                \"newsfeed\", // feel free to remove or swap out\n              ],\n              [\n                \"calendar\", // feel free to remove or swap out\n                \"compliments\", // feel free to remove or swap out\n              ],\n            ],\n            fixed: [\n              \"clock\", // feel free to remove or swap out\n              \"currentweather\", // feel free to remove or swap out\n              \"MMM-page-indicator\", // REQUIRED\n              \"MMM-Simple-Swiper\", // REQUIRED\n            ],\n          },\n        },\n        {\n          module: \"MMM-page-indicator\", //REQUIRED\n          position: \"bottom_bar\", // feel free to adjust\n          config: {\n            pages: 3, // feel free to adjust\n          },\n        },\n        {\n          module: \"MMM-Simple-Swiper\",\n          disabled: false,\n          config: {\n            echoLeftPin: 24, // GPIO #\n            triggerLeftPin: 23, // GPIO #\n            echoRightPin: 26, // GPIO #\n            triggerRightPin: 25, // GPIO #\n            threshold: 175, // in centimeters\n            distanceDiff: 1.25, // difference between both sensors\n            debug: false, // if true, the raw data is printed to stdout while MagicMirror is running\n            delay: 1000, // time between passing data from C executable to the node_helper in milliseconds\n          },\n        },\n        {\n          module: \"alert\", // feel free to remove or swap out\n          disabled: false,\n        },\n        {\n          module: \"updatenotification\", // feel free to remove or swap out\n          position: \"top_bar\",\n          disabled: false,\n        },\n        {\n          module: \"clock\", // feel free to remove or swap out\n          position: \"top_right\",\n          timeFormat: 12,\n          showPeriodUpper: true,\n          disabled: false,\n        },\n        {\n          module: \"calendar\", // feel free to remove or swap out\n          header: \"US Holidays\",\n          position: \"top_right\",\n          disabled: false,\n          config: {\n            calendars: [\n              {\n                symbol: \"calendar-check-o \",\n                url: \"webcal://www.calendarlabs.com/templates/ical/US-Holidays.ics\",\n              },\n            ],\n          },\n        },\n\n        {\n          module: \"compliments\", // feel free to remove or swap out\n          position: \"lower_third\",\n          disabled: true,\n        },\n\n        {\n          module: \"weatherforecast\", // feel free to remove or swap out\n          position: \"top_right\",\n          header: \"Weather Forecast\",\n          disabled: false,\n          config: {\n            location: \"New York, NY, USA\",\n            units: \"imperial\",\n            appid: \"c0520f8e8537b2c7555a9f7d5c2d53ec\",\n          },\n        },\n\n        {\n          module: \"currentweather\", // feel free to remove or swap out\n          position: \"top_right\",\n          disabled: false,\n          config: {\n            location: \"New York, NY, USA\",\n            units: \"imperial\",\n            appid: \"c0520f8e8537b2c7555a9f7d5c2d53ec\",\n          },\n        },\n\n        {\n          module: \"newsfeed\", // feel free to remove or swap out\n          position: \"bottom_bar\",\n          config: {\n            feeds: [\n              {\n                title: \"New York Times\",\n                url: \"http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml\",\n              },\n              {\n                title: \"CNET\",\n                url: \"https://www.cnet.com/rss/news/\",\n              },\n              {\n                title: \"TechRepublic\",\n                url: \"https://www.techrepublic.com/rssfeeds/articles/\",\n              },\n            ],\n            showSourceTitle: true,\n            showPublishDate: true,\n          },\n        },\n      ],\n    };\n\n    /*************** DO NOT EDIT THE LINE BELOW ***************/\n    if (typeof module !== \"undefined\") {\n      module.exports = config;\n    }\n  #+END_SRC\n\n\n** Start MagicMirror\n   #+BEGIN_SRC sh\n\n     cd ~/MagicMirror\n\n     npm start\n\n     # check to ensure the MMM-Simple-Swiper module is running\n     ps -ef | egrep -i \"sudo\\s+.*./MMM-Simple-Swiper/swiper\"\n\n     # if it is running, you should see an output similar to this\n     sudo /home/pi/MagicMirror/modules/MMM-Simple-Swiper/main {\"echoLeftPin\":24,\"triggerLeftPin\":23,\"echoRightPin\":26,\"triggerRightPin\":25,\"threshold\":175,\"distanceDiff\":1.25,\"debug\":false,\"delay\":1000}\n\n     # depending on the arguments provided to the config, your JSON string may differ\n\n   #+END_SRC\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBee-Mar%2FMMM-Simple-Swiper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FBee-Mar%2FMMM-Simple-Swiper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBee-Mar%2FMMM-Simple-Swiper/lists"}