|
| 1 | +/** |
| 2 | + * @file ext_wakeup.ino |
| 3 | + * @author SeanKwok ([email protected]) |
| 4 | + * @brief TimerCAM Ext Wakeup Test |
| 5 | + * @version 0.1 |
| 6 | + * @date 2024-04-08 |
| 7 | + * |
| 8 | + * |
| 9 | + * @Hardwares: TimerCAM |
| 10 | + * @Platform Version: Arduino M5Stack Board Manager v2.1.0 |
| 11 | + * @Dependent Library: |
| 12 | + * TimerCam-arduino: https://github.com/m5stack/TimerCam-arduino |
| 13 | + */ |
| 14 | + |
| 15 | +#include "M5TimerCAM.h" |
| 16 | + |
| 17 | +#define CAM_EXT_WAKEUP_PIN 4 |
| 18 | + |
| 19 | +void led_breathe(int ms) { |
| 20 | + for (int16_t i = 0; i < 255; i++) { |
| 21 | + TimerCAM.Power.setLed(i); |
| 22 | + vTaskDelay(pdMS_TO_TICKS(ms)); |
| 23 | + } |
| 24 | + |
| 25 | + for (int16_t i = 255; i >= 0; i--) { |
| 26 | + TimerCAM.Power.setLed(i); |
| 27 | + vTaskDelay(pdMS_TO_TICKS(ms)); |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +void setup() { |
| 32 | + TimerCAM.begin(true); |
| 33 | + Serial.println("Wake up!!!"); |
| 34 | + led_breathe(5); |
| 35 | + |
| 36 | + if (!TimerCAM.Camera.begin()) { |
| 37 | + Serial.println("Camera Init Fail"); |
| 38 | + return; |
| 39 | + } |
| 40 | + Serial.println("Camera Init Success"); |
| 41 | + TimerCAM.Camera.sensor->set_pixformat(TimerCAM.Camera.sensor, |
| 42 | + PIXFORMAT_JPEG); |
| 43 | + TimerCAM.Camera.sensor->set_framesize(TimerCAM.Camera.sensor, |
| 44 | + FRAMESIZE_QVGA); |
| 45 | + |
| 46 | + TimerCAM.Camera.sensor->set_vflip(TimerCAM.Camera.sensor, 1); |
| 47 | + TimerCAM.Camera.sensor->set_hmirror(TimerCAM.Camera.sensor, 0); |
| 48 | + |
| 49 | + if (TimerCAM.Camera.get()) { |
| 50 | + Serial.printf("pic size: %d\n", TimerCAM.Camera.fb->len); |
| 51 | + TimerCAM.Camera.free(); |
| 52 | + } |
| 53 | + |
| 54 | + TimerCAM.Camera.deinit(); |
| 55 | + |
| 56 | + // sleep after 5s wakeup! |
| 57 | + // TimerCAM.Power.timerSleep(5); |
| 58 | + gpio_hold_en((gpio_num_t)POWER_HOLD_PIN); |
| 59 | + gpio_deep_sleep_hold_en(); |
| 60 | + esp_sleep_enable_ext0_wakeup((gpio_num_t)CAM_EXT_WAKEUP_PIN, |
| 61 | + 1); // 1 = High, 0 = Low |
| 62 | + |
| 63 | + while (digitalRead(CAM_EXT_WAKEUP_PIN) == HIGH) { |
| 64 | + // wait for singal to go low |
| 65 | + delay(1); |
| 66 | + } |
| 67 | + |
| 68 | + // Go to sleep now |
| 69 | + Serial.println("Going to sleep now"); |
| 70 | + esp_deep_sleep_start(); |
| 71 | +} |
| 72 | + |
| 73 | +void loop() { |
| 74 | +} |
0 commit comments