Beispiel #1
0
/*
 * show all tasks
 */
int show_task_all(struct shell_session *ss, int argc, char **argv)
{
	int i;

	ss->output(" id name     state  flags pri  pri_origin    ticks    ticks_left\n");
	for(i=0; i<MAX_TASK_NUMBER; i++)
	{
		if(systask[i].state != TASK_STATE_DEAD)
			task_dump(ss, i);
	}

	return SHELL_RET_OK;
}
Beispiel #2
0
/*
 * show a task
 */
int show_task(struct shell_session *ss, int argc, char **argv)
{
	int i;

	for(i=0; i<MAX_TASK_NUMBER; i++)
	{
		if(strcmp((const char *)systask[i].name, argv[2]) == 0)
		{
			ss->output(" id name     state  flags pri  pri_origin    ticks    ticks_left\n");
			task_dump(ss, i);
			return SHELL_RET_OK;
		}
	}
	
	ss->output("unknown task\n");
	return SHELL_RET_WARN;
}
Beispiel #3
0
// Removes a task given the file and the index.
int remove_task(char* filename, int number){
    
    FILE* file = fopen(filename, "r");
    if (file == NULL){
        perror("Cannot remove task");
        errno = 0;
        goto error;
    }

    // Open up the tasklist.
    tasklist* list = tasklist_new();
    if (tasklist_read(list, file) != 0){
        puts("ERROR: could not read tasklist.");
        goto error;
    }

    fclose(file);
    fopen(filename, "w");
    Task* t = tasklist_get(list, number-1);
    if (t == NULL){
        puts("There is no task with that number.");
        goto error;
    }

    printf("Are you sure you want to remove %d: %s? (y/n)\n", number, task_dump(t));
    char answer[5];
    char* ans = answer;
    fgets(ans, 5, stdin);
    if (strcmp(answer, "y\n") == 0){
        tasklist_remove(list, number-1);
        if (tasklist_dump(list, file) != 0){
            puts("ERROR: could not write tasklist.");
        }
    }
    printf("Task %d deleted.\n", number);
    task_free(t);
    tasklist_free(list);
    error:
        fclose(file);
        return 1;
}
Beispiel #4
0
/** Main loop for handling the user interface. */
static void sim_interface_thread (void)
{
	char inbuf[2];
	struct key_binding *kb;
	int simulator_keys = 1;
	int toggle_mode = 1;

#ifndef CONFIG_UI_SDL
	/* Put stdin in raw mode so that 'enter' doesn't have to
	be pressed after each keystroke. */
	keybuffering (0);

	/* Let the system initialize before accepting keystrokes */
	task_sleep_sec (3);
#endif

	if (exec_file && exec_late_flag)
		exec_script_file (exec_file);

	for (;;)
	{
		task_yield ();
#ifdef CONFIG_GTK
		gtk_poll ();
#endif
#ifdef CONFIG_UI_SDL
		ui_refresh_all ();
		*inbuf = ui_poll_events ();
#else
		*inbuf = sim_getchar ();
#endif

		/* Try again if no character was read */
		if (*inbuf == '\0')
			continue;

		/* If switch simulation is turned off, then keystrokes
		are fed into the simulated serial port... meaning it is interpreted
		by the game program itself, and not the simulator.  Use the
		tilde to toggle between the two modes. */
		if (simulator_keys == 0)
		{
			/* Except tilde turns it off as usual. */
			if (*inbuf == '`')
			{
				simlog (SLC_DEBUG, "Input directed to switch matrix.");
				simulator_keys ^= 1;
			}
			else
			{
				wpc_key_press (*inbuf);
			}
			continue;
		}

		switch (*inbuf)
		{
			/* Carriage returns and line feeds are ignored so that you can
			put these commands into a script file. */
			case '\r':
			case '\n':
				break;

			case ':':
			{
				/* Read and execute a script command */
				char cmd[128];
				char *p = cmd;

				memset (p, 0, 128);
				ui_print_command (" ");
				for (;;)
				{
					*p = sim_getchar ();
					if (*p == '\x1B')
					{
						break;
					}
					else if (*p == '\010')
					{
						*p = '\0';
						p--;
					}
					else if ((*p == '\r') || (*p == '\n'))
					{
						*p = '\0';
						exec_script (cmd);
						break;
					}
					ui_print_command (cmd);
					p++;
				}
				ui_print_command ("");
				break;
			}

			case 'C':
				gdb_break ();
				break;

			case '{':
				signal_trace_start (signo_under_trace);
				break;

			case '}':
				signal_trace_stop (signo_under_trace);
				break;

			case 'q':
				node_kick (&open_node);
				break;

			case '`':
				/* The tilde toggles between keystrokes being treated as switches,
				and as input into the runtime debugger. */
				simulator_keys ^= 1;
				simlog (SLC_DEBUG, "Input directed to built-in debugger.");
				break;

			case '\x1b':
				sim_exit (0);
				break;

			case 'T':
				task_dump ();
				break;

			case '#':
				/* Treat '#' as a comment until end of line.
				This is useful for creating scripts. */
				do {
					*inbuf = sim_getchar ();
				} while (*inbuf != '\n');
				break;

			case '"':
				simlog (SLC_DEBUG, "next key will toggle, not press");
				toggle_mode = 0;
				break;

			default:
				/* For all other keystrokes, use the keymap table
				to turn the keystroke into a switch trigger. */
				kb = &keymaps[(int)*inbuf];
#ifdef MACHINE_SHOOTER_SWITCH
				if (kb->flags & KEY_SHOOTER)
				{
					node_kick (&shooter_node);
				}
				else
#endif
				if (kb->flags & KEY_NODE)
				{
					node_move (kb->node, &open_node);
				}
				else if (kb->flags & KEY_SW)
				{
					if ((switch_table[kb->sw].flags & SW_EDGE) || !toggle_mode)
					{
						simlog (SLC_DEBUG, "switch %d toggled", kb->sw);
						sim_switch_toggle (kb->sw);
						toggle_mode = 1;
					}
#if (MACHINE_FLIPTRONIC == 1)
					else if (kb->sw >= 72)
					{
						flipper_button_depress (kb->sw);
					}
#endif
					else
					{
						sim_switch_depress (kb->sw);
					}
				}
				else
					simlog (SLC_DEBUG, "invalid key '%c' pressed (0x%02X)",
						*inbuf, *inbuf);
			}
	}
}