ESP8266-based WiFi serial modem emulator ROM
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Pixel: Add AT$LED? and AT$LED=n commands to adjust brightness

These are AT*LED in the WiModem232 ROM but we use $ for these types
of commands.

+36 -12
+12 -4
pixel.cpp
··· 27 27 { 28 28 pixel.begin(); 29 29 pixel.clear(); 30 - pixel.setBrightness(10); 31 - pixel.show(); 30 + pixel_adjust_brightness(); 31 + } 32 32 33 - /* default to red */ 34 - pixel_set_rgb(255, 0, 0); 33 + void 34 + pixel_adjust_brightness(void) 35 + { 36 + int br = 255 * (double)(settings->pixel_brightness / 10.0); 37 + #ifdef PIXEL_TRACE 38 + syslog.logf(LOG_DEBUG, "pixel: setting brightness to %d", br); 39 + #endif 40 + pixel.setBrightness(br); 41 + pixel.show(); 42 + pixel_set_rgb(cur_color); 35 43 } 36 44 37 45 void
+2
util.cpp
··· 67 67 IP4_ADDR(&settings->ppp_server_ip, 10, 10, 10, 10); 68 68 IP4_ADDR(&settings->ppp_client_ip, 10, 10, 10, 20); 69 69 70 + settings->pixel_brightness = 10; 71 + 70 72 EEPROM.commit(); 71 73 } 72 74
+2
wifippp.h
··· 62 62 uint8_t echo; 63 63 uint8_t quiet; 64 64 uint8_t verbal; 65 + uint8_t pixel_brightness; 65 66 }; 66 67 67 68 enum { ··· 97 98 void pixel_set_rgb(int, int, int); 98 99 void pixel_set_rgb(uint32_t); 99 100 void pixel_color_by_state(void); 101 + void pixel_adjust_brightness(void); 100 102 101 103 /* ppp.cpp */ 102 104 bool ppp_start(void);
+20 -8
wifippp.ino
··· 614 614 break; 615 615 case '$': 616 616 /* wifi232 commands, all consume the rest of the input string */ 617 - if (strcmp(lcmd, "net=0") == 0) { 617 + if (strcmp(lcmd, "led?") == 0) { 618 + /* AT$LED?: show pixel brightness setting */ 619 + outputf("\n%d\r\n", settings->pixel_brightness); 620 + did_nl = true; 621 + } else if (strncmp(lcmd, "led=", 4) == 0) { 622 + /* AT$LED=n: set pixel brightness */ 623 + int br, chars; 624 + if (sscanf(lcmd, "led=%d%n", &br, &chars) != 1 || 625 + chars == 0 || br < 0 || br > 10) { 626 + errstr = strdup("brightness must be between " 627 + "0 and 10"); 628 + goto error; 629 + } 630 + settings->pixel_brightness = br; 631 + pixel_adjust_brightness(); 632 + } else if (strcmp(lcmd, "net=0") == 0) { 618 633 /* AT$NET=0: disable telnet setting */ 619 634 settings->telnet = 0; 620 635 } else if (strcmp(lcmd, "net=1") == 0) { ··· 680 695 /* AT$SB=...: set baud rate */ 681 696 if (sscanf(lcmd, "sb=%d%n", &baud, &chars) != 1 || 682 697 chars == 0) { 683 - if (settings->verbal) 684 - output("ERROR invalid baud rate\r\n"); 685 - else 686 - output("4\r"); 687 - break; 698 + errstr = strdup("invalid baud rate"); 699 + goto error; 688 700 } 689 701 690 702 switch (baud) { ··· 710 722 serial_start(settings->baud); 711 723 break; 712 724 default: 713 - output("ERROR unsupported baud rate\r\n"); 714 - break; 725 + errstr = strdup("unsupported baud rate"); 726 + goto error; 715 727 } 716 728 } else if (strcmp(lcmd, "sb?") == 0) { 717 729 /* AT$SB?: print baud rate */