CCCPaste

BigBuddy Talker Dialog 2 memory

#!/bin/bash

#3% more efficient, and generates 5 times fewer lines of code!
#Read dialog get the word on a line, then find the memory location and chip it is on
#rec_column2 is the address in the chip for the word 
#cs=Chip Select, the value of rec_column3
#wordlist is the library xlsx coverted via: for i  in *.xlsx; do  libreoffice --headless --convert-to csv "$i" ; done
#then put in all lower case becuase I dont know how to compare values that only differ by case
#command used: tr '[:upper:]' '[:lower:]' < input.csv > wordlist.csv

echo "#include     // include the SPI communcation library
// Connect pin#13 (SCLK) To S2 on AP23 
// Connect pin#11 (DATOUT) To S3 on AP23 
// Connect pin#13 (SCLK) To S2 on AP23 
// Connect pin#10 (CS) To S1 on AP23
// DO from Ap23 optional S4 - Not used here
#define cs 10          // These are the chip-select pins for SPI. They control chips 1-4
#define cs2 9
#define cs3 8
#define cs4 7
int hold = 0;       // Integer used when calling words
int del=200;        // short 200ms delay
int value1 = 0x98;  // play command - This value never changes
int value2 = 0;  // voice address - when you place a hex value in this integer and call the readout() function, that specific word will play
int value3 = 0xA8;  // COUT ramp up - This value never changes
int value4 = 0xB8;   // COUT ramp down - This value never changes
// ALL OF THE ABOVE CODE IS REQUIRED FOR THE OPERATION OF THE LBT
"
echo "int DTime=666;"
echo "void readWord(int addr, int chip){
digitalWrite(chip,LOW);          //Turn a chip on
SPI.transfer(152);                //playcommand
SPI.transfer(addr);              //Transfer the word
digitalWrite(chip,HIGH);        //Turn the chip off
delay(DTime);                       // Dealy between words
}"

echo "
void setup(){
  SPI.begin();             // Initialize SPI
  SPI.setClockDivider(SPI_CLOCK_DIV32); // low frequency SPI
  pinMode(cs,OUTPUT);    // Chip select pins is an output
  pinMode(cs2,OUTPUT);    // Chip select pins is an output
  pinMode(cs3,OUTPUT);    // Chip select pins is an output
  pinMode(cs4,OUTPUT);    // Chip select pins is an output
  digitalWrite(cs,HIGH); // Set chip select to be HIGH (5v) by default.  The chip on the shield is selected when this line is brought low. 
  digitalWrite(cs2,HIGH); // Set chip select to be HIGH (5v) by default.  The chip on the shield is selected when this line is brought low. 
  digitalWrite(cs3,HIGH); // Set chip select to be HIGH (5v) by default.  The chip on the shield is selected when this line is brought low. 
  digitalWrite(cs4,HIGH); // Set chip select to be HIGH (5v) by default.  The chip on the shield is selected when this line is brought low. 
  SPI.setBitOrder(MSBFIRST);  // OTP requires MSB first
  SPI.setDataMode(SPI_MODE0);  // Use MODE0, as all other modes to not work
  value2 = 0x00; // Start at voice group 0
  delay(1000);   // One second delay
  // The following code sets up the output of each chip.  
  digitalWrite(cs,LOW);
  SPI.transfer(value3);
  SPI.transfer(0x00);
  digitalWrite(cs,HIGH);
  delay(5);
  digitalWrite(cs2,LOW);
  SPI.transfer(value3);
  SPI.transfer(0x00);
  digitalWrite(cs2,HIGH);
  delay(5);
   digitalWrite(cs3,LOW);
  SPI.transfer(value3);
  SPI.transfer(0x00);
  digitalWrite(cs3,HIGH);
  delay(5);
  digitalWrite(cs4,LOW);
  SPI.transfer(value3);
  SPI.transfer(0x00);
  digitalWrite(cs4,HIGH);
}
"
echo "void loop(){"
input="dialog"
while IFS= read -r line
do

while IFS="," read -r rec_column1 rec_column2 rec_column3 
do
if test "$line" = "$rec_column1"
    then
           echo "// " $line " , " $rec_column1 " :: " $rec_column2 ", " $rec_column3        
     echo "readWord($rec_column2,  $rec_column3);"

    break
fi

done < wordlist.csv

#Word Not Found
if test "$line" != "$rec_column1"
then 
echo "//" $line " Not Found"

fi

done < $input

echo "}"
       
  ###PINS###
  #cs==10
  #cs2==9
  #cs3==8
  #cs4==7