This commit is contained in:
kraus 2018-05-07 20:20:22 +02:00
parent d1ed185bd9
commit ef106170cb
3 changed files with 138 additions and 7 deletions

View File

@ -61,6 +61,9 @@ uint8_t max_on_cnt; // last number max number of "on" switches
int8_t max_on_cnt_pos1 = -1;
int8_t max_on_cnt_pos2 = -1;
int8_t user_pos1;
int8_t user_pos2;
int8_t max_on_cnt_npos1 = -1;
int8_t max_on_cnt_npos2 = -1;
@ -263,8 +266,8 @@ void next_state(void)
else if ( max_on_cnt_pos1 == 1 ) // sub cmd user choice
{
state = STATE_DELAYED_SWAP_WAIT;
max_on_cnt_npos1 = -1;
max_on_cnt_npos2 = -1;
user_pos1 = -1;
user_pos2 = -1;
u8g2log.print(F("user\n"));
}
@ -288,24 +291,45 @@ void next_state(void)
break;
case STATE_DELAYED_SWAP_WAIT: // user choice
{
uint8_t i;
uint8_t i, j;
for( i = 0; i < 4; i++ )
{
if ( switch_status[i] == SWITCH_ON )
if ( user_pos1 != i && switch_status[i] == SWITCH_ON )
{
if ( max_on_cnt_pos1 < 0 )
max_on_cnt_pos1 = i;
if ( user_pos1 < 0 )
user_pos1 = i;
else
{
uint8_t tmp;
max_on_cnt_pos2 = i;
user_pos2 = i;
tmp = 1<<user_pos1;
tmp |= 1<<user_pos2;
max_on_cnt_npos1 = -1;
max_on_cnt_npos2 = -1;
for( j = 0; j < 4; j++ )
{
if ( ( tmp & (1<<j) ) == 0 )
{
if ( max_on_cnt_npos1 < 0 )
max_on_cnt_npos1 = j;
else
max_on_cnt_npos2 = j;
}
}
tmp = map_switch_to_light[max_on_cnt_npos1];
map_switch_to_light[max_on_cnt_npos1] = map_switch_to_light[max_on_cnt_npos2];
map_switch_to_light[max_on_cnt_npos2] = tmp;
u8g2log.print(F("swap2\n"));
u8g2log.print(max_on_cnt_npos1);
u8g2log.print(F("<>"));
u8g2log.print(max_on_cnt_npos2);
u8g2log.print(F("\n"));
state = STATE_WAIT;
switch_changed_millis = millis();
}

View File

@ -0,0 +1,12 @@
CFLAGS = -g -Wall -I../../../csrc/. `sdl2-config --cflags` -fsanitize=address -fsanitize=undefined -fsanitize=bounds-strict -fsanitize=object-size
SRC = $(shell ls ../../../csrc/*.c) ../../bitmap/common/u8x8_d_bitmap.c $(shell ls ../common/*.c ) main.c
OBJ = $(SRC:.c=.o)
helloworld: $(OBJ)
$(CC) $(CFLAGS) $(LDFLAGS) $(OBJ) `sdl2-config --libs` -o u8g2_sdl
clean:
-rm $(OBJ) u8g2_sdl

95
sys/sdl/vietnamese/main.c Normal file
View File

@ -0,0 +1,95 @@
#include "u8g2.h"
#include <stdio.h>
u8g2_t u8g2;
int main(void)
{
int x, y;
int k;
int i;
u8g2_SetupBuffer_SDL_128x64_4(&u8g2, &u8g2_cb_r0);
u8x8_ConnectBitmapToU8x8(u8g2_GetU8x8(&u8g2)); /* connect to bitmap */
u8x8_InitDisplay(u8g2_GetU8x8(&u8g2));
u8x8_SetPowerSave(u8g2_GetU8x8(&u8g2), 0);
u8g2_SetFont(&u8g2, u8g2_font_unifont_t_vietnamese2);
x = 50;
y = 30;
for(;;)
{
/*
u8g2_ClearBuffer(&u8g2);
u8g2_SetFontDirection(&u8g2, 0);
u8g2_DrawStr(&u8g2, x, y, "ABC");
u8g2_SetFontDirection(&u8g2, 1);
u8g2_DrawStr(&u8g2, x, y, "abc");
u8g2_SetFontDirection(&u8g2, 2);
u8g2_DrawStr(&u8g2, x, y, "abc");
u8g2_SetFontDirection(&u8g2, 3);
u8g2_DrawStr(&u8g2, x, y, "abc");
u8g2_SendBuffer(&u8g2);
*/
u8g2_FirstPage(&u8g2);
i = 0;
do
{
u8g2_SetFontDirection(&u8g2, 0);
u8g2_DrawUTF8(&u8g2, x, y, "Xin Chào Á À");
if ( i == 1 )
{
u8g2_DrawHVLine(&u8g2, u8g2.user_x0, u8g2.user_y0, 1, 0);
u8g2_DrawHVLine(&u8g2, u8g2.user_x0, u8g2.user_y1-1, 1, 0);
u8g2_DrawHVLine(&u8g2, u8g2.user_x1-1, u8g2.user_y1-1, 1, 0);
u8g2_DrawHVLine(&u8g2, u8g2.user_x1-1, u8g2.user_y0, 1, 0);
}
i++;
} while( u8g2_NextPage(&u8g2) );
do
{
k = u8g_sdl_get_key();
} while( k < 0 );
if ( k == 273 ) y -= 7;
if ( k == 274 ) y += 7;
if ( k == 276 ) x -= 7;
if ( k == 275 ) x += 7;
if ( k == 'e' ) y -= 1;
if ( k == 'x' ) y += 1;
if ( k == 's' ) x -= 1;
if ( k == 'd' ) x += 1;
if ( k == 'q' ) break;
if ( k == 't' )
u8x8_SaveBitmapTGA(u8g2_GetU8x8(&u8g2), "screenshot.tga");
}
//u8x8_Set8x8Font(u8g2_GetU8x8(&u8g2), bdf_font);
//u8x8_Draw8x8String(u8g2_GetU8x8(&u8g2), 0, 0, "Hello World!");
return 0;
}