Browse Source

Added ESPNow

master
Englebert 2 years ago
parent
commit
9ab69b2109
  1. 6
      README.md
  2. 54
      openscad/BoxMode.scad
  3. 9
      src/Screen.cpp
  4. 10
      src/Screen.h
  5. 41
      src/main.cpp
  6. 8
      src/main.h

6
README.md

@ -126,3 +126,9 @@ Pushing [yawincrease.raw]...
### HOW TO DELETE THE FILE
To delete it is easy:
curl -s http://192.168.1.1/erase?filename=the_filename
### REFERENCE
1. https://randomnerdtutorials.com/esp-now-auto-pairing-esp32-esp8266/ - Auto pairing
2. https://github.com/Servayejc

54
openscad/BoxMode.scad

@ -1,9 +1,10 @@
round_quality=500;
draft=true;
show_gimbal=false;
show_body=true;
show_body=false;
show_all=false;
show_m5_back=true;
show_m5_back=false;
show_gimbal_back=true;
if(show_body) {
controller();
@ -13,6 +14,17 @@ if(show_m5_back) {
m5_back();
}
if(show_gimbal_back) {
translate([-47,-66,-48])
gimbal_back();
if(show_body) {
translate([-47,66,-48])
rotate([0,0,180])
gimbal_back();
}
}
if(show_gimbal) {
translate([0,-41,-8.5])
gimbal_ring();
@ -44,6 +56,44 @@ translate([-23.5,-70,13])
**/
/******* Modules *******/
module gimbal_back() {
difference() {
cube([70,70,13], center=true);
translate([0,0,0.76])
cube([62.5,62.5,11.5], center=true);
translate([0,30,4])
cube([20,20,7], center=true);
// Corners
translate([36.3,-36.3,-10])
rotate([0,0,45])
cube([10,10,40], center=true);
translate([-36.3,-36.3,-10])
rotate([0,0,45])
cube([10,10,40], center=true);
translate([-36.3,36.3,-10])
rotate([0,0,45])
cube([10,10,40], center=true);
translate([36.3,36.3,-10])
rotate([0,0,45])
cube([10,10,40], center=true);
}
translate([0,-30.7,4])
cube([62,1,20], center=true);
translate([0,30.7,4])
difference() {
cube([62,1,20], center=true);
translate([0,0,0]);
cube([25,20,100], center=true);
}
translate([30.7,0,4])
cube([1,62.4,20], center=true);
translate([-30.7,0,4])
cube([1,62.4,20], center=true);
}
module m5_back() {
translate([-95,0,-6]) {
difference() {

9
src/Screen.cpp

@ -41,6 +41,8 @@ void Screen::update(void) {
menu_poweroff();
} else if(current_screen == SCREEN_MENU_BLUETOOTH) {
blegamepad.show(&mainscreen_buffer);
} else if(current_screen == SCREEN_MENU_ESPNOW_PAIRING) {
esppair.show(&mainscreen_buffer);
} else if(current_screen == SCREEN_MENU_STICK_CALIBRATION) {
stickcalibration.show(&mainscreen_buffer);
} else if(current_screen == SCREEN_MENU_STICK_POSITIONS) {
@ -86,13 +88,10 @@ void Screen::menu(void) {
static String menu_items_name[] = {
"Bluetooth ",
"ESPNow Pairing ",
"Stick Calibration ",
"Stick Positions ",
"Trims ",
"WiFi ",
"RX Binding ",
"RF Settings ",
"RF Scanners ",
"Save Settings ",
"Reset ",
"Reboot ",
@ -185,6 +184,8 @@ void Screen::menu(void) {
stickcalibration.updated = true;
} else if(current_menu == MENU_STICK_POSITIONS) {
current_screen = SCREEN_MENU_STICK_POSITIONS;
} else if(current_menu == MENU_ESPNOW_PAIRING) {
current_screen = SCREEN_MENU_ESPNOW_PAIRING;
}
updated = true;
}

10
src/Screen.h

@ -4,6 +4,7 @@
#include <Arduino.h>
#include <M5Core2.h>
#include "BLEGamepad.h"
#include "ESPPair.h"
#include "StickCalibration.h"
#include "StickPositions.h"
@ -11,7 +12,7 @@
#define INTRO_TIME 100
#define MENU_HEIGHT 20
#define MENU_MAX_ITEMS 12
#define MENU_MAX_ITEMS 9
#define DIALOGBOX_FOREGROUND TFT_WHITE
#define DIALOGBOX_BACKGROUND TFT_NAVY
@ -24,18 +25,15 @@ enum screen_names {
SCREEN_MENU_BLUETOOTH,
SCREEN_MENU_STICK_CALIBRATION,
SCREEN_MENU_STICK_POSITIONS,
SCREEN_MENU_RC_CONTROLLER
SCREEN_MENU_ESPNOW_PAIRING
};
enum menu_items {
MENU_BLUETOOTH,
MENU_ESPNOW_PAIRING,
MENU_STICK_CALIBRATION,
MENU_STICK_POSITIONS,
MENU_TRIMS,
MENU_WIFI,
MENU_RX_BINDING,
MENU_RF_SETTINGS,
MENU_RF_SCANNERS,
MENU_SAVE_SETTINGS,
MENU_RESET,
MENU_REBOOT,

41
src/main.cpp

@ -27,9 +27,11 @@ void setup() {
// speak.dingdong();
storage.begin();
customwifi.begin();
///////customwifi.begin();
inputs.begin();
stickcalibration.begin();
esppair.begin();
espnow2.begin();
// tx.begin();
web.begin();
@ -205,3 +207,40 @@ void taskBLE(void *pvParameters) {
vTaskDelay(5);
}
}
/***
void on_data_sent(const uint8_t *mac_addr, esp_now_send_status_t status) {
// Remove the serial print to speed up the process. Only uncomment it for debugging purposes.
Serial.print("\r\nLast Packet Send Status:\t");
Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
}
void on_data_recv(const uint8_t * mac_addr, const uint8_t *incoming_data, int len) {
// Remove the serial print to speed up the process. Only uncomment it for debugging purposes.
Serial.print("Packet received from: ");
//// espnow.printMAC(mac_addr);
Serial.println();
Serial.print("data size = ");
Serial.println(sizeof(incoming_data));
uint8_t type = incoming_data[0];
switch(type) {
case DATA: // received data from server
// Do nothing. As this program interested on sending data but not receiving.
break;
case PAIRING: // received pairing data from server
memcpy(&espnow2.pairing_data, incoming_data, sizeof(espnow2.pairing_data));
espnow2.printMAC(mac_addr);
Serial.print("Pairing done for ");
espnow2.printMAC(espnow2.pairing_data.mac_address);
Serial.print(" on channel " );
Serial.print(espnow2.pairing_data.channel); // channel used by the server
espnow2.addPeer(espnow2.pairing_data.mac_address, espnow2.pairing_data.channel); // add the server to the peer list
// Save the details into LittleFS
espnow2.pairing_status = PAIR_PAIRED; // set the pairing status
break;
}
}
***/

8
src/main.h

@ -10,13 +10,18 @@
#define VERSION_MINOR 0
#define VERSION_BUILD 9
#include <M5Core2.h>
#include "esp_wifi.h"
#include <esp_now.h>
#include "Inputs.h"
#include "BLE.h"
// #include "Speak.h"
#include "Screen.h"
#include "Storage.h"
#include "CustomWiFi.h"
#include "ESPNow2.h"
#include "ESPPair.h"
#include "Web.h"
// Task Handler
@ -27,4 +32,7 @@ void taskInput(void *pvParameters);
void taskBLE(void *pvParameters);
void taskCharger(void *pvParameters);
// void on_data_sent(const uint8_t *mac_addr, esp_now_send_status_t status);
// void on_data_recv(const uint8_t * mac_addr, const uint8_t *incoming_data, int len);
#endif
Loading…
Cancel
Save