u08 ve_read_write (char cmd, u08 display) { int d; EIndex = EE_VAREDITOR; // starting address if(cmd=='W') { // Write to EEPROM // write marker first so that erased EEPROM can be detected // this will make an assumption that EE_VAREDITOR has not been changed as would // be possible if flashing new program code, but leaving EERPOM untouched // checksum might be nicer here, but this is simple d = 0xFACE; while(!eeprom_is_ready()); eeprom_write_block(&d,(void *) EIndex,2); // write marker EIndex += 2; } // if Reading, look for marker if (cmd=='R') { while (!eeprom_is_ready()); eeprom_read_block(&d,(void*) EIndex,2); if (d != 0xFACE) return (0); // EEPROM does not contain saved var editor data EIndex+=2; } if(vePort==-1) { if(display) { lcd_clear(); if (cmd=='R') lcd_textPS(0,0,"Reading EEPROM"); else lcd_textPS(0,0,"Writing EEPROM"); } } else { if (cmd=='R') printf(PS("\nReading EEPROM...")); else printf(PS("\nWriting EEPROM...")); } if (cmd=='R') veFlags = _BV(veREAD); else veFlags = _BV(veWRITE); ve_process(); // iterate through all vars veFlags = 0; if (vePort==-1) { if(display) delay_ms(1000); } else printf (PS("Finished\n\n")); return (1); // success }
int process_input (DESCRIPTOR_DATA * t) { int sofar; int thisround; int begin; int squelch; int i; int k; int flag; char tmp[MAX_STRING_LENGTH + 100]; char buffer[MAX_STRING_LENGTH + 100]; sofar = 0; flag = 0; begin = strlen (t->buf); /* Read in some stuff */ do { if ((thisround = read (t->hSocketFD, t->buf + begin + sofar, MAX_INPUT_LENGTH - (begin + sofar) - 1)) > 0) sofar += thisround; else if (thisround < 0) if (errno != EWOULDBLOCK) { return -1; } else break; else { return -1; } } while (!ISNEWL (*(t->buf + begin + sofar - 1))); *(t->buf + begin + sofar) = 0; if (!IS_SET (t->edit_mode, MODE_DONE_EDITING)) { ve_process (t, t->buf); /* Editor subsystem call */ *t->buf = '\0'; /* This may cause some data to be lost if */ return (0); /* chars are typed after @ & before processing */ } /* if no newline is contained in input, return without proc'ing */ for (i = begin; !ISNEWL (*(t->buf + i)); i++) if (!*(t->buf + i)) return (0); /* input contains 1 or more newlines; process the stuff */ for (i = 0, k = 0; *(t->buf + i);) { if (!ISNEWL (*(t->buf + i)) && !(flag = (k >= (MAX_INPUT_LENGTH - 2)))) if (*(t->buf + i) == '\b') /* backspace */ if (k) /* more than one char ? */ { i++; } else i++; /* no or just one char.. Skip backsp */ else /* KILLER CDR: $$ problem here. */ if (isascii (*(t->buf + i)) && isprint (*(t->buf + i))) { *(tmp + k) = *(t->buf + i); k++; i++; } else i++; else { *(tmp + k) = 0; if (*tmp == '!') strcpy (tmp, t->last_input); else strcpy (t->last_input, tmp); write_to_q (tmp, &t->input); if (t->snoop.snoop_by && t->snoop.snoop_by->desc != NULL && !IS_NPC (t->snoop.snoop_by)) { write_to_q ("% ", &t->snoop.snoop_by->desc->output); write_to_q (tmp, &t->snoop.snoop_by->desc->output); write_to_q ("\n\r", &t->snoop.snoop_by->desc->output); } if (flag) { sprintf (buffer, "Line too long. Truncated to:\n\r%s\n\r", tmp); if (write_to_descriptor (t, buffer) < 0) return (-1); /* skip the rest of the line */ for (; !ISNEWL (*(t->buf + i)); i++); } /* find end of entry */ for (; ISNEWL (*(t->buf + i)); i++); /* squelch the entry from the buffer */ for (squelch = 0;; squelch++) if ((*(t->buf + squelch) = *(t->buf + i + squelch)) == '\0') break; k = 0; i = 0; } } return (1); }
u08 ve_update(void ) // do we need param? { COORD mds; u08 cmd; if (vePort == -1) { // LCD GUI MENU_CONTROLS menu_exitbutton(); mds = (CHAR_WIDTH*BUTTON_SIZE) + ButtonBorder + ButtonRowSpacing; //!!! ButtonBorder*2 #ifdef RES_128x64 menu_label (0,0,PS("Var Editor")); menu_buttonrow(5,XROWS-(CHAR_HEIGHT+6), PS("G \xAE\xAF #WR")); menu_button (5+mds*6,XROWS-CHAR_HEIGHT*4+2, PS("+"),'+'); menu_button (5+mds*7,XROWS-CHAR_HEIGHT*4+2, PS("-"),'-'); #else menu_label (0,0,PS("Variable Editor")); menu_buttonrow(5,XROWS-(CHAR_HEIGHT+6), PS("G \xAE\xAF # WR")); menu_button (5+mds*8,XROWS-CHAR_HEIGHT*4-6, PS("+"),'+'); menu_button (5+mds*9,XROWS-CHAR_HEIGHT*4-6, PS("-"),'-'); #endif varedit_slider(); if(MenuDraw) ve_setflag (veDO_REFRESH); // if MenuDraw (set by menu_init) then screen was cleared and controls just // redrawn, so redraw current variable MENU_COMMANDS cmd = menu_cmd(); } else // Serial Console { MenuCmd = 0; // make sure disabled cmd = 0; switch (vePort) { case 0 : if (rx_haschar()) {cmd = rx_getchar(); beep(20,1000); } break; case 1 : if (rx1_haschar()) {cmd = rx1_getchar(); beep(20,1000); } break; } if ((cmd>='a') && (cmd<='z')) cmd -=32; // shift to uppercase // handle numeric entry using local buffer if ((cmd>='0') && (cmd<='9') && (veBufIndex < VE_BUF_SIZE)) { veBuf[veBufIndex++] = cmd; printf("%c",cmd); // echo character cmd = 0; // prevent refresh (display of group / var) } // handle backspace if ((cmd ==8) && (veBufIndex>0)) { veBufIndex--; printf("%c",cmd); cmd = 0; // prevent refresh } if (cmd==13) { veStoreSerialBuffer=1; // leave cmd alone to force refresh } } // menu button/control responses switch(cmd) { case 1 : // slider ve_setflag(veUPDATE_FROM_SLIDER); // current var will set to slider value break; // on next call to ve_process() // select next group case 'G' : if(++veCurGroup>veGroupCount) veCurGroup=1; veCurVar = 1; veCurVal = MAXLONG; ve_setflag(veCOUNT_VARS); ve_process(); ve_clrflag(veCOUNT_VARS); break; // next group // select previous / next variable // special arrow characters 0xAE <- 0xAF -> case '<':; // greater than or ".' char (for Serial Console Support) case ',':; case 0xAE: if(veVarCount && (--veCurVar==0)) veCurVar=veVarCount; break; // prev variable case '>':; case '.':; case 0xAF: if(veVarCount && (++veCurVar>veVarCount)) veCurVar=1; break; // next variable case '=':; case '+': veDelta = ( 1); break; // flag for inc/dec of current variable case '_':; case '-': veDelta = (-1); break; case '#': ve_setflag(veCALL_INPUT_DIALOG); break; // flag case 'W': case 'R': ve_read_write(cmd,1); // do 'R'-Read or 'W'-Write of vars from/to EEPROM menu_init(); ve_setflag(veDO_REFRESH); break; case 'X': MenuCmd = MENU_EXITCODE; // Close Variable Editor (Remote Serial Console) printf (PS("Exit. Thank You for using Megadonkey Variable Editor\n")); break; } if(ve_flag(veDO_REFRESH) || (((cmd!=0)||menu_cmd()) && (menu_cmd() != MENU_EXITCODE))) { if(ve_flag(veDO_REFRESH)) { ve_setflag(veCOUNT_VARS); // do a variable count pass through list ve_process(); // really this could be done one time with static defs ve_clrflag(veCOUNT_VARS); // thinking toward dynamic list ve_clrflag(veDO_REFRESH); } if (vePort==-1) // output to LCD { // if 'G' command erase group label and variable label // if not just erase variable label set_color(color ^ WHITE); if(menu_cmd() == 'G') { filled_box(0,CHAR_HEIGHT*3/2,XCOLS-1, CHAR_HEIGHT*3/2+CHAR_HEIGHT-1); } #ifdef RES_128x64 filled_box(0,CHAR_HEIGHT*3, XCOLS-1,CHAR_HEIGHT*4-1); #else filled_box(0,CHAR_HEIGHT*4, XCOLS-1,CHAR_HEIGHT*5-1); #endif set_color(color ^ WHITE); ve_process(); // update display of current var & update slider vals mds = MenuDraw; // save MenuDraw state MenuDraw = 1; // force redraw of slider varedit_slider(); MenuDraw = mds; // restore MenuDraw state } else // Output to Serial Port { if (cmd != 0) ve_process(); // update display of current var : output to serial port } } if ((menu_cmd() == MENU_EXITCODE) && (vePort != -1)) { lcd_set_stdout(); // ASSUME LCD was connected to std out (maybe should have saved state) printf (PS("VE Exit")); } return (menu_cmd() != MENU_EXITCODE); // return TRUE unless close [X] }