Created
December 11, 2012 02:02
-
-
Save kshoji/4255171 to your computer and use it in GitHub Desktop.
Hentai Advent Calender 2012
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "mbed.h" | |
| #include "USBKeyboard.h" | |
| // Large buffer may cause time rag when file loading. | |
| #define BUFFER_LENGTH (128) | |
| LocalFileSystem local("mbed"); | |
| unsigned char controllerData[BUFFER_LENGTH]; | |
| int controllerDataPosition = 0; | |
| FILE *fp; | |
| long fileLength = 0; | |
| long filePosition = 0; | |
| Ticker keyTicker; | |
| USBKeyboard keyboard; | |
| DigitalOut finishLed = LED1; | |
| bool trigger() { | |
| keyboard.keyCode(controllerData[controllerDataPosition], controllerData[controllerDataPosition + 1]); | |
| filePosition += 2; | |
| if (filePosition >= fileLength) { | |
| return false; | |
| } | |
| controllerDataPosition += 2; | |
| if (controllerDataPosition >= BUFFER_LENGTH) { | |
| fread(controllerData, 1, BUFFER_LENGTH, fp); | |
| controllerDataPosition = 0; | |
| } | |
| return true; | |
| } | |
| int main() { | |
| // TODO replace your filename | |
| fp = fopen("/mbed/tas.txt", "rb"); | |
| controllerDataPosition = 0; | |
| fseek(fp, 0L, SEEK_END); | |
| fileLength = ftell(fp); | |
| fseek(fp, 0L, SEEK_SET); | |
| fread(controllerData, 1, BUFFER_LENGTH, fp); | |
| while (trigger()); | |
| fclose(fp); | |
| finishLed = 1; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| TextToSpeech textToSpeech = new TextToSpeech(getApplicationContext(), new OnInitListener() { | |
| @Override | |
| public void onInit(int status) { | |
| int result = status; | |
| if (status == TextToSpeech.SUCCESS) { | |
| result = textToSpeech.setLanguage(Locale.JAPAN); | |
| if (result != TextToSpeech.LANG_MISSING_DATA && result != TextToSpeech.LANG_NOT_SUPPORTED) { | |
| onInitSuccess(); | |
| return; | |
| } | |
| } | |
| onInitFailure(result); | |
| } | |
| }); | |
| abstract void onInitSuccess(); | |
| abstract void onInitFailure(int reason); | |
| void speech() { | |
| // 音程は標準よりちょっと低く | |
| textToSpeech.setPitch(0.85f); | |
| // しゃべる速さは標準で | |
| textToSpeech.setSpeechRate(1f); | |
| // 今しゃべっているのを止めて、今すぐしゃべる | |
| textToSpeech.speak("変態じゃないよ。仮に変態だとしても、変態という名の紳士だよ。", TextToSpeech.QUEUE_FLUSH, null); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package jp.kshoji; | |
| import java.io.ByteArrayOutputStream; | |
| import java.io.File; | |
| import java.io.FileInputStream; | |
| import java.io.FileOutputStream; | |
| import java.io.IOException; | |
| public class TextToKeyCode { | |
| private static final String keyCodeShiftTable = "~!@#$%^&*()_+{}|:\"<>?"; | |
| private static final String keyCodeTable = "`1234567890-=[]\\;',./"; | |
| private static final int KEY_SHIFT = 2; | |
| private static String readFileToString(File file) throws IOException { | |
| byte[] byteArray = new byte[(int) file.length()]; | |
| FileInputStream fis = new FileInputStream(file); | |
| fis.read(byteArray); | |
| fis.close(); | |
| return new String(byteArray); | |
| } | |
| public static void main(String[] args) throws IOException { | |
| String toKeyCode = readFileToString(new File("totas.txt")); | |
| int indexOfCharAt; | |
| ByteArrayOutputStream output = new ByteArrayOutputStream(); | |
| for (int i = 0; i < toKeyCode.length(); i++) { | |
| byte byte1; | |
| byte byte2 = 0; | |
| char charAt = toKeyCode.charAt(i); | |
| if (charAt >= '0' && charAt <= '9') { | |
| byte1 = (byte) charAt; | |
| } else if (charAt >= 'a' && charAt <= 'z') { | |
| byte1 = (byte) charAt; | |
| } else if (charAt >= 'A' && charAt <= 'Z') { | |
| byte1 = (byte) (charAt - 'A' + 'a'); | |
| byte2 = KEY_SHIFT; | |
| } else if ((indexOfCharAt = keyCodeShiftTable.indexOf(charAt)) != -1) { | |
| byte1 = (byte) keyCodeTable.charAt(indexOfCharAt); | |
| byte2 = KEY_SHIFT; | |
| } else if ((indexOfCharAt = keyCodeTable.indexOf(charAt)) != -1) { | |
| byte1 = (byte) charAt; | |
| } else if (charAt == '\n' || charAt == ' ' || charAt == '\t') { | |
| byte1 = (byte) charAt; | |
| } else { | |
| continue; | |
| } | |
| output.write(new byte[]{byte1, byte2}); | |
| } | |
| FileOutputStream fos = new FileOutputStream(new File("tas.txt")); | |
| fos.write(output.toByteArray()); | |
| fos.flush(); | |
| fos.close(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment