/* Hello Wokwi! */
#include <LiquidCrystal_I2C.h>
#include <cppQueue.h>
#include "commands.h"
#include "pot_switch.h"
LiquidCrystal_I2C lcd(0x27, 20, 4);
typedef struct strEvent {
uint8_t slaveId;
uint16_t eventId;
uint16_t value;
} Event;
typedef struct strCommand {
unsigned type: 16;
char pins[3];
} Command;
#define IMPLEMENTATION FIFO
cppQueue q(sizeof(Command), 5, IMPLEMENTATION); // Instantiate queue
cppQueue qOfPots(sizeof( PotSwitch ), 5, IMPLEMENTATION); // Instantiate queue
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.setCursor(1, 0);
/*Set up all command mappings*/
initCommands();
lcd.print("JJCC loaded...");
Serial.println("...");
}
void loop() {
char data[100];
unsigned int i;
while (Serial.available()) {
data[i] = Serial.read();
data[i + 1] = '\0'; // Append a null
DynamicJsonDocument doc(2048);
// Deserialize the JSON document in the response
deserializeJson(doc, data);
JsonArray pots = doc["pots"].as<JsonArray>();
i++;
}
Serial.print(data);
if (1 == 2) {
char stat = Serial.read();
if (stat == '9') {
Command command = { 300, 1655};
q.push(&command);
char data[16];
int availableBytes = Serial.available();
unsigned int i;
for (int i = 0; i < availableBytes; i++)
{
data[i] = Serial.read();
data[i + 1] = '\0'; // Append a null
}
/*
Add to config q to be processed by method in loop.
*/
Serial.print("momo: ");
Serial.write(data);
DynamicJsonDocument doc(2048);
// Deserialize the JSON document in the response
deserializeJson(doc, data);
// for (JsonVariant v : pots) {
// Serial.print("Has Controls? ");
// Serial.println(v.containsKey("controls"));
// }
// compute the required size
//const size_t CAPACITY = JSON_ARRAY_SIZE(3);
// allocate the memory for the document
//StaticJsonDocument<CAPACITY> doc;
// create an empty array
//JsonArray array = doc.to<JsonArray>();
// array.add(77);
// array.add(42);
// array.add(3.14);
// for (JsonVariant v : array) {
// Serial.println(v.as<int>());
// }
// PotSwitch potSwitches[1] = {
// PotSwitch( setPinMapping(33, A9) )
// };
// PotSwitch p = PotSwitch( setPinMapping(33, A9) );
// qOfPots.push(&p);
// parseAndQ(*data);
} else if (stat == '8') {
} else if (stat == '0') {
char data[1];
data[0] = doc["A0"];
Serial.write(data);
int val;
val = analogRead(doc["A0"]); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
}
// Serial.println(stat);
}
/*Rollover qOfPots*/
}