finish single track naming function
This commit is contained in:
+237
-132
@@ -45,107 +45,112 @@
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
char *key;
|
char key;
|
||||||
uint8_t value;
|
uint8_t value;
|
||||||
} record_type;
|
} record_type;
|
||||||
|
|
||||||
record_type upperCaseAlphaChar[26] = {
|
record_type upperCaseAlphaChars[26] = {
|
||||||
{"A", 0x1D},
|
{'A', 0x1D},
|
||||||
{"B", 0x1E},
|
{'B', 0x1E},
|
||||||
{"C", 0x1F},
|
{'C', 0x1F},
|
||||||
{"D", 0x1B},
|
{'D', 0x1B},
|
||||||
{"E", 0x1A},
|
{'E', 0x1A},
|
||||||
{"F", 0x0},
|
{'F', 0x0},
|
||||||
{"G", 0x1},
|
{'G', 0x1},
|
||||||
{"H", 0x2},
|
{'H', 0x2},
|
||||||
{"I", 0x3},
|
{'I', 0x3},
|
||||||
{"J", 0x4},
|
{'J', 0x4},
|
||||||
{"K", 0x5},
|
{'K', 0x5},
|
||||||
{"L", 0x6},
|
{'L', 0x6},
|
||||||
{"M", 0x7},
|
{'M', 0x7},
|
||||||
{"N", 0x8},
|
{'N', 0x8},
|
||||||
{"O", 0x9},
|
{'O', 0x9},
|
||||||
{"P", 0x40},
|
{'P', 0x40},
|
||||||
{"Q", 0x41},
|
{'Q', 0x41},
|
||||||
{"R", 0x42},
|
{'R', 0x42},
|
||||||
{"S", 0x43},
|
{'S', 0x43},
|
||||||
{"T", 0x44},
|
{'T', 0x44},
|
||||||
{"U", 0x45},
|
{'U', 0x45},
|
||||||
{"V", 0x46},
|
{'V', 0x46},
|
||||||
{"W", 0x47},
|
{'W', 0x47},
|
||||||
{"X", 0x48},
|
{'X', 0x48},
|
||||||
{"Y", 0x49},
|
{'Y', 0x49},
|
||||||
{"Z", 0x4A}};
|
{'Z', 0x4A}};
|
||||||
|
|
||||||
record_type lowerCaseAlphaChar[26] = {
|
record_type lowerCaseAlphaChars[26] = {
|
||||||
{"a", 0x1D},
|
{'a', 0x1D},
|
||||||
{"b", 0x1E},
|
{'b', 0x1E},
|
||||||
{"c", 0x1F},
|
{'c', 0x1F},
|
||||||
{"d", 0x1B},
|
{'d', 0x1B},
|
||||||
{"e", 0x1A},
|
{'e', 0x1A},
|
||||||
{"f", 0x0},
|
{'f', 0x0},
|
||||||
{"g", 0x1},
|
{'g', 0x1},
|
||||||
{"h", 0x2},
|
{'h', 0x2},
|
||||||
{"i", 0x3},
|
{'i', 0x3},
|
||||||
{"j", 0x4},
|
{'j', 0x4},
|
||||||
{"k", 0x5},
|
{'k', 0x5},
|
||||||
{"l", 0x6},
|
{'l', 0x6},
|
||||||
{"m", 0x7},
|
{'m', 0x7},
|
||||||
{"n", 0x8},
|
{'n', 0x8},
|
||||||
{"o", 0x9},
|
{'o', 0x9},
|
||||||
{"p", 0x40},
|
{'p', 0x40},
|
||||||
{"q", 0x41},
|
{'q', 0x41},
|
||||||
{"r", 0x42},
|
{'r', 0x42},
|
||||||
{"s", 0x43},
|
{'s', 0x43},
|
||||||
{"t", 0x44},
|
{'t', 0x44},
|
||||||
{"u", 0x45},
|
{'u', 0x45},
|
||||||
{"v", 0x46},
|
{'v', 0x46},
|
||||||
{"w", 0x47},
|
{'w', 0x47},
|
||||||
{"x", 0x48},
|
{'x', 0x48},
|
||||||
{"y", 0x49},
|
{'y', 0x49},
|
||||||
{"z", 0x4A}};
|
{'z', 0x4A}};
|
||||||
|
|
||||||
record_type numberChar[10] = {
|
record_type numberChars[10] = {
|
||||||
{"1", 0x0},
|
{'1', 0x0},
|
||||||
{"2", 0x1},
|
{'2', 0x1},
|
||||||
{"3", 0x2},
|
{'3', 0x2},
|
||||||
{"4", 0x3},
|
{'4', 0x3},
|
||||||
{"5", 0x4},
|
{'5', 0x4},
|
||||||
{"6", 0x5},
|
{'6', 0x5},
|
||||||
{"7", 0x6},
|
{'7', 0x6},
|
||||||
{"8", 0x7},
|
{'8', 0x7},
|
||||||
{"9", 0x8},
|
{'9', 0x8},
|
||||||
{"0", 0x9}};
|
{'0', 0x9}};
|
||||||
|
|
||||||
record_type specialChar[8] = {
|
record_type specialChars[8] = {
|
||||||
{"-", 0x4B},
|
{'-', 0x4B},
|
||||||
{".", 0x4D},
|
{'.', 0x4D},
|
||||||
{",", 0x4E},
|
{',', 0x4E},
|
||||||
{"/", 0xA},
|
{'/', 0xA},
|
||||||
{"?", 0x26},
|
{'?', 0x26},
|
||||||
{"!", 0x27},
|
{'!', 0x27},
|
||||||
{"(", 0x33},
|
{'(', 0x33},
|
||||||
{")", 0x34}};
|
{')', 0x34}};
|
||||||
|
|
||||||
bool isLowercase = false;
|
bool beginTask = false;
|
||||||
bool isNumber = false;
|
bool taskIsRunning = false;
|
||||||
|
|
||||||
//! Vielleicht smarter immer den vorherigen zu setzen und damit zu vergleichen
|
|
||||||
bool wasLowercase = false;
|
bool wasLowercase = false;
|
||||||
bool wasNumber = false;
|
bool wasNumber = false;
|
||||||
|
int delayAmount = 1000;
|
||||||
|
String titleString = "";
|
||||||
|
|
||||||
//------------------------------------------------
|
//------------------------------------------------
|
||||||
|
|
||||||
// Create AsyncWebServer object on port 80
|
// Create AsyncWebServer object on port 80
|
||||||
AsyncWebServer server(80);
|
AsyncWebServer server(80);
|
||||||
|
|
||||||
const char *PARAM_MESSAGE = "message";
|
|
||||||
|
|
||||||
void notFound(AsyncWebServerRequest *request)
|
void notFound(AsyncWebServerRequest *request)
|
||||||
{
|
{
|
||||||
request->send(404, "text/plain", "Not found");
|
request->send(404, "text/plain", "Not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------
|
||||||
|
//------------- Helper Functions -----------------
|
||||||
|
void triggerDelay()
|
||||||
|
{
|
||||||
|
delay(delayAmount);
|
||||||
|
}
|
||||||
|
|
||||||
//------------------------------------------------
|
//------------------------------------------------
|
||||||
//--------------- IR Functions -------------------
|
//--------------- 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)
|
void sendCommand20(String commandString)
|
||||||
{
|
{
|
||||||
if (commandString == "Q")
|
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()
|
void caseToggleLow()
|
||||||
{
|
{
|
||||||
if (wasNumber == true)
|
if (wasNumber == true)
|
||||||
|
{
|
||||||
Serial.println("toggle to char");
|
Serial.println("toggle to char");
|
||||||
wasNumber = false;
|
wasNumber = false;
|
||||||
|
IrSender.sendSony(0xF, 0x37, 2, 12);
|
||||||
|
triggerDelay();
|
||||||
if (wasLowercase == false)
|
if (wasLowercase == false)
|
||||||
|
{
|
||||||
Serial.println("toggle case low");
|
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)
|
if (wasLowercase == true)
|
||||||
Serial.println("no toggle");
|
Serial.println("no toggle");
|
||||||
}
|
}
|
||||||
@@ -234,10 +248,24 @@ void caseToggleLow()
|
|||||||
void caseToggleUp()
|
void caseToggleUp()
|
||||||
{
|
{
|
||||||
if (wasNumber == true)
|
if (wasNumber == true)
|
||||||
|
{
|
||||||
Serial.println("toggle to char");
|
Serial.println("toggle to char");
|
||||||
wasNumber = false;
|
wasNumber = false;
|
||||||
if (wasLowercase == true)
|
if (wasLowercase == true)
|
||||||
|
{
|
||||||
Serial.println("toggle case up");
|
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)
|
if (wasLowercase == false)
|
||||||
Serial.println("no toggle");
|
Serial.println("no toggle");
|
||||||
}
|
}
|
||||||
@@ -247,13 +275,83 @@ void toggleDigit()
|
|||||||
if (wasNumber == true)
|
if (wasNumber == true)
|
||||||
Serial.println("no toggle");
|
Serial.println("no toggle");
|
||||||
if (wasNumber == false)
|
if (wasNumber == false)
|
||||||
|
{
|
||||||
Serial.println("toggle to digit");
|
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()
|
void finalizeTrack()
|
||||||
{
|
{
|
||||||
Serial.println("Finalize track");
|
Serial.println("Finalize track");
|
||||||
|
IrSender.sendSony(0xF, 0x3C, 2, 12); // Send "name" command
|
||||||
|
wasLowercase = false;
|
||||||
|
wasNumber = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void nameSingleTrack(String titlestring)
|
void nameSingleTrack(String titlestring)
|
||||||
@@ -261,7 +359,6 @@ void nameSingleTrack(String titlestring)
|
|||||||
Serial.print("track name: ");
|
Serial.print("track name: ");
|
||||||
Serial.println(titlestring);
|
Serial.println(titlestring);
|
||||||
|
|
||||||
//! Brauche ich den null terminator?
|
|
||||||
int str_len = titlestring.length() + 1; // Length (with one extra character for the null terminator)
|
int str_len = titlestring.length() + 1; // Length (with one extra character for the null terminator)
|
||||||
Serial.print("string length: ");
|
Serial.print("string length: ");
|
||||||
Serial.println(str_len);
|
Serial.println(str_len);
|
||||||
@@ -270,56 +367,56 @@ void nameSingleTrack(String titlestring)
|
|||||||
|
|
||||||
titlestring.toCharArray(char_array, str_len); // Copy it over
|
titlestring.toCharArray(char_array, str_len); // Copy it over
|
||||||
|
|
||||||
|
beginEditing();
|
||||||
|
|
||||||
for (int i = 0; i < str_len; i++) // Loop over array
|
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:
|
if (i == str_len - 1) // array length minus null terminator
|
||||||
//! 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)
|
|
||||||
{
|
{
|
||||||
Serial.println("End of line.");
|
Serial.println("End of line.");
|
||||||
finalizeTrack();
|
finalizeTrack();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Serial.print("index: ");
|
||||||
Serial.println(i);
|
Serial.println(i);
|
||||||
Serial.println("char: ");
|
Serial.print("char: ");
|
||||||
Serial.println(char_array[i]);
|
Serial.println(c);
|
||||||
// Test if char is a lowerCase letter
|
|
||||||
if (isLowerCase(char_array[i]))
|
if (isLowerCase(c)) // Test if char is a lowerCase letter
|
||||||
{
|
{
|
||||||
Serial.println("The character is lower case");
|
Serial.println("The character is lower case");
|
||||||
caseToggleLow();
|
caseToggleLow();
|
||||||
wasLowercase = true;
|
wasLowercase = true;
|
||||||
wasNumber = false;
|
wasNumber = false;
|
||||||
|
sendLowerCaseChar(c);
|
||||||
}
|
}
|
||||||
// Test if char is a upperCase letter
|
if (isUpperCase(c)) // Test if char is a upperCase letter
|
||||||
if (isUpperCase(char_array[i]))
|
|
||||||
{
|
{
|
||||||
Serial.println("The character is upper case");
|
Serial.println("The character is upper case");
|
||||||
caseToggleUp();
|
caseToggleUp();
|
||||||
wasLowercase = false;
|
wasLowercase = false;
|
||||||
wasNumber = false;
|
wasNumber = false;
|
||||||
|
sendUpperCaseChar(c);
|
||||||
}
|
}
|
||||||
// Test if char is a digit
|
if (isDigit(c)) // Test if char is a digit
|
||||||
if (isDigit(char_array[i]))
|
|
||||||
{
|
{
|
||||||
Serial.println("The character is digit");
|
Serial.println("The character is digit");
|
||||||
toggleDigit();
|
toggleDigit();
|
||||||
wasNumber = true;
|
wasNumber = true;
|
||||||
|
sendDigitChar(c);
|
||||||
}
|
}
|
||||||
// Test if char is special char
|
if (isPunct(c)) // Test if char is special char
|
||||||
if (isPunct(char_array[i]))
|
|
||||||
{
|
{
|
||||||
Serial.println("The character is special char");
|
Serial.println("The character is special char");
|
||||||
|
sendSpecialChar(c);
|
||||||
}
|
}
|
||||||
// Test if char is a space
|
if (isSpace(c)) // Test if char is a space
|
||||||
if (isSpace(char_array[i]))
|
|
||||||
{
|
{
|
||||||
Serial.println("The character is a space");
|
Serial.println("The character is a space");
|
||||||
|
sendSpace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -333,30 +430,33 @@ void nameAllTracks(String message)
|
|||||||
// use nameSingleTrack with each track
|
// 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 ---------------------
|
//-------------------- Setup ---------------------
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//------------------------------------------------
|
||||||
|
|
||||||
Serial.begin(115200);
|
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();
|
initWiFi();
|
||||||
initSDCard();
|
initSDCard();
|
||||||
|
|
||||||
@@ -401,14 +501,11 @@ void setup()
|
|||||||
server.on("/api/gettrack", HTTP_GET, [](AsyncWebServerRequest *request)
|
server.on("/api/gettrack", HTTP_GET, [](AsyncWebServerRequest *request)
|
||||||
{
|
{
|
||||||
String message;
|
String message;
|
||||||
if (request->hasParam("singletrack"))
|
if (request->hasParam("singletrack")) {
|
||||||
{
|
|
||||||
message = request->getParam("singletrack")->value();
|
message = request->getParam("singletrack")->value();
|
||||||
//Serial.println(message);
|
titleString = message;
|
||||||
nameSingleTrack(message);
|
beginTask = true;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
message = "No message sent";
|
message = "No message sent";
|
||||||
}
|
}
|
||||||
request->send(SD, "/index.html", "text/html"); });
|
request->send(SD, "/index.html", "text/html"); });
|
||||||
@@ -444,4 +541,12 @@ void setup()
|
|||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
|
if (beginTask)
|
||||||
|
{
|
||||||
|
taskIsRunning = true;
|
||||||
|
triggerNewTrackNaming();
|
||||||
|
taskIsRunning = false;
|
||||||
|
Serial.println("work has finished");
|
||||||
|
beginTask = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user