int main(){ DI();//disable interrupts or hell breaks loose during hardware config construct_system();//bind device addresses init_system();//init devices //clear all interrupts clearall_interrupts(); EI();//enable interrupts: we have UART_recieve //set the lcd contrast //lcd_contrast(0x42); lcd_contrast(0x32); //clear the lcd clearram(); //show boot up message show_bootup(); //clear boot message clearram(); //screen layout screen_layout(); send(1, 225); send(1, 255); send(1, 2); while(1) { get_temperature1(); get_temperature2(); get_light(); get_pressure(); get_humidity(); get_soilwetness(); display(); delay_ms(800); } return 0; }
///////////////////////////////////////////////////////////////////// // First byte, hex: Row number if less then 32, Display text in title else // Rest: Text to display, up to 16 char. // 00:title (big font). // 01-08:body // 09:scroll up, add row at bottom // 0A:scroll down, add row at top // 0B:redraw screen. // FF:control functions: Switch LCD on/of, set contrast void lcdfunc(char *in) { uint8_t hb[4]; uint8_t narg = fromhex(in+1, hb, 4); if(narg > 0 && hb[0] == 0xFF) { if(hb[1] != 0xFF) lcd_switch(hb[1]); if(hb[2] != 0xFF) lcd_contrast(hb[2]); #ifdef LCD_BL_PWM if(hb[3] != 0xFF) lcd_brightness(hb[3]); #endif return; } if(narg == 0 || hb[0] >= 0x20) { // Strange lines go to the title hb[0] = 0; in += 1; } else { in += 3; } lcd_putline(hb[0], in); }
void env_relocate(bd_t *bd) { char *s, *e; int reg; bd->bi_env = malloc(sizeof(env_t)); if (board_env_copy(bd, bd->bi_env, sizeof(env_t)) < 0) { printf("*** Using default environment\n"); memcpy(bd->bi_env_data, default_environment, sizeof(default_environment)); bd->bi_env_crc = crc32(0, bd->bi_env_data, sizeof(bd->bi_env_data)); } /* now initialise some variables */ /* MAC address */ s = getenv(bd, "ethaddr"); for (reg=0; reg<6; reg++) { bd->bi_enetaddr[reg] = s ? simple_strtoul(s, &e, 16) : 0; if (s) s = (*e) ? e+1 : e; } #if (CONFIG_COMMANDS & CFG_CMD_NET) /* IP address */ s = getenv(bd, "ipaddr"); bd->bi_ip_addr = string_to_ip(s); #endif if ((s = getenv(bd, "loadaddr")) != NULL) { load_addr = simple_strtoul(s, NULL, 16); } if ((s = getenv(bd, "pagelength")) != NULL) { pagelength = simple_strtoul(s, NULL, 10); } #if (CONFIG_COMMANDS & CFG_CMD_NET) if ((s = getenv(bd, "bootfile")) != NULL) { copy_filename (BootFile, s, sizeof(BootFile)); } #endif /* CFG_CMD_NET */ #ifdef CONFIG_KEYBOARD if ((s = getenv(bd, "keymap")) != NULL) { kbd_mapping (s); } #endif /* CONFIG_KEYBOARD */ #ifdef CONFIG_ADJUST_LCD if ((s = getenv(bd, "contrast")) != NULL) { lcd_contrast(simple_strtoul(s, NULL, 10)); } if ((s = getenv(bd, "brightness")) != NULL) { lcd_brightness(simple_strtoul(s, NULL, 10)); } #endif /* CONFIG_ADJUST_LCD */ }
int _do_setenv (bd_t *bd, int flag, int argc, char *argv[]) { int i, len, oldval; uchar *env, *nxt = 0; uchar *name; /* need writable copy in RAM */ if (!bd->bi_env_data) return 1; name = argv[1]; /* * search if variable with this name already exists */ oldval = -1; for (env = bd->bi_env_data; *env; env = nxt+1) { for (nxt = env; *nxt; ++nxt) ; if ((oldval = envmatch(bd, name, (ulong)env - (ulong)bd->bi_env_data)) >= 0) break; } /* * Delete any existing definition */ if (oldval >= 0) { #ifndef CONFIG_ENV_OVERWRITE /* * Ethernet Address and serial# can be set only once */ if ( (strcmp (name, "serial#") == 0) || ((strcmp (name, "ethaddr") == 0) # if defined(CONFIG_OVERWRITE_ETHADDR_ONCE) && defined(CONFIG_ETHADDR) && (strcmp (get_env_addr(bd, oldval),MK_STR(CONFIG_ETHADDR)) != 0) # endif /* CONFIG_OVERWRITE_ETHADDR_ONCE && CONFIG_ETHADDR */ ) ) { printf ("Can't overwrite \"%s\"\n", name); return 1; } #endif /* * Switch to new baudrate if new baudrate is supported */ if (strcmp(argv[1],"baudrate") == 0) { int baudrate = simple_strtoul(argv[2], NULL, 10); int i; for (i=0; i<N_BAUDRATES; ++i) { if (baudrate == baudrate_table[i]) break; } if (i == N_BAUDRATES) { printf ("## Baudrate %d bps not supported\n", baudrate); return 1; } printf ("## Switch baudrate to %d bps and press ENTER ...\n", baudrate); udelay(50000); serial_setbrg (bd, baudrate); udelay(50000); for (;;) { if (getc() == '\r') break; } bd->bi_baudrate = baudrate; } if (*++nxt == '\0') { if ((ulong)env > (ulong)bd->bi_env_data) { env--; } else { *env = '\0'; } } else { for (;;) { *env = *nxt++; if ((*env == '\0') && (*nxt == '\0')) break; ++env; } } *++env = '\0'; } /* Delete only ? */ if ((argc < 3) || argv[2] == NULL) { /* Update CRC */ bd->bi_env_crc = crc32(0, bd->bi_env_data, sizeof(bd->bi_env_data)); return 0; } /* * Append new definition at the end */ for (env = bd->bi_env_data; *env || *(env+1); ++env) ; if ((ulong)env > (ulong)bd->bi_env_data) ++env; /* * Overflow when: * "name" + "=" + "val" +"\0\0" > * sizeof(bd->bi_env_data) - (env-bd->bi_env_data) */ len = strlen(name) + 2; /* add '=' for first arg, ' ' for all others */ for (i=2; i<argc; ++i) { len += strlen(argv[i]) + 1; } if (len > sizeof(bd->bi_env_data)) { printf ("## Error: environment overflow, \"%s\" deleted\n", name); return 1; } while ((*env = *name++) != '\0') env++; for (i=2; i<argc; ++i) { char *val = argv[i]; *env = (i==2) ? '=' : ' '; while ((*++env = *val++) != '\0') ; } /* end is marked with double '\0' */ *++env = '\0'; /* Update CRC */ bd->bi_env_crc = crc32(0, bd->bi_env_data, sizeof(bd->bi_env_data)); /* * Some variables should be updated when the corresponding * entry in the enviornment is changed */ if (strcmp(argv[1],"ethaddr") == 0) { char *s = argv[2]; /* always use only one arg */ char *e; for (i=0; i<6; ++i) { bd->bi_enetaddr[i] = s ? simple_strtoul(s, &e, 16) : 0; if (s) s = (*e) ? e+1 : e; } return 0; } #if (CONFIG_COMMANDS & CFG_CMD_NET) if (strcmp(argv[1],"ipaddr") == 0) { char *s = argv[2]; /* always use only one arg */ bd->bi_ip_addr = string_to_ip(s); return 0; } #endif if (strcmp(argv[1],"loadaddr") == 0) { load_addr = simple_strtoul(argv[2], NULL, 16); return 0; } if (strcmp(argv[1],"pagelength") == 0) { pagelength = simple_strtoul(argv[2], NULL, 10); return 0; } #if (CONFIG_COMMANDS & CFG_CMD_NET) if (strcmp(argv[1],"bootfile") == 0) { copy_filename (BootFile, argv[2], sizeof(BootFile)); return 0; } #endif /* CFG_CMD_NET */ #ifdef CONFIG_KEYBOARD if (strcmp(argv[1],"keymap") == 0) { kbd_mapping (argv[2]); return 0; } #endif /* CONFIG_KEYBOARD */ #ifdef CONFIG_ADJUST_LCD if (strcmp(argv[1],"contrast") == 0) { lcd_contrast(simple_strtoul(argv[2], NULL, 10)); return 0; } if (strcmp(argv[1],"brightness") == 0) { lcd_brightness(simple_strtoul(argv[2], NULL, 10)); return 0; } #endif /* CONFIG_ADJUST_LCD */ return 0; }
void menu_handle_joystick(uint8_t key) { uint8_t menu_line[MLINESIZE+1]; //////////////////////////////////////// // Scrolling up/down. if(key == KEY_DOWN || key == KEY_UP) { menu_setbg(menu_curitem); lcd_putchar(menu_curitem-menu_topitem+1, ' '); uint8_t insert_line = 0; if(key == KEY_DOWN) { if(menu_curitem == menu_nitems-1) menu_curitem = 0; else menu_curitem++; if(menu_curitem - menu_topitem >= BODY_LINES) { menu_topitem++; insert_line = 9; } } if(key == KEY_UP) { if(menu_curitem == 0) menu_curitem = menu_nitems-1; else menu_curitem--; if(menu_topitem > menu_curitem) { menu_topitem--; insert_line = 10; } } menu_setbg(menu_curitem); if(insert_line) { uint8_t dpybuf[17]; menu_get_line(menu_item_offset[menu_curitem], menu_line, sizeof(menu_line)); menu_getlineword(1, menu_line, dpybuf+1, sizeof(dpybuf)-1); dpybuf[0] = ' '; lcd_putline(insert_line, (char *)dpybuf); } lcd_putchar(menu_curitem-menu_topitem+1, '>'); } //////////////////////////////////////// // Exec current command if(key == KEY_RIGHT) { // Save the current position menu_lastsel[menu_stack[menu_stackidx-1]] = menu_curitem; menu_get_line(menu_item_offset[menu_curitem], menu_line, sizeof(menu_line)); uint8_t arg[MLINESIZE]; menu_getlineword(2, menu_line, arg, sizeof(arg)); if(menu_line[0] == 'S') { // submenu uint8_t sm; fromhex((char *)arg, &sm, 1); menu_push(sm); } if(menu_line[0] == 'C') { // Command lcd_invon(); callfn((char *)arg); lcd_invoff(); } if(menu_line[0] == 'm') { // Macro uint8_t idx; uint16_t off; lcd_invon(); fromhex((char *)arg, &idx, 1); off = menu_get_line(menu_offset[idx], menu_line, sizeof(menu_line)); while(off && menu_line[0]) { off = menu_get_line(off, menu_line, sizeof(menu_line)); if(off == 0 || !menu_line[0]) break; callfn((char *)menu_line); } lcd_invoff(); } } if(key == KEY_LEFT) { // pop menu stack // Save the current position menu_lastsel[menu_stack[menu_stackidx-1]] = menu_curitem; menu_pop(); } //////////////////////////////////////// // Switch display on / off if(key == KEY_ENTER) { if(lcd_on) { if(lcd_on == 0xff) { lcd_switch(1); lcd_cls(); lcd_contrast(0xfc); menu_stackidx = 0; menu_push(0); } else { dosleep(); } } else { lcd_switch(1); } bat_drawstate(); } }