From 8a08b9dce9cfc161494ddb07a1c979c7796780ff Mon Sep 17 00:00:00 2001 From: Sebastian Reichel Date: Fri, 15 Jun 2012 22:56:00 +0200 Subject: restructure code it is now loading its components from plugins --- test-shell.vala | 158 -------------------------------------------------------- 1 file changed, 158 deletions(-) delete mode 100644 test-shell.vala (limited to 'test-shell.vala') diff --git a/test-shell.vala b/test-shell.vala deleted file mode 100644 index 4e78406..0000000 --- a/test-shell.vala +++ /dev/null @@ -1,158 +0,0 @@ -/* Copyright 2012, Sebastian Reichel - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -static int i; - -public static string? generator(string cmd, int state) { - string[] commands = { "firmware", "get", "set", "stop", "play", "help", "pressure", "temperature", "altitude", "gyro-temperature", "gyro-data" }; - - if(state == 0) - i = -1; - - while(i < commands.length-1) { - i++; - if(commands[i].has_prefix(cmd)) { - return commands[i]; - } - } - - return null; -} - -public static string[]? completion(string cmd, int start, int end) { - string[] matches = null; - - if(start == 0) - matches = Readline.completion_matches(cmd, generator); - - return matches; -} - -public static bool shell(out string cmd) { - cmd = Readline.readline("[blinkm] $ "); - Readline.History.add(cmd); - - if(cmd == "exit") - cmd = null; - - if(cmd == null) - stdout.printf("exit\n"); - - return (cmd != null) ? true : false; -} - -public static int main(string[] args) { - Readline.attempted_completion_function = completion; - Readline.bind_key('\t', Readline.complete); - - try { - string cmd; - BlinkM led = new BlinkM(3, 0x10); -#if BMP085 - BMP085 bmp085 = new BMP085(3); -#endif - ITG3200 itg3200 = new ITG3200(3); - - while(shell(out cmd)) { - var cmdparts = cmd.split(" "); - switch(cmdparts[0]) { - case null: - break; - case "firmware": - char major, minor; - led.get_firmware_version(out major, out minor); - stdout.printf("firmware: (%c.%c)\n", major, minor); - break; - case "get": - switch(cmdparts[1]) { - case "address": - stdout.printf("address: %02x\n", led.get_address()); - break; - default: - stdout.printf("unknown get parameter!\n"); - break; - } - break; - case "stop": - led.script_stop(); - break; - case "play": - led.script_play((BlinkM.Script) uint64.parse(cmdparts[1])); - break; - case "set": - if(cmdparts[1] == "fade" && cmdparts[2] == "speed") { - if(cmdparts.length == 4) - led.set_fade_speed((uint8) uint64.parse(cmdparts[3])); - else - stdout.printf("\tset fade speed \n"); - } else if(cmdparts[1] == "time" && cmdparts[2] == "adjust") { - if(cmdparts.length == 4) - led.set_time_adjust((int8) int.parse(cmdparts[3])); - else - stdout.printf("\tset time adjust