Skip to content

Commit

Permalink
[inspection] Progress by USER button
Browse files Browse the repository at this point in the history
  • Loading branch information
matsujirushi committed Aug 8, 2024
1 parent 4d4ce67 commit fc8aa2d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/compile-examples-and-tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ jobs:
- source-url: https://github.com/matsujirushi/ntshell.git
- name: Grove Ultrasonic Ranger
version: 1.0.1
- name: AceButton
version: 1.10.1
sketch-paths: |
- examples
- extras/tools
2 changes: 2 additions & 0 deletions .github/workflows/create_prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ jobs:
libraries: |
- source-path: .
- source-url: https://github.com/matsujirushi/ntshell.git
- name: AceButton
version: 1.10.1
sketch-paths: |
- ${{ matrix.sketch_path }}
cli-compile-flags: |
Expand Down
44 changes: 39 additions & 5 deletions extras/tools/inspection/inspection.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@
* MIT License
*/

////////////////////////////////////////////////////////////////////////////////
// Libraries:
// http://librarymanager#AceButton 1.10.1

#include <Adafruit_TinyUSB.h>
#include <WioCellular.h>
#include <AceButton.h>

using namespace ace_button;

static constexpr int POWER_ON_TIMEOUT = 20000; // [ms]

static const char* CELLULAR_REVISION = "BG770AGLAAR02A05_JP_01.200.01.200";

static AceButton UserButton(PIN_BUTTON1);
static bool UserButtonPressed = false;
static int ErrorCount = 0;

void setup(void) {
Expand All @@ -25,18 +34,21 @@ void setup(void) {
Serial.println();

Serial.println("Initialize");
auto config = UserButton.getButtonConfig();
config->setEventHandler(userButtonHandler);
config->setDebounceDelay(50);
WioCellular.begin();

delay(1000);
Serial.println("Wait for USER button");

UserButtonPressed = false;
while (true) {
if (millis() % 400 < 200)
ledOn(LED_BUILTIN);
else
ledOff(LED_BUILTIN);

if (digitalRead(PIN_BUTTON1) == LOW) break;
UserButton.check();
if (UserButtonPressed) break;

delay(2);
}
Expand All @@ -46,12 +58,26 @@ void setup(void) {
Serial.print("Enable Grove ... ");
WioCellular.enableGrovePower();
Serial.println("OK");
delay(5000);

Serial.println("Wait for USER button");
UserButtonPressed = false;
while (true) {
UserButton.check();
if (UserButtonPressed) break;
delay(2);
}

Serial.print("Disable Grove ... ");
WioCellular.disableGrovePower();
Serial.println("OK");
delay(5000);

Serial.println("Wait for USER button");
UserButtonPressed = false;
while (true) {
UserButton.check();
if (UserButtonPressed) break;
delay(2);
}

Serial.print("Power ON cellular ... ");
{
Expand Down Expand Up @@ -99,3 +125,11 @@ void loop(void) {
Serial.flush();
suspendLoop();
}

static void userButtonHandler(AceButton* button, uint8_t eventType, uint8_t buttonState) {
switch (eventType) {
case AceButton::kEventPressed:
UserButtonPressed = true;
break;
}
}

0 comments on commit fc8aa2d

Please sign in to comment.