void Str_show() { uint8 i,j; //i表示第几个字,j表示横坐标 LCD_TABLE = LCD_TABLE2; for( i=0,j=0; i<8; i++,j++ ) { LCD_Str(j*16, 0, i ); } for( j=0; i<16; i++,j++ ) { LCD_Str(j*16, 2, i ); } for( j=0; i<24; i++,j++ ) { LCD_Str(j*16, 4, i ); } for( j=0; i<32; i++,j++ ) { LCD_Str(j*16, 6, i ); } }
void LCD_Err(unsigned char *str) { int i; char buf0[17]; char buf1[17]; char buf2[17]; memset(buf0, 0x20, 16); memset(buf1, 0x20, 16); memset(buf2, 0x20, 16); buf0[16] = 0; buf1[16] = 0; buf2[16] = 0; int len = strlen(str); if (len > 16 * 3) len = 16 * 3; for (i = 0; i < len; ++i) { if (i < 16) { buf0[i] = str[i]; } else if (i < 16 * 2) { buf1[i - 16] = str[i]; } else if (i < 16 * 3) { buf2[i - 16 * 2] = str[i]; } } LCD_Str(0,0,"#### ERROR ####"); LCD_Str(0,2,buf0); LCD_Str(0,4,buf1); LCD_Str(0,6,buf2); }
int main(int argc, char *argv[]) { int i, j, len; char buf[17]; redisContext *ctx; redisReply *reply; wiringPiSetup(); LCD_Init(); // banner LCD_Str(0,0,"================"); LCD_Str(0,2," Redis->OLED "); LCD_Str(0,4," Display "); LCD_Str(0,6,"================"); delay(3000); // clear LCD_CLS(); delay(1000); // connect to redis ctx = redisConnect("127.0.0.1", 6379); if (ctx->err) { LCD_Err("cannot connect to Redis..."); delay(2000); LCD_Err(ctx->errstr); return -1; } while(1) { for (i = 0; i < 4; ++i) { // clear buffer memset(buf, 0x20, 16); buf[16] = 0; // get string from Redis...(oled:0-3) reply = redisCommand(ctx, "GET oled:%d", i); if (reply == NULL) { LCD_Err("redisCommand() failed..."); continue; } if (reply->type == REDIS_REPLY_ERROR) { LCD_Str(0, 2 * i, " "); freeReplyObject(reply); continue; } printf("oled:%d -> %s\n", i, reply->str); if (reply->str == NULL) { LCD_Str(0, 2 * i, " "); freeReplyObject(reply); continue; } // copy string to buffer len = strlen(reply->str); if (len > 16) len = 16; for (j = 0; j < len; ++j) { buf[j] = reply->str[j]; } // set string to OLED LCD_Str(0, 2 * i, buf); freeReplyObject(reply); } delay(200); } return 0; }