finish single track naming function
This commit is contained in:
+240
-135
@@ -45,107 +45,112 @@
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char *key;
|
||||
char key;
|
||||
uint8_t value;
|
||||
} record_type;
|
||||
|
||||
record_type upperCaseAlphaChar[26] = {
|
||||
{"A", 0x1D},
|
||||
{"B", 0x1E},
|
||||
{"C", 0x1F},
|
||||
{"D", 0x1B},
|
||||
{"E", 0x1A},
|
||||
{"F", 0x0},
|
||||
{"G", 0x1},
|
||||
{"H", 0x2},
|
||||
{"I", 0x3},
|
||||
{"J", 0x4},
|
||||
{"K", 0x5},
|
||||
{"L", 0x6},
|
||||
{"M", 0x7},
|
||||
{"N", 0x8},
|
||||
{"O", 0x9},
|
||||
{"P", 0x40},
|
||||
{"Q", 0x41},
|
||||
{"R", 0x42},
|
||||
{"S", 0x43},
|
||||
{"T", 0x44},
|
||||
{"U", 0x45},
|
||||
{"V", 0x46},
|
||||
{"W", 0x47},
|
||||
{"X", 0x48},
|
||||
{"Y", 0x49},
|
||||
{"Z", 0x4A}};
|
||||
record_type upperCaseAlphaChars[26] = {
|
||||
{'A', 0x1D},
|
||||
{'B', 0x1E},
|
||||
{'C', 0x1F},
|
||||
{'D', 0x1B},
|
||||
{'E', 0x1A},
|
||||
{'F', 0x0},
|
||||
{'G', 0x1},
|
||||
{'H', 0x2},
|
||||
{'I', 0x3},
|
||||
{'J', 0x4},
|
||||
{'K', 0x5},
|
||||
{'L', 0x6},
|
||||
{'M', 0x7},
|
||||
{'N', 0x8},
|
||||
{'O', 0x9},
|
||||
{'P', 0x40},
|
||||
{'Q', 0x41},
|
||||
{'R', 0x42},
|
||||
{'S', 0x43},
|
||||
{'T', 0x44},
|
||||
{'U', 0x45},
|
||||
{'V', 0x46},
|
||||
{'W', 0x47},
|
||||
{'X', 0x48},
|
||||
{'Y', 0x49},
|
||||
{'Z', 0x4A}};
|
||||
|
||||
record_type lowerCaseAlphaChar[26] = {
|
||||
{"a", 0x1D},
|
||||
{"b", 0x1E},
|
||||
{"c", 0x1F},
|
||||
{"d", 0x1B},
|
||||
{"e", 0x1A},
|
||||
{"f", 0x0},
|
||||
{"g", 0x1},
|
||||
{"h", 0x2},
|
||||
{"i", 0x3},
|
||||
{"j", 0x4},
|
||||
{"k", 0x5},
|
||||
{"l", 0x6},
|
||||
{"m", 0x7},
|
||||
{"n", 0x8},
|
||||
{"o", 0x9},
|
||||
{"p", 0x40},
|
||||
{"q", 0x41},
|
||||
{"r", 0x42},
|
||||
{"s", 0x43},
|
||||
{"t", 0x44},
|
||||
{"u", 0x45},
|
||||
{"v", 0x46},
|
||||
{"w", 0x47},
|
||||
{"x", 0x48},
|
||||
{"y", 0x49},
|
||||
{"z", 0x4A}};
|
||||
record_type lowerCaseAlphaChars[26] = {
|
||||
{'a', 0x1D},
|
||||
{'b', 0x1E},
|
||||
{'c', 0x1F},
|
||||
{'d', 0x1B},
|
||||
{'e', 0x1A},
|
||||
{'f', 0x0},
|
||||
{'g', 0x1},
|
||||
{'h', 0x2},
|
||||
{'i', 0x3},
|
||||
{'j', 0x4},
|
||||
{'k', 0x5},
|
||||
{'l', 0x6},
|
||||
{'m', 0x7},
|
||||
{'n', 0x8},
|
||||
{'o', 0x9},
|
||||
{'p', 0x40},
|
||||
{'q', 0x41},
|
||||
{'r', 0x42},
|
||||
{'s', 0x43},
|
||||
{'t', 0x44},
|
||||
{'u', 0x45},
|
||||
{'v', 0x46},
|
||||
{'w', 0x47},
|
||||
{'x', 0x48},
|
||||
{'y', 0x49},
|
||||
{'z', 0x4A}};
|
||||
|
||||
record_type numberChar[10] = {
|
||||
{"1", 0x0},
|
||||
{"2", 0x1},
|
||||
{"3", 0x2},
|
||||
{"4", 0x3},
|
||||
{"5", 0x4},
|
||||
{"6", 0x5},
|
||||
{"7", 0x6},
|
||||
{"8", 0x7},
|
||||
{"9", 0x8},
|
||||
{"0", 0x9}};
|
||||
record_type numberChars[10] = {
|
||||
{'1', 0x0},
|
||||
{'2', 0x1},
|
||||
{'3', 0x2},
|
||||
{'4', 0x3},
|
||||
{'5', 0x4},
|
||||
{'6', 0x5},
|
||||
{'7', 0x6},
|
||||
{'8', 0x7},
|
||||
{'9', 0x8},
|
||||
{'0', 0x9}};
|
||||
|
||||
record_type specialChar[8] = {
|
||||
{"-", 0x4B},
|
||||
{".", 0x4D},
|
||||
{",", 0x4E},
|
||||
{"/", 0xA},
|
||||
{"?", 0x26},
|
||||
{"!", 0x27},
|
||||
{"(", 0x33},
|
||||
{")", 0x34}};
|
||||
record_type specialChars[8] = {
|
||||
{'-', 0x4B},
|
||||
{'.', 0x4D},
|
||||
{',', 0x4E},
|
||||
{'/', 0xA},
|
||||
{'?', 0x26},
|
||||
{'!', 0x27},
|
||||
{'(', 0x33},
|
||||
{')', 0x34}};
|
||||
|
||||
bool isLowercase = false;
|
||||
bool isNumber = false;
|
||||
|
||||
//! Vielleicht smarter immer den vorherigen zu setzen und damit zu vergleichen
|
||||
bool beginTask = false;
|
||||
bool taskIsRunning = false;
|
||||
bool wasLowercase = false;
|
||||
bool wasNumber = false;
|
||||
int delayAmount = 1000;
|
||||
String titleString = "";
|
||||
|
||||
//------------------------------------------------
|
||||
|
||||
// Create AsyncWebServer object on port 80
|
||||
AsyncWebServer server(80);
|
||||
|
||||
const char *PARAM_MESSAGE = "message";
|
||||
|
||||
void notFound(AsyncWebServerRequest *request)
|
||||
{
|
||||
request->send(404, "text/plain", "Not found");
|
||||
}
|
||||
|
||||
//------------------------------------------------
|
||||
//------------- Helper Functions -----------------
|
||||
void triggerDelay()
|
||||
{
|
||||
delay(delayAmount);
|
||||
}
|
||||
|
||||
//------------------------------------------------
|
||||
//--------------- IR Functions -------------------
|
||||
|
||||
@@ -193,10 +198,6 @@ void sendCommand12(String commandString)
|
||||
}
|
||||
}
|
||||
|
||||
//! Ich brauche eine Funktion, die den vorherigen und den folgenden char prüft und checked, ob der lowercase, oder num ist und dann entsprechend den Modus umschaltet.
|
||||
|
||||
//! Ich brauche eine Funktion, die den char mit einem IR command vergleicht und den IrSender.sendSony() ausführt.
|
||||
|
||||
void sendCommand20(String commandString)
|
||||
{
|
||||
if (commandString == "Q")
|
||||
@@ -217,16 +218,29 @@ void sendCommand20(String commandString)
|
||||
}
|
||||
}
|
||||
|
||||
//! void findCommandAndSend(String char)
|
||||
//! { find char in Array and use value to send command }
|
||||
|
||||
void caseToggleLow()
|
||||
{
|
||||
if (wasNumber == true)
|
||||
{
|
||||
Serial.println("toggle to char");
|
||||
wasNumber = false;
|
||||
wasNumber = false;
|
||||
IrSender.sendSony(0xF, 0x37, 2, 12);
|
||||
triggerDelay();
|
||||
if (wasLowercase == false)
|
||||
{
|
||||
Serial.println("toggle case low");
|
||||
IrSender.sendSony(0xF, 0x36, 2, 12);
|
||||
triggerDelay();
|
||||
}
|
||||
if (wasLowercase == true)
|
||||
Serial.println("no toggle");
|
||||
}
|
||||
if (wasLowercase == false)
|
||||
{
|
||||
Serial.println("toggle case low");
|
||||
IrSender.sendSony(0xF, 0x36, 2, 12);
|
||||
triggerDelay();
|
||||
}
|
||||
if (wasLowercase == true)
|
||||
Serial.println("no toggle");
|
||||
}
|
||||
@@ -234,10 +248,24 @@ void caseToggleLow()
|
||||
void caseToggleUp()
|
||||
{
|
||||
if (wasNumber == true)
|
||||
{
|
||||
Serial.println("toggle to char");
|
||||
wasNumber = false;
|
||||
wasNumber = false;
|
||||
if (wasLowercase == true)
|
||||
{
|
||||
Serial.println("toggle case up");
|
||||
IrSender.sendSony(0xF, 0x36, 2, 12);
|
||||
triggerDelay();
|
||||
}
|
||||
if (wasLowercase == false)
|
||||
Serial.println("no toggle");
|
||||
}
|
||||
if (wasLowercase == true)
|
||||
{
|
||||
Serial.println("toggle case up");
|
||||
IrSender.sendSony(0xF, 0x36, 2, 12);
|
||||
triggerDelay();
|
||||
}
|
||||
if (wasLowercase == false)
|
||||
Serial.println("no toggle");
|
||||
}
|
||||
@@ -247,13 +275,83 @@ void toggleDigit()
|
||||
if (wasNumber == true)
|
||||
Serial.println("no toggle");
|
||||
if (wasNumber == false)
|
||||
{
|
||||
Serial.println("toggle to digit");
|
||||
wasNumber = true;
|
||||
wasNumber = true;
|
||||
IrSender.sendSony(0xF, 0x37, 2, 12);
|
||||
triggerDelay();
|
||||
}
|
||||
}
|
||||
|
||||
void sendSpace()
|
||||
{
|
||||
IrSender.sendSony(0xF, 0x4C, 2, 12);
|
||||
triggerDelay();
|
||||
}
|
||||
|
||||
void sendUpperCaseChar(char uppercaseCharString)
|
||||
{
|
||||
for (int x = 0; x <= sizeof(upperCaseAlphaChars) / sizeof(upperCaseAlphaChars[0]); x++)
|
||||
{
|
||||
if (upperCaseAlphaChars[x].key == uppercaseCharString)
|
||||
{
|
||||
IrSender.sendSony(0xF, upperCaseAlphaChars[x].value, 2, 12);
|
||||
triggerDelay();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void sendLowerCaseChar(char lowercaseCharString)
|
||||
{
|
||||
for (int x = 0; x <= sizeof(lowerCaseAlphaChars) / sizeof(lowerCaseAlphaChars[0]); x++)
|
||||
{
|
||||
if (lowerCaseAlphaChars[x].key == lowercaseCharString)
|
||||
{
|
||||
IrSender.sendSony(0xF, lowerCaseAlphaChars[x].value, 2, 12);
|
||||
triggerDelay();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void sendDigitChar(char digitCharString)
|
||||
{
|
||||
for (int x = 0; x <= sizeof(numberChars) / sizeof(numberChars[0]); x++)
|
||||
{
|
||||
if (numberChars[x].key == digitCharString)
|
||||
{
|
||||
IrSender.sendSony(0xF, numberChars[x].value, 2, 12);
|
||||
triggerDelay();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void sendSpecialChar(char specialCharString)
|
||||
{
|
||||
for (int x = 0; x <= sizeof(specialChars) / sizeof(specialChars[0]); x++)
|
||||
{
|
||||
if (specialChars[x].key == specialCharString)
|
||||
{
|
||||
/* Serial.println("specialChar value: ");
|
||||
Serial.println(specialChars[x].value); */
|
||||
IrSender.sendSony(0xF, specialChars[x].value, 2, 12);
|
||||
triggerDelay();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void beginEditing()
|
||||
{
|
||||
Serial.println("Begin editing");
|
||||
IrSender.sendSony(0xF, 0x3C, 2, 12); // Send "name" command
|
||||
triggerDelay();
|
||||
}
|
||||
|
||||
void finalizeTrack()
|
||||
{
|
||||
Serial.println("Finalize track");
|
||||
IrSender.sendSony(0xF, 0x3C, 2, 12); // Send "name" command
|
||||
wasLowercase = false;
|
||||
wasNumber = false;
|
||||
}
|
||||
|
||||
void nameSingleTrack(String titlestring)
|
||||
@@ -261,7 +359,6 @@ void nameSingleTrack(String titlestring)
|
||||
Serial.print("track name: ");
|
||||
Serial.println(titlestring);
|
||||
|
||||
//! Brauche ich den null terminator?
|
||||
int str_len = titlestring.length() + 1; // Length (with one extra character for the null terminator)
|
||||
Serial.print("string length: ");
|
||||
Serial.println(str_len);
|
||||
@@ -270,56 +367,56 @@ void nameSingleTrack(String titlestring)
|
||||
|
||||
titlestring.toCharArray(char_array, str_len); // Copy it over
|
||||
|
||||
beginEditing();
|
||||
|
||||
for (int i = 0; i < str_len; i++) // Loop over array
|
||||
{
|
||||
int s = char_array[i];
|
||||
char c = char_array[i];
|
||||
|
||||
//! Hier müssen verschiedene Sachen getestet werden:
|
||||
//! Ist das Array-Ende erreicht? Ist der case ein anderer als vom vorigen char? Prüft aktuelle char und entscheidet, welches Command gesendet wird
|
||||
//! Wie kann ich das in eigene Funktionen verpacken?
|
||||
|
||||
if (i == str_len - 1)
|
||||
if (i == str_len - 1) // array length minus null terminator
|
||||
{
|
||||
Serial.println("End of line.");
|
||||
finalizeTrack();
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print("index: ");
|
||||
Serial.println(i);
|
||||
Serial.println("char: ");
|
||||
Serial.println(char_array[i]);
|
||||
// Test if char is a lowerCase letter
|
||||
if (isLowerCase(char_array[i]))
|
||||
Serial.print("char: ");
|
||||
Serial.println(c);
|
||||
|
||||
if (isLowerCase(c)) // Test if char is a lowerCase letter
|
||||
{
|
||||
Serial.println("The character is lower case");
|
||||
caseToggleLow();
|
||||
wasLowercase = true;
|
||||
wasNumber = false;
|
||||
sendLowerCaseChar(c);
|
||||
}
|
||||
// Test if char is a upperCase letter
|
||||
if (isUpperCase(char_array[i]))
|
||||
if (isUpperCase(c)) // Test if char is a upperCase letter
|
||||
{
|
||||
Serial.println("The character is upper case");
|
||||
caseToggleUp();
|
||||
wasLowercase = false;
|
||||
wasNumber = false;
|
||||
sendUpperCaseChar(c);
|
||||
}
|
||||
// Test if char is a digit
|
||||
if (isDigit(char_array[i]))
|
||||
if (isDigit(c)) // Test if char is a digit
|
||||
{
|
||||
Serial.println("The character is digit");
|
||||
toggleDigit();
|
||||
wasNumber = true;
|
||||
sendDigitChar(c);
|
||||
}
|
||||
// Test if char is special char
|
||||
if (isPunct(char_array[i]))
|
||||
if (isPunct(c)) // Test if char is special char
|
||||
{
|
||||
Serial.println("The character is special char");
|
||||
sendSpecialChar(c);
|
||||
}
|
||||
// Test if char is a space
|
||||
if (isSpace(char_array[i]))
|
||||
if (isSpace(c)) // Test if char is a space
|
||||
{
|
||||
Serial.println("The character is a space");
|
||||
sendSpace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -333,30 +430,33 @@ void nameAllTracks(String message)
|
||||
// use nameSingleTrack with each track
|
||||
}
|
||||
|
||||
void triggerNewTrackNaming()
|
||||
{
|
||||
Serial.print("START TITLING");
|
||||
if (titleString == "")
|
||||
{
|
||||
Serial.print("titleString: ");
|
||||
Serial.println(titleString);
|
||||
}
|
||||
if (titleString != "")
|
||||
{
|
||||
Serial.print("new titleString: ");
|
||||
Serial.println(titleString);
|
||||
nameSingleTrack(titleString);
|
||||
titleString = "";
|
||||
}
|
||||
Serial.print("END TITLING");
|
||||
}
|
||||
|
||||
//------------------------------------------------
|
||||
//-------------------- Setup ---------------------
|
||||
void setup()
|
||||
{
|
||||
|
||||
//------------------------------------------------
|
||||
|
||||
Serial.begin(115200);
|
||||
|
||||
Serial.print("numberChar[1].value: ");
|
||||
Serial.println(numberChar[1].value);
|
||||
Serial.print("numberChar[1].key: ");
|
||||
Serial.println(numberChar[1].key);
|
||||
|
||||
Serial.print("specialChar[0].value: ");
|
||||
Serial.println(specialChar[0].value);
|
||||
Serial.print("specialChar[0].key: ");
|
||||
Serial.println(specialChar[0].key);
|
||||
|
||||
Serial.print("specialChar[2].value: ");
|
||||
Serial.println(specialChar[2].value);
|
||||
|
||||
Serial.print("specialChar[7].value: ");
|
||||
Serial.println(specialChar[7].value);
|
||||
Serial.print("specialChar[7].key: ");
|
||||
Serial.println(specialChar[7].key);
|
||||
|
||||
initWiFi();
|
||||
initSDCard();
|
||||
|
||||
@@ -401,14 +501,11 @@ void setup()
|
||||
server.on("/api/gettrack", HTTP_GET, [](AsyncWebServerRequest *request)
|
||||
{
|
||||
String message;
|
||||
if (request->hasParam("singletrack"))
|
||||
{
|
||||
if (request->hasParam("singletrack")) {
|
||||
message = request->getParam("singletrack")->value();
|
||||
//Serial.println(message);
|
||||
nameSingleTrack(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
titleString = message;
|
||||
beginTask = true;
|
||||
} else {
|
||||
message = "No message sent";
|
||||
}
|
||||
request->send(SD, "/index.html", "text/html"); });
|
||||
@@ -444,4 +541,12 @@ void setup()
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (beginTask)
|
||||
{
|
||||
taskIsRunning = true;
|
||||
triggerNewTrackNaming();
|
||||
taskIsRunning = false;
|
||||
Serial.println("work has finished");
|
||||
beginTask = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user