Sorry, I thought it would be easier to read/
/**********************************************************************************
* Checks for a USART command
*********************************************************************************/
void CommandCheck_Routine()
{
if (BytesNbuffer() > 0 )
{
if ( Get_Byte(0) == '+' )
{
MoneyCommand(); //if it starts with a + symbol, it's a money deposit
}
else
{
DebugCommand();
}
}
}
/**********************************************************************************
* Checks for money deposited by serial port comman
*********************************************************************************/
void MoneyCommand()
{
char* command = checkfor_Instruction();
snprintf((char *)string, SERIAL_MESSAGE, "\n\n %s ", command);
mySerialWrite(string);
MoneyDeposited( command ); ShowMoney();
}
/**********************************************************************************
* Actions for Money being Deposited
*********************************************************************************/
void MoneyDeposited(char* command) //for single commands at a time
{
if ( strcmp(command, "+0.00" ) == 0)
{
msnprint(8); ShowMoney(); msnprint(5); g_dollars = 0; g_moneyTotal = 0;
}
else
{
msnprint(5); // A function to access PROGMEM lines and transmit them via USART
if ( strcmp(command, "+0.10" ) == 0)
{
printhis(" $0.10 "); g_moneyTotal += 10;
}
else if ( strcmp(command, "+0.25" ) == 0)
{
printhis(" $0.25 "); g_moneyTotal += 25;
}
else if ( strcmp(command, "+1.00" ) == 0)
{
printhis(" $1.00 "); g_moneyTotal += 100;
}
else
{
g_moneyTotal += multiDeposit( command ); //if not a single command
} //hand it over to the multideposit function
}
}
/**********************************************************************************
* Show's current amount of money
*********************************************************************************/
void ShowMoney()
{
g_cents = g_moneyTotal; g_dollars = 0;
while (g_cents >= 100)
{
g_dollars += 1; g_cents -= 100;
}
snprintf((char *)string, SERIAL_MESSAGE, " Total: $%d.%.2d ", g_dollars, g_cents);
mySerialWrite(string);
}
uint16_t multiDeposit( char* src1)
{
uint8_t string[SERIAL_MESSAGE];
uint16_t deposit = 0;
uint8_t length = strlen( src1 ); //length of command string
// char dst1[6]; //working
char dst1[length];
void *c;
c = memccpy( dst1 , src1 , NULL , length );
//c = memcpy(dst1, src1, length);
//c = memcpy(dst1, &src1[1], 4); //working
//For some reason, without this snprintf here. Thigns don't work.
snprintf((char *)string, SERIAL_MESSAGE, " %d ", length);
//mySerialWrite(string);
char* pointchar;
char character;
pointchar = strchr(dst1, '+'); //looks for + signs
uint8_t index;
char dst2[6];
//These while loops are my attempt to get it to do more than one command at a time
while ( pointchar != NULL )
{
while (( pointchar != NULL ) )
{
index = (pointchar - dst1) ;
snprintf((char *)string, SERIAL_MESSAGE, "\n found @ %d \n", index);
mySerialWrite(string);
pointchar = strchr ( pointchar+1, '+');
character = dst1[index+1];
}
c = memcpy(dst2, &dst1[index+1] , 4);
deposit = SingleDeposit(dst2);
index = (pointchar - dst1) ;
pointchar = strchr ( pointchar+1, '+');
}
return deposit;
}
//These change amounts are just temporary until I can get it all figured out
uint16_t SingleDeposit(char* dstA)
{
uint16_t deposit = 0;
if ( strcmp(dstA, "0.50" ) == 0)
{
printhis(" $0.50 "); deposit += 50;
}
else if ( strcmp(dstA, "0.05" ) == 0)
{
printhis(" $0.05 "); deposit += 5;
}
else if ( strcmp(dstA, "0.01" ) == 0)
{
printhis(" $0.01 "); deposit += 1;
}
else
{
msnprint(6);
uint8_t string[SERIAL_MESSAGE];
snprintf((char *)string, SERIAL_MESSAGE, "\n\n Entered %s ", dstA);
mySerialWrite(string);
}
return deposit;
}