123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- #include <Arduino.h>
- #include <stdio.h>
- #include <esp_now.h>
- #include <WiFi.h>
- #include "buzzer.h"
- #include "coaster_switch.h"
- #include "crv2_esp_now.h"
- #include "configuration.h"
- #include "credentials.h"
- #include "display.h"
- #include "neighbors.h"
- #include "ota.h"
- #include "led_ring.h"
- Neighbor_List NList;
- void setup() {
- Serial.begin(115200);
- Serial.println("Welcome to the CRV2!");
- +
- Serial.println("Here's what I know about myself:");
- Serial.print(" ESP_NOW_MAX_DATA_LEN = "); Serial.println(ESP_NOW_MAX_DATA_LEN);
- // Initialize Display
- Serial.println("Initializing display...");
- display_setup();
- // Initialize leds first to turn of pwm
- Serial.println("Initializing LEDs...");
- led_setup();
- led_setall(255, 0, 0); // Start at red
-
- Serial.println("Initializing Buzzer...");
- buzzer_setup();
- beep(); delay(200); beep(); delay(200); beep(); delay(200);
- //Set device in STA mode to begin with
- Serial.println("Initializing WiFi...");
- #ifdef WIFI_CONNECT
- ota_setup();
- #else
- WiFi.mode(WIFI_STA);
- #endif
- // This is the mac address of the Master in Station Mode
- Serial.print("WiFi Channel: "); Serial.println(WiFi.channel());
- Serial.print("STA MAC: "); Serial.println(WiFi.macAddress());
- Serial.println("Initializing ESP Now");
-
- if (esp_now_init() == ESP_OK) {
- Serial.println("ESPNow Init Success");
- }
- else {
- Serial.println("ESPNow Init Failed");
- ESP.restart();
- }
-
- esp_now_register_send_cb(OnDataSent);
- esp_now_register_recv_cb(OnDataRecv);
- Serial.println("Initializing coaster...");
- coaster_setup();
-
- // Initializing broadcast
- initBroadcast();
- led_setall(0, 0, 255); // Blue after initialization
- }
- void loop() {
- receive_buffer_t *incoming;
- if(WIFI_Enabled) ota_handle(); // handle OTA updates on if enabled and connected successfully
-
- while( (incoming = get_message()) != NULL ) {
- process_message(*incoming);
- }
- NList.beacon();
- if(millis() % 1000 == 0 && DEBUG) {
- Serial.print("Debug: Coaster Value: "); Serial.println(coaster_current_value());
- }
-
- if(millis() % 5000 == 0 && DEBUG) {
- Serial.print("Debug: Neighbor List: "); NList.print_list();
- }
-
- //if(NList.ready()) {
- // led_setall(0, 255, 0); // Green if we're good
- //} else {
- // led_setall(0, 0, 255); // Blue for determining
- //}
- //buzz(); delay(200);
- //buzz(); delay(200);
- //buzz(); delay(200);
- //led_examples(); // testing
- }
|