import stamp.core.*;
/*
* Hello world を喋らせる
*/
public class EmicTest1 {
// Emic Commands (Hex Mode)
final static int Say = 0x00; // say Engish text
final static int Volume = 0x01; // set volume, 0 - 7
final static int Speed = 0x02; // set speed, 0 - 4
final static int Pitch = 0x03; // set pitch, 0 - 6
final static int AddAbbr = 0x04; // add abbreviation
final static int DelAbbr = 0x05; // delete abbreviation
final static int ListAbbr= 0x06; // list abbreviations
final static int Version = 0x07; // get version
final static int Reset = 0x08; // soft reset
final static int Audio = 0x09; // enable audio in
final static int PhT = 0x10; // start of phonetic text
final static int Help = 0xFE; // display help
final static int EOM = 0xAA; // end of message
final static int OK = 0x55; // "okay" for hex mode
final static int Space = 0x20; // ASCII space character
final static int SERIAL_TX_PIN = CPU.pin0;
final static int SERIAL_RTS_PIN = CPU.pin3;
final static int SERIAL_CTS_PIN = CPU.pin2;
final static int SERIAL_RX_PIN = CPU.pin1;
static Uart rxUart = new Uart( Uart.dirReceive, SERIAL_RX_PIN, Uart.dontInvert,
SERIAL_CTS_PIN,Uart.speed2400,
Uart.stop1 );
static Uart txUart = new Uart( Uart.dirTransmit, SERIAL_TX_PIN,Uart.dontInvert,
SERIAL_RTS_PIN, Uart.speed2400,
Uart.stop1 );
public static void main() {
System.out.println("reset");
Soft_Reset();
System.out.println("volume");
setCommand(Volume, 5);
do {
talk("Hello world!");
} while(true);
}
public static void talk(String val) {
Check_Busy();
txUart.sendByte(Say);
txUart.sendString(val);
txUart.sendByte(EOM);
Wait_OK();
}
public static void setCommand(int cmd) {
Check_Busy();
txUart.sendByte(cmd);
txUart.sendByte(EOM);
Wait_OK();
}
public static void setCommand(int cmd, int val) {
Check_Busy();
txUart.sendByte(cmd);
txUart.sendByte(val);
txUart.sendByte(EOM);
Wait_OK();
}
public static void Wait_OK(){
int ret=0;
for(int j=0; j<3; j++) {
if(rxUart.byteAvailable())
while((ret = rxUart.receiveByte()) != OK);;
if(ret == OK ) break;
}
}
public static void Check_Busy(){
CPU.delay(800);
while(CPU.readPin(SERIAL_CTS_PIN) == true) ;
}
public static void Soft_Reset(){
txUart.sendByte(EOM);
setCommand(Reset);
}
}
|