Changeset 600:e02ba62645fc

Show
Ignore:
Timestamp:
06/11/08 10:02:13 (7 months ago)
Author:
Maxime Petazzoni <maxime.petazzoni@…>
Branch:
default
Message:

Split code a bit to make it more readable. Start working on RCMD reception via USB.

Location:
nxos/systems/tag-route
Files:
4 added
1 modified

Legend:

Unmodified
Added
Removed
  • nxos/systems/tag-route/main.c

    r592 r600  
    1212#include "base/core.h" 
    1313#include "base/display.h" 
    14 #include "base/util.h" 
    1514#include "base/drivers/avr.h" 
    1615#include "base/drivers/systick.h" 
    17 #include "base/drivers/motors.h" 
    18 #include "base/lib/fs/fs.h" 
    1916#include "base/lib/gui/gui.h" 
    20 #include "base/lib/rcmd/rcmd.h" 
    2117 
    22 #define ROUTE_FILE "tag.data" 
    23  
    24 #define TEST_DATA "print hello world\nmove A,B 100 1500\nwait 2000\nplay 1500 1000 sync\nprint done" 
    25 #define DATA_SIZE strlen(TEST_DATA) 
    26  
    27 void record(char *filename); 
    28 void replay(char *filename); 
    29 void defrag(void); 
    30 void stats(void); 
    31  
    32 void record(char *filename) { 
    33   fs_fd_t fd; 
    34   fs_err_t err; 
    35   size_t i; 
    36  
    37   nx_display_clear(); 
    38   nx_display_string("Creating file...\n"); 
    39  
    40   err = nx_fs_open(filename, FS_FILE_MODE_CREATE, &fd); 
    41   if (err == FS_ERR_FILE_ALREADY_EXISTS) { 
    42     if (nx_gui_text_menu_yesno("Overwrite?")) { 
    43       nx_display_clear(); 
    44  
    45       nx_fs_open(filename, FS_FILE_MODE_OPEN, &fd); 
    46       if (nx_fs_unlink(fd) != FS_ERR_NO_ERROR) { 
    47         nx_display_string("Erase error.\n"); 
    48         return; 
    49       } 
    50  
    51       if (nx_fs_open(filename, FS_FILE_MODE_CREATE, &fd) != FS_ERR_NO_ERROR) { 
    52         nx_display_string("Create error.\n"); 
    53         return; 
    54       } 
    55     } else { 
    56       nx_display_string("Aborting.\n"); 
    57       return; 
    58     } 
    59   } 
    60  
    61   nx_display_string("File opened.\n\n"); 
    62   nx_display_string("Writing...\n"); 
    63  
    64   for (i=0; i<DATA_SIZE; i++) { 
    65     err = nx_fs_write(fd, (U8)TEST_DATA[i]); 
    66  
    67     if (err != FS_ERR_NO_ERROR) { 
    68       nx_display_string("Err: "); 
    69       nx_display_uint(err); 
    70       nx_display_end_line(); 
    71     } 
    72   } 
    73  
    74   nx_display_uint(nx_fs_get_filesize(fd)); 
    75   nx_display_string("/"); 
    76   nx_display_uint(DATA_SIZE); 
    77   nx_display_string("B written.\n"); 
    78   nx_fs_close(fd); 
    79 } 
    80  
    81 void replay(char *filename) { 
    82   nx_display_clear(); 
    83   nx_rcmd_parse(filename); 
    84 } 
    85  
    86 void defrag(void) { 
    87   nx_display_clear(); 
    88   nx_display_string("- Defrag -\n\n"); 
    89   nx_fs_defrag_best_overall(); 
    90   nx_display_string("Done.\n"); 
    91  
    92         while (nx_avr_get_button() != BUTTON_CANCEL); 
    93 } 
    94  
    95 void stats(void) { 
    96   U32 files = 0, used = 0, free_pages = 0, wasted = 0; 
    97  
    98   nx_display_clear(); 
    99   nx_display_string("- FS stats -\n\n"); 
    100  
    101   nx_fs_get_occupation(&files, &used, &free_pages, &wasted); 
    102  
    103   nx_display_uint(files); 
    104   nx_display_string(" file(s).\n"); 
    105  
    106   nx_display_uint(used); 
    107   nx_display_string("B used.\n"); 
    108  
    109   nx_display_uint(free_pages); 
    110   nx_display_string(" free page(s).\n"); 
    111  
    112   nx_display_uint(wasted); 
    113   nx_display_string("B wasted.\n"); 
    114 } 
     18#include "main.h" 
    11519 
    11620void main(void) { 
    117   char *entries[] = {"Replay", "Record", "Stats", "Defrag", "Halt", NULL}; 
     21  char *entries[] = {"Replay", "Record", "From USB", "Halt", NULL}; 
    11822  gui_text_menu_t menu; 
    11923  U8 res; 
     
    12933  menu.active_mark = GUI_DEFAULT_TEXT_MARK; 
    13034 
    131   while ((res = nx_gui_text_menu(menu)) != 4) { 
     35  while (TRUE) { 
     36    res = nx_gui_text_menu(menu); 
     37 
    13238    switch (res) { 
    13339      case 0: 
     
    13844        break; 
    13945      case 2: 
    140         stats(); 
     46        usb_recv(); 
    14147        break; 
    14248      case 3: 
    143         defrag(); 
     49        return; 
    14450        break; 
    14551      default: 
     
    15258    nx_systick_wait_ms(500); 
    15359  } 
     60} 
    15461 
    155   nx_display_string(">> Halting..."); 
    156   nx_systick_wait_ms(1000); 
    157 }