Skip to content

Commit

Permalink
Merge pull request #29 from htotoo/i2cshell
Browse files Browse the repository at this point in the history
I2cshell part 1
  • Loading branch information
htotoo authored Nov 6, 2024
2 parents 35bb9a6 + 801c4c9 commit 0a8494a
Show file tree
Hide file tree
Showing 9 changed files with 612 additions and 590 deletions.
2 changes: 1 addition & 1 deletion Source/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@
"cinttypes": "cpp",
"typeinfo": "cpp"
},
"idf.portWin": "COM6",
"idf.portWin": "COM14",
"idf.flashType": "UART"
}
12 changes: 10 additions & 2 deletions Source/data/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>

<head>
<title>ESP32PP v0.12</title>
<title>ESP32PP v0.13</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
Expand Down Expand Up @@ -109,7 +109,7 @@
<body>
<div class="setupicon"><a href="setup.html">&#9881;</a></div>

<h1>ESP32 PP v0.12</h1>
<h1>ESP32 PP v0.13</h1>
<div id="connState">WS Connecting...</div>
<div id="connStatePP">PP not connected to ESP</div>
<div class="management">
Expand Down Expand Up @@ -307,6 +307,14 @@ <h1>ESP32 PP v0.12</h1>
document.getElementById("connStatePP").innerHTML = "PP NOT connected to ESP";
return false;
}
if (msg == "#$##$$#USB_CC\r\n") {
log("PP Connected");
enadisaControls(true); //not yet working
fileManClose();
document.getElementById("connStatePP").innerHTML = "PP connected to ESP";
autoScreenRefresh();
return false;
}
if (msg == "#$##$$#I2C_CC\r\n") {
log("PP Connected (I2C)");
enadisaControls(false); //not yet working
Expand Down
2 changes: 1 addition & 1 deletion Source/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

idf_component_register(SRCS "wifim.cpp" "led.cpp" "configuration.cpp" "sensordb.c" "orientation.c" "environment.c" "ppi2c/pp_handler.cpp" "ppi2c/i2c_slave_driver.c" "drivers/i2cdev.c" "drivers/hmc5883l.c" "drivers/lsm303.c" "drivers/mpu925x.c" "drivers/sht3x.c" "drivers/bh1750.c" "drivers/bmp280.c" "drivers/adxl345.c" "nmea_parser.c" "main.cpp"
idf_component_register(SRCS "ppshellcomm.cpp" "wifim.cpp" "led.cpp" "configuration.cpp" "sensordb.c" "orientation.c" "environment.c" "ppi2c/pp_handler.cpp" "ppi2c/i2c_slave_driver.c" "drivers/i2cdev.c" "drivers/hmc5883l.c" "drivers/lsm303.c" "drivers/mpu925x.c" "drivers/sht3x.c" "drivers/bh1750.c" "drivers/bmp280.c" "drivers/adxl345.c" "nmea_parser.c" "main.cpp"
"sgp4/brent.cpp"
"sgp4/sgp4coord.cpp"
"sgp4/sgp4ext.cpp"
Expand Down
40 changes: 22 additions & 18 deletions Source/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ static const char* TAG = "ESP32PP";
#include "webserver.h"

#include "nmea_parser.h"
#include "usbpart.h"
#include "wifim.h"

#include "ppshellcomm.h"
#include "orientation.h"
#include "environment.h"

Expand Down Expand Up @@ -81,7 +80,7 @@ uint32_t last_millis[TimerEntry_MAX] = {0};
// ______________________________________SEN GPS ORI ENV TIME WEB RGB SAT DOWN
uint32_t timer_millis[TimerEntry_MAX] = {2000, 2000, 1000, 2000, 60000 * 10, 2000, 1000, 2000, 20000};

float heading = 0.0;
float heading = 400.0;
float tilt = 0.0;
float temperatureEsp = 0.0;
float temperature = 0.0;
Expand Down Expand Up @@ -410,7 +409,7 @@ void app_main(void) {
i2c_scan();

ESP_ERROR_CHECK(esp_event_loop_create_default());
usb_init();
PPShellComm::init();

WifiM::initialise_wifi();
WifiM::wifi_apsta();
Expand Down Expand Up @@ -484,6 +483,11 @@ void app_main(void) {
PPHandler::add_app((uint8_t*)sattrack, sizeof(sattrack));
PPHandler::add_app((uint8_t*)digitalrain, sizeof(digitalrain));

PPShellComm::set_data_rx_callback([](const uint8_t* data, size_t data_len) -> bool {
ws_sendall((uint8_t*)data, data_len);
return true;
});

while (true) {
time_millis = esp_timer_get_time() / 1000;
if (sat_to_track_new != "") {
Expand All @@ -506,7 +510,7 @@ void app_main(void) {
}

// REPORT ALL SENSOR DATA TO WEB
if (!getInCommand() && (time_millis - last_millis[TimerEntry_REPORTWEB] > timer_millis[TimerEntry_REPORTWEB])) {
if (!PPShellComm::getInCommand() && (time_millis - last_millis[TimerEntry_REPORTWEB] > timer_millis[TimerEntry_REPORTWEB])) {
char buff[300] = {0};
snprintf(buff, 300,
"#$##$$#GOTSENS"
Expand All @@ -525,49 +529,49 @@ void app_main(void) {

// REPORT SENSOR DATA TO PP. EACH HAS OWN TIMER!
char gotusb[300];
if (getUsbConnected() && !getInCommand() && (time_millis - last_millis[TimerEntry_REPORTPPGPS] > timer_millis[TimerEntry_REPORTPPGPS])) {
if (PPShellComm::getAnyConnected() && !PPShellComm::getInCommand() && (time_millis - last_millis[TimerEntry_REPORTPPGPS] > timer_millis[TimerEntry_REPORTPPGPS])) {
if (gpsdata.latitude != 0 || gpsdata.longitude != 0) {
snprintf(gotusb, 290, "gotgps %.06f %.06f %.02f %.01f %d\r\n", gpsdata.latitude, gpsdata.longitude, gpsdata.altitude, gpsdata.speed, gpsdata.sats_in_use);
ESP_LOGI(TAG, "%s", gotusb);
if (wait_till_usb_sending(1)) {
write_usb_blocking((uint8_t*)gotusb, strnlen(gotusb, 290), true, false);
if (PPShellComm::wait_till_sending(1)) {
PPShellComm::write_blocking((uint8_t*)gotusb, strnlen(gotusb, 290), true, false);
last_millis[TimerEntry_REPORTPPGPS] = time_millis;
ESP_LOGI(TAG, "gotgps sent");
}
}
}
if (getUsbConnected() && !getInCommand() && (time_millis - last_millis[TimerEntry_REPORTPPORI] > timer_millis[TimerEntry_REPORTPPORI])) {
if (PPShellComm::getAnyConnected() && !PPShellComm::getInCommand() && (time_millis - last_millis[TimerEntry_REPORTPPORI] > timer_millis[TimerEntry_REPORTPPORI])) {
if (heading < 400) // got heading data
{
snprintf(gotusb, 290, "gotorientation %.01f %.01f\r\n", heading, tilt);
ESP_LOGI(TAG, "%s", gotusb);
if (wait_till_usb_sending(1)) {
write_usb_blocking((uint8_t*)gotusb, strnlen(gotusb, 290), true, false);
if (PPShellComm::wait_till_sending(1)) {
PPShellComm::write_blocking((uint8_t*)gotusb, strnlen(gotusb, 290), true, false);
last_millis[TimerEntry_REPORTPPORI] = time_millis;
ESP_LOGI(TAG, "gotorientation sent");
}
}
}
if (getUsbConnected() && !getInCommand() && (time_millis - last_millis[TimerEntry_REPORTPPENVI] > timer_millis[TimerEntry_REPORTPPENVI])) {
if (PPShellComm::getAnyConnected() && !PPShellComm::getInCommand() && (time_millis - last_millis[TimerEntry_REPORTPPENVI] > timer_millis[TimerEntry_REPORTPPENVI])) {
if (heading < 400) // got heading data
{
snprintf(gotusb, 290, "gotenv %.02f %.01f %.02f %d\r\n", temperature, humidity, pressure, light);
ESP_LOGI(TAG, "%s", gotusb);
if (wait_till_usb_sending(1)) {
write_usb_blocking((uint8_t*)gotusb, strnlen(gotusb, 290), true, false);
if (PPShellComm::wait_till_sending(1)) {
PPShellComm::write_blocking((uint8_t*)gotusb, strnlen(gotusb, 290), true, false);
last_millis[TimerEntry_REPORTPPENVI] = time_millis;
ESP_LOGI(TAG, "gotenv sent");
}
}
}
if (getUsbConnected() && !getInCommand() && (time_millis - last_millis[TimerEntry_REPORTPPTIME] > timer_millis[TimerEntry_REPORTPPTIME])) {
if (PPShellComm::getAnyConnected() && !PPShellComm::getInCommand() && (time_millis - last_millis[TimerEntry_REPORTPPTIME] > timer_millis[TimerEntry_REPORTPPTIME])) {
uint16_t cmxs = gpsdata.tim.minute * gpsdata.tim.second + gpsdata.tim.second + gpsdata.tim.hour;
if (gpsdata.date.year < 44 && gpsdata.date.year >= 23 && lastReportedMxS != cmxs) // got a valid time, and ti is not the last
{
snprintf(gotusb, 290, "rtcset %d %d %d %d %d %d\r\n", gpsdata.date.year, gpsdata.date.month, gpsdata.date.day, gpsdata.tim.hour, gpsdata.tim.minute, gpsdata.tim.second);
ESP_LOGI(TAG, "%s", gotusb);
if (wait_till_usb_sending(1)) {
write_usb_blocking((uint8_t*)gotusb, strnlen(gotusb, 290), true, false);
if (PPShellComm::wait_till_sending(1)) {
PPShellComm::write_blocking((uint8_t*)gotusb, strnlen(gotusb, 290), true, false);
last_millis[TimerEntry_REPORTPPTIME] = time_millis;
ESP_LOGI(TAG, "settime sent");
lastReportedMxS = cmxs;
Expand All @@ -576,7 +580,7 @@ void app_main(void) {
}

if (time_millis - last_millis[TimerEntry_REPORTRGB] > timer_millis[TimerEntry_REPORTRGB]) {
LedFeedback::rgb_set_by_status(getUsbConnected() | i2p_pp_conn_state, WifiM::getWifiStaStatus(), WifiM::getWifiApClientNum() > 0, gpsdata.latitude != 0 && gpsdata.longitude != 0 && gpsdata.sats_in_use > 2);
LedFeedback::rgb_set_by_status(PPShellComm::getAnyConnected() | i2p_pp_conn_state, WifiM::getWifiStaStatus(), WifiM::getWifiApClientNum() > 0, gpsdata.latitude != 0 && gpsdata.longitude != 0 && gpsdata.sats_in_use > 2);
last_millis[TimerEntry_REPORTRGB] = time_millis;
}

Expand Down
27 changes: 14 additions & 13 deletions Source/main/ppi2c/pp_structures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
#define PP_API_VERSION 1
#define ESP_SLAVE_ADDR 0x51

enum class SupportedFeatures : uint64_t
{
enum class SupportedFeatures : uint64_t {
FEAT_NONE = 0,
FEAT_EXT_APP = 1 << 0,
FEAT_UART = 1 << 1,
Expand Down Expand Up @@ -67,8 +66,7 @@ typedef struct
uint32_t application_count;
} device_info;

enum app_location_t : uint32_t
{
enum app_location_t : uint32_t {
UTILITIES = 0,
RX,
TX,
Expand All @@ -86,8 +84,7 @@ typedef struct
uint32_t binary_size;
} standalone_app_info;

enum class Command : uint16_t
{
enum class Command : uint16_t {
COMMAND_NONE = 0,

// will respond with device_info
Expand All @@ -104,24 +101,28 @@ enum class Command : uint16_t
COMMAND_GETFEAT_DATA_ORIENTATION,
COMMAND_GETFEAT_DATA_ENVIRONMENT,
COMMAND_GETFEAT_DATA_LIGHT,
// Shell specific communication
COMMAND_SHELL_WRITE_DATA, // pp shell to esp. size not defined
COMMAND_SHELL_READ_DATA_SIZE, // how many bytes the esp has to send to pp's shell
COMMAND_SHELL_READ_DATA, // the actual bytes sent by esp. 1st byte's 1st bit is the "hasmore" flag, the remaining 7 bits are the size of the data. exactly 64 byte follows.

};

typedef void (*get_features_CB)(uint64_t &feat);
typedef void (*get_gps_data_CB)(ppgpssmall_t &gpsdata);
typedef void (*get_orientation_data_CB)(orientation_t &gpsdata);
typedef void (*get_environment_data_CB)(environment_t &envdata);
typedef void (*get_light_data_CB)(uint16_t &light);
typedef void (*get_features_CB)(uint64_t& feat);
typedef void (*get_gps_data_CB)(ppgpssmall_t& gpsdata);
typedef void (*get_orientation_data_CB)(orientation_t& gpsdata);
typedef void (*get_environment_data_CB)(environment_t& envdata);
typedef void (*get_light_data_CB)(uint16_t& light);

typedef struct
{
uint8_t *binary;
uint8_t* binary;
uint32_t size;
} app_list_element_t;

typedef struct
{
std::vector<uint8_t> *data;
std::vector<uint8_t>* data;
} pp_command_data_t;

typedef void (*pp_i2c_command)(pp_command_data_t data);
Expand Down
Loading

0 comments on commit 0a8494a

Please sign in to comment.