Пример #1
0
//******************************************************************************************************************************************
// Setup
//******************************************************************************************************************************************
void setup()
{
  pinMode(9,OUTPUT);
  pinMode(10,OUTPUT);
  pinMode(11,OUTPUT);
  Serial.begin(9600);
  delay(20);      // Enter command mode (30mS)
  start();
  command_mode();
  stop();
}
Пример #2
0
int lcd_spi_complete_event(void * context, const void * data){
	int j;
	int i;

	//deassert CS each time a SPI event completes
	deassert_cs();

	i = lcd_page - 0xB0;
	if( i == LCD_COLS ){
		lcd_hold = 0x00;
		update_count(); //interrupt again on next timer match
		return 0; //all done
	}

	switch(lcd_write_state){
	case LCD_WRITE_PAGE:

		command_mode();
		lcd_buffer[0] = lcd_page;
		lcd_buffer[1] = 0x10;
		lcd_buffer[2] = 0x00;

		op.nbyte = 3;

		assert_cs();

		lcd_write_state = LCD_WRITE_DATA;
		hwpl_spi_write(context, &op);
		return 1;
	case LCD_WRITE_DATA:

		data_mode();
		assert_cs();

		for(j=0;j<LCD_ROWS;j++){			//128 rows high
			lcd_buffer[j] = mem[LCD_ROWS - j - 1][i];
		}

		op.nbyte = LCD_ROWS;

		lcd_page++;
		lcd_write_state = LCD_WRITE_PAGE;
		hwpl_spi_write(context, &op);
		break;
	}

	return 1;
}
Пример #3
0
int main(int argc, char *argv[]) {
    menu_options current_option;
    cdc_entry current_cdc_entry;
    int command_result;

    // this block provides a command line api via `command_mode`
    if (argc > 1) {
        command_result = command_mode(argc, argv);
        exit(command_result);
    }

    // if we get here, then we are in interactive mode....
    //    start with an announcement message
    announce();

    // initialize the db. Using 0 here means open an exiting db (actually it
    // will create one, but it won't delete old data for you). To clear the
    // dbs and initialize a new one, use cmd line mode with -i.
    if (!database_initialize(0)) {
        fprintf(stderr, "Sorry, unable to initialize database\n");
        fprintf(stderr, "To create a new database use %s -i\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    // loop over an interactive console menu
    //    the semantics are kind of similar to the ch6 menu, where there's
    //    an "active" cd, and the operations you can do affect that cd

    while(current_option != mo_exit) {
        current_option = get_menu_choice(&current_cdc_entry);
        switch(current_option) {
            case mo_add_cat:
                // add a new catalog item. Lots of error checking here.
                if (enter_new_cat_entry(&current_cdc_entry)) {
                    if (!add_cdc_entry(current_cdc_entry)) {
                        // print message, but also make sure to zero out data
                        fprintf(stderr, "Failed to add new entry\n");
                        memset(&current_cdc_entry, '\0',
                               sizeof(current_cdc_entry));
                    }
                }
                break;
            case mo_add_tracks:
                enter_new_track_entries(&current_cdc_entry);
                break;
            case mo_del_cat:
                del_cat_entry(&current_cdc_entry);
                break;
            case mo_find_cat:
                current_cdc_entry = find_cat();
                break;
            case mo_list_cat_tracks:
                list_tracks(&current_cdc_entry);
                break;
            case mo_del_tracks:
                del_track_entries(&current_cdc_entry);
                break;
            case mo_count_entries:
                count_all_entries();
                break;
            case mo_exit:
            case mo_invalid:
            default:
                // in all three cases, do nothing
                break;
        }
    }

    // close db and exit
    database_close();
    exit(EXIT_SUCCESS);
} // end of main
Пример #4
0
void main(int argc, char *argv[])
{
    menu_options current_option;
    cdc_entry current_cdc_entry;
    int command_result;

    memset(&current_cdc_entry, '\0', sizeof(current_cdc_entry));

    if (argc > 1) {
        command_result = command_mode(argc, argv);
        exit(command_result);
    }
       
    announce();

    if (!database_initialize(0)) {
        fprintf(stderr, "Sorry, unable to initialize database\n");
        fprintf(stderr, "To create a new database use %s -i\n", argv[0]);
        exit(EXIT_FAILURE);
    }

/*  We're now ready to process user input. We sit in a loop, asking for a menu choice
 and processing it, until the user selects the exit option.
 We pass the current_cdc_entry structure to the show_menu function.
 We do this to allow the menu choices to change if a catalog entry is currently selected.  */

while(current_option != mo_exit) {
        current_option = show_menu(&current_cdc_entry);

        switch(current_option) {
            case mo_add_cat:
                if (enter_new_cat_entry(&current_cdc_entry)) {
                    if (!add_cdc_entry(current_cdc_entry)) {
                        fprintf(stderr, "Failed to add new entry\n");
                        memset(&current_cdc_entry, '\0', 
                               sizeof(current_cdc_entry));
                    }
                }
                break;
            case mo_add_tracks:
                enter_new_track_entries(&current_cdc_entry);
                break;
            case mo_del_cat:
                del_cat_entry(&current_cdc_entry);
                break;
            case mo_find_cat:
                current_cdc_entry = find_cat();
                break;
            case mo_list_cat_tracks:
                list_tracks(&current_cdc_entry);
                break;
            case mo_del_tracks:
                del_track_entries(&current_cdc_entry);
                break;
            case mo_count_entries:
                count_all_entries();
                break;
            case mo_exit:
                break;
            case mo_invalid:
                break;
            default:
                break;
        } /* switch */
    } /* while */

/* When the main loop exits, we close the database and exit back to the environment.
 The welcoming sentence is printed by the announce function. */

    database_close();
    exit(EXIT_SUCCESS);
} /* main */
Пример #5
0
int main(int argc, char *argv[]) {
    menu_options current_option;
    cdc_entry current_cdc_entry;
    int command_result;

    memset(&current_cdc_entry, '\0', sizeof(current_cdc_entry));

    // if there's an arg, switch to command mode and exit
    if (argc > 1) {
        command_result = command_mode(argc, argv);
        exit(command_result);
    }
       
    // print a greeting, and initialize the database (it must already exist)
    announce();
    if (!database_initialize(0)) {
        fprintf(stderr, "Sorry, unable to initialize database\n");
        fprintf(stderr, "To create a new database use %s -i\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    /* loop over menu choices, calling show_menu every time.
     * the behavior of show_menu depends on whether a track is currently
     * selected (which is determined by the var `current_cdc_entry`) */
    while(current_option != mo_exit) {
        current_option = show_menu(&current_cdc_entry);

        switch(current_option) {
            case mo_add_cat:
                if (enter_new_cat_entry(&current_cdc_entry)) {
                    if (!add_cdc_entry(current_cdc_entry)) {
                        fprintf(stderr, "Failed to add new entry\n");
                        memset(&current_cdc_entry, '\0', 
                               sizeof(current_cdc_entry));
                    }
                }
                break;
            case mo_add_tracks:
                enter_new_track_entries(&current_cdc_entry);
                break;
            case mo_del_cat:
                del_cat_entry(&current_cdc_entry);
                break;
            case mo_find_cat:
                current_cdc_entry = find_cat();
                break;
            case mo_list_cat_tracks:
                list_tracks(&current_cdc_entry);
                break;
            case mo_del_tracks:
                del_track_entries(&current_cdc_entry);
                break;
            case mo_count_entries:
                count_all_entries();
                break;
            case mo_exit:
                break;
            case mo_invalid:
                break;
            default:
                break;
        } /* switch */
    } /* while */


    // when the loop exits, clean up and quit
    database_close();
    exit(EXIT_SUCCESS);
}
Пример #6
0
int main(int argc, char *argv[])
{
  menu_options current_option;
  cdc_entry current_cdc_entry;
  int command_result;

  memset(&current_cdc_entry, '\0', sizeof(current_cdc_entry));

  if (argc > 1) {
    command_result = command_mode(argc, argv);
    exit(command_result);
  }

  announce();

  if (!database_initialize(0)) {
    fprintf(stderr, "Sorry, unable to initialize database\n");
    fprintf(stderr, "To create a new database use %s -i\n", argv[0]);
    exit(EXIT_FAILURE);
  }

  while (current_option != mo_exit) {
    current_option = show_menu(&current_cdc_entry);
    switch (current_option) {
      case mo_add_cat:
        if (enter_new_cat_entry(&current_cdc_entry)) {
          if (!add_cdc_entry(current_cdc_entry)) {
            fprintf(stderr, "Failed to add new entry\n");
            memset(&current_cdc_entry, '\0', sizeof(current_cdc_entry));
          }
        }
        break;
      case mo_add_tracks:
        enter_new_track_entries(&current_cdc_entry);
        break;
      case mo_del_cat:
        del_cat_entry(&current_cdc_entry);
        break;
      case mo_find_cat:
        current_cdc_entry = find_cat();
        break;
      case mo_list_cat_tracks:
        list_tracks(&current_cdc_entry);
        break;
      case mo_del_tracks:
        del_track_entries(&current_cdc_entry);
        break;
      case mo_count_entries:
        count_all_entries();
        break;
      case mo_exit:
        break;
      case mo_invalid:
        break;
      default:
        break;
    }
  }

  database_close();
  return 0;
}
Пример #7
0
void pconsole(void) {
int key, typed = 0;
char kar;
Conn *c, *c_next;

	if (AllConns == NULL)
		command_mode();										/* start in command mode */
	else {
		printf("\n"
			"Press <Ctlr-A> for command mode\n"
			"> ");
		fflush(stdout);
		terminal_mode(TERMINAL_RAW);
	}
	while(read(fileno(stdin), &kar, 1) > 0) {
		key = kar & 0xff;
		if (key == 1) {										/* Ctrl-A => command mode */
			printf("<Ctrl-A>\n");
			command_mode();
			continue;
		}
		if (key == KEY_CTRL('S')) {							/* Ctrl-S => toggle echo */
			printf("<Ctrl-S> ");
			cmd_echo(NULL);

			printf("> ");
			fflush(stdout);
			typed = 0;
			continue;
		}
		if (key == '\r' || key == '\n') {					/* return */
			printf("\n> ");
			fflush(stdout);
			typed = 0;
		} else {
			if (flags & FLAGS_ECHO) {
				if (key == 0x7f || key == '\b') {			/* backspace */
					if (typed) {
						printf("\b \b");
						fflush(stdout);
						typed--;
					}
				} else {
					if (key >= ' ' && key <= '~') {
						fputc(key, stdout);
						typed++;
					} else {
						switch(key) {
							case 0x1b:
								printf("<Esc>");
								break;

							case '\t':
								printf("<Tab>");
								break;

							default:
								printf("<Ctrl-%c>", key - 1 + 'A');
						}
						printf("\n> ");
						typed = 0;
					}
					fflush(stdout);
				}
			}
		}
/*
	put character in everyones input buffer
*/
		for(c = AllConns; c != NULL; c = c_next) {
			c_next = c->next;

			if (c->fd > 0) {
				seteuid(0);											/* regain root privs */
				if (ioctl(c->fd, TIOCSTI, &kar) == -1) {			/* simulate terminal input */
					seteuid(getuid());								/* drop root privs again */
					printf("\nioctl() : %s\n", strerror(errno));
					if (c->hostname != NULL)
						printf("detaching from %s#%s\n", c->hostname, c->dev);
					else
						printf("detaching from %s\n", c->dev);
					remove_Conn(c);
					destroy_Conn(c);
				} else
					seteuid(getuid());								/* drop the root privs */
			}
		}
		if (AllConns == NULL)
			command_mode();
	}
}
Пример #8
0
int lcd_ioctl(const device_cfg_t * cfg, int request, void * ctl){
	mlcd_attr_t * attr = (mlcd_attr_t*)ctl;
	tmr_action_t action;
	pio_attr_t pattr;
	device_periph_t p;

	switch(request){
	case I_MLCD_GETATTR:
		attr->freq = LCD_FREQ; //LCD updates 30 times per second
		attr->h = LCD_HEIGHT;
		attr->w = LCD_WIDTH;
		attr->size = LCD_ROWS * LCD_COLS;
		attr->mem = mem;
		attr->hold = lcd_hold;
		attr->rows = LCD_ROWS;
		attr->cols = LCD_COLS/4;
		attr->orientation = (ORIENT_BOTTOM)|(ORIENT_LEFT);
		break;

	case I_MLCD_CLEAR:
		memset(mem, 0, LCD_ROWS * LCD_COLS);
		lcd_hold = 0x80;
		break;

	case I_MLCD_HOLD:
		if( LCD_HOLD_COUNT() < 127 ){
			lcd_hold++;
		}
		break;

	case I_MLCD_RELEASE:
		if( LCD_HOLD_COUNT() > 0 ){
			lcd_hold--;
			LCD_TOUCH();
		}
		break;

	case I_MLCD_INIT:

		//initialize the IO -- chip select first
		pattr.mask = LCD_SPI_CS_PINMASK;
		pattr.mode = PIO_MODE_OUTPUT;
		p.port = LCD_SPI_CS_PORT;
		hwpl_pio_open((device_cfg_t*)&p);
		hwpl_pio_setattr(LCD_SPI_CS_PORT, &pattr);
		hwpl_pio_setmask(LCD_SPI_CS_PORT, (void*)LCD_SPI_CS_PINMASK);

		//Now A0
		pattr.mask = LCD_SPI_A0_PINMASK;
		if( p.port != LCD_SPI_A0_PORT ){
			p.port = LCD_SPI_A0_PORT;
			hwpl_pio_open((device_cfg_t*)&p);
		}
		hwpl_pio_setattr(LCD_SPI_A0_PORT, &pattr);
		hwpl_pio_setmask(LCD_SPI_A0_PORT, (void*)LCD_SPI_A0_PINMASK);

		//configure the timer to update the LCD
		action.channel = LCD_USECOND_OC;
		action.event = TMR_ACTION_EVENT_INTERRUPT;
		action.callback = lcd_usecond_match_event;
		action.context = (void*)cfg;
		hwpl_tmr_setaction(LCD_USECOND_TMR, &action);

		const char start[] = {0xA0, 0xAE, 0xC0, 0xA2, 0x2F, 0x21, 0x81, 0x2F};
		int i;
		const char * p = (const char*)start;

		command_mode();
		hwpl_pio_clrmask(LCD_SPI_A0_PORT, (void*)LCD_SPI_A0_PINMASK); //enter command mode

		for(i=0; i < 8; i++){
			assert_cs();
			hwpl_spi_swap(LCD_SPI_PORT, (void*)(uint32_t)(*p++));
			deassert_cs();
		}

		//start the timer update to refresh the screen
		update_count();
		break;

	case I_MLCD_ON:
		command_mode();
		assert_cs();
		hwpl_spi_swap(LCD_SPI_PORT, (void*)0xAF);
		deassert_cs();
		break;

	case I_MLCD_OFF:
		command_mode();
		assert_cs();
		hwpl_spi_swap(LCD_SPI_PORT, (void*)0xAE);
		deassert_cs();
		break;

	default:
		errno = EINVAL;
		return -1;
	}


	return 0;
}