Skip to content

Commit

Permalink
Merge pull request #4 from youseetoo/devInk
Browse files Browse the repository at this point in the history
Dev ink
  • Loading branch information
KillerInk authored Nov 23, 2022
2 parents f8fdd46 + bf6a388 commit f5b6dc1
Show file tree
Hide file tree
Showing 41 changed files with 462 additions and 567 deletions.
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@
path = lib/Adafruit-ST7735-Library
url = https://github.com/adafruit/Adafruit-ST7735-Library.git
branch = master
[submodule "lib/Adafruit-GFX-Library"]
path = lib/Adafruit-GFX-Library
url = https://github.com/youseetoo/Adafruit-GFX-Library.git
[submodule "lib/arduinoWebSockets"]
path = lib/arduinoWebSockets
url = https://github.com/youseetoo/arduinoWebSockets.git
1 change: 1 addition & 0 deletions lib/Adafruit-GFX-Library
Submodule Adafruit-GFX-Library added at 91d916
1 change: 1 addition & 0 deletions lib/arduinoWebSockets
Submodule arduinoWebSockets added at 323592
7 changes: 4 additions & 3 deletions main/Module.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
#include <esp32-hal-log.h>
#include <ArduinoJson.h>

class Module
{
Expand All @@ -8,7 +9,7 @@ class Module
virtual ~Module();
virtual void setup() = 0;
virtual void loop() = 0;
virtual void act() = 0;
virtual void set() = 0;
virtual void get() = 0;
virtual void act(JsonObject job) = 0;
virtual void set(JsonObject job) = 0;
virtual void get(JsonObject job) = 0;
};
64 changes: 31 additions & 33 deletions main/ModuleController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ namespace RestApi
}
void setModules()
{
deserialize();
moduleController.set();
moduleController.set(deserialize());
serialize();
}
};
Expand Down Expand Up @@ -139,42 +138,41 @@ void ModuleController::get()
(*jdoc)[key_modules][key_joy] = moduleConfig->analogJoystick;
}
// {"task":"/modules_set", "modules" : {"led" : 1, "motor": 1, "slm" : 0, "analogin" : 0, "pid" : 0, "laser" : 0, "dac" : 0, "analogout" : 0, "digitalout" : 0, "digitalin" : 0, "scanner" : 0}}
void ModuleController::set()
void ModuleController::set(JsonObject j)
{
DynamicJsonDocument *jdoc = WifiController::getJDoc();
if (jdoc->containsKey(key_modules))
{
if ((*jdoc)[key_modules].containsKey(keyLed))
moduleConfig->led = (*jdoc)[key_modules][keyLed];
if ((*jdoc)[key_modules].containsKey(key_motor))
moduleConfig->motor = (*jdoc)[key_modules][key_motor];
if ((*jdoc)[key_modules].containsKey(key_home))
moduleConfig->home = (*jdoc)[key_modules][key_home];
if ((*jdoc)[key_modules].containsKey(key_slm))
moduleConfig->slm = (*jdoc)[key_modules][key_slm];
if ((*jdoc)[key_modules].containsKey(key_analogin))
moduleConfig->analogin = (*jdoc)[key_modules][key_analogin];
if ((*jdoc)[key_modules].containsKey(key_pid))
moduleConfig->pid = (*jdoc)[key_modules][key_pid];
if ((*jdoc)[key_modules].containsKey(key_laser))
moduleConfig->laser = (*jdoc)[key_modules][key_laser];
if ((*jdoc)[key_modules].containsKey(key_dac))
moduleConfig->dac = (*jdoc)[key_modules][key_dac];
if ((*jdoc)[key_modules].containsKey(key_analogout))
moduleConfig->analogout = (*jdoc)[key_modules][key_analogout];
if ((*jdoc)[key_modules].containsKey(key_digitalout))
moduleConfig->digitalout = (*jdoc)[key_modules][key_digitalout];
if ((*jdoc)[key_modules].containsKey(key_digitalin))
moduleConfig->digitalin = (*jdoc)[key_modules][key_digitalin];
if ((*jdoc)[key_modules].containsKey(key_scanner))
moduleConfig->scanner = (*jdoc)[key_modules][key_scanner];
if ((*jdoc)[key_modules].containsKey(key_joy))
moduleConfig->analogJoystick = (*jdoc)[key_modules][key_joy];
if (j.containsKey(key_modules))
{
if (j[key_modules].containsKey(keyLed))
moduleConfig->led = j[key_modules][keyLed];
if (j[key_modules].containsKey(key_motor))
moduleConfig->motor = j[key_modules][key_motor];
if (j[key_modules].containsKey(key_home))
moduleConfig->home = j[key_modules][key_home];
if (j[key_modules].containsKey(key_slm))
moduleConfig->slm = j[key_modules][key_slm];
if (j[key_modules].containsKey(key_analogin))
moduleConfig->analogin = j[key_modules][key_analogin];
if (j[key_modules].containsKey(key_pid))
moduleConfig->pid = j[key_modules][key_pid];
if (j[key_modules].containsKey(key_laser))
moduleConfig->laser = j[key_modules][key_laser];
if (j[key_modules].containsKey(key_dac))
moduleConfig->dac = j[key_modules][key_dac];
if (j[key_modules].containsKey(key_analogout))
moduleConfig->analogout = j[key_modules][key_analogout];
if (j[key_modules].containsKey(key_digitalout))
moduleConfig->digitalout = j[key_modules][key_digitalout];
if (j[key_modules].containsKey(key_digitalin))
moduleConfig->digitalin = j[key_modules][key_digitalin];
if (j[key_modules].containsKey(key_scanner))
moduleConfig->scanner = j[key_modules][key_scanner];
if (j[key_modules].containsKey(key_joy))
moduleConfig->analogJoystick = j[key_modules][key_joy];
Config::setModuleConfig(moduleConfig);
setup();
WifiController::restartWebServer();
}
jdoc->clear();
WifiController::getJDoc()->clear();
}

ModuleController moduleController;
2 changes: 1 addition & 1 deletion main/ModuleController.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ModuleController
void loop();
Module *get(AvailableModules mod);
void get();
void set();
void set(JsonObject j);
};

extern ModuleController moduleController;
6 changes: 6 additions & 0 deletions main/docs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
{"task": "/state_set", "isdebug":0}
{"task": "/state_get", "active":1}
{"task": "/wifi/connect", "AP": 1,"PW": "","ssid": "Uc2"}
//cant run inside tasks
{"task": "/wifi/connect", "AP": 1,"PW": "","ssid": "Uc2"}
//cant run inside tasks
{"task":"/modules_set", "modules" : {"motor": 1, joy:1}}
//apply all pins at once
{"tasks": [{"task":"/motor_set","motor":{"steppers": [{ "stepperid": 1, "step": 26, "dir": 16, "enable": 12, "step_inverted": 0, "dir_inverted": 0, "enable_inverted": 1 },{ "stepperid": 2, "step": 25, "dir": 27, "enable": 12, "step_inverted": 0, "dir_inverted": 0, "enable_inverted": 1 }]}},{"task":"/analog_joystick_set", "joy" : {"joyX": 35, joyY:34}}]}


retrieve sensor value
Expand Down
27 changes: 11 additions & 16 deletions main/src/analogin/AnalogInController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ AnalogInController::~AnalogInController(){};
void AnalogInController::loop() {}

// Custom function accessible by the API
void AnalogInController::act() {
void AnalogInController::act(JsonObject ob) {

// here you can do something
if (DEBUG) Serial.println("readanalogin_act_fct");
int readanaloginID = (int)(*WifiController::getJDoc())["readanaloginID"];
int readanaloginID = (int)(ob)["readanaloginID"];
int mN_analogin_avg = N_analogin_avg;
if (WifiController::getJDoc()->containsKey("N_analogin_avg"))
mN_analogin_avg = (int)(*WifiController::getJDoc())["N_analogin_avg"];
if (ob.containsKey("N_analogin_avg"))
mN_analogin_avg = (int)(ob)["N_analogin_avg"];
int analoginpin = 0 ;

if (DEBUG) Serial.print("readanaloginID "); Serial.println(readanaloginID);
Expand Down Expand Up @@ -46,12 +46,12 @@ void AnalogInController::act() {



void AnalogInController::get() {
void AnalogInController::get(JsonObject ob) {
if (DEBUG) Serial.println("readanalogin_set_fct");
int readanaloginID = (int)(*WifiController::getJDoc())["readanaloginID"];
int readanaloginPIN = (int)(*WifiController::getJDoc())["readanaloginPIN"];
if (WifiController::getJDoc()->containsKey("N_analogin_avg"))
N_analogin_avg = (int)(*WifiController::getJDoc())["N_analogin_avg"];
int readanaloginID = (int)(ob)["readanaloginID"];
int readanaloginPIN = (int)(ob)["readanaloginPIN"];
if (ob.containsKey("N_analogin_avg"))
N_analogin_avg = (int)(ob)["N_analogin_avg"];

switch (readanaloginID) {
case 0:
Expand All @@ -74,9 +74,9 @@ void AnalogInController::get() {


// Custom function accessible by the API
void AnalogInController::set() {
void AnalogInController::set(JsonObject jsonDocument) {
if (DEBUG) Serial.println("readanalogin_get_fct");
int readanaloginID = (int)(*WifiController::getJDoc())["readanaloginID"];
int readanaloginID = (int)(jsonDocument)["readanaloginID"];
int readanaloginPIN = 0;
switch (readanaloginID) {
case 0:
Expand All @@ -89,11 +89,6 @@ if (DEBUG) Serial.println("readanalogin_get_fct");
readanaloginPIN = pins.analogin_PIN_2;
break;
}

WifiController::getJDoc()->clear();
(*WifiController::getJDoc())["N_analogin_avg"] = N_analogin_avg;
(*WifiController::getJDoc())["readanaloginPIN"] = readanaloginPIN;
(*WifiController::getJDoc())["readanaloginID"] = readanaloginID;
}


Expand Down
6 changes: 3 additions & 3 deletions main/src/analogin/AnalogInController.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class AnalogInController : public Module
int N_analogin_avg; //no idea if it should be equal to that that one inside PidController.h

void setup() override;
void act() override;
void set() override;
void get() override;
void act(JsonObject jsonDocument) override;
void set(JsonObject jsonDocument) override;
void get(JsonObject jsonDocument) override;
void loop() override;
};

25 changes: 11 additions & 14 deletions main/src/analogin/AnalogJoystick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ namespace RestApi
{
void AnalogJoystick_set()
{
deserialize();
moduleController.get(AvailableModules::analogJoystick)->set();
moduleController.get(AvailableModules::analogJoystick)->set(deserialize());
serialize();
}
void AnalogJoystick_get()
{
deserialize();
moduleController.get(AvailableModules::analogJoystick)->get();
moduleController.get(AvailableModules::analogJoystick)->get(deserialize());
serialize();
}
};
Expand All @@ -25,21 +23,20 @@ void AnalogJoystick::setup()
pinMode(pins->x_pin, INPUT);
pinMode(pins->y_pin, INPUT);
}
void AnalogJoystick::act() {}
void AnalogJoystick::set() {
DynamicJsonDocument *doc = WifiController::getJDoc();
if (doc->containsKey(key_joy))
void AnalogJoystick::act(JsonObject jsonDocument) {}
void AnalogJoystick::set(JsonObject doc) {
if (doc.containsKey(key_joy))
{
if((*doc)[key_joy].containsKey(key_joiypinX))
pins->x_pin = (*doc)[key_joy][key_joiypinX];
if((*doc)[key_joy].containsKey(key_joiypinY))
pins->y_pin = (*doc)[key_joy][key_joiypinY];
if((doc)[key_joy].containsKey(key_joiypinX))
pins->x_pin = (doc)[key_joy][key_joiypinX];
if((doc)[key_joy].containsKey(key_joiypinY))
pins->y_pin = (doc)[key_joy][key_joiypinY];
}
doc->clear();
doc.clear();
Config::setAnalogJoyStickPins(pins);
setup();
}
void AnalogJoystick::get() {
void AnalogJoystick::get(JsonObject jsonDocument) {
DynamicJsonDocument *doc = WifiController::getJDoc();
doc->clear();
(*doc)[key_joy][key_joiypinX] = pins->x_pin;
Expand Down
6 changes: 3 additions & 3 deletions main/src/analogin/AnalogJoystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ class AnalogJoystick : public Module
AnalogJoystick();
virtual ~AnalogJoystick();
void setup() override;
void act() override;
void set() override;
void get() override;
void act(JsonObject jsonDocument) override;
void set(JsonObject jsonDocument) override;
void get(JsonObject jsonDocument) override;
void loop() override;

};
30 changes: 13 additions & 17 deletions main/src/analogout/AnalogOutController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,19 @@ namespace RestApi
{
void AnalogOut_act()
{
deserialize();
moduleController.get(AvailableModules::analogout)->act();
moduleController.get(AvailableModules::analogout)->act(deserialize());
serialize();
}

void AnalogOut_get()
{
deserialize();
moduleController.get(AvailableModules::analogout)->get();
moduleController.get(AvailableModules::analogout)->get(deserialize());
serialize();
}

void AnalogOut_set()
{
deserialize();
moduleController.get(AvailableModules::analogout)->set();
moduleController.get(AvailableModules::analogout)->set(deserialize());
serialize();
}
}
Expand All @@ -45,13 +42,13 @@ void AnalogOutController::setup()
}

// Custom function accessible by the API
void AnalogOutController::act()
void AnalogOutController::act(JsonObject ob)
{
// here you can do something
Serial.println("analogout_act_fct");

int analogoutid = (*WifiController::getJDoc())["analogoutid"];
int analogoutval = (*WifiController::getJDoc())["analogoutval"];
int analogoutid = (ob)["analogoutid"];
int analogoutval = (ob)["analogoutval"];

if (DEBUG)
{
Expand Down Expand Up @@ -80,20 +77,20 @@ void AnalogOutController::act()
(*WifiController::getJDoc())["return"] = 1;
}

void AnalogOutController::set()
void AnalogOutController::set(JsonObject ob)
{
// here you can set parameters

int analogoutid = 0;
if (WifiController::getJDoc()->containsKey("analogoutid"))
if (ob.containsKey("analogoutid"))
{
analogoutid = (*WifiController::getJDoc())["analogoutid"];
analogoutid = (ob)["analogoutid"];
}

int analogoutpin = 0;
if (WifiController::getJDoc()->containsKey("analogoutpin"))
if (ob.containsKey("analogoutpin"))
{
int analogoutpin = (*WifiController::getJDoc())["analogoutpin"];
int analogoutpin = (ob)["analogoutpin"];
}

if (DEBUG)
Expand Down Expand Up @@ -137,12 +134,11 @@ void AnalogOutController::set()
ledcWrite(PWM_CHANNEL_analogout_3, 0);
}
Config::setAnalogOutPins(pins);
WifiController::getJDoc()->clear();
(*WifiController::getJDoc())["return"] = 1;

}

// Custom function accessible by the API
void AnalogOutController::get()
void AnalogOutController::get(JsonObject jsonDocument)
{
// GET SOME PARAMETERS HERE
int analogoutid = (*WifiController::getJDoc())["analogoutid"];
Expand Down
6 changes: 3 additions & 3 deletions main/src/analogout/AnalogOutController.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ class AnalogOutController : public Module
int PWM_CHANNEL_analogout_2 = 5;
int PWM_CHANNEL_analogout_3 = 6;

void act() override;
void set() override;
void get() override;
void act(JsonObject jsonDocument) override;
void set(JsonObject jsonDocument) override;
void get(JsonObject jsonDocument) override;

void setup() override;
void loop() override;
Expand Down
Loading

0 comments on commit f5b6dc1

Please sign in to comment.