text,length,is_long_context,metric_val,label_metric "; ; jidctint.asm - accurate integer IDCT (SSE2) ; ; Copyright 2009 Pierre Ossman for Cendio AB ; ; Based on ; x86 SIMD extension for IJG JPEG library ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; ; This file should be assembled with NASM (Netwide Assembler), ; can *not* be assembled with Microsoft's MASM or any compatible ; assembler (including Borland's Turbo Assembler). ; NASM is available from http://nasm.sourceforge.net/ or ; http://sourceforge.net/project/showfiles.php?group_id=6208 ; ; This file contains a slow-but-accurate integer implementation of the ; inverse DCT (Discrete Cosine Transform). The following code is based ; directly on the IJG's original jidctint.c; see the jidctint.c for ; more details. ; ; [TAB8] %include ""jsimdext.inc"" %include ""jdct.inc"" ; -------------------------------------------------------------------------- %define CONST_BITS 13 %define PASS1_BITS 2 %define DESCALE_P1 (CONST_BITS-PASS1_BITS) %define DESCALE_P2 (CONST_BITS+PASS1_BITS+3) %if CONST_BITS == 13 F_0_298 equ 2446 ; FIX(0.298631336) F_0_390 equ 3196 ; FIX(0.390180644) F_0_541 equ 4433 ; FIX(0.541196100) F_0_765 equ 6270 ; FIX(0.765366865) F_0_899 equ 7373 ; FIX(0.899976223) F_1_175 equ 9633 ; FIX(1.175875602) F_1_501 equ 12299 ; FIX(1.501321110) F_1_847 equ 15137 ; FIX(1.847759065) F_1_961 equ 16069 ; FIX(1.961570560) F_2_053 equ 16819 ; FIX(2.053119869) F_2_562 equ 20995 ; FIX(2.562915447) F_3_072 equ 25172 ; FIX(3.072711026) %else ; NASM cannot do compile-time arithmetic on floating-point constants. %define DESCALE(x,n) (((x)+(1<<((n)-1)))>>(n)) F_0_298 equ DESCALE( 320652955,30-CONST_BITS) ; FIX(0.298631336) F_0_390 equ DESCALE( 418953276,30-CONST_BITS) ; FIX(0.390180644) F_0_541 equ DESCALE( 581104887,30-CONST_BITS) ; FIX(0.541196100) F_0_765 equ DESCALE( 821806413,30-CONST_BITS) ; FIX(0.765366865) F_0_899 equ DESCALE( 966342111,30-CONST_BITS) ; FIX(0.899976223) F_1_175 equ DESCALE(1262586813,30-CONST_BITS) ; FIX(1.175875602) F_1_501 equ DESCALE(1612031267,30-CONST_BITS) ; FIX(1.501321110) F_1_847 equ DESCALE(1984016188,30-CONST_BITS) ; FIX(1.847759065) F_1_961 equ DESCALE(2106220350,30-CONST_BITS) ; FIX(1.961570560) F_2_053 equ DESCALE(2204520673,30-CONST_BITS) ; FIX(2.053119869) F_2_562 equ DESCALE(2751909506,30-CONST_BITS) ; FIX(2.562915447) F_3_072 equ DESCALE(3299298341,30-CONST_BITS) ; FIX(3.072711026) %endif ; -------------------------------------------------------------------------- SECTION SEG_CONST alignz 16 global EXTN(jconst_idct_islow_sse2) PRIVATE EXTN(jconst_idct_islow_sse2): PW_F130_F054 times 4 dw (F_0_541+F_0_765), F_0_541 PW_F054_MF130 times 4 dw F_0_541, (F_0_541-F_1_847) PW_MF078_F117 times 4 dw (F_1_175-F_1_961), F_1_175 PW_F117_F078 times 4 dw F_1_175, (F_1_175-F_0_390) PW_MF060_MF089 times 4 dw (F_0_298-F_0_899),-F_0_899 PW_MF089_F060 times 4 dw -F_0_899, (F_1_501-F_0_899) PW_MF050_MF256 times 4 dw (F_2_053-F_2_562),-F_2_562 PW_MF256_F050 times 4 dw -F_2_562, (F_3_072-F_2_562) PD_DESCALE_P1 times 4 dd 1 << (DESCALE_P1-1) PD_DESCALE_P2 times 4 dd 1 << (DESCALE_P2-1) PB_CENTERJSAMP times 16 db CENTERJSAMPLE alignz 16 ; -------------------------------------------------------------------------- SECTION SEG_TEXT BITS 32 ; ; Perform dequantization and inverse DCT on one block of coefficients. ; ; GLOBAL(void) ; jsimd_idct_islow_sse2 (void *dct_table, JCOEFPTR coef_block, ; JSAMPARRAY output_buf, JDIMENSION output_col) ; %define dct_table(b) (b)+8 ; jpeg_component_info *compptr %define coef_block(b) (b)+12 ; JCOEFPTR coef_block %define output_buf(b) (b)+16 ; JSAMPARRAY output_buf %define output_col(b) (b)+20 ; JDIMENSION output_col %define original_ebp ebp+0 %define wk(i) ebp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM] %define WK_NUM 12 align 16 global EXTN(jsimd_idct_islow_sse2) PRIVATE EXTN(jsimd_idct_islow_sse2): push ebp mov eax,esp ; eax = original ebp sub esp, byte 4 and esp, byte (-SIZEOF_XMMWORD) ; align to 128 bits mov [esp],eax mov ebp,esp ; ebp = aligned ebp lea esp, [wk(0)] pushpic ebx ; push ecx ; unused ; push edx ; need not be preserved push esi push edi get_GOT ebx ; get GOT address ; ---- Pass 1: process columns from input. ; mov eax, [original_ebp] mov edx, POINTER [dct_table(eax)] ; quantptr mov esi, JCOEFPTR [coef_block(eax)] ; inptr %ifndef NO_ZERO_COLUMN_TEST_ISLOW_SSE2 mov eax, DWORD [DWBLOCK(1,0,esi,SIZEOF_JCOEF)] or eax, DWORD [DWBLOCK(2,0,esi,SIZEOF_JCOEF)] jnz near .columnDCT movdqa xmm0, XMMWORD [XMMBLOCK(1,0,esi,SIZEOF_JCOEF)] movdqa xmm1, XMMWORD [XMMBLOCK(2,0,esi,SIZEOF_JCOEF)] por xmm0, XMMWORD [XMMBLOCK(3,0,esi,SIZEOF_JCOEF)] por xmm1, XMMWORD [XMMBLOCK(4,0,esi,SIZEOF_JCOEF)] por xmm0, XMMWORD [XMMBLOCK(5,0,esi,SIZEOF_JCOEF)] por xmm1, XMMWORD [XMMBLOCK(6,0,esi,SIZEOF_JCOEF)] por xmm0, XMMWORD [XMMBLOCK(7,0,esi,SIZEOF_JCOEF)] por xmm1,xmm0 packsswb xmm1,xmm1 packsswb xmm1,xmm1 movd eax,xmm1 test eax,eax jnz short .columnDCT ; -- AC terms all zero movdqa xmm5, XMMWORD [XMMBLOCK(0,0,esi,SIZEOF_JCOEF)] pmullw xmm5, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)] psllw xmm5,PASS1_BITS movdqa xmm4,xmm5 ; xmm5=in0=(00 01 02 03 04 05 06 07) punpcklwd xmm5,xmm5 ; xmm5=(00 00 01 01 02 02 03 03) punpckhwd xmm4,xmm4 ; xmm4=(04 04 05 05 06 06 07 07) pshufd xmm7,xmm5,0x00 ; xmm7=col0=(00 00 00 00 00 00 00 00) pshufd xmm6,xmm5,0x55 ; xmm6=col1=(01 01 01 01 01 01 01 01) pshufd xmm1,xmm5,0xAA ; xmm1=col2=(02 02 02 02 02 02 02 02) pshufd xmm5,xmm5,0xFF ; xmm5=col3=(03 03 03 03 03 03 03 03) pshufd xmm0,xmm4,0x00 ; xmm0=col4=(04 04 04 04 04 04 04 04) pshufd xmm3,xmm4,0x55 ; xmm3=col5=(05 05 05 05 05 05 05 05) pshufd xmm2,xmm4,0xAA ; xmm2=col6=(06 06 06 06 06 06 06 06) pshufd xmm4,xmm4,0xFF ; xmm4=col7=(07 07 07 07 07 07 07 07) movdqa XMMWORD [wk(8)], xmm6 ; wk(8)=col1 movdqa XMMWORD [wk(9)], xmm5 ; wk(9)=col3 movdqa XMMWORD [wk(10)], xmm3 ; wk(10)=col5 movdqa XMMWORD [wk(11)], xmm4 ; wk(11)=col7 jmp near .column_end alignx 16,7 %endif .columnDCT: ; -- Even part movdqa xmm0, XMMWORD [XMMBLOCK(0,0,esi,SIZEOF_JCOEF)] movdqa xmm1, XMMWORD [XMMBLOCK(2,0,esi,SIZEOF_JCOEF)] pmullw xmm0, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)] pmullw xmm1, XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_ISLOW_MULT_TYPE)] movdqa xmm2, XMMWORD [XMMBLOCK(4,0,esi,SIZEOF_JCOEF)] movdqa xmm3, XMMWORD [XMMBLOCK(6,0,esi,SIZEOF_JCOEF)] pmullw xmm2, XMMWORD [XMMBLOCK(4,0,edx,SIZEOF_ISLOW_MULT_TYPE)] pmullw xmm3, XMMWORD [XMMBLOCK(6,0,edx,SIZEOF_ISLOW_MULT_TYPE)] ; (Original) ; z1 = (z2 + z3) * 0.541196100; ; tmp2 = z1 + z3 * -1.847759065; ; tmp3 = z1 + z2 * 0.765366865; ; ; (This implementation) ; tmp2 = z2 * 0.541196100 + z3 * (0.541196100 - 1.847759065); ; tmp3 = z2 * (0.541196100 + 0.765366865) + z3 * 0.541196100; movdqa xmm4,xmm1 ; xmm1=in2=z2 movdqa xmm5,xmm1 punpcklwd xmm4,xmm3 ; xmm3=in6=z3 punpckhwd xmm5,xmm3 movdqa xmm1,xmm4 movdqa xmm3,xmm5 pmaddwd xmm4,[GOTOFF(ebx,PW_F130_F054)] ; xmm4=tmp3L pmaddwd xmm5,[GOTOFF(ebx,PW_F130_F054)] ; xmm5=tmp3H pmaddwd xmm1,[GOTOFF(ebx,PW_F054_MF130)] ; xmm1=tmp2L pmaddwd xmm3,[GOTOFF(ebx,PW_F054_MF130)] ; xmm3=tmp2H movdqa xmm6,xmm0 paddw xmm0,xmm2 ; xmm0=in0+in4 psubw xmm6,xmm2 ; xmm6=in0-in4 pxor xmm7,xmm7 pxor xmm2,xmm2 punpcklwd xmm7,xmm0 ; xmm7=tmp0L punpckhwd xmm2,xmm0 ; xmm2=tmp0H psrad xmm7,(16-CONST_BITS) ; psrad xmm7,16 & pslld xmm7,CONST_BITS psrad xmm2,(16-CONST_BITS) ; psrad xmm2,16 & pslld xmm2,CONST_BITS movdqa xmm0,xmm7 paddd xmm7,xmm4 ; xmm7=tmp10L psubd xmm0,xmm4 ; xmm0=tmp13L movdqa xmm4,xmm2 paddd xmm2,xmm5 ; xmm2=tmp10H psubd xmm4,xmm5 ; xmm4=tmp13H movdqa XMMWORD [wk(0)], xmm7 ; wk(0)=tmp10L movdqa XMMWORD [wk(1)], xmm2 ; wk(1)=tmp10H movdqa XMMWORD [wk(2)], xmm0 ; wk(2)=tmp13L movdqa XMMWORD [wk(3)], xmm4 ; wk(3)=tmp13H pxor xmm5,xmm5 pxor xmm7,xmm7 punpcklwd xmm5,xmm6 ; xmm5=tmp1L punpckhwd xmm7,xmm6 ; xmm7=tmp1H psrad xmm5,(16-CONST_BITS) ; psrad xmm5,16 & pslld xmm5,CONST_BITS psrad xmm7,(16-CONST_BITS) ; psrad xmm7,16 & pslld xmm7,CONST_BITS movdqa xmm2,xmm5 paddd xmm5,xmm1 ; xmm5=tmp11L psubd xmm2,xmm1 ; xmm2=tmp12L movdqa xmm0,xmm7 paddd xmm7,xmm3 ; xmm7=tmp11H psubd xmm0,xmm3 ; xmm0=tmp12H movdqa XMMWORD [wk(4)], xmm5 ; wk(4)=tmp11L movdqa XMMWORD [wk(5)], xmm7 ; wk(5)=tmp11H movdqa XMMWORD [wk(6)], xmm2 ; wk(6)=tmp12L movdqa XMMWORD [wk(7)], xmm0 ; wk(7)=tmp12H ; -- Odd part movdqa xmm4, XMMWORD [XMMBLOCK(1,0,esi,SIZEOF_JCOEF)] movdqa xmm6, XMMWORD [XMMBLOCK(3,0,esi,SIZEOF_JCOEF)] pmullw xmm4, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_ISLOW_MULT_TYPE)] pmullw xmm6, XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_ISLOW_MULT_TYPE)] movdqa xmm1, XMMWORD [XMMBLOCK(5,0,esi,SIZEOF_JCOEF)] movdqa xmm3, XMMWORD [XMMBLOCK(7,0,esi,SIZEOF_JCOEF)] pmullw xmm1, XMMWORD [XMMBLOCK(5,0,edx,SIZEOF_ISLOW_MULT_TYPE)] pmullw xmm3, XMMWORD [XMMBLOCK(7,0,edx,SIZEOF_ISLOW_MULT_TYPE)] movdqa xmm5,xmm6 movdqa xmm7,xmm4 paddw xmm5,xmm3 ; xmm5=z3 paddw xmm7,xmm1 ; xmm7=z4 ; (Original) ; z5 = (z3 + z4) * 1.175875602; ; z3 = z3 * -1.961570560; z4 = z4 * -0.390180644; ; z3 += z5; z4 += z5; ; ; (This implementation) ; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602; ; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644); movdqa xmm2,xmm5 movdqa xmm0,xmm5 punpcklwd xmm2,xmm7 punpckhwd xmm0,xmm7 movdqa xmm5,xmm2 movdqa xmm7,xmm0 pmaddwd xmm2,[GOTOFF(ebx,PW_MF078_F117)] ; xmm2=z3L pmaddwd xmm0,[GOTOFF(ebx,PW_MF078_F117)] ; xmm0=z3H pmaddwd xmm5,[GOTOFF(ebx,PW_F117_F078)] ; xmm5=z4L pmaddwd xmm7,[GOTOFF(ebx,PW_F117_F078)] ; xmm7=z4H movdqa XMMWORD [wk(10)], xmm2 ; wk(10)=z3L movdqa XMMWORD [wk(11)], xmm0 ; wk(11)=z3H ; (Original) ; z1 = tmp0 + tmp3; z2 = tmp1 + tmp2; ; tmp0 = tmp0 * 0.298631336; tmp1 = tmp1 * 2.053119869; ; tmp2 = tmp2 * 3.072711026; tmp3 = tmp3 * 1.501321110; ; z1 = z1 * -0.899976223; z2 = z2 * -2.562915447; ; tmp0 += z1 + z3; tmp1 += z2 + z4; ; tmp2 += z2 + z3; tmp3 += z1 + z4; ; ; (This implementation) ; tmp0 = tmp0 * (0.298631336 - 0.899976223) + tmp3 * -0.899976223; ; tmp1 = tmp1 * (2.053119869 - 2.562915447) + tmp2 * -2.562915447; ; tmp2 = tmp1 * -2.562915447 + tmp2 * (3.072711026 - 2.562915447); ; tmp3 = tmp0 * -0.899976223 + tmp3 * (1.501321110 - 0.899976223); ; tmp0 += z3; tmp1 += z4; ; tmp2 += z3; tmp3 += z4; movdqa xmm2,xmm3 movdqa xmm0,xmm3 punpcklwd xmm2,xmm4 punpckhwd xmm0,xmm4 movdqa xmm3,xmm2 movdqa xmm4,xmm0 pmaddwd xmm2,[GOTOFF(ebx,PW_MF060_MF089)] ; xmm2=tmp0L pmaddwd xmm0,[GOTOFF(ebx,PW_MF060_MF089)] ; xmm0=tmp0H pmaddwd xmm3,[GOTOFF(ebx,PW_MF089_F060)] ; xmm3=tmp3L pmaddwd xmm4,[GOTOFF(ebx,PW_MF089_F060)] ; xmm4=tmp3H paddd xmm2, XMMWORD [wk(10)] ; xmm2=tmp0L paddd xmm0, XMMWORD [wk(11)] ; xmm0=tmp0H paddd xmm3,xmm5 ; xmm3=tmp3L paddd xmm4,xmm7 ; xmm4=tmp3H movdqa XMMWORD [wk(8)], xmm2 ; wk(8)=tmp0L movdqa XMMWORD [wk(9)], xmm0 ; wk(9)=tmp0H movdqa xmm2,xmm1 movdqa xmm0,xmm1 punpcklwd xmm2,xmm6 punpckhwd xmm0,xmm6 movdqa xmm1,xmm2 movdqa xmm6,xmm0 pmaddwd xmm2,[GOTOFF(ebx,PW_MF050_MF256)] ; xmm2=tmp1L pmaddwd xmm0,[GOTOFF(ebx,PW_MF050_MF256)] ; xmm0=tmp1H pmaddwd xmm1,[GOTOFF(ebx,PW_MF256_F050)] ; xmm1=tmp2L pmaddwd xmm6,[GOTOFF(ebx,PW_MF256_F050)] ; xmm6=tmp2H paddd xmm2,xmm5 ; xmm2=tmp1L paddd xmm0,xmm7 ; xmm0=tmp1H paddd xmm1, XMMWORD [wk(10)] ; xmm1=tmp2L paddd xmm6, XMMWORD [wk(11)] ; xmm6=tmp2H movdqa XMMWORD [wk(10)], xmm2 ; wk(10)=tmp1L movdqa XMMWORD [wk(11)], xmm0 ; wk(11)=tmp1H ; -- Final output stage movdqa xmm5, XMMWORD [wk(0)] ; xmm5=tmp10L movdqa xmm7, XMMWORD [wk(1)] ; xmm7=tmp10H movdqa xmm2,xmm5 movdqa xmm0,xmm7 paddd xmm5,xmm3 ; xmm5=data0L paddd xmm7,xmm4 ; xmm7=data0H psubd xmm2,xmm3 ; xmm2=data7L psubd xmm0,xmm4 ; xmm0=data7H movdqa xmm3,[GOTOFF(ebx,PD_DESCALE_P1)] ; xmm3=[PD_DESCALE_P1] paddd xmm5,xmm3 paddd xmm7,xmm3 psrad xmm5,DESCALE_P1 psrad xmm7,DESCALE_P1 paddd xmm2,xmm3 paddd xmm0,xmm3 psrad xmm2,DESCALE_P1 psrad xmm0,DESCALE_P1 packssdw xmm5,xmm7 ; xmm5=data0=(00 01 02 03 04 05 06 07) packssdw xmm2,xmm0 ; xmm2=data7=(70 71 72 73 74 75 76 77) movdqa xmm4, XMMWORD [wk(4)] ; xmm4=tmp11L movdqa xmm3, XMMWORD [wk(5)] ; xmm3=tmp11H movdqa xmm7,xmm4 movdqa xmm0,xmm3 paddd xmm4,xmm1 ; xmm4=data1L paddd xmm3,xmm6 ; xmm3=data1H psubd xmm7,xmm1 ; xmm7=data6L psubd xmm0,xmm6 ; xmm0=data6H movdqa xmm1,[GOTOFF(ebx,PD_DESCALE_P1)] ; xmm1=[PD_DESCALE_P1] paddd xmm4,xmm1 paddd xmm3,xmm1 psrad xmm4,DESCALE_P1 psrad xmm3,DESCALE_P1 paddd xmm7,xmm1 paddd xmm0,xmm1 psrad xmm7,DESCALE_P1 psrad xmm0,DESCALE_P1 packssdw xmm4,xmm3 ; xmm4=data1=(10 11 12 13 14 15 16 17) packssdw xmm7,xmm0 ; xmm7=data6=(60 61 62 63 64 65 66 67) movdqa xmm6,xmm5 ; transpose coefficients(phase 1) punpcklwd xmm5,xmm4 ; xmm5=(00 10 01 11 02 12 03 13) punpckhwd xmm6,xmm4 ; xmm6=(04 14 05 15 06 16 07 17) movdqa xmm1,xmm7 ; transpose coefficients(phase 1) punpcklwd xmm7,xmm2 ; xmm7=(60 70 61 71 62 72 63 73) punpckhwd xmm1,xmm2 ; xmm1=(64 74 65 75 66 76 67 77) movdqa xmm3, XMMWORD [wk(6)] ; xmm3=tmp12L movdqa xmm0, XMMWORD [wk(7)] ; xmm0=tmp12H movdqa xmm4, XMMWORD [wk(10)] ; xmm4=tmp1L movdqa xmm2, XMMWORD [wk(11)] ; xmm2=tmp1H movdqa XMMWORD [wk(0)], xmm5 ; wk(0)=(00 10 01 11 02 12 03 13) movdqa XMMWORD [wk(1)], xmm6 ; wk(1)=(04 14 05 15 06 16 07 17) movdqa XMMWORD [wk(4)], xmm7 ; wk(4)=(60 70 61 71 62 72 63 73) movdqa XMMWORD [wk(5)], xmm1 ; wk(5)=(64 74 65 75 66 76 67 77) movdqa xmm5,xmm3 movdqa xmm6,xmm0 paddd xmm3,xmm4 ; xmm3=data2L paddd xmm0,xmm2 ; xmm0=data2H psubd xmm5,xmm4 ; xmm5=data5L psubd xmm6,xmm2 ; xmm6=data5H movdqa xmm7,[GOTOFF(ebx,PD_DESCALE_P1)] ; xmm7=[PD_DESCALE_P1] paddd xmm3,xmm7 paddd xmm0,xmm7 psrad xmm3,DESCALE_P1 psrad xmm0,DESCALE_P1 paddd xmm5,xmm7 paddd xmm6,xmm7 psrad xmm5,DESCALE_P1 psrad xmm6,DESCALE_P1 packssdw xmm3,xmm0 ; xmm3=data2=(20 21 22 23 24 25 26 27) packssdw xmm5,xmm6 ; xmm5=data5=(50 51 52 53 54 55 56 57) movdqa xmm1, XMMWORD [wk(2)] ; xmm1=tmp13L movdqa xmm4, XMMWORD [wk(3)] ; xmm4=tmp13H movdqa xmm2, XMMWORD [wk(8)] ; xmm2=tmp0L movdqa xmm7, XMMWORD [wk(9)] ; xmm7=tmp0H movdqa xmm0,xmm1 movdqa xmm6,xmm4 paddd xmm1,xmm2 ; xmm1=data3L paddd xmm4,xmm7 ; xmm4=data3H psubd xmm0,xmm2 ; xmm0=data4L psubd xmm6,xmm7 ; xmm6=data4H movdqa xmm2,[GOTOFF(ebx,PD_DESCALE_P1)] ; xmm2=[PD_DESCALE_P1] paddd xmm1,xmm2 paddd xmm4,xmm2 psrad xmm1,DESCALE_P1 psrad xmm4,DESCALE_P1 paddd xmm0,xmm2 paddd xmm6,xmm2 psrad xmm0,DESCALE_P1 psrad xmm6,DESCALE_P1 packssdw xmm1,xmm4 ; xmm1=data3=(30 31 32 33 34 35 36 37) packssdw xmm0,xmm6 ; xmm0=data4=(40 41 42 43 44 45 46 47) movdqa xmm7, XMMWORD [wk(0)] ; xmm7=(00 10 01 11 02 12 03 13) movdqa xmm2, XMMWORD [wk(1)] ; xmm2=(04 14 05 15 06 16 07 17) movdqa xmm4,xmm3 ; transpose coefficients(phase 1) punpcklwd xmm3,xmm1 ; xmm3=(20 30 21 31 22 32 23 33) punpckhwd xmm4,xmm1 ; xmm4=(24 34 25 35 26 36 27 37) movdqa xmm6,xmm0 ; transpose coefficients(phase 1) punpcklwd xmm0,xmm5 ; xmm0=(40 50 41 51 42 52 43 53) punpckhwd xmm6,xmm5 ; xmm6=(44 54 45 55 46 56 47 57) movdqa xmm1,xmm7 ; transpose coefficients(phase 2) punpckldq xmm7,xmm3 ; xmm7=(00 10 20 30 01 11 21 31) punpckhdq xmm1,xmm3 ; xmm1=(02 12 22 32 03 13 23 33) movdqa xmm5,xmm2 ; transpose coefficients(phase 2) punpckldq xmm2,xmm4 ; xmm2=(04 14 24 34 05 15 25 35) punpckhdq xmm5,xmm4 ; xmm5=(06 16 26 36 07 17 27 37) movdqa xmm3, XMMWORD [wk(4)] ; xmm3=(60 70 61 71 62 72 63 73) movdqa xmm4, XMMWORD [wk(5)] ; xmm4=(64 74 65 75 66 76 67 77) movdqa XMMWORD [wk(6)], xmm2 ; wk(6)=(04 14 24 34 05 15 25 35) movdqa XMMWORD [wk(7)], xmm5 ; wk(7)=(06 16 26 36 07 17 27 37) movdqa xmm2,xmm0 ; transpose coefficients(phase 2) punpckldq xmm0,xmm3 ; xmm0=(40 50 60 70 41 51 61 71) punpckhdq xmm2,xmm3 ; xmm2=(42 52 62 72 43 53 63 73) movdqa xmm5,xmm6 ; transpose coefficients(phase 2) punpckldq xmm6,xmm4 ; xmm6=(44 54 64 74 45 55 65 75) punpckhdq xmm5,xmm4 ; xmm5=(46 56 66 76 47 57 67 77) movdqa xmm3,xmm7 ; transpose coefficients(phase 3) punpcklqdq xmm7,xmm0 ; xmm7=col0=(00 10 20 30 40 50 60 70) punpckhqdq xmm3,xmm0 ; xmm3=col1=(01 11 21 31 41 51 61 71) movdqa xmm4,xmm1 ; transpose coefficients(phase 3) punpcklqdq xmm1,xmm2 ; xmm1=col2=(02 12 22 32 42 52 62 72) punpckhqdq xmm4,xmm2 ; xmm4=col3=(03 13 23 33 43 53 63 73) movdqa xmm0, XMMWORD [wk(6)] ; xmm0=(04 14 24 34 05 15 25 35) movdqa xmm2, XMMWORD [wk(7)] ; xmm2=(06 16 26 36 07 17 27 37) movdqa XMMWORD [wk(8)], xmm3 ; wk(8)=col1 movdqa XMMWORD [wk(9)], xmm4 ; wk(9)=col3 movdqa xmm3,xmm0 ; transpose coefficients(phase 3) punpcklqdq xmm0,xmm6 ; xmm0=col4=(04 14 24 34 44 54 64 74) punpckhqdq xmm3,xmm6 ; xmm3=col5=(05 15 25 35 45 55 65 75) movdqa xmm4,xmm2 ; transpose coefficients(phase 3) punpcklqdq xmm2,xmm5 ; xmm2=col6=(06 16 26 36 46 56 66 76) punpckhqdq xmm4,xmm5 ; xmm4=col7=(07 17 27 37 47 57 67 77) movdqa XMMWORD [wk(10)], xmm3 ; wk(10)=col5 movdqa XMMWORD [wk(11)], xmm4 ; wk(11)=col7 .column_end: ; -- Prefetch the next coefficient block prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 0*32] prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 1*32] prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 2*32] prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 3*32] ; ---- Pass 2: process rows from work array, store into output array. mov eax, [original_ebp] mov edi, JSAMPARRAY [output_buf(eax)] ; (JSAMPROW *) mov eax, JDIMENSION [output_col(eax)] ; -- Even part ; xmm7=col0, xmm1=col2, xmm0=col4, xmm2=col6 ; (Original) ; z1 = (z2 + z3) * 0.541196100; ; tmp2 = z1 + z3 * -1.847759065; ; tmp3 = z1 + z2 * 0.765366865; ; ; (This implementation) ; tmp2 = z2 * 0.541196100 + z3 * (0.541196100 - 1.847759065); ; tmp3 = z2 * (0.541196100 + 0.765366865) + z3 * 0.541196100; movdqa xmm6,xmm1 ; xmm1=in2=z2 movdqa xmm5,xmm1 punpcklwd xmm6,xmm2 ; xmm2=in6=z3 punpckhwd xmm5,xmm2 movdqa xmm1,xmm6 movdqa xmm2,xmm5 pmaddwd xmm6,[GOTOFF(ebx,PW_F130_F054)] ; xmm6=tmp3L pmaddwd xmm5,[GOTOFF(ebx,PW_F130_F054)] ; xmm5=tmp3H pmaddwd xmm1,[GOTOFF(ebx,PW_F054_MF130)] ; xmm1=tmp2L pmaddwd xmm2,[GOTOFF(ebx,PW_F054_MF130)] ; xmm2=tmp2H movdqa xmm3,xmm7 paddw xmm7,xmm0 ; xmm7=in0+in4 psubw xmm3,xmm0 ; xmm3=in0-in4 pxor xmm4,xmm4 pxor xmm0,xmm0 punpcklwd xmm4,xmm7 ; xmm4=tmp0L punpckhwd xmm0,xmm7 ; xmm0=tmp0H psrad xmm4,(16-CONST_BITS) ; psrad xmm4,16 & pslld xmm4,CONST_BITS psrad xmm0,(16-CONST_BITS) ; psrad xmm0,16 & pslld xmm0,CONST_BITS movdqa xmm7,xmm4 paddd xmm4,xmm6 ; xmm4=tmp10L psubd xmm7,xmm6 ; xmm7=tmp13L movdqa xmm6,xmm0 paddd xmm0,xmm5 ; xmm0=tmp10H psubd xmm6,xmm5 ; xmm6=tmp13H movdqa XMMWORD [wk(0)], xmm4 ; wk(0)=tmp10L movdqa XMMWORD [wk(1)], xmm0 ; wk(1)=tmp10H movdqa XMMWORD [wk(2)], xmm7 ; wk(2)=tmp13L movdqa XMMWORD [wk(3)], xmm6 ; wk(3)=tmp13H pxor xmm5,xmm5 pxor xmm4,xmm4 punpcklwd xmm5,xmm3 ; xmm5=tmp1L punpckhwd xmm4,xmm3 ; xmm4=tmp1H psrad xmm5,(16-CONST_BITS) ; psrad xmm5,16 & pslld xmm5,CONST_BITS psrad xmm4,(16-CONST_BITS) ; psrad xmm4,16 & pslld xmm4,CONST_BITS movdqa xmm0,xmm5 paddd xmm5,xmm1 ; xmm5=tmp11L psubd xmm0,xmm1 ; xmm0=tmp12L movdqa xmm7,xmm4 paddd xmm4,xmm2 ; xmm4=tmp11H psubd xmm7,xmm2 ; xmm7=tmp12H movdqa XMMWORD [wk(4)], xmm5 ; wk(4)=tmp11L movdqa XMMWORD [wk(5)], xmm4 ; wk(5)=tmp11H movdqa XMMWORD [wk(6)], xmm0 ; wk(6)=tmp12L movdqa XMMWORD [wk(7)], xmm7 ; wk(7)=tmp12H ; -- Odd part movdqa xmm6, XMMWORD [wk(9)] ; xmm6=col3 movdqa xmm3, XMMWORD [wk(8)] ; xmm3=col1 movdqa xmm1, XMMWORD [wk(11)] ; xmm1=col7 movdqa xmm2, XMMWORD [wk(10)] ; xmm2=col5 movdqa xmm5,xmm6 movdqa xmm4,xmm3 paddw xmm5,xmm1 ; xmm5=z3 paddw xmm4,xmm2 ; xmm4=z4 ; (Original) ; z5 = (z3 + z4) * 1.175875602; ; z3 = z3 * -1.961570560; z4 = z4 * -0.390180644; ; z3 += z5; z4 += z5; ; ; (This implementation) ; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602; ; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644); movdqa xmm0,xmm5 movdqa xmm7,xmm5 punpcklwd xmm0,xmm4 punpckhwd xmm7,xmm4 movdqa xmm5,xmm0 movdqa xmm4,xmm7 pmaddwd xmm0,[GOTOFF(ebx,PW_MF078_F117)] ; xmm0=z3L pmaddwd xmm7,[GOTOFF(ebx,PW_MF078_F117)] ; xmm7=z3H pmaddwd xmm5,[GOTOFF(ebx,PW_F117_F078)] ; xmm5=z4L pmaddwd xmm4,[GOTOFF(ebx,PW_F117_F078)] ; xmm4=z4H movdqa XMMWORD [wk(10)], xmm0 ; wk(10)=z3L movdqa XMMWORD [wk(11)], xmm7 ; wk(11)=z3H ; (Original) ; z1 = tmp0 + tmp3; z2 = tmp1 + tmp2; ; tmp0 = tmp0 * 0.298631336; tmp1 = tmp1 * 2.053119869; ; tmp2 = tmp2 * 3.072711026; tmp3 = tmp3 * 1.501321110; ; z1 = z1 * -0.899976223; z2 = z2 * -2.562915447; ; tmp0 += z1 + z3; tmp1 += z2 + z4; ; tmp2 += z2 + z3; tmp3 += z1 + z4; ; ; (This implementation) ; tmp0 = tmp0 * (0.298631336 - 0.899976223) + tmp3 * -0.899976223; ; tmp1 = tmp1 * (2.053119869 - 2.562915447) + tmp2 * -2.562915447; ; tmp2 = tmp1 * -2.562915447 + tmp2 * (3.072711026 - 2.562915447); ; tmp3 = tmp0 * -0.899976223 + tmp3 * (1.501321110 - 0.899976223); ; tmp0 += z3; tmp1 += z4; ; tmp2 += z3; tmp3 += z4; movdqa xmm0,xmm1 movdqa xmm7,xmm1 punpcklwd xmm0,xmm3 punpckhwd xmm7,xmm3 movdqa xmm1,xmm0 movdqa xmm3,xmm7 pmaddwd xmm0,[GOTOFF(ebx,PW_MF060_MF089)] ; xmm0=tmp0L pmaddwd xmm7,[GOTOFF(ebx,PW_MF060_MF089)] ; xmm7=tmp0H pmaddwd xmm1,[GOTOFF(ebx,PW_MF089_F060)] ; xmm1=tmp3L pmaddwd xmm3,[GOTOFF(ebx,PW_MF089_F060)] ; xmm3=tmp3H paddd xmm0, XMMWORD [wk(10)] ; xmm0=tmp0L paddd xmm7, XMMWORD [wk(11)] ; xmm7=tmp0H paddd xmm1,xmm5 ; xmm1=tmp3L paddd xmm3,xmm4 ; xmm3=tmp3H movdqa XMMWORD [wk(8)], xmm0 ; wk(8)=tmp0L movdqa XMMWORD [wk(9)], xmm7 ; wk(9)=tmp0H movdqa xmm0,xmm2 movdqa xmm7,xmm2 punpcklwd xmm0,xmm6 punpckhwd xmm7,xmm6 movdqa xmm2,xmm0 movdqa xmm6,xmm7 pmaddwd xmm0,[GOTOFF(ebx,PW_MF050_MF256)] ; xmm0=tmp1L pmaddwd xmm7,[GOTOFF(ebx,PW_MF050_MF256)] ; xmm7=tmp1H pmaddwd xmm2,[GOTOFF(ebx,PW_MF256_F050)] ; xmm2=tmp2L pmaddwd xmm6,[GOTOFF(ebx,PW_MF256_F050)] ; xmm6=tmp2H paddd xmm0,xmm5 ; xmm0=tmp1L paddd xmm7,xmm4 ; xmm7=tmp1H paddd xmm2, XMMWORD [wk(10)] ; xmm2=tmp2L paddd xmm6, XMMWORD [wk(11)] ; xmm6=tmp2H movdqa XMMWORD [wk(10)], xmm0 ; wk(10)=tmp1L movdqa XMMWORD [wk(11)], xmm7 ; wk(11)=tmp1H ; -- Final output stage movdqa xmm5, XMMWORD [wk(0)] ; xmm5=tmp10L movdqa xmm4, XMMWORD [wk(1)] ; xmm4=tmp10H movdqa xmm0,xmm5 movdqa xmm7,xmm4 paddd xmm5,xmm1 ; xmm5=data0L paddd xmm4,xmm3 ; xmm4=data0H psubd xmm0,xmm1 ; xmm0=data7L psubd xmm7,xmm3 ; xmm7=data7H movdqa xmm1,[GOTOFF(ebx,PD_DESCALE_P2)] ; xmm1=[PD_DESCALE_P2] paddd xmm5,xmm1 paddd xmm4,xmm1 psrad xmm5,DESCALE_P2 psrad xmm4,DESCALE_P2 paddd xmm0,xmm1 paddd xmm7,xmm1 psrad xmm0,DESCALE_P2 psrad xmm7,DESCALE_P2 packssdw xmm5,xmm4 ; xmm5=data0=(00 10 20 30 40 50 60 70) packssdw xmm0,xmm7 ; xmm0=data7=(07 17 27 37 47 57 67 77) movdqa xmm3, XMMWORD [wk(4)] ; xmm3=tmp11L movdqa xmm1, XMMWORD [wk(5)] ; xmm1=tmp11H movdqa xmm4,xmm3 movdqa xmm7,xmm1 paddd xmm3,xmm2 ; xmm3=data1L paddd xmm1,xmm6 ; xmm1=data1H psubd xmm4,xmm2 ; xmm4=data6L psubd xmm7,xmm6 ; xmm7=data6H movdqa xmm2,[GOTOFF(ebx,PD_DESCALE_P2)] ; xmm2=[PD_DESCALE_P2] paddd xmm3,xmm2 paddd xmm1,xmm2 psrad xmm3,DESCALE_P2 psrad xmm1,DESCALE_P2 paddd xmm4,xmm2 paddd xmm7,xmm2 psrad xmm4,DESCALE_P2 psrad xmm7,DESCALE_P2 packssdw xmm3,xmm1 ; xmm3=data1=(01 11 21 31 41 51 61 71) packssdw xmm4,xmm7 ; xmm4=data6=(06 16 26 36 46 56 66 76) packsswb xmm5,xmm4 ; xmm5=(00 10 20 30 40 50 60 70 06 16 26 36 46 56 66 76) packsswb xmm3,xmm0 ; xmm3=(01 11 21 31 41 51 61 71 07 17 27 37 47 57 67 77) movdqa xmm6, XMMWORD [wk(6)] ; xmm6=tmp12L movdqa xmm2, XMMWORD [wk(7)] ; xmm2=tmp12H movdqa xmm1, XMMWORD [wk(10)] ; xmm1=tmp1L movdqa xmm7, XMMWORD [wk(11)] ; xmm7=tmp1H movdqa XMMWORD [wk(0)], xmm5 ; wk(0)=(00 10 20 30 40 50 60 70 06 16 26 36 46 56 66 76) movdqa XMMWORD [wk(1)], xmm3 ; wk(1)=(01 11 21 31 41 51 61 71 07 17 27 37 47 57 67 77) movdqa xmm4,xmm6 movdqa xmm0,xmm2 paddd xmm6,xmm1 ; xmm6=data2L paddd xmm2,xmm7 ; xmm2=data2H psubd xmm4,xmm1 ; xmm4=data5L psubd xmm0,xmm7 ; xmm0=data5H movdqa xmm5,[GOTOFF(ebx,PD_DESCALE_P2)] ; xmm5=[PD_DESCALE_P2] paddd xmm6,xmm5 paddd xmm2,xmm5 psrad xmm6,DESCALE_P2 psrad xmm2,DESCALE_P2 paddd xmm4,xmm5 paddd xmm0,xmm5 psrad xmm4,DESCALE_P2 psrad xmm0,DESCALE_P2 packssdw xmm6,xmm2 ; xmm6=data2=(02 12 22 32 42 52 62 72) packssdw xmm4,xmm0 ; xmm4=data5=(05 15 25 35 45 55 65 75) movdqa xmm3, XMMWORD [wk(2)] ; xmm3=tmp13L movdqa xmm1, XMMWORD [wk(3)] ; xmm1=tmp13H movdqa xmm7, XMMWORD [wk(8)] ; xmm7=tmp0L movdqa xmm5, XMMWORD [wk(9)] ; xmm5=tmp0H movdqa xmm2,xmm3 movdqa xmm0,xmm1 paddd xmm3,xmm7 ; xmm3=data3L paddd xmm1,xmm5 ; xmm1=data3H psubd xmm2,xmm7 ; xmm2=data4L psubd xmm0,xmm5 ; xmm0=data4H movdqa xmm7,[GOTOFF(ebx,PD_DESCALE_P2)] ; xmm7=[PD_DESCALE_P2] paddd xmm3,xmm7 paddd xmm1,xmm7 psrad xmm3,DESCALE_P2 psrad xmm1,DESCALE_P2 paddd xmm2,xmm7 paddd xmm0,xmm7 psrad xmm2,DESCALE_P2 psrad xmm0,DESCALE_P2 movdqa xmm5,[GOTOFF(ebx,PB_CENTERJSAMP)] ; xmm5=[PB_CENTERJSAMP] packssdw xmm3,xmm1 ; xmm3=data3=(03 13 23 33 43 53 63 73) packssdw xmm2,xmm0 ; xmm2=data4=(04 14 24 34 44 54 64 74) movdqa xmm7, XMMWORD [wk(0)] ; xmm7=(00 10 20 30 40 50 60 70 06 16 26 36 46 56 66 76) movdqa xmm1, XMMWORD [wk(1)] ; xmm1=(01 11 21 31 41 51 61 71 07 17 27 37 47 57 67 77) packsswb xmm6,xmm2 ; xmm6=(02 12 22 32 42 52 62 72 04 14 24 34 44 54 64 74) packsswb xmm3,xmm4 ; xmm3=(03 13 23 33 43 53 63 73 05 15 25 35 45 55 65 75) paddb xmm7,xmm5 paddb xmm1,xmm5 paddb xmm6,xmm5 paddb xmm3,xmm5 movdqa xmm0,xmm7 ; transpose coefficients(phase 1) punpcklbw xmm7,xmm1 ; xmm7=(00 01 10 11 20 21 30 31 40 41 50 51 60 61 70 71) punpckhbw xmm0,xmm1 ; xmm0=(06 07 16 17 26 27 36 37 46 47 56 57 66 67 76 77) movdqa xmm2,xmm6 ; transpose coefficients(phase 1) punpcklbw xmm6,xmm3 ; xmm6=(02 03 12 13 22 23 32 33 42 43 52 53 62 63 72 73) punpckhbw xmm2,xmm3 ; xmm2=(04 05 14 15 24 25 34 35 44 45 54 55 64 65 74 75) movdqa xmm4,xmm7 ; transpose coefficients(phase 2) punpcklwd xmm7,xmm6 ; xmm7=(00 01 02 03 10 11 12 13 20 21 22 23 30 31 32 33) punpckhwd xmm4,xmm6 ; xmm4=(40 41 42 43 50 51 52 53 60 61 62 63 70 71 72 73) movdqa xmm5,xmm2 ; transpose coefficients(phase 2) punpcklwd xmm2,xmm0 ; xmm2=(04 05 06 07 14 15 16 17 24 25 26 27 34 35 36 37) punpckhwd xmm5,xmm0 ; xmm5=(44 45 46 47 54 55 56 57 64 65 66 67 74 75 76 77) movdqa xmm1,xmm7 ; transpose coefficients(phase 3) punpckldq xmm7,xmm2 ; xmm7=(00 01 02 03 04 05 06 07 10 11 12 13 14 15 16 17) punpckhdq xmm1,xmm2 ; xmm1=(20 21 22 23 24 25 26 27 30 31 32 33 34 35 36 37) movdqa xmm3,xmm4 ; transpose coefficients(phase 3) punpckldq xmm4,xmm5 ; xmm4=(40 41 42 43 44 45 46 47 50 51 52 53 54 55 56 57) punpckhdq xmm3,xmm5 ; xmm3=(60 61 62 63 64 65 66 67 70 71 72 73 74 75 76 77) pshufd xmm6,xmm7,0x4E ; xmm6=(10 11 12 13 14 15 16 17 00 01 02 03 04 05 06 07) pshufd xmm0,xmm1,0x4E ; xmm0=(30 31 32 33 34 35 36 37 20 21 22 23 24 25 26 27) pshufd xmm2,xmm4,0x4E ; xmm2=(50 51 52 53 54 55 56 57 40 41 42 43 44 45 46 47) pshufd xmm5,xmm3,0x4E ; xmm5=(70 71 72 73 74 75 76 77 60 61 62 63 64 65 66 67) mov edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW] mov esi, JSAMPROW [edi+2*SIZEOF_JSAMPROW] movq XMM_MMWORD [edx+eax*SIZEOF_JSAMPLE], xmm7 movq XMM_MMWORD [esi+eax*SIZEOF_JSAMPLE], xmm1 mov edx, JSAMPROW [edi+4*SIZEOF_JSAMPROW] mov esi, JSAMPROW [edi+6*SIZEOF_JSAMPROW] movq XMM_MMWORD [edx+eax*SIZEOF_JSAMPLE], xmm4 movq XMM_MMWORD [esi+eax*SIZEOF_JSAMPLE], xmm3 mov edx, JSAMPROW [edi+1*SIZEOF_JSAMPROW] mov esi, JSAMPROW [edi+3*SIZEOF_JSAMPROW] movq XMM_MMWORD [edx+eax*SIZEOF_JSAMPLE], xmm6 movq XMM_MMWORD [esi+eax*SIZEOF_JSAMPLE], xmm0 mov edx, JSAMPROW [edi+5*SIZEOF_JSAMPROW] mov esi, JSAMPROW [edi+7*SIZEOF_JSAMPROW] movq XMM_MMWORD [edx+eax*SIZEOF_JSAMPLE], xmm2 movq XMM_MMWORD [esi+eax*SIZEOF_JSAMPLE], xmm5 pop edi pop esi ; pop edx ; need not be preserved ; pop ecx ; unused poppic ebx mov esp,ebp ; esp <- aligned ebp pop esp ; esp <- original ebp pop ebp ret ; For some reason, the OS X linker does not honor the request to align the ; segment unless we do this. align 16 ",16300,True,4069.9141629684154,median " /* TODO: check for maximum when changing CVs 31 ... 34 TODO: implement change of direction --> forward / backward */ /* ********************************************************************************** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ********************************************************************************** */ #include // Needed for automatic reset functions. /* ******************************************************************************* */ // The next line is there to prevent large in-rush currents during PWM cycly. #define SOFTPWM_OUTPUT_DELAY #include SOFTPWM_DEFINE_CHANNEL( 1, DDRD, PORTD, PORTD7); //Arduino pin D7 --> LS1 SOFTPWM_DEFINE_CHANNEL( 2, DDRC, PORTC, PORTC1); //Arduino pin A1 --> LS2 SOFTPWM_DEFINE_CHANNEL( 3, DDRD, PORTD, PORTD5); //Arduino pin D5 --> LS3 SOFTPWM_DEFINE_CHANNEL( 4, DDRD, PORTD, PORTD3); //Arduino pin D3 --> LS4 SOFTPWM_DEFINE_CHANNEL( 5, DDRD, PORTD, PORTD6); //Arduino pin D6 --> LB1 SOFTPWM_DEFINE_CHANNEL( 6, DDRC, PORTC, PORTC0); //Arduino pin A0 --> LB2 SOFTPWM_DEFINE_CHANNEL( 7, DDRD, PORTD, PORTD4); //Arduino pin D4 --> LB3 #if defined( LAMPS36 ) SOFTPWM_DEFINE_CHANNEL( 8, DDRC, PORTC, PORTC3); //Arduino pin A3 --> LB4 SOFTPWM_DEFINE_CHANNEL( 9, DDRC, PORTC, PORTC4); //Arduino pin A4 --> LB5 SOFTPWM_DEFINE_CHANNEL(10, DDRC, PORTC, PORTC5); //Arduino pin A5 --> LB6 SOFTPWM_DEFINE_CHANNEL(11, DDRB, PORTB, PORTB0); //Arduino pin D8 --> AX1 SOFTPWM_DEFINE_CHANNEL(12, DDRB, PORTB, PORTB1); //Arduino pin D9 --> AX2 SOFTPWM_DEFINE_CHANNEL(13, DDRB, PORTB, PORTB2); //Arduino pin 10 --> AX3 SOFTPWM_DEFINE_CHANNEL(14, DDRC, PORTC, PORTC2); //Arduino pin A2 --> AX4 #endif SOFTPWM_DEFINE_CHANNEL(15, DDRB, PORTB, PORTB5); //Arduino pin 13 --> LED SOFTPWM_DEFINE_OBJECT_WITH_PWM_LEVELS( 15, 100); // Set 15 pulsed outputs ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // ***** Uncomment to use the PinChangeInterrupts iso External Interrupts ***** // #define PIN_CHANGE_INT #include NmraDcc Dcc ; DCC_MSG Packet ; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // ******** UNLESS YOU WANT ALL CV'S RESET UPON EVERY POWER UP REMOVE THE ""//"" IN THE FOLLOWING LINE!! #define DECODER_LOADED // ******** REMOVE THE ""//"" IN THE FOLLOWING LINE TO SEND DEBUGGING INFO TO THE SERIAL OUTPUT // #define DEBUG36 // ******** REMOVE THE ""//"" IN THE NEXT LINE IF YOU WANT TO USE YOUR SERIAL PORT FOR COMMANDS // #define MONITOR // ******** REMOVE THE ""//"" IN THE FOLLOWING LINE TO USE AS A '6LAMP PCB WITH AUX PORTS' ELSE IT'S A '3LAMP W/O AUX PORTS' // #define LAMPS36 #ifdef DEBUG36 #define _PP( a ) Serial.print( a ); #define _PL( a ) Serial.println( a ); #define _2P(a,b) Serial.print( a, b ); #define _2L(a,b) Serial.println(a, b); #else #define _PP( a ) #define _PL( a ) #define _2P(a,b) #define _2L(a,b) #endif #ifdef MONITOR #define _MP( a ) Serial.print( a ); #define _ML( a ) Serial.println( a ); #define _3P(a,b) Serial.print( a, b); #define _3L(a,b) Serial.println(a, b); #else #define _MP( a ) #define _ML( a ) #define _3P(a,b) #define _3L(a,b) #endif ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// extern int __heap_start, *__brkval; #ifdef MONITOR char bomMarker = '<'; // Begin of message marker. char eomMarker = '>'; // End of message marker. char commandString[ 32] ; // Max length for a buffer. char sprintfBuffer[ 32] ; // Max length for a buffer. boolean foundBom = false; // Found begin of messages. boolean foundEom = false; // Founf end of messages. #endif /* ******************************************************************************* */ int tim_delay = 500; int numfpins = 17; byte fpins [] = { 11, 7, 15, 5, 3, 6, 14, 4, 17, 18, 19, 8, 9, 10, 16, 13, 12}; // pinnames: > DNU, PD7, PC1, PD5, PD3, PD6, PC0, PD4, PC3, PC4, PC5, PB0, PB1, PB2, PC2, PB5, DNU < const int FunctionPinRx = 0; // PD0 Tx0 const int FunctionPinTx = 1; // PD1 Rx1 const int FunctionPinDcc = 2; // PD2 DCC const int FunctionPin0 = 3; // PD3 LS4 const int FunctionPin1 = 4; // PD4 LB3 const int FunctionPin2 = 5; // PD5 LS3 const int FunctionPin3 = 6; // PD6 LB1 const int FunctionPin4 = 7; // PD7 LS1 const int FunctionPin5 = 8; // PB0 AX1 const int FunctionPin6 = 9; // PB1 AX2 const int FunctionPin7 = 10; // PB2 AX3 const int FunctionPin8 = 11; // PB3 DNU const int FunctionPin9 = 12; // PB4 DNU const int FunctionPinLed = 13; // PB5 LED const int FunctionPin10 = 14; // PC0 LB2 const int FunctionPin11 = 15; // PC1 LS2 const int FunctionPin12 = 16; // PC2 AX4 const int FunctionPin13 = 17; // PC3 LB4 const int FunctionPin14 = 18; // PC4 LB5 const int FunctionPin15 = 19; // PC5 LB6 // AD0 = LB2 PD0 = Rx1 PB0 = AX1 // AD1 = LS2 PD1 = Tx0 PB1 = AX2 // AD2 = AX4 PD2 = DCC PB2 = AX3 // AD3 = LB4 PD3 = LS4 PB3 = ICSP // AD4 = LB5 PD4 = LB3 PB4 = ICSP // AD5 = LB6 PD5 = LS3 PB5 = ICSP // AD6 = DNU PD6 = LB1 PB6 = Xtal1 // AD7 = DNU PD7 = LS1 PB7 = Xtal2 /* ******************************************************************************* */ #define SET_CV_Address 24 // THIS ADDRESS IS FOR SETTING CV'S (LIKE A LOCO) #define Accessory_Address 140 // THIS ADDRESS IS THE ADDRESS OF THIS DCC DECODER uint8_t CV_DECODER_MASTER_RESET = 120; // THIS IS THE CV ADDRESS OF THE FULL RESET #define CV_To_Store_SET_CV_Address 121 #define CV_Accessory_Address CV_ACCESSORY_DECODER_ADDRESS_LSB struct QUEUE { int inUse; // output in use or not unsigned long previousMicros; // last time for fading unsigned long waitMicros; // interval in micros() int fadeCounter; // count of fadinglevel int maxLevel; // maximum output level bool upDown; // travel direction led unsigned long previousMillis; // last time we blinked unsigned long blinkInterval; // interval in millis() int ledState; // state of this output int previousState; // previous outputstate }; QUEUE volatile *ftn_queue = new QUEUE[ 17 ]; struct CVPair { uint16_t CV; uint8_t Value; }; CVPair FactoryDefaultCVs [] = { // These two CVs define the Long Accessory Address {CV_ACCESSORY_DECODER_ADDRESS_LSB, Accessory_Address & 0xFF}, {CV_ACCESSORY_DECODER_ADDRESS_MSB, (Accessory_Address >> 8) & 0x07}, {CV_MULTIFUNCTION_EXTENDED_ADDRESS_MSB, 0}, {CV_MULTIFUNCTION_EXTENDED_ADDRESS_LSB, 0}, // Speed Steps don't matter for this decoder, only for loc decoders // ONLY uncomment 1 CV_29_CONFIG line below as approprate DEFAULT IS SHORT ADDRESS // {CV_29_CONFIG, 0}, // Short Address 14 Speed Steps {CV_29_CONFIG, CV29_F0_LOCATION}, // Short Address 28/128 Speed Steps // {CV_29_CONFIG, CV29_EXT_ADDRESSING | CV29_F0_LOCATION}, // Long Address 28/128 Speed Steps // {CV_29_CONFIG, CV29_ACCESSORY_DECODER | CV29_OUTPUT_ADDRESS_MODE | CV29_F0_LOCATION}, // Accesory Decoder Short Address // {CV_29_CONFIG, CV29_ACCESSORY_DECODER | CV29_OUTPUT_ADDRESS_MODE | CV29_EXT_ADDRESSING | CV29_F0_LOCATION}, // Accesory Decoder Long Address {CV_DECODER_MASTER_RESET, 0}, {CV_To_Store_SET_CV_Address, SET_CV_Address & 0xFF }, // LSB Set CV Address {CV_To_Store_SET_CV_Address + 1, (SET_CV_Address >> 8) & 0x3F }, // MSB Set CV Address { 30, 0}, // GEN 0 = Off, 1 = On, 2 = Blink Off, 3 = Blink On, 4 = Fade Off, 5 = Fade On { 31, 50}, // Maximum level outputs (100 max) { 32, 100}, // Waitmicros (250 * 100,000 max) { 33, 5}, // Waitmicros divider (standard 5) { 34, 100}, // Standard blink interval (* 10) { 35, 0}, // LS1 0 = Off, 1 = On, 2 = Blink Off, 3 = Blink On, 4 = Fade Off, 5 = Fade On { 36, 50}, // Maximum level this output { 37, 100}, // Waitmicros output highend { 38, 5}, // Waitmicros output divider { 39, 100}, // Blinkinterval this output { 40, 0}, // LS2 0 = Off, 1 = On, 2 = Blink Off, 3 = Blink On, 4 = Fade Off, 5 = Fade On { 41, 50}, // Maximum level this output { 42, 100}, // Waitmicros output highend { 43, 5}, // Waitmicros output divider { 44, 100}, // Blinkinterval this output { 45, 0}, // LS3 0 = Off, 1 = On, 2 = Blink Off, 3 = Blink On, 4 = Fade Off, 5 = Fade On { 46, 50}, // Maximum level this output { 47, 100}, // Waitmicros output highend { 48, 5}, // Waitmicros output divider { 49, 100}, // Blinkinterval this output { 50, 0}, // LS4 0 = Off, 1 = On, 2 = Blink Off, 3 = Blink On, 4 = Fade Off, 5 = Fade On { 51, 50}, // Maximum level this output { 52, 100}, // Waitmicros output highend { 53, 5}, // Waitmicros output divider { 54, 100}, // Blinkinterval this output { 55, 0}, // LB1 0 = Off, 1 = On, 2 = Blink Off, 3 = Blink On, 4 = Fade Off, 5 = Fade On { 56, 50}, // Maximum level this output { 57, 100}, // Waitmicros output highend { 58, 5}, // Waitmicros output divider { 59, 100}, // Blinkinterval this output { 60, 0}, // LB2 0 = Off, 1 = On, 2 = Blink Off, 3 = Blink On, 4 = Fade Off, 5 = Fade On { 61, 50}, // Maximum level this output { 62, 100}, // Waitmicros output highend { 63, 5}, // Waitmicros output divider { 64, 100}, // Blinkinterval this output { 65, 0}, // LB3 0 = Off, 1 = On, 2 = Blink Off, 3 = Blink On, 4 = Fade Off, 5 = Fade On { 66, 50}, // Maximum level this output { 67, 100}, // Waitmicros output highend { 68, 5}, // Waitmicros output divider { 69, 100}, // Blinkinterval this output #if defined( LAMPS36 ) { 70, 0}, // LB4 0 = Off, 1 = On, 2 = Blink Off, 3 = Blink On, 4 = Fade Off, 5 = Fade On { 71, 50}, // Maximum level this output { 72, 100}, // Waitmicros output highend { 73, 5}, // Waitmicros output divider { 74, 100}, // Blinkinterval this output { 75, 0}, // LB5 0 = Off, 1 = On, 2 = Blink Off, 3 = Blink On, 4 = Fade Off, 5 = Fade On { 76, 50}, // Maximum level this output { 77, 100}, // Waitmicros output highend { 78, 5}, // Waitmicros output divider { 79, 100}, // Blinkinterval this output { 80, 0}, // LB6 0 = Off, 1 = On, 2 = Blink Off, 3 = Blink On, 4 = Fade Off, 5 = Fade On { 81, 50}, // Maximum level this output { 82, 100}, // Waitmicros output highend { 83, 5}, // Waitmicros output divider { 84, 100}, // Blinkinterval this output { 85, 0}, // AX1 0 = Off, 1 = On, 2 = Blink Off, 3 = Blink On, 4 = Fade Off, 5 = Fade On { 86, 0}, // Maximum level this output { 87, 0}, // Waitmicros output highend { 88, 0}, // Waitmicros output divider { 89, 0}, // Blinkinterval this output { 90, 0}, // AX2 0 = Off, 1 = On, 2 = Blink Off, 3 = Blink On, 4 = Fade Off, 5 = Fade On { 91, 0}, // Maximum level this output { 92, 0}, // Waitmicros output highend { 93, 0}, // Waitmicros output divider { 94, 0}, // Blinkinterval this output { 95, 0}, // AX3 0 = Off, 1 = On, 2 = Blink Off, 3 = Blink On, 4 = Fade Off, 5 = Fade On { 96, 0}, // Maximum level this output { 97, 0}, // Waitmicros output highend { 98, 0}, // Waitmicros output divider { 99, 0}, // Blinkinterval this output {100, 0}, // AX4 0 = Off, 1 = On, 2 = Blink Off, 3 = Blink On, 4 = Fade Off, 5 = Fade On {101, 0}, // Maximum level this output {102, 0}, // Waitmicros output highend {103, 0}, // Waitmicros output divider {104, 0}, // Blinkinterval this output #endif // LAMPS36 {105, 1}, // LED 0 = Off, 1 = On, 2 = Blink Off, 3 = Blink On, 4 = Fade Off, 5 = Fade On {106, 50}, // Maximum level this output {107, 100}, // Waitmicros output highend {108, 5}, // Waitmicros output divider {109, 100}, // Blinkinterval this output {110, 0}, // DNU 0 = Off, 1 = On, 2 = Blink Off, 3 = Blink On, 4 = Fade Off, 5 = Fade On {111, 0}, // Maximum level this output {112, 0}, // Waitmicros output highend {113, 0}, // Waitmicros output divider {114, 0}, // Blinkinterval this output }; volatile uint8_t FactoryDefaultCVIndex = sizeof( FactoryDefaultCVs ) / sizeof( CVPair ); // These are the absolute maximums allowed !!! volatile uint8_t M_maxLevel = Dcc.getCV( 31 ); volatile uint8_t M_highend = Dcc.getCV( 32 ); volatile uint8_t M_divider = Dcc.getCV( 33 ); volatile uint8_t M_interval = Dcc.getCV( 34 ); // This is the switch between F0 or F1 - F14 volatile uint8_t C_between = Dcc.getCV(111 ); /* ******************************************************************************* */ void setup() { noInterrupts(); // initialize the digital pins as outputs for (int i = 1; i < numfpins - 1; i++) { digitalWrite( fpins[ i ], 0 ); // Switch the pin off first. pinMode( fpins[ i ], OUTPUT ); // Then set it as an output. } // Start SoftPWM with 60hz pwm frequency Palatis::SoftPWM.begin( 60); #if defined(DEBUG36) || defined(MONITOR) Serial.begin(115200); while (!Serial) { ; // wait for Serial port to connect. Needed for native USB port. } Serial.flush(); // Wait for all the rubbish to finish displaying. while (Serial.available() > 0) { Serial.read(); // Clear the input buffer to get 'real' inputdata. } Serial.println(""-------------------------------------""); Serial.println(""""); // An extra empty line for clearness // SoftPWM print interrupt load for diagnostic purposes Palatis::SoftPWM.printInterruptLoad(); Serial.println(""""); // An extra empty line for clearness #endif Dcc.pin( digitalPinToInterrupt( FunctionPinDcc ), FunctionPinDcc, false ); Dcc.init( MAN_ID_DIY, 201, FLAGS_MY_ADDRESS_ONLY, CV_To_Store_SET_CV_Address ); #if defined(DECODER_LOADED) if ( Dcc.getCV( CV_DECODER_MASTER_RESET ) == CV_DECODER_MASTER_RESET ) { #endif FactoryDefaultCVIndex = sizeof( FactoryDefaultCVs ) / sizeof( CVPair ); for (int i = 0; i < FactoryDefaultCVIndex; i++) { Dcc.setCV( FactoryDefaultCVs[ i ].CV, FactoryDefaultCVs[ i ].Value ); digitalWrite( FunctionPinLed, 1 ); delay ( tim_delay ); digitalWrite( FunctionPinLed, 0 ); } #if defined(DECODER_LOADED) } #endif // These are the absolute maximums allowed M_maxLevel = Dcc.getCV( 31 ); // Maximum level outputs (100 max) M_highend = Dcc.getCV( 32 ); // Waitmicros (250 * 100,000 max) M_divider = Dcc.getCV( 33 ); // Waitmicros divider (standard 5) M_interval = Dcc.getCV( 34 ); // Standard blink interval (* 10) // This is the switch between F0 or F1 - F14 C_between = Dcc.getCV( 111 ); // Loop through all the settings for checking and correcting for (int i = 1; i < numfpins - 1; i++) { calculateFtnQueue( i ); } #ifdef MONITOR displayText(); // Shows the standard text. #endif // Switch on the LED to signal we're ready. digitalWrite(FunctionPinLed, 0); delay (tim_delay); digitalWrite(FunctionPinLed, 1); delay (tim_delay); digitalWrite(FunctionPinLed, 0); delay (tim_delay); digitalWrite(FunctionPinLed, 1); interrupts(); // Ready to rumble.... } /* ******************************************************************************* */ void loop() { unsigned long currentMillis = millis(); unsigned long currentMicros = micros(); Dcc.process(); // Loop through the DCC process. // Check the number of outputs, not the number of numfpins!!! for (unsigned int i = 1; i < Palatis::SoftPWM.size(); ++i) { switch ( ftn_queue[ i ].inUse ) { case 1: // 0 = Off, 1 = On, 2 = Blink Off, 3 = Blink On, 4 = Fade Off, 5 = Fade On { Palatis::SoftPWM.set( i, ftn_queue[ i ].maxLevel ); break; } case 3: // 0 = Off, 1 = On, 2 = Blink Off, 3 = Blink On, 4 = Fade Off, 5 = Fade On { if (currentMillis - ftn_queue[ i ].previousMillis >= ftn_queue[ i ].blinkInterval) { // Save the last time you blinked the LED ftn_queue[ i ].previousMillis = currentMillis; // If the LED is off turn it on and vice-versa if (ftn_queue[ i ].ledState == LOW) { Palatis::SoftPWM.set( i, ftn_queue[ i ].maxLevel); ftn_queue[ i ].ledState = HIGH; } else { ftn_queue[ i ].ledState = LOW; Palatis::SoftPWM.set( i, 0); } } break; } case 5: // 0 = Off, 1 = On, 2 = Blink Off, 3 = Blink On, 4 = Fade Off, 5 = Fade On { if (currentMicros - ftn_queue[ i ].previousMicros > ftn_queue[ i ].waitMicros) { ftn_queue[ i ].previousMicros = currentMicros; if ((ftn_queue[ i ].fadeCounter > ftn_queue[ i ].maxLevel - 1) || (ftn_queue[ i ].fadeCounter < 1)) { ftn_queue[ i ].upDown = !ftn_queue[ i ].upDown; } if (ftn_queue[ i ].upDown == true) { ftn_queue[ i ].fadeCounter++; } else { ftn_queue[ i ].fadeCounter--; } Palatis::SoftPWM.set( i, ftn_queue[ i ].fadeCounter); } break; } default: // 0 = Off, 1 = On, 2 = Blink Off, 3 = Blink On, 4 = Fade Off, 5 = Fade On { Palatis::SoftPWM.set( i, 0); break; } } } #ifdef MONITOR if (foundEom) { foundBom = false; foundEom = false; parseCom( commandString ); } #endif } /* ******************************************************************************* */ void softwareReset( uint8_t preScaler ) { wdt_enable( preScaler ); while( 1 ) {} // Wait for the prescaler time to expire and do an auto-reset } /* ******************************************************************************* */ void setAllOutputCVs( uint8_t cvvalue ) { noInterrupts(); // Disable interrupts. for (int i = 1; i < numfpins - 2; i++) { Dcc.setCV( 30 + ( i * 5 ), cvvalue ); ftn_queue[ i ].inUse = cvvalue; } interrupts(); // Enable the interrupts. #if defined(DEBUG36) || defined(MONITOR) // Send feedback if requested. _MP( ""\\t"" ""<"" ); _3P( cvvalue, DEC ); _ML( "">"" ); #endif } /* ******************************************************************************* */ void setFtnQueue( uint16_t cvNumber, uint8_t cvValue ) { #if defined(DEBUG36) || defined(MONITOR) _PP( ""setFTNQueue: ""); _2P( cvNumber, DEC); _PP( "" Value: "" ); _2L( cvValue, DEC); #endif switch ( cvNumber ) { case 30: { char recData[ 4 ] = "" 0 ""; recData[ 1 ] = 48 + cvValue; // Make it an ASCII code parseCom( recData ); // Recursive action on CV value break; } case 31 ... 34: { // These are the absolute maximums allowed M_maxLevel = Dcc.getCV( 31 ); // Maximum level outputs (100 max) M_highend = Dcc.getCV( 32 ); // Waitmicros (250 * 100,000 max) M_divider = Dcc.getCV( 33 ); // Waitmicros divider (standard 5) M_interval = Dcc.getCV( 34 ); // Standard blink interval (* 10) // Loop through all the settings for checking, correcting the values for (int i = 1; i < numfpins - 1; i++) { calculateFtnQueue( i ); } break; } case 35 ... 104: { calculateFtnQueue( ( cvNumber - 30 ) / 5 ); // Group of 5 values break; } case 105 ... 109: { break; } case 110 ... 114: { // This is the switch between F0 or F1 - F14 C_between = Dcc.getCV( 111 ); break; } default: { break; } } } /* ******************************************************************************* */ void calculateFtnQueue( int number ) { // Now we're going to do some calculations ftn_queue[ number ].inUse = Dcc.getCV( 30 + ( number * 5 ) ); #if defined(DEBUG36) || defined(MONITOR) // Print some values - if requested _PP( ""\\t"" ""calculateFtnQueue cv: ""); _2P( 30 + ( number * 5 ), DEC); _PP( ""\\t"" "" value: ""); _2L( ftn_queue[ number ].inUse, DEC); #endif // Default settings for counters and states ftn_queue[ number ].fadeCounter = 0; ftn_queue[ number ].ledState = LOW; ftn_queue[ number ].previousMicros = 0; ftn_queue[ number ].previousMillis = 0; ftn_queue[ number ].upDown = false; ftn_queue[ number ].waitMicros = 0; // These values stored in the Configuration Variables uint8_t S_maxLevel = Dcc.getCV( 31 + ( number * 5 )); uint8_t S_highend = Dcc.getCV( 32 + ( number * 5 )); uint8_t S_divider = Dcc.getCV( 33 + ( number * 5 )); uint8_t S_interval = Dcc.getCV( 34 + ( number * 5 )); if (M_maxLevel > S_maxLevel) { ftn_queue[ number ].maxLevel = S_maxLevel; } else { ftn_queue[ number ].maxLevel = M_maxLevel; } if (M_interval > S_interval) { ftn_queue[ number ].blinkInterval = S_interval * 10; } else { ftn_queue[ number ].blinkInterval = M_interval * 10; } if (M_highend > S_highend) { ftn_queue[ number ].waitMicros = ( (S_highend * 100000) / Palatis::SoftPWM.PWMlevels() ); } else { ftn_queue[ number ].waitMicros = ( (M_highend * 100000) / Palatis::SoftPWM.PWMlevels() ); } if (M_divider > S_divider) { ftn_queue[ number ].waitMicros = ( ftn_queue[ number ].waitMicros / S_divider ); } else { ftn_queue[ number ].waitMicros = ( ftn_queue[ number ].waitMicros / M_divider ); } } /* ******************************************************************************* */ // The next part will / can only be used for an mpu with enough memory #if defined(MONITOR) /* ******************************************************************************* */ // 0 = Off, 1 = On, 2 = Blink Off, 3 = Blink On, 4 = Fade Off, 5 = Fade On *** /* ********************************************************************************** <0> all outputs: Off <1> all outputs: On <2> all outputs: Blink Off <3> all outputs: Blink On <4> all outputs: Fade Off <5> all outputs: Fade On clear everything: Factory Default dumps everything: to Serial.Print controls mobile engine decoder functions F0-F12: lists all funtions and settings for all outputs: list the available SRAM on the chip reads a configuration variable: write a configuration variable: */ void displayText() { Serial.println(""""); // An extra empty line for clearness Serial.println(F(""Put in one of the following commands: "" )); Serial.println(F(""------------------------------------------------"")); Serial.println(F(""<0> all outputs: Power Off"" )); Serial.println(F(""<1> all outputs: Power On"" )); Serial.println(F(""<2> all outputs: Blink Off"" )); Serial.println(F(""<3> all outputs: Blink On"" )); Serial.println(F(""<4> all outputs: Fader Off"" )); Serial.println(F(""<5> all outputs: Fader On"" )); Serial.println(""""); Serial.println(F("" clear everything: Factory Default"" )); Serial.println(F("" prints CV values: to your monitor"" )); Serial.println(""""); Serial.println(F("" control decoder functions F0-F14: "")); Serial.println(F("" dump the functionqueue and settings: "")); Serial.println(""""); Serial.println(F("" list the available SRAM on the chip"" )); Serial.println(""""); Serial.println(F("" reads a configuration variable: "" )); Serial.println(F("" write a configuration variable: "" )); Serial.println(F(""----------------------------------------------- "")); Serial.println(F(""* include '<', '>' and spaces in your command * "")); Serial.println(""""); // An extra empty line for clearness } /* ******************************************************************************* */ /* .* SerialEvent occurs whenever a new data comes in the hardware serial RX. This .* routine is run between each time loop() runs, so using delay inside loop can .* delay response. Multiple bytes may be available and be put in commandString .*/ void serialEvent() { while (Serial.available()) { char inChar = (char)Serial.read(); // get the new byte if (inChar == bomMarker) // start of new command { sprintf(commandString, "" ""); foundBom = true; } else if (inChar == eomMarker) // end of new command { // sprintf(commandString, "" ""); foundEom = true; // parse(commandString) in the loop } else if (strlen(commandString) < 64) // put it all in { sprintf(commandString, ""%s%c"", commandString, inChar); // if comandString still has space, append character just read from serial line // otherwise, character is ignored, (but we'll continue to look for '<' or '>') } } } #endif // MONITOR /* ******************************************************************************* */ void parseCom( char *com ) { switch ( com[1] ) // com[0] = '<' or ' ' { /***** SWITCH ALL THE OUTPUTS AT ONCE ****/ case '0': // <0> all outputs: Off /* * returns: <0> */ { setAllOutputCVs( 0 ); break; } case '1': // <1> all outputs: On /* * returns: <1> */ { setAllOutputCVs( 1 ); break; } case '2': // <2> all outputs: Blink Off /* * returns: <2> */ { setAllOutputCVs( 2 ); break; } case '3': // <3> all outputs: Blink On /* * returns: <3> */ { setAllOutputCVs( 3 ); break; } case '4': // <4> all outputs: Fade Off /* * returns: <4> */ { setAllOutputCVs( 4 ); break; } case '5': // <5> all outputs: Fade On /* * returns: <5> */ { setAllOutputCVs( 5 ); break; } #if defined(DEBUG36) || defined(MONITOR) /**** CLEAR SETTINGS TO FACTORY DEFAULTS ****/ case 'C': // /* * clears settings to Factory Defaults * * returns: */ { uint8_t cvCheck = Dcc.setCV( 120, 120 ); #if defined(DEBUG36) || defined(MONITOR) _MP( ""\\t"" """" ""\\t"" ); _3L( cvCheck, DEC ); #endif softwareReset( WDTO_15MS ); break; } /***** DUMPS CONFIGURATION VARIABLES FROM DECODER ****/ case 'D': // /* * dumps all Configuration Variables from the decoder * * returns a list of: /* * dumps all FTNqueue settings from memory * * returns a list of: */ { #if defined(DEBUG36) || defined(MONITOR) _ML(""\\n\\npin iU prevMic waitMic fC mL uD prevMil blnkInt lS pS \\n""); for (int i = 1; i < numfpins - 2; i++) { sprintf( sprintfBuffer, "" %2i %3i %11lu"" , i, ftn_queue[ i ].inUse, ftn_queue[ i ].previousMicros ); _MP( sprintfBuffer ); sprintf( sprintfBuffer, "" %11lu %3i %3i"" , ftn_queue[ i ].waitMicros, ftn_queue[ i ].fadeCounter, ftn_queue[ i ].maxLevel ); _MP( sprintfBuffer ); sprintf( sprintfBuffer, "" %3i %11lu %11lu"", ftn_queue[ i ].upDown, ftn_queue[ i ].previousMillis, ftn_queue[ i ].blinkInterval ); _MP( sprintfBuffer ); sprintf( sprintfBuffer, "" %3i %3i "" , ftn_queue[ i ].ledState, ftn_queue[ i ].previousState ); _ML( sprintfBuffer ); } _ML( ""\\n"" ); #endif break; } /***** DUMPS CONFIGURATION VARIABLES FROM DECODER ****/ case 'f': // /* * dumps all Configuration Variables from the decoder * * returns a list of: /* * measure amount of free SRAM memory left on the Arduino based on trick found on the internet. * Useful when setting dynamic array sizes, considering the Uno only has 2048 bytes of dynamic SRAM. * Unfortunately not very reliable --- would be great to find a better method * * returns: * where MEM is the number of free bytes remaining in the Arduino's SRAM */ { int v; _MP( """" ); break; } /***** READ CONFIGURATION VARIABLE BYTE FROM DECODER ****/ case 'R': // /* * reads a Configuration Variable from the decoder * * CV: the number of the Configuration Variable memory location in the decoder to read from (1-1024) * * returns: * where VALUE is a number from 0-255 as read from the requested CV, or -1 if read could not be verified */ { int cv; if( sscanf( com + 2, ""%d"", &cv ) != 1 ) { return; } uint8_t cvCheck = Dcc.getCV( cv ); #if defined(DEBUG36) || defined(MONITOR) _MP( """" ); #endif break; } /***** WRITE CONFIGURATION VARIABLE BYTE TO DECODER ****/ case 'W': // /* * writes, and then verifies, a Configuration Variable to the decoder * * CV: the number of the Configuration Variable memory location in the decoder to write to (1-1024) * VALUE: the value to be written to the Configuration Variable memory location (0-255) * * returns: "" ); #endif break; } /**** PRINT CARRIAGE RETURN IN SERIAL MONITOR WINDOW ****/ case ' ': // < > /* * simply prints a carriage return - useful when interacting with Ardiuno through serial monitor window * * returns: a carriage return and the menu text */ { _ML(""""); #ifdef MONITOR displayText(); // Shows the standard explanation text #endif break; } #endif /**** DEFAULT FOR THE SWITCH FUNCTION = NO ACTION ****/ default: break; } } /************************************************************************************ Call-back functions ************************************************************************************/ #if defined (__cplusplus) extern ""C"" { #endif // Some functions below are left, which might be needed in some future expansions. /* ********************************************************************************** * notifyDccSpeed() Callback for a multifunction decoder speed command. * The received speed and direction are unpacked to separate values. * * Inputs: * Addr - Active decoder address. * AddrType - DCC_ADDR_SHORT or DCC_ADDR_LONG. * Speed - Decoder speed. 0 = Emergency stop * 1 = Regular stop * 2 to SpeedSteps = Speed step 1 to max. * Dir - DCC_DIR_REV or DCC_DIR_FWD * SpeedSteps - Highest speed, SPEED_STEP_14 = 15 * SPEED_STEP_28 = 29 * SPEED_STEP_128 = 127 * * Returns: * None */ /* void notifyDccSpeed( uint16_t Addr, DCC_ADDR_TYPE AddrType, uint8_t Speed, DCC_DIRECTION Dir, DCC_SPEED_STEPS SpeedSteps ) { _PL(""notifyDccSpeed""); } */ /* ********************************************************************************** * notifyDccReset(uint8_t hardReset) Callback for a DCC reset command. * * Inputs: * hardReset - 0 normal reset command. * 1 hard reset command. * * Returns: * None */ /* void notifyDccReset(uint8_t hardReset ) { _PL( ""notifyDccReset"" ); } */ /* ********************************************************************************** * notifyDccFunc() Callback for a multifunction decoder function command. * * Inputs: * Addr - Active decoder address. * AddrType - DCC_ADDR_SHORT or DCC_ADDR_LONG. * FuncGrp - Function group. FN_0 - 14 speed headlight Mask FN_BIT_00 * * FN_0_4 - Functions 0 to 4. Mask FN_BIT_00 - FN_BIT_04 * FN_5_8 - Functions 5 to 8. Mask FN_BIT_05 - FN_BIT_08 * FN_9_12 - Functions 9 to 12. Mask FN_BIT_09 - FN_BIT_12 * FN_13_20 - Functions 13 to 20. Mask FN_BIT_13 - FN_BIT_20 * FN_21_28 - Functions 21 to 28. Mask FN_BIT_21 - FN_BIT_28 * FuncState - Function state. Bitmask where active functions have a 1 at that bit. * You must & FuncState with the appropriate * FN_BIT_nn value to isolate a given bit. * * Returns: * None */ void notifyDccFunc( uint16_t Addr, DCC_ADDR_TYPE AddrType, FN_GROUP FuncGrp, uint8_t FuncState ) { static bool B_between = ( FuncState & FN_BIT_00 ? true : false ); // Keeps track of F0 function. if ( C_between == 0 ) // Use the F0 function to switch lights. { if ( B_between != ( FuncState & FN_BIT_00 ? true : false ) && ( FuncGrp == FN_0_4 ) ) { B_between = ( FuncState & FN_BIT_00 ? true : false ); Dcc.setCV( 30, FuncState & FN_BIT_00 ? 1 : 0 ); } } else { switch( FuncGrp ) { case FN_0_4: //Function Group 1 F0 F4 F3 F2 F1 { Dcc.setCV( 35, FuncState & FN_BIT_01 ? 1 : 0 ); Dcc.setCV( 40, FuncState & FN_BIT_02 ? 1 : 0 ); Dcc.setCV( 45, FuncState & FN_BIT_03 ? 1 : 0 ); Dcc.setCV( 50, FuncState & FN_BIT_04 ? 1 : 0 ); break; } case FN_5_8: //Function Group 1 F8 F7 F6 F5 { Dcc.setCV( 55, FuncState & FN_BIT_05 ? 1 : 0 ); Dcc.setCV( 60, FuncState & FN_BIT_06 ? 1 : 0 ); Dcc.setCV( 65, FuncState & FN_BIT_07 ? 1 : 0 ); Dcc.setCV( 70, FuncState & FN_BIT_08 ? 1 : 0 ); break; } case FN_9_12: //Function Group 1 F12 F11 F10 F9 { Dcc.setCV( 75, FuncState & FN_BIT_09 ? 1 : 0 ); Dcc.setCV( 80, FuncState & FN_BIT_10 ? 1 : 0 ); Dcc.setCV( 85, FuncState & FN_BIT_11 ? 1 : 0 ); Dcc.setCV( 90, FuncState & FN_BIT_12 ? 1 : 0 ); break; } case FN_13_20: //Function Group 2 == F20 - F13 { Dcc.setCV( 95, FuncState & FN_BIT_13 ? 1 : 0 ); Dcc.setCV(100, FuncState & FN_BIT_14 ? 1 : 0 ); break; } case FN_21_28: { break; } } } } /* ********************************************************************************** * notifyCVChange() Called when a CV value is changed. * This is called whenever a CV's value is changed. * notifyDccCVChange() Called only when a CV value is changed by a Dcc packet or a lib function. * it is NOT called if the CV is changed by means of the setCV() method. * Note: It is not called if notifyCVWrite() is defined * or if the value in the EEPROM is the same as the value * in the write command. * * Inputs: * CV - CV number. * Value - Value of the CV. * * Returns: * None */ void notifyCVChange( uint16_t CV, uint8_t Value ) { #if defined(DEBUG36) || defined(MONITOR) _PP( "" notifyCVChange: CV: ""); _2P( CV, DEC ); _PP( "" Value: "" ); _2L( Value, DEC ); #endif setFtnQueue( CV, Value ); } // void notifyDccCVChange( uint16_t CV, uint8_t Value ) // { // _PP( "" notifyDccCVChange: CV: ""); // _2P( CV, DEC); // _PP( "" Value: "" ); // _2L( Value, DEC); // setFtnQueue( CV, Value ); // } /* ********************************************************************************** * notifyCVResetFactoryDefault() Called when CVs must be reset. * This is called when CVs must be reset * to their factory defaults. This callback * should write the factory default value of * relevent CVs using the setCV() method. * setCV() must not block whens this is called. * Test with isSetCVReady() prior to calling setCV() * * Inputs: * None * * Returns: * None */ void notifyCVResetFactoryDefault() { // Make 'FactoryDefaultCVIndex' non-zero and equal to num CVs to be reset // to flag to the loop() function that a reset to FacDef needs to be done. FactoryDefaultCVIndex = sizeof( FactoryDefaultCVs ) / sizeof( CVPair ); } #if defined (__cplusplus) } #endif // ",12256,False,1833.609768288602,median "/* MessageBox.ino Example for the Message Box for U8x8 Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/) Copyright (c) 2016, olikraus@gmail.com All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #ifdef U8X8_HAVE_HW_SPI #include #endif // Please UNCOMMENT one of the contructor lines below // U8x8 Contructor List // The complete list is available here: https://github.com/olikraus/u8g2/wiki/u8x8setupcpp // Please update the pin numbers according to your setup. Use U8X8_PIN_NONE if the reset pin is not connected //U8X8_NULL u8x8; // null device, a 8x8 pixel display which does nothing //U8X8_SSD1306_128X64_NONAME_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1306_128X64_NONAME_4W_HW_SPI u8x8(/* cs=*/ 6, /* dc=*/ 4, /* reset=*/ 12); // Arduboy (DevKit) //U8X8_SSD1306_128X64_NONAME_4W_HW_SPI u8x8(/* cs=*/ 12, /* dc=*/ 4, /* reset=*/ 6); // Arduboy 10 (Production, Kickstarter Edition) //U8X8_SSD1306_128X64_NONAME_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1306_128X64_NONAME_3W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* reset=*/ 8); //U8X8_SSD1306_128X64_NONAME_3W_HW_SPI u8x8(/* cs=*/ 10, /* reset=*/ 8); //U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); //U8X8_SSD1306_128X64_ALT0_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); // same as the NONAME variant, but may solve the ""every 2nd line skipped"" problem //U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(/* clock=*/ 2, /* data=*/ 0, /* reset=*/ U8X8_PIN_NONE); // Digispark ATTiny85 //U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(/* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // OLEDs without Reset of the Display //U8X8_SSD1306_128X64_VCOMH0_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // same as the NONAME variant, but maximizes setContrast() range //U8X8_SSD1306_128X64_ALT0_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // same as the NONAME variant, but may solve the ""every 2nd line skipped"" problem //U8X8_SH1106_128X64_NONAME_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SH1106_128X64_NONAME_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); //U8X8_SH1106_128X64_VCOMH0_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // same as the NONAME variant, but maximizes setContrast() range //U8X8_SH1106_128X64_WINSTAR_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // same as the NONAME variant, but uses updated SH1106 init sequence //U8X8_SH1106_128X32_VISIONOX_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); //U8X8_SH1106_128X32_VISIONOX_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SH1106_72X40_WISE_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SH1107_64X128_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SH1107_128X128_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SH1107_128X128_HW_I2C u8x8(/* reset=*/ 8); //U8X8_SH1107_PIMORONI_128X128_HW_I2C u8x8(/* reset=*/ 8); //U8X8_SH1107_SEEED_128X128_SW_I2C u8x8(/* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); //U8X8_SH1107_SEEED_128X128_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); //U8X8_SH1107_SEEED_96X96_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SH1108_160X160_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1306_128X32_UNIVISION_SW_I2C u8x8(/* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // Adafruit Feather ESP8266/32u4 Boards + FeatherWing OLED //U8X8_SSD1306_128X32_UNIVISION_SW_I2C u8x8(/* clock=*/ 21, /* data=*/ 20, /* reset=*/ U8X8_PIN_NONE); // Adafruit Feather M0 Basic Proto + FeatherWing OLED //U8X8_SSD1306_128X32_UNIVISION_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); // Adafruit ESP8266/32u4/ARM Boards + FeatherWing OLED //U8X8_SSD1306_128X32_UNIVISION_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE, /* clock=*/ SCL, /* data=*/ SDA); // pin remapping with ESP8266 HW I2C //U8X8_SSD1306_128X32_WINSTAR_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE, /* clock=*/ SCL, /* data=*/ SDA); // pin remapping with ESP8266 HW I2C //U8X8_SSD1306_64X48_ER_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); // EastRising 0.66"" OLED breakout board, Uno: A4=SDA, A5=SCL, 5V powered //U8X8_SSD1306_48X64_WINSTAR_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); //U8X8_SSD1306_64X32_NONAME_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); //U8X8_SSD1306_64X32_1F_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); //U8X8_SSD1306_96X16_ER_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); // EastRising 0.69"" //U8X8_SSD1306_72X40_ER_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); // EastRising 0.42"" //U8X8_SSD1306_128X64_NONAME_6800 u8x8(13, 11, 2, 3, 4, 5, 6, A4, /*enable=*/ 7, /*cs=*/ 10, /*dc=*/ 9, /*reset=*/ 8); //U8X8_SSD1306_128X64_NONAME_8080 u8x8(13, 11, 2, 3, 4, 5, 6, A4, /*enable=*/ 7, /*cs=*/ 10, /*dc=*/ 9, /*reset=*/ 8); //U8X8_SSD1309_128X64_NONAME0_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1309_128X64_NONAME0_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1309_128X64_NONAME2_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1309_128X64_NONAME2_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1316_128X32_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1316_128X32_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1317_96X96_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // not tested, not confirmed //U8X8_SSD1317_96X96_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // not tested, not confirmed //U8X8_SSD1318_128X96_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1318_128X96_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1320_160X132_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1320_160X132_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1322_NHD_256X64_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1322_NHD_256X64_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1322_NHD_128X64_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1322_NHD_128X64_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1325_NHD_128X64_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1325_NHD_128X64_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD0323_OS128064_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD0323_OS128064_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1326_ER_256X32_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // experimental driver for ER-OLED018-1 //U8X8_SSD1327_SEEED_96X96_SW_I2C u8x8(/* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // Seeedstudio Grove OLED 96x96 //U8X8_SSD1327_SEEED_96X96_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); // Seeedstudio Grove OLED 96x96 //U8X8_SSD1327_EA_W128128_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1327_EA_W128128_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1327_MIDAS_128X128_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1327_MIDAS_128X128_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1327_WS_128X128_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1327_WS_128X128_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1327_VISIONOX_128X96_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1327_VISIONOX_128X96_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1329_128X96_NONAME_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1329_128X96_NONAME_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1329_96X96_NONAME_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1329_96X96_NONAME_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1329_96X96_NONAME_4W_HW_SPI u8x8(/* cs=*/ A4, /* dc=*/ A2, /* reset=*/ U8X8_PIN_NONE); // Adafruit Feather 32u4 Basic Proto //U8X8_SSD1305_128X32_NONAME_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1305_128X32_NONAME_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1305_128X32_ADAFRUIT_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1305_128X32_ADAFRUIT_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1305_128X64_ADAFRUIT_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1305_128X64_ADAFRUIT_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1305_128X64_RAYSTAR_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1305_128X64_RAYSTAR_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_KS0108_128X64 u8x8(8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18, /*dc=*/ 17, /*cs0=*/ 14, /*cs1=*/ 15, /*cs2=*/ U8X8_PIN_NONE, /* reset=*/ U8X8_PIN_NONE); // Set R/W to low! //U8X8_KS0108_ERM19264 u8x8(8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18, /*dc=*/ 17, /*cs0=*/ 14, /*cs1=*/ 15, /*cs2=*/ 16, /* reset=*/ U8X8_PIN_NONE); // Set R/W to low! //U8X8_HD44102_100X64 u8x8(4, 5, 6, 7, 8, 9, 10, 11, /*enable=*/ 2, /*dc=*/ 3, /*cs0=*/ A0, /*cs1=*/ A1, /*cs2=*/ A2, /* reset=*/ U8X8_PIN_NONE); // Set R/W to low! //U8X8_T7932_150X32 u8x8(4, 5, 6, 7, 8, 9, 10, 11, /*enable=*/ 2, /*dc=*/ 3, /*cs0=*/ A0, /*cs1=*/ A1, /*cs2=*/ A2, /* reset=*/ U8X8_PIN_NONE); // Set R/W to low! //U8X8_UC1701_EA_DOGS102_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_UC1701_EA_DOGS102_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_PCD8544_84X48_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Nokia 5110 Display //U8X8_PCD8544_84X48_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Nokia 5110 Display //U8X8_PCF8812_96X65_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Could be also PCF8814 //U8X8_PCF8812_96X65_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Could be also PCF8814 //U8X8_HX1230_96X68_3W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* reset=*/ 8); //U8X8_HX1230_96X68_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7528_ERC16064_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7528_ERC16064_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7565_EA_DOGM128_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7565_EA_DOGM128_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7565_64128N_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7565_64128N_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7565_EA_DOGM132_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ U8X8_PIN_NONE); // DOGM132 Shield //U8X8_ST7565_EA_DOGM132_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ U8X8_PIN_NONE); // DOGM132 Shield //U8X8_ST7565_ZOLEN_128X64_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7565_ZOLEN_128X64_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7565_LM6059_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Adafruit ST7565 GLCD //U8X8_ST7565_LM6059_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Adafruit ST7565 GLCD //U8X8_ST7565_KS0713_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // KS0713 controller //U8X8_ST7565_KS0713_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // KS0713 controller //U8X8_ST7565_LX12864_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7565_LX12864_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7565_ERC12864_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7565_ERC12864_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7565_ERC12864_ALT_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // contrast improved version for ERC12864 //U8X8_ST7565_ERC12864_ALT_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // contrast improved version for ERC12864 //U8X8_ST7565_NHD_C12832_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7565_NHD_C12832_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7565_NHD_C12864_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7565_NHD_C12864_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7565_JLX12864_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7565_JLX12864_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7567_PI_132X64_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 7, /* dc=*/ 9, /* reset=*/ 8); // Pax Instruments Shield, LCD_BL=6 //U8X8_ST7567_PI_132X64_4W_HW_SPI u8x8(/* cs=*/ 7, /* dc=*/ 9, /* reset=*/ 8); // Pax Instruments Shield, LCD_BL=6 //U8X8_ST7567_JLX12864_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 7, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7567_JLX12864_4W_HW_SPI u8x8(/* cs=*/ 7, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7567_OS12864_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 7, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7567_OS12864_4W_HW_SPI u8x8(/* cs=*/ 7, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7567_ENH_DG128064_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7567_ENH_DG128064_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7567_ENH_DG128064I_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7567_ENH_DG128064I_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7567_64X32_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); //U8X8_ST7567_HEM6432_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); //U8X8_ST7571_128X128_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7571_128X128_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST75256_JLX172104_4W_SW_SPI u8x8( /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST75256_JLX172104_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST75256_JLX19296_4W_SW_SPI u8x8( /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST75256_JLX19296_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST75256_JLX256128_4W_SW_SPI u8x8( /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST75256_JLX256128_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST75256_WO256X128_4W_SW_SPI u8x8( /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST75256_WO256X128_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST75256_JLX256160_4W_SW_SPI u8x8( /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST75256_JLX256160_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST75256_JLX256160M_4W_SW_SPI u8x8( /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST75256_JLX256160M_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST75256_JLX256160_ALT_4W_SW_SPI u8x8( /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST75256_JLX256160_ALT_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST75256_JLX240160_4W_SW_SPI u8x8( /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST75256_JLX240160_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST75256_JLX25664_2ND_HW_I2C u8x8(/* reset=*/ 8); // Due, 2nd I2C //U8X8_ST75320_JLX320240_4W_SW_SPI u8x8( /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST75320_JLX320240_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_NT7534_TG12864R_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_NT7534_TG12864R_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7588_JLX12864_SW_I2C u8x8(/* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ 5); //U8X8_ST7588_JLX12864_HW_I2C u8x8(/* reset=*/ 5); //U8X8_IST3020_ERC19264_6800 u8x8(44, 43, 42, 41, 40, 39, 38, 37, /*enable=*/ 28, /*cs=*/ 32, /*dc=*/ 30, /*reset=*/ 31); // Connect WR pin with GND //U8X8_IST3020_ERC19264_8080 u8x8(44, 43, 42, 41, 40, 39, 38, 37, /*enable=*/ 29, /*cs=*/ 32, /*dc=*/ 30, /*reset=*/ 31); // Connect RD pin with 3.3V //U8X8_IST3020_ERC19264_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_IST7920_128X128_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Round display //U8X8_IST7920_128X128_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Round display //U8X8_UC1601_128X32_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_UC1601_128X32_3W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* reset=*/ 8); //U8X8_UC1601_128X64_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_UC1604_JLX19264_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_UC1604_JLX19264_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_UC1608_ERC24064_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Due, SW SPI, ERC24064-1 Test Board //U8X8_UC1608_DEM240064_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Due, SW SPI, ERC24064-1 Test Board //U8X8_UC1608_ERC240120_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_UC1608_240X128_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_UC1610_EA_DOGXL160_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ U8X8_PIN_NONE); //U8X8_UC1610_EA_DOGXL160_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ U8X8_PIN_NONE); //U8X8_UC1611_EA_DOGM240_2ND_HW_I2C u8x8(/* reset=*/ 8); // Due, 2nd I2C, DOGM240 Test Board //U8X8_UC1611_EA_DOGM240_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // SW SPI, Due DOGXL240 Test Board //U8X8_UC1611_EA_DOGXL240_2ND_HW_I2C u8x8(/* reset=*/ 8); // Due, 2nd I2C, DOGXL240 Test Board //U8X8_UC1611_EA_DOGXL240_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // SW SPI, Due DOGXL240 Test Board //U8X8_UC1611_IDS4073_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_UC1611_IDS4073_4W_HW_SPI u8x8( /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_UC1611_EW50850_8080 u8x8(8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18, /*cs=*/ 3, /*dc=*/ 16, /*reset=*/ 17); // 240x160, Connect RD/WR1 pin with 3.3V, CS is aktive high //U8X8_UC1611_CG160160_8080 u8x8(8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18, /*cs=*/ 3, /*dc=*/ 16, /*reset=*/ 17); // Connect WR1 and CD1 pin with 3.3V, connect CS0 with cs, WR0 with enable, CD with dc //U8X8_UC1617_JLX128128_4W_SW_SPI u8x8( /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_UC1617_JLX128128_4W_HW_SPI u8x8( /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_UC1638_192X96_4W_SW_SPI u8x8( /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_UC1638_192X96_4W_HW_SPI u8x8( /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_UC1638_192X96_SW_I2C u8x8(/* clock=*/ 13, /* data=*/ 11, /* reset=*/ 8); // u8g2 test board: I2C clock/data is same as SPI, I2C default address is 0x78 //U8X8_SSD1606_172X72_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // eInk/ePaper Display //U8X8_SSD1607_200X200_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // eInk/ePaper Display, original LUT from embedded artists //U8X8_SSD1607_GS_200X200_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Good Display //U8X8_SSD1607_WS_200X200_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Waveshare //U8X8_IL3820_296X128_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // eInk/ePaper Display, original LUT //U8X8_IL3820_V2_296X128_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // eInk/ePaper Display, optimized (lesser screen flicker) //U8X8_ST7511_AVD_320X240_8080 u8x8(13, 11, 2, 3, 4, 5, 6, A4, /*enable/WR=*/ 7, /*cs=*/ 10, /*dc=*/ 9, /*reset=*/ 8); // Connect RD pin with 3.3V/5V //U8X8_S1D15721_240X64_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_S1D15721_240X64_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // End of constructor list void setup(void) { // DOGS102 Shield (http://shieldlist.org/controlconnection/dogs102) // u8x8.begin(/* menu_select_pin= */ 5, /* menu_next_pin= */ 4, /* menu_prev_pin= */ 2, /* menu_up_pin= */ U8X8_PIN_NONE, /* menu_down_pin= */ U8X8_PIN_NONE, /* menu_home_pin= */ 3); // DOGM128 Shield (http://shieldlist.org/schmelle2/dogm128) + DOGXL160 Shield //u8x8.begin(/* menu_select_pin= */ 2, /* menu_next_pin= */ 3, /* menu_prev_pin= */ 7, /* menu_up_pin= */ U8X8_PIN_NONE, /* menu_down_pin= */ U8X8_PIN_NONE, /* menu_home_pin= */ 8); // Arduboy //u8x8.begin(/*Select=*/ A0, /*Right/Next=*/ 5, /*Left/Prev=*/ 9, /*Up=*/ 8, /*Down=*/ 10, /*Home/Cancel=*/ A1); // Arduboy DevKit u8x8.begin(/*Select=*/ 7, /*Right/Next=*/ A1, /*Left/Prev=*/ A2, /*Up=*/ A0, /*Down=*/ A3, /*Home/Cancel=*/ 8); // Arduboy 10 (Production) } void loop(void) { uint8_t r; u8x8.setFont(u8x8_font_chroma48medium8_r); r = u8x8_UserInterfaceMessage(u8x8.getU8x8(), ""Message"", ""Box"", NULL, "" Ok \\n Cancel ""); if ( r == 0 ) { u8x8.userInterfaceMessage(""You pressed the"", ""Home/Quit"", ""Button"", "" Ok ""); } else if ( r == 1 ) { u8x8.userInterfaceMessage(""You selected the"", ""Ok"", ""Button"", "" Ok ""); } else if ( r == 2 ) { u8x8.userInterfaceMessage(""You selected the"", ""Cancel"", ""Button"", "" Ok ""); } } ",12481,True,3685.385576978746,median "/* ButtonTest.ino Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/) Copyright (c) 2016, olikraus@gmail.com All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #ifdef U8X8_HAVE_HW_SPI #include #endif // Please UNCOMMENT one of the contructor lines below // U8x8 Contructor List // The complete list is available here: https://github.com/olikraus/u8g2/wiki/u8x8setupcpp // Please update the pin numbers according to your setup. Use U8X8_PIN_NONE if the reset pin is not connected //U8X8_NULL u8x8; // null device, a 8x8 pixel display which does nothing //U8X8_SSD1306_128X64_NONAME_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1306_128X64_NONAME_4W_HW_SPI u8x8(/* cs=*/ 6, /* dc=*/ 4, /* reset=*/ 12); // Arduboy (DevKit) //U8X8_SSD1306_128X64_NONAME_4W_HW_SPI u8x8(/* cs=*/ 12, /* dc=*/ 4, /* reset=*/ 6); // Arduboy 10 (Production, Kickstarter Edition) //U8X8_SSD1306_128X64_NONAME_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1306_128X64_NONAME_3W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* reset=*/ 8); //U8X8_SSD1306_128X64_NONAME_3W_HW_SPI u8x8(/* cs=*/ 10, /* reset=*/ 8); //U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); //U8X8_SSD1306_128X64_ALT0_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); // same as the NONAME variant, but may solve the ""every 2nd line skipped"" problem //U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(/* clock=*/ 2, /* data=*/ 0, /* reset=*/ U8X8_PIN_NONE); // Digispark ATTiny85 //U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(/* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // OLEDs without Reset of the Display //U8X8_SSD1306_128X64_VCOMH0_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // same as the NONAME variant, but maximizes setContrast() range //U8X8_SSD1306_128X64_ALT0_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // same as the NONAME variant, but may solve the ""every 2nd line skipped"" problem //U8X8_SSD1306_102X64_EA_OLEDS102_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // same as the NONAME variant, but may solve the ""every 2nd line skipped"" problem //U8X8_SH1106_128X64_NONAME_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SH1106_128X64_NONAME_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); //U8X8_SH1106_128X64_VCOMH0_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // same as the NONAME variant, but maximizes setContrast() range //U8X8_SH1106_128X64_WINSTAR_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // same as the NONAME variant, but uses updated SH1106 init sequence //U8X8_SH1106_128X32_VISIONOX_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); //U8X8_SH1106_128X32_VISIONOX_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SH1106_72X40_WISE_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SH1107_64X128_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SH1107_128X128_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SH1107_128X128_HW_I2C u8x8(/* reset=*/ 8); //U8X8_SH1107_PIMORONI_128X128_HW_I2C u8x8(/* reset=*/ 8); //U8X8_SH1107_SEEED_128X128_SW_I2C u8x8(/* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); //U8X8_SH1107_SEEED_128X128_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); //U8X8_SH1107_SEEED_96X96_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SH1108_160X160_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1306_128X32_UNIVISION_SW_I2C u8x8(/* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // Adafruit Feather ESP8266/32u4 Boards + FeatherWing OLED //U8X8_SSD1306_128X32_UNIVISION_SW_I2C u8x8(/* clock=*/ 21, /* data=*/ 20, /* reset=*/ U8X8_PIN_NONE); // Adafruit Feather M0 Basic Proto + FeatherWing OLED //U8X8_SSD1306_128X32_UNIVISION_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); // Adafruit ESP8266/32u4/ARM Boards + FeatherWing OLED //U8X8_SSD1306_128X32_UNIVISION_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE, /* clock=*/ SCL, /* data=*/ SDA); // pin remapping with ESP8266 HW I2C //U8X8_SSD1306_128X32_WINSTAR_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE, /* clock=*/ SCL, /* data=*/ SDA); // pin remapping with ESP8266 HW I2C //U8X8_SSD1306_64X48_ER_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); // EastRising 0.66"" OLED breakout board, Uno: A4=SDA, A5=SCL, 5V powered //U8X8_SSD1306_48X64_WINSTAR_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); //U8X8_SSD1306_64X32_NONAME_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); //U8X8_SSD1306_64X32_1F_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); //U8X8_SSD1306_96X16_ER_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); // EastRising 0.69"" //U8X8_SSD1306_72X40_ER_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); // EastRising 0.42"" //U8X8_SSD1306_128X64_NONAME_6800 u8x8(13, 11, 2, 3, 4, 5, 6, A4, /*enable=*/ 7, /*cs=*/ 10, /*dc=*/ 9, /*reset=*/ 8); //U8X8_SSD1306_128X64_NONAME_8080 u8x8(13, 11, 2, 3, 4, 5, 6, A4, /*enable=*/ 7, /*cs=*/ 10, /*dc=*/ 9, /*reset=*/ 8); //U8X8_SSD1309_128X64_NONAME0_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1309_128X64_NONAME0_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1309_128X64_NONAME2_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1309_128X64_NONAME2_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1316_128X32_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1316_128X32_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1317_96X96_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // not tested, not confirmed //U8X8_SSD1317_96X96_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // not tested, not confirmed //U8X8_SSD1318_128X96_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1318_128X96_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1320_160X132_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1320_160X132_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1322_NHD_256X64_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1322_NHD_256X64_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1322_NHD_128X64_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1322_NHD_128X64_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1325_NHD_128X64_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1325_NHD_128X64_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD0323_OS128064_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD0323_OS128064_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1326_ER_256X32_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // experimental driver for ER-OLED018-1 //U8X8_SSD1327_SEEED_96X96_SW_I2C u8x8(/* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // Seeedstudio Grove OLED 96x96 //U8X8_SSD1327_SEEED_96X96_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); // Seeedstudio Grove OLED 96x96 //U8X8_SSD1327_EA_W128128_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1327_EA_W128128_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1327_MIDAS_128X128_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1327_MIDAS_128X128_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1327_WS_128X128_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1327_WS_128X128_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1327_VISIONOX_128X96_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1327_VISIONOX_128X96_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1329_128X96_NONAME_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1329_128X96_NONAME_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1329_96X96_NONAME_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1329_96X96_NONAME_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1329_96X96_NONAME_4W_HW_SPI u8x8(/* cs=*/ A4, /* dc=*/ A2, /* reset=*/ U8X8_PIN_NONE); // Adafruit Feather 32u4 Basic Proto //U8X8_SSD1305_128X32_NONAME_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1305_128X32_NONAME_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1305_128X32_ADAFRUIT_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1305_128X32_ADAFRUIT_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1305_128X64_ADAFRUIT_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1305_128X64_ADAFRUIT_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1305_128X64_RAYSTAR_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_SSD1305_128X64_RAYSTAR_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_KS0108_128X64 u8x8(8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18, /*dc=*/ 17, /*cs0=*/ 14, /*cs1=*/ 15, /*cs2=*/ U8X8_PIN_NONE, /* reset=*/ U8X8_PIN_NONE); // Set R/W to low! //U8X8_KS0108_ERM19264 u8x8(8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18, /*dc=*/ 17, /*cs0=*/ 14, /*cs1=*/ 15, /*cs2=*/ 16, /* reset=*/ U8X8_PIN_NONE); // Set R/W to low! //U8X8_HD44102_100X64 u8x8(4, 5, 6, 7, 8, 9, 10, 11, /*enable=*/ 2, /*dc=*/ 3, /*cs0=*/ A0, /*cs1=*/ A1, /*cs2=*/ A2, /* reset=*/ U8X8_PIN_NONE); // Set R/W to low! //U8X8_T7932_150X32 u8x8(4, 5, 6, 7, 8, 9, 10, 11, /*enable=*/ 2, /*dc=*/ 3, /*cs0=*/ A0, /*cs1=*/ A1, /*cs2=*/ A2, /* reset=*/ U8X8_PIN_NONE); // Set R/W to low! //U8X8_UC1701_EA_DOGS102_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_UC1701_EA_DOGS102_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_PCD8544_84X48_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Nokia 5110 Display //U8X8_PCD8544_84X48_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Nokia 5110 Display //U8X8_PCF8812_96X65_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Could be also PCF8814 //U8X8_PCF8812_96X65_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Could be also PCF8814 //U8X8_HX1230_96X68_3W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* reset=*/ 8); //U8X8_HX1230_96X68_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7528_ERC16064_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7528_ERC16064_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7565_EA_DOGM128_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7565_EA_DOGM128_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7565_64128N_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7565_64128N_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7565_EA_DOGM132_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ U8X8_PIN_NONE); // DOGM132 Shield //U8X8_ST7565_EA_DOGM132_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ U8X8_PIN_NONE); // DOGM132 Shield //U8X8_ST7565_ZOLEN_128X64_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7565_ZOLEN_128X64_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7565_LM6059_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Adafruit ST7565 GLCD //U8X8_ST7565_LM6059_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Adafruit ST7565 GLCD //U8X8_ST7565_KS0713_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // KS0713 controller //U8X8_ST7565_KS0713_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // KS0713 controller //U8X8_ST7565_LX12864_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7565_LX12864_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7565_ERC12864_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7565_ERC12864_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7565_ERC12864_ALT_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // contrast improved version for ERC12864 //U8X8_ST7565_ERC12864_ALT_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // contrast improved version for ERC12864 //U8X8_ST7565_NHD_C12832_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7565_NHD_C12832_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7565_NHD_C12864_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7565_NHD_C12864_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7565_JLX12864_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7565_JLX12864_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7567_PI_132X64_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 7, /* dc=*/ 9, /* reset=*/ 8); // Pax Instruments Shield, LCD_BL=6 //U8X8_ST7567_PI_132X64_4W_HW_SPI u8x8(/* cs=*/ 7, /* dc=*/ 9, /* reset=*/ 8); // Pax Instruments Shield, LCD_BL=6 //U8X8_ST7567_JLX12864_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 7, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7567_JLX12864_4W_HW_SPI u8x8(/* cs=*/ 7, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7567_OS12864_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 7, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7567_OS12864_4W_HW_SPI u8x8(/* cs=*/ 7, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7567_ENH_DG128064_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7567_ENH_DG128064_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7567_ENH_DG128064I_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7567_ENH_DG128064I_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7567_64X32_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); //U8X8_ST7567_HEM6432_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); //U8X8_ST7571_128X128_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7571_128X128_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7571_128X96_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7571_128X96_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST75256_JLX172104_4W_SW_SPI u8x8( /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST75256_JLX172104_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST75256_JLX19296_4W_SW_SPI u8x8( /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST75256_JLX19296_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST75256_JLX256128_4W_SW_SPI u8x8( /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST75256_JLX256128_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST75256_WO256X128_4W_SW_SPI u8x8( /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST75256_WO256X128_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST75256_JLX256160_4W_SW_SPI u8x8( /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST75256_JLX256160_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST75256_JLX256160M_4W_SW_SPI u8x8( /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST75256_JLX256160M_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST75256_JLX256160_ALT_4W_SW_SPI u8x8( /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST75256_JLX256160_ALT_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST75256_JLX240160_4W_SW_SPI u8x8( /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST75256_JLX240160_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST75256_JLX25664_2ND_HW_I2C u8x8(/* reset=*/ 8); // Due, 2nd I2C //U8X8_ST75320_JLX320240_4W_SW_SPI u8x8( /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST75320_JLX320240_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_NT7534_TG12864R_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_NT7534_TG12864R_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_ST7588_JLX12864_SW_I2C u8x8(/* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ 5); //U8X8_ST7588_JLX12864_HW_I2C u8x8(/* reset=*/ 5); //U8X8_IST3020_ERC19264_6800 u8x8(44, 43, 42, 41, 40, 39, 38, 37, /*enable=*/ 28, /*cs=*/ 32, /*dc=*/ 30, /*reset=*/ 31); // Connect WR pin with GND //U8X8_IST3020_ERC19264_8080 u8x8(44, 43, 42, 41, 40, 39, 38, 37, /*enable=*/ 29, /*cs=*/ 32, /*dc=*/ 30, /*reset=*/ 31); // Connect RD pin with 3.3V //U8X8_IST3020_ERC19264_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_IST7920_128X128_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Round display //U8X8_IST7920_128X128_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Round display //U8X8_UC1601_128X32_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_UC1601_128X32_3W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* reset=*/ 8); //U8X8_UC1601_128X64_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_UC1604_JLX19264_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_UC1604_JLX19264_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_UC1608_ERC24064_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Due, SW SPI, ERC24064-1 Test Board //U8X8_UC1608_DEM240064_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Due, SW SPI, ERC24064-1 Test Board //U8X8_UC1608_ERC240120_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_UC1608_240X128_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_UC1610_EA_DOGXL160_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ U8X8_PIN_NONE); //U8X8_UC1610_EA_DOGXL160_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ U8X8_PIN_NONE); //U8X8_UC1611_EA_DOGM240_2ND_HW_I2C u8x8(/* reset=*/ 8); // Due, 2nd I2C, DOGM240 Test Board //U8X8_UC1611_EA_DOGM240_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // SW SPI, Due DOGXL240 Test Board //U8X8_UC1611_EA_DOGXL240_2ND_HW_I2C u8x8(/* reset=*/ 8); // Due, 2nd I2C, DOGXL240 Test Board //U8X8_UC1611_EA_DOGXL240_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // SW SPI, Due DOGXL240 Test Board //U8X8_UC1611_IDS4073_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_UC1611_IDS4073_4W_HW_SPI u8x8( /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_UC1611_EW50850_8080 u8x8(8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18, /*cs=*/ 3, /*dc=*/ 16, /*reset=*/ 17); // 240x160, Connect RD/WR1 pin with 3.3V, CS is aktive high //U8X8_UC1611_CG160160_8080 u8x8(8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18, /*cs=*/ 3, /*dc=*/ 16, /*reset=*/ 17); // Connect WR1 and CD1 pin with 3.3V, connect CS0 with cs, WR0 with enable, CD with dc //U8X8_UC1617_JLX128128_4W_SW_SPI u8x8( /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_UC1617_JLX128128_4W_HW_SPI u8x8( /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_UC1638_192X96_4W_SW_SPI u8x8( /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_UC1638_192X96_4W_HW_SPI u8x8( /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_UC1638_192X96_SW_I2C u8x8(/* clock=*/ 13, /* data=*/ 11, /* reset=*/ 8); // u8g2 test board: I2C clock/data is same as SPI, I2C default address is 0x78 //U8X8_SSD1606_172X72_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // eInk/ePaper Display //U8X8_SSD1607_200X200_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // eInk/ePaper Display, original LUT from embedded artists //U8X8_SSD1607_GS_200X200_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Good Display //U8X8_SSD1607_WS_200X200_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Waveshare //U8X8_IL3820_296X128_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // eInk/ePaper Display, original LUT //U8X8_IL3820_V2_296X128_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // eInk/ePaper Display, optimized (lesser screen flicker) //U8X8_ST7511_AVD_320X240_8080 u8x8(13, 11, 2, 3, 4, 5, 6, A4, /*enable/WR=*/ 7, /*cs=*/ 10, /*dc=*/ 9, /*reset=*/ 8); // Connect RD pin with 3.3V/5V //U8X8_S1D15721_240X64_4W_SW_SPI u8x8(/* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8X8_S1D15721_240X64_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // End of constructor list void setup(void) { // U8g2 SH1106 Proto-Shield u8x8.begin(/* menu_select_pin= */ 2, /* menu_next_pin= */ 4, /* menu_prev_pin= */ 7, /* menu_up_pin= */ 6, /* menu_down_pin= */ 5, /* menu_home_pin= */ 3); u8x8.setPowerSave(0); u8x8.clear(); u8x8.setFont(u8x8_font_chroma48medium8_r); } void loop(void) { uint8_t e; u8x8.drawUTF8(0, 0, ""Event Test""); e = u8x8.getMenuEvent(); switch(e) { case U8X8_MSG_GPIO_MENU_SELECT: u8x8.drawUTF8(0, 1, ""Select""); break; case U8X8_MSG_GPIO_MENU_NEXT: u8x8.drawUTF8(0, 1, ""Next ""); break; case U8X8_MSG_GPIO_MENU_PREV: u8x8.drawUTF8(0, 1, ""Prev ""); break; case U8X8_MSG_GPIO_MENU_HOME: u8x8.drawUTF8(0, 1, ""Home ""); break; case U8X8_MSG_GPIO_MENU_UP: u8x8.drawUTF8(0, 1, ""Up ""); break; case U8X8_MSG_GPIO_MENU_DOWN: u8x8.drawUTF8(0, 1, ""Down ""); break; } } ",12514,True,3705.868380546625,median "#include #include #include ""Adafruit_GFX.h"" #include ""Waveshare_HX8347D.h"" Waveshare_HX8347D tft = Waveshare_HX8347D(); byte SPEED = 1; // 1=SLOW 2=NORMAL 4=FAST //do not try other values!!! /******************************************************************************/ /* MAIN GAME VARIABLES */ /******************************************************************************/ #define BONUS_INACTIVE_TIME 600 #define BONUS_ACTIVE_TIME 300 #define START_LIFES 2 #define START_LEVEL 1 byte MAXLIFES = 5; byte LIFES = START_LIFES; byte GAMEWIN = 0; byte GAMEOVER = 0; byte DEMO=1; byte LEVEL=START_LEVEL; byte ACTUALBONUS = 0; //actual bonus icon byte ACTIVEBONUS = 0; //status of bonus byte GAMEPAUSED = 0; byte PACMANFALLBACK = 0; RC100 Controller; /******************************************************************************/ /* Controll KEYPAD LOOP */ /******************************************************************************/ boolean but_START = false; //38 boolean but_SELECT = false; //40 boolean but_A = false; //44 boolean but_B = false; //42 boolean but_UP = false; //52 boolean but_DOWN = false; //50 boolean but_LEFT = false; //48 boolean but_RIGHT = false; //46 void ClearKeys() { but_START=false; but_SELECT=false; but_A=false; but_B=false; but_UP=false; but_DOWN=false; but_LEFT=false; but_RIGHT=false; } void KeyPadLoop(){ /* if (digitalRead(51)==0) { ClearKeys(); but_START=true; delay(300); } //else but_START=false; if (digitalRead(53)==0) { ClearKeys(); but_SELECT=true; delay(300); } else but_SELECT=false; if (digitalRead(44)==0) { ClearKeys(); but_A=true; } else but_A=false; if (digitalRead(49)==0) { ClearKeys(); but_B=true; } else but_B=false; if (digitalRead(52)==0) { ClearKeys(); but_UP=true; } //else but_UP=false; if (digitalRead(50)==0) { ClearKeys(); but_DOWN=true; } //else but_DOWN=false; if (digitalRead(48)==0) { ClearKeys(); but_LEFT=true; } // else but_LEFT=false; if (digitalRead(46)==0) { ClearKeys(); but_RIGHT=true; } //else but_RIGHT=false; */ int RcvData; if (Controller.available()) { RcvData = Controller.readData(); switch( RcvData ) { case 256: { ClearKeys(); but_START=true; delay(300); } break; case 512: { ClearKeys(); but_SELECT=true; delay(300); } break; case 16: { ClearKeys(); but_A=true; } break; case 128: { ClearKeys(); but_B=true; } break; case 1: { ClearKeys(); but_UP=true; } break; case 2: { ClearKeys(); but_DOWN=true; } break; case 4: { ClearKeys(); but_LEFT=true; } break; case 8: { ClearKeys(); but_RIGHT=true; } break; case 32: if(SPEED == 1) SPEED = 2; else if(SPEED == 2) SPEED = 4; else SPEED = 1; delay(300); break; default: ClearKeys(); break; } } } /******************************************************************************/ /* GAME VARIABLES AND DEFINITIONS */ /******************************************************************************/ #include ""PacmanTiles.h"" enum GameState { ReadyState, PlayState, DeadGhostState, // Player got a ghost, show score sprite and only move eyes DeadPlayerState, EndLevelState }; enum SpriteState { PenState, RunState, FrightenedState, DeadNumberState, DeadEyesState, AteDotState, // pacman DeadPacmanState }; enum { MStopped = 0, MRight = 1, MDown = 2, MLeft = 3, MUp = 4, }; #define ushort uint16_t //#define C16(_rr,_gg,_bb) (((ushort)(((_rr & 0xE0)) | ((_gg & 0xE0) >> 3) | ((_bb & 0xC0) >> 6)) <<8 )) #define C16(_rr,_gg,_bb) ((_rr & 0xF8) << 8) | ((_gg & 0xFC) << 3) | (_bb >> 3) // 8 bit palette for ILI9341 uint16_t _paletteW[] = { C16(0,0,0), C16(255,0,0), // 1 red C16(222,151,81), // 2 brown C16(255,0,255), // 3 pink C16(0,0,0), C16(0,255,255), // 5 cyan C16(71,84,255), // 6 mid blue C16(255,184,81), // 7 lt brown C16(0,0,0), C16(255,255,0), // 9 yellow C16(0,0,0), C16(33,33,255), // 11 blue C16(0,255,0), // 12 green C16(71,84,174), // 13 aqua C16(255,184,174), // 14 lt pink C16(222,222,255), // 15 whiteish }; #define BINKY 0 #define PINKY 1 #define INKY 2 #define CLYDE 3 #define PACMAN 4 #define BONUS 5 const byte _initSprites[] = { BINKY, 14, 17-3, 31, MLeft, PINKY, 14-2, 17, 79, MLeft, INKY, 14, 17, 137, MLeft, CLYDE, 14+2, 17, 203, MRight, PACMAN, 14, 17+9, 0, MLeft, BONUS, 14, 17+3, 0, MLeft, }; // Ghost colors const byte _palette2[] = { 0,11,1,15, // BINKY red 0,11,3,15, // PINKY pink 0,11,5,15, // INKY cyan 0,11,7,15, // CLYDE brown 0,11,9,9, // PACMAN yellow 0,11,15,15,// FRIGHTENED 0,11,0,15, // DEADEYES 0,1,15,2, // cherry 0,1,15,12, // strawberry 0,7,2,12, // peach 0,9,15,0, // bell 0,15,1,2, // apple 0,12,15,5, // grape 0,11,9,1, // galaxian 0,5,15,15, // key }; const byte _paletteIcon2[] = { 0,9,9,9, // PACMAN 0,2,15,1, // cherry 0,12,15,1, // strawberry 0,12,2,7, // peach 0,0,15,9, // bell 0,2,15,1, // apple 0,12,15,5, // grape 0,1,9,11, // galaxian 0,5,15,15, // key }; #define PACMANICON 1 #define BONUSICON 2 #define FRIGHTENEDPALETTE 5 #define DEADEYESPALETTE 6 #define BONUSPALETTE 7 #define FPS 60 #define CHASE 0 #define SCATTER 1 #define DOT 7 #define PILL 14 #define PENGATE 0x1B const byte _opposite[] = { MStopped,MLeft,MUp,MRight,MDown }; #define OppositeDirection(_x) pgm_read_byte(_opposite + _x) const byte _scatterChase[] = { 7,20,7,20,5,20,5,0 }; const byte _scatterTargets[] = { 2,0,25,0,0,35,27,35 }; // inky/clyde scatter targets are backwards const char _pinkyTargetOffset[] = { 4,0,0,4,-4,0,-4,4 }; // Includes pinky target bug #define FRIGHTENEDGHOSTSPRITE 0 #define GHOSTSPRITE 2 #define NUMBERSPRITE 10 #define PACMANSPRITE 14 const byte _pacLeftAnim[] = { 5,6,5,4 }; const byte _pacRightAnim[] = { 2,0,2,4 }; const byte _pacVAnim[] = { 4,3,1,3 }; word _BonusInactiveTimmer=BONUS_INACTIVE_TIME; word _BonusActiveTimmer=0; void drawIndexedmap(const uint8_t *indexmap, int16_t x, int16_t y, uint16_t w, uint16_t h) { byte i = 0; word color=(word)_paletteW[indexmap[0]]; for (byte tmpY=0;tmpY<8;tmpY++) { byte width=1; for (byte tmpX=0;tmpX<8;tmpX++) { word next_color=(word)_paletteW[indexmap[++i]]; //if ((color!=next_color && width>=1) || tmpX==7 ) { ///drawPixel_cont(x+tmpX, y+tmpY, color); //VGA.drawHLine( y+tmpY,x+tmpX-width+1, x+tmpX+1 + width, color); //tft.drawFastHLine( y+tmpY,x+tmpX-width+1, x+tmpX+1 + width, color); tft.drawPixel(x+tmpX, y+tmpY, color>>8 | color<<8); color=next_color; width=0; //} width++; } } } /******************************************************************************/ /* GAME - Sprite Class */ /******************************************************************************/ class Sprite { public: int16_t _x,_y; int16_t lastx,lasty; byte cx,cy; // cell x and y byte tx,ty; // target x and y SpriteState state; byte pentimer; // could be the same byte who; byte _speed; byte dir; byte phase; // Sprite bits byte palette2; // 4->16 color map index byte bits; // index of sprite bits signed char sy; void Init(const byte* s) { who = pgm_read_byte(s++); cx = pgm_read_byte(s++); cy = pgm_read_byte(s++); pentimer = pgm_read_byte(s++); dir = pgm_read_byte(s); _x = lastx = (int16_t)cx*8-4; _y = lasty = (int16_t)cy*8; state = PenState; _speed = 0; Target(random(20),random(20)); } void Target(byte x, byte y) { tx = x; ty = y; } int16_t Distance(byte x, byte y) { int16_t dx = cx - x; int16_t dy = cy - y; return dx*dx + dy*dy; // Distance to target } // once per sprite, not 9 times void SetupDraw(GameState gameState, byte deadGhostIndex) { sy = 1; palette2 = who; byte p = phase >> 3; if (who == BONUS) { //BONUS ICONS bits = 21 + ACTUALBONUS; palette2 = BONUSPALETTE + ACTUALBONUS; return; } if (who != PACMAN) { bits = GHOSTSPRITE + ((dir-1) << 1) + (p&1); // Ghosts switch (state) { case FrightenedState: bits = FRIGHTENEDGHOSTSPRITE + (p&1); // frightened palette2 = FRIGHTENEDPALETTE; break; case DeadNumberState: palette2 = FRIGHTENEDPALETTE; bits = NUMBERSPRITE+ deadGhostIndex; break; case DeadEyesState: palette2 = DEADEYESPALETTE; break; default: ; } return; } // PACMAN animation byte f = (phase>>1) & 3; if (dir == MLeft) f = pgm_read_byte(_pacLeftAnim + f); else if (dir == MRight) f = pgm_read_byte(_pacRightAnim + f); else f = pgm_read_byte(_pacVAnim + f); if (dir == MUp) sy = -1; bits = f + PACMANSPRITE; } // Draw this sprite into the tile at x,y void Draw8(int16_t x, int16_t y, byte* tile) { int16_t px = x - (_x-4); if (px <= -8 || px >= 16) return; int16_t py = y - (_y-4); if (py <= -8 || py >= 16) return; // Clip y int16_t lines = py+8; if (lines > 16) lines = 16; if (py < 0) { tile -= py*8; py = 0; } lines -= py; // Clip in X byte right = 16 - px; if (right > 8) right = 8; byte left = 0; if (px < 0) { left = -px; px = 0; } // Get bitmap signed char dy = sy; if (dy < 0) py = 15-py; // VFlip byte* data = (byte*)(pacman16x16+bits*64); data += py << 2; dy <<= 2; data += px >> 2; px &= 3; const byte* palette = _palette2 + (palette2<<2); while (lines) { const byte *src = data; byte d = pgm_read_byte(src++); d >>= px << 1; byte sx = 4 - px; byte x = left; do { byte p = d & 3; if (p) { p = pgm_read_byte(palette+p); if (p) tile[x] = p; } d >>= 2; // Next pixel if (!--sx) { d = pgm_read_byte(src++); sx = 4; } } while (++x < right); tile += 8; data += dy; lines--; } } }; /******************************************************************************/ /* GAME - Playfield Class */ /******************************************************************************/ class Playfield { Sprite _sprites[5]; Sprite _BonusSprite; //Bonus byte _dotMap[(32/4)*(36-6)]; GameState _state; long _score; // 7 digits of score long _hiscore; // 7 digits of score long _lifescore; signed char _scoreStr[8]; signed char _hiscoreStr[8]; byte _icons[14]; // Along bottom of screen ushort _stateTimer; ushort _frightenedTimer; byte _frightenedCount; byte _scIndex; // ushort _scTimer; // next change of sc status bool _inited; byte* _dirty; public: Playfield() : _inited(false) { // Swizzle palette TODO just fix in place byte * p = (byte*)_paletteW; for (int16_t i = 0; i < 16; i++) { ushort w = _paletteW[i]; // Swizzle *p++ = w >> 8; *p++ = w; } } // Draw 2 bit BG into 8 bit icon tiles at bottom void DrawBG2(byte cx, byte cy, byte* tile) { byte index=0; signed char b=0; index = _icons[cx >> 1]; // 13 icons across bottom if (index == 0) { memset(tile,0,64); return; } index--; index <<= 2; // 4 tiles per icon b = (1-(cx&1)) + ((cy&1)<<1); // Index of tile const byte* bg = pacman8x8x2 + ((b + index) << 4); const byte* palette = _paletteIcon2 + index; byte x = 16; while (x--) { byte bits = (signed char)pgm_read_byte(bg++); byte i = 4; while (i--) { tile[i] = pgm_read_byte(palette + (bits & 3)); bits >>= 2; } tile += 4; } } byte GetTile(int16_t cx, int16_t ty) { if (_state != ReadyState && ty==20 && cx>10 && cx<17) return(0); //READY TEXT ZONE if (LEVEL%5==1) return pgm_read_byte(playMap1 + ty*28 + cx); if (LEVEL%5==2) return pgm_read_byte(playMap2 + ty*28 + cx); if (LEVEL%5==3) return pgm_read_byte(playMap3 + ty*28 + cx); if (LEVEL%5==4) return pgm_read_byte(playMap4 + ty*28 + cx); if (LEVEL%5==0) return pgm_read_byte(playMap5 + ty*28 + cx); } // Draw 1 bit BG into 8 bit tile void DrawBG(byte cx, byte cy, byte* tile) { if (cy >= 34) //DRAW ICONS BELLOW MAZE { DrawBG2(cx,cy,tile); return; } byte c = 11; if (LEVEL%8==1) c = 11; // Blue if (LEVEL%8==2) c = 12; // Green if (LEVEL%8==3) c = 1; // Red if (LEVEL%8==4) c = 9; // Yellow if (LEVEL%8==5) c = 2; // Brown if (LEVEL%8==6) c = 5; // Cyan if (LEVEL%8==7) c = 3; // Pink if (LEVEL%8==0) c = 15; // White byte b = GetTile(cx,cy); const byte* bg; // This is a little messy memset(tile,0,64); if (cy == 20 && cx >= 11 && cx < 17) { if (DEMO==1 && ACTIVEBONUS==1) return; if ((_state != ReadyState && GAMEPAUSED != 1 && DEMO!=1) || ACTIVEBONUS==1) b = 0; // hide 'READY!' else if (DEMO==1 && cx==11) b=0; else if (DEMO==1 && cx==12) b='D'; else if (DEMO==1 && cx==13) b='E'; else if (DEMO==1 && cx==14) b='M'; else if (DEMO==1 && cx==15) b='O'; else if (DEMO==1 && cx==16) b=0; else if (GAMEPAUSED==1 && cx==11) b='P'; else if (GAMEPAUSED==1 && cx==12) b='A'; else if (GAMEPAUSED==1 && cx==13) b='U'; else if (GAMEPAUSED==1 && cx==14) b='S'; else if (GAMEPAUSED==1 && cx==15) b='E'; else if (GAMEPAUSED==1 && cx==16) b='D'; } else if (cy == 1) { if (cx < 7) b = _scoreStr[cx]; else if (cx >= 10 && cx < 17) b = _hiscoreStr[cx-10]; // HiScore } else { if (b == DOT || b == PILL) // DOT==7 or PILL==16 { if (!GetDot(cx,cy)) return; c = 14; } if (b == PENGATE) c = 14; } bg = playTiles + (b << 3); if (b >= '0') c = 15; // text is white for (byte y = 0; y < 8; y++) { signed char bits = (signed char)pgm_read_byte(bg++); ///WARNING CHAR MUST BE signed !!! byte x = 0; while (bits) { if (bits < 0) tile[x] = c; bits <<= 1; x++; } tile += 8; } } // Draw BG then all sprites in this cell void Draw(uint16_t x, uint16_t y, bool sprites) { byte tile[8*8]; // Fill with BG if (y == 20 && x >= 11 && x < 17 && DEMO==1 && ACTIVEBONUS==1) return; DrawBG(x,y,tile); // Overlay sprites x <<= 3; y <<= 3; if (sprites) { for (byte i = 0; i < 5; i++) _sprites[i].Draw8(x,y,tile); //AND BONUS if (ACTIVEBONUS) _BonusSprite.Draw8(x,y,tile); } // Show sprite block #if 0 for (byte i = 0; i < 5; i++) { Sprite* s = _sprites + i; if (s->cx == (x>>3) && s->cy == (y>>3)) { memset(tile,0,8); for (byte j = 1; j < 7; j++) tile[j*8] = tile[j*8+7] = 0; memset(tile+56,0,8); } } #endif x += (240-224)/2; y += (320-288)/2; // Should be a direct Graphics call byte n = tile[0]; byte i = 0; word color=(word)_paletteW[n]; //------------------------------------------------------------------------------ drawIndexedmap(tile,x,y,8,8); // Call Custom function in ILI9341_DUE.h library //------------------------------------------------------------------------------ } boolean updateMap [36][28]; // Mark tile as dirty (should not need range checking here) void Mark(int16_t x, int16_t y, byte* m) { x -= 4; y -= 4; updateMap[(y>>3)][(x>>3)]=true; updateMap[(y>>3)][(x>>3)+1]=true; updateMap[(y>>3)][(x>>3)+2]=true; updateMap[(y>>3)+1][(x>>3)]=true; updateMap[(y>>3)+1][(x>>3)+1]=true; updateMap[(y>>3)+1][(x>>3)+2]=true; updateMap[(y>>3)+2][(x>>3)]=true; updateMap[(y>>3)+2][(x>>3)+1]=true; updateMap[(y>>3)+2][(x>>3)+2]=true; } void DrawAllBG() { for (byte y = 0; y < 36; y++) for (byte x = 0; x < 28; x++) { Draw(x,y,false); } } // Draw sprites overlayed on cells void DrawAll() { byte* m = _dirty; // Mark sprite old/new positions as dirty for (byte i = 0; i < 5; i++) { Sprite* s = _sprites + i; Mark(s->lastx,s->lasty,m); Mark(s->_x,s->_y,m); } // Mark BONUS sprite old/new positions as dirty Sprite* _s = &_BonusSprite; Mark(_s->lastx,_s->lasty,m); Mark(_s->_x,_s->_y,m); // Animation for (byte i = 0; i < 5; i++) _sprites[i].SetupDraw(_state,_frightenedCount-1); _BonusSprite.SetupDraw(_state,_frightenedCount-1); for (byte tmpY=0;tmpY<36;tmpY++){ for (byte tmpX=0;tmpX<28;tmpX++){ if (updateMap[tmpY][tmpX]==true) Draw(tmpX,tmpY,true); updateMap[tmpY][tmpX]=false; } } static int i=0; if(i) tft.drawFrame(); i ^= 1; } int16_t Chase(Sprite* s, int16_t cx, int16_t cy) { while (cx < 0) // Tunneling cx += 28; while (cx >= 28) cx -= 28; byte t = GetTile(cx,cy); if (!(t == 0 || t == DOT || t == PILL || t == PENGATE)) return 0x7FFF; if (t == PENGATE) { if (s->who == PACMAN) return 0x7FFF; // Pacman can't cross this to enter pen if (!(InPen(s->cx,s->cy) || s->state == DeadEyesState)) return 0x7FFF; // Can cross if dead or in pen trying to get out } int16_t dx = s->tx-cx; int16_t dy = s->ty-cy; return (dx*dx + dy*dy); // Distance to target } void UpdateTimers() { // Update scatter/chase selector, low bit of index indicates scatter if (_scIndex < 8) { if (_scTimer-- == 0) { byte duration = pgm_read_byte(_scatterChase + _scIndex++); _scTimer = duration*FPS; } } // BONUS timmer if (ACTIVEBONUS==0 && _BonusInactiveTimmer--==0) { _BonusActiveTimmer=BONUS_ACTIVE_TIME; //5*FPS; ACTIVEBONUS=1; } if (ACTIVEBONUS==1 && _BonusActiveTimmer--==0) { _BonusInactiveTimmer=BONUS_INACTIVE_TIME; //10*FPS; ACTIVEBONUS=0; } // Release frightened ghosts if (_frightenedTimer && !--_frightenedTimer) { for (byte i = 0; i < 4; i++) { Sprite* s = _sprites + i; if (s->state == FrightenedState) { s->state = RunState; s->dir = OppositeDirection(s->dir); } } } } // Target closes pill, run from ghosts? void PacmanAI() { Sprite* pacman; pacman = _sprites + PACMAN; // Chase frightened ghosts Sprite* closestGhost = NULL; Sprite* frightenedGhost = NULL; Sprite* closestAttackingGhost = NULL; Sprite* DeadEyesStateGhost = NULL; int16_t dist = 0x7FFF; int16_t closestfrightenedDist = 0x7FFF; int16_t closestAttackingDist = 0x7FFF; for (byte i = 0; i < 4; i++) { Sprite* s = _sprites+i; int16_t d = s->Distance(pacman->cx,pacman->cy); if (d < dist) { dist = d; if (s->state == FrightenedState ) { frightenedGhost = s; closestfrightenedDist = d; } else { closestAttackingGhost = s; closestAttackingDist = d; } closestGhost = s; if ( s->state == DeadEyesState ) DeadEyesStateGhost=s; } } PACMANFALLBACK=0; if (DEMO==1 && !DeadEyesStateGhost && frightenedGhost ) { pacman->Target(frightenedGhost->cx,frightenedGhost->cy); return; } // Under threat; just avoid closest ghost if (DEMO==1 && !DeadEyesStateGhost && dist <= 32 && closestAttackingDistTarget( pacman->cx*2 - closestAttackingGhost->cx, pacman->cy*2 - closestAttackingGhost->cy); PACMANFALLBACK=1; } else { pacman->Target( pacman->cx*2 - closestAttackingGhost->cx, pacman->cy*2 - closestAttackingGhost->cy); } return; } if (ACTIVEBONUS==1) { pacman->Target(13,20); return; } // Go for the pill if (GetDot(1,6)) pacman->Target(1,6); else if (GetDot(26,6)) pacman->Target(26,6); else if (GetDot(1,26)) pacman->Target(1,26); else if (GetDot(26,26)) pacman->Target(26,26); else { // closest dot int16_t dist = 0x7FFF; for (byte y = 4; y < 32; y++) { for (byte x = 1; x < 26; x++) { if (GetDot(x,y)) { int16_t d = pacman->Distance(x,y); if (d < dist) { dist = d; pacman->Target(x,y); } } } } if (dist == 0x7FFF) { GAMEWIN=1; // No dots, GAME WIN! } } } void Scatter(Sprite* s) { const byte* st = _scatterTargets + (s->who << 1); s->Target(pgm_read_byte(st),pgm_read_byte(st+1)); } void UpdateTargets() { if (_state == ReadyState) return; PacmanAI(); Sprite* pacman = _sprites + PACMAN; // Ghost AI bool scatter = _scIndex & 1; for (byte i = 0; i < 4; i++) { Sprite* s = _sprites+i; // Deal with returning ghost to pen if (s->state == DeadEyesState) { if (s->cx == 14 && s->cy == 17) // returned to pen { s->state = PenState; // Revived in pen s->pentimer = 80; } else s->Target(14,17); // target pen continue; // } // Release ghost from pen when timer expires if (s->pentimer) { if (--s->pentimer) // stay in pen for awhile continue; s->state = RunState; } if (InPen(s->cx,s->cy)) { s->Target(14,14-2); // Get out of pen first } else { if (scatter || s->state == FrightenedState) Scatter(s); else { // Chase mode targeting signed char tx = pacman->cx; signed char ty = pacman->cy; switch (s->who) { case PINKY: { const char* pto = _pinkyTargetOffset + ((pacman->dir-1)<<1); tx += pgm_read_byte(pto); ty += pgm_read_byte(pto+1); } break; case INKY: { const char* pto = _pinkyTargetOffset + ((pacman->dir-1)<<1); Sprite* binky = _sprites + BINKY; tx += pgm_read_byte(pto)>>1; ty += pgm_read_byte(pto+1)>>1; tx += tx - binky->cx; ty += ty - binky->cy; } break; case CLYDE: { if (s->Distance(pacman->cx,pacman->cy) < 64) { const byte* st = _scatterTargets + CLYDE*2; tx = pgm_read_byte(st); ty = pgm_read_byte(st+1); } } break; } s->Target(tx,ty); } } } } // Default to current direction byte ChooseDir(int16_t dir, Sprite* s) { int16_t choice[4]; choice[0] = Chase(s,s->cx,s->cy-1); // Up choice[1] = Chase(s,s->cx-1,s->cy); // Left choice[2] = Chase(s,s->cx,s->cy+1); // Down choice[3] = Chase(s,s->cx+1,s->cy); // Right if (DEMO==0 && s->who == PACMAN && choice[0]<0x7FFF && but_UP) dir=MUp; else if (DEMO==0 && s->who == PACMAN && choice[1]<0x7FFF && but_LEFT) dir=MLeft; else if (DEMO==0 && s->who == PACMAN && choice[2]<0x7FFF && but_DOWN) dir=MDown; else if (DEMO==0 && s->who == PACMAN && choice[3]<0x7FFF && but_RIGHT) dir=MRight; else if (DEMO==0 && choice[0]<0x7FFF && s->who == PACMAN && dir==MUp) dir=MUp; else if (DEMO==0 && choice[1]<0x7FFF && s->who == PACMAN && dir==MLeft) dir=MLeft; else if (DEMO==0 && choice[2]<0x7FFF && s->who == PACMAN && dir==MDown) dir=MDown; else if (DEMO==0 && choice[3]<0x7FFF && s->who == PACMAN && dir==MRight) dir=MRight; else if ((DEMO==0 && s->who != PACMAN) || DEMO==1 ) { // Don't choose opposite of current direction? int16_t dist = choice[4-dir]; // favor current direction byte opposite = OppositeDirection(dir); for (byte i = 0; i < 4; i++) { byte d = 4-i; if ((d != opposite && choice[i] < dist) || (s->who == PACMAN && PACMANFALLBACK && choice[i] < dist)) { if (s->who == PACMAN && PACMANFALLBACK) PACMANFALLBACK=0; dist = choice[i]; dir = d; } } } else { dir=MStopped; } return dir; } bool InPen(byte cx, byte cy) { if (cx <= 10 || cx >= 18) return false; if (cy <= 14 || cy >= 18) return false; return true; } byte GetSpeed(Sprite* s) { if (s->who == PACMAN) return _frightenedTimer ? 90 : 80; if (s->state == FrightenedState) return 40; if (s->state == DeadEyesState) return 100; if (s->cy == 17 && (s->cx <= 5 || s->cx > 20)) return 40; // tunnel return 75; } void PackmanDied() { // Noooo... PACMAN DIED :( if (LIFES<=0) { GAMEOVER=1; LEVEL=START_LEVEL; LIFES=START_LIFES; DEMO=1; Init(); } else { LIFES--; _inited = true; _state = ReadyState; _stateTimer = FPS/2; _frightenedCount = 0; _frightenedTimer = 0; const byte* s = _initSprites; for (int16_t i = 0; i < 5; i++) _sprites[i].Init(s + i*5); _scIndex = 0; _scTimer = 1; memset(_icons,0,sizeof(_icons)); //AND BONUS _BonusSprite.Init(s + 5*5); _BonusInactiveTimmer=BONUS_INACTIVE_TIME; _BonusActiveTimmer=0; for (byte i=0;istate == DeadNumberState) s->state = DeadEyesState; } break; default: ; } } else { if (_state == ReadyState) return; } } for (byte i = 0; i < 5; i++) { Sprite* s = _sprites + i; // In DeadGhostState, only eyes move if (_state == DeadGhostState && s->state != DeadEyesState) continue; // Calculate speed s->_speed += GetSpeed(s); if (s->_speed < 100) continue; s->_speed -= 100; s->lastx = s->_x; s->lasty = s->_y; s->phase++; int16_t x = s->_x; int16_t y = s->_y; if ((x & 0x7) == 0 && (y & 0x7) == 0) // cell aligned s->dir = ChooseDir(s->dir,s); // time to choose another direction switch (s->dir) { case MLeft: x -= SPEED; break; case MRight: x += SPEED; break; case MUp: y -= SPEED; break; case MDown: y += SPEED; break; case MStopped: break; } // Wrap x because of tunnels while (x < 0) x += 224; while (x >= 224) x -= 224; s->_x = x; s->_y = y; s->cx = (x + 4) >> 3; s->cy = (y + 4) >> 3; if (s->who == PACMAN) EatDot(s->cx,s->cy); } // Collide Sprite* pacman = _sprites + PACMAN; // Collide with BONUS Sprite* _s = &_BonusSprite; if (ACTIVEBONUS==1 && _s->cx == pacman->cx && _s->cy == pacman->cy) { Score(ACTUALBONUS*50); ACTUALBONUS++; if (ACTUALBONUS>7) { ACTUALBONUS=0; if (LIFEScx == pacman->cx && s->cy == pacman->cy) if (s->_x+SPEED >= pacman->_x && s->_x-SPEED <= pacman->_x && s->_y+SPEED >= pacman->_y && s->_y-SPEED <= pacman->_y) { if (s->state == FrightenedState) { s->state = DeadNumberState; // Killed a ghost _frightenedCount++; _state = DeadGhostState; _stateTimer=10; Score((1 << _frightenedCount)*100); } else { // pacman died if (s->state == DeadNumberState || s->state == FrightenedState || s->state == DeadEyesState) { } else { PackmanDied(); } } } } } // Mark a position dirty void Mark(int16_t pos) { for (byte tmp=0;tmp<28;tmp++) updateMap[1][tmp]=true; } void SetScoreChar(byte i, signed char c) { if (_scoreStr[i] == c) return; _scoreStr[i] = c; Mark(i+32); //Score //Mark(i+32+10); //HiScore } void SetHiScoreChar(byte i, signed char c) { if (_hiscoreStr[i] == c) return; _hiscoreStr[i] = c; //Mark(i+32); //Score Mark(i+32+10); //HiScore } void Score(int16_t delta) { char str[8]; _score += delta; if (DEMO==0 && _score> _hiscore) _hiscore=_score; if (_score > _lifescore && _score%10000 > 0) { _lifescore=(_score/10000 + 1) * 10000; LIFES++; // EVERY 10000 points = 1UP for (byte i=0;i> 3)] & (0x80 >> (cx & 7)); } void EatDot(byte cx, byte cy) { if (!GetDot(cx,cy)) return; byte mask = 0x80 >> (cx & 7); _dotMap[(cy-3)*4 + (cx >> 3)] &= ~mask; byte t = GetTile(cx,cy); if (t == PILL) { _frightenedTimer = 10*FPS; _frightenedCount = 0; for (byte i = 0; i < 4; i++) { Sprite* s = _sprites+i; if (s->state == RunState) { s->state = FrightenedState; s->dir = OppositeDirection(s->dir); } } Score(50); } else Score(10); } void Init() { if (GAMEWIN==1) { GAMEWIN=0; } else { LEVEL=START_LEVEL; LIFES=START_LIFES; ACTUALBONUS=0; //actual bonus icon ACTIVEBONUS=0; //status of bonus _score = 0; _lifescore=10000; memset(_scoreStr,0,sizeof(_scoreStr)); _scoreStr[5] = _scoreStr[6] = '0'; } _inited = true; _state = ReadyState; _stateTimer = FPS/2; _frightenedCount = 0; _frightenedTimer = 0; const byte* s = _initSprites; for (int16_t i = 0; i < 5; i++) _sprites[i].Init(s + i*5); //AND BONUS _BonusSprite.Init(s + 5*5); _BonusInactiveTimmer=BONUS_INACTIVE_TIME; _BonusActiveTimmer=0; _scIndex = 0; _scTimer = 1; memset(_icons,0,sizeof(_icons)); // SET BONUS icons for (byte i=0;i>3] |= (0x80 >> s); } } map += 4; } DrawAllBG(); } void Step() { int16_t keys=0; if (GAMEWIN==1){ LEVEL++; Init(); } // Start GAME if (but_START && DEMO==1 && GAMEPAUSED==0) { but_START=false; DEMO=0; Init(); } else if (but_START && DEMO==0 && GAMEPAUSED==0) { // Or PAUSE GAME but_START=false; GAMEPAUSED = 1; } if (GAMEPAUSED && but_START && DEMO==0) { but_START=false; GAMEPAUSED = 0; for (byte tmpX=11;tmpX<17;tmpX++) Draw(tmpX,20,false); } // Reset / Start GAME if (but_SELECT) { DEMO=0; Init(); } else if (!_inited) { DEMO=1; Init(); } // Create a bitmap of dirty tiles byte m[(32/8)*36]; // 144 bytes memset(m,0,sizeof(m)); _dirty = m; if (!GAMEPAUSED) MoveAll(); // IF GAME is PAUSED STOP ALL if ((ACTIVEBONUS==0 && DEMO==1) || GAMEPAUSED == 1 ) for (byte tmpX=11;tmpX<17;tmpX++) Draw(tmpX,20,false); // Draw 'PAUSED' or 'DEMO' text DrawAll(); } }; Playfield _game; void setup() { uint32_t t_time; Serial.begin(9600); Controller.begin(1); tft.begin(); tft.setRotation(1); tft.fillScreen(HX8347D_BLACK); tft.drawFrame(); } void loop(void) { _game.Step(); KeyPadLoop(); } ",12101,False,2273.2019528648475,median "/* GraphicsTest.ino Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/) Copyright (c) 2016, olikraus@gmail.com All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #ifdef U8X8_HAVE_HW_SPI #include #endif #ifdef U8X8_HAVE_HW_I2C #include #endif /* U8glib Example Overview: Frame Buffer Examples: clearBuffer/sendBuffer. Fast, but may not work with all Arduino boards because of RAM consumption Page Buffer Examples: firstPage/nextPage. Less RAM usage, should work with all Arduino boards. U8x8 Text Only Example: No RAM usage, direct communication with display controller. No graphics, 8x8 Text only. This is a page buffer example. */ // Please UNCOMMENT one of the contructor lines below // U8g2 Contructor List (Picture Loop Page Buffer) // The complete list is available here: https://github.com/olikraus/u8g2/wiki/u8g2setupcpp // Please update the pin numbers according to your setup. Use U8X8_PIN_NONE if the reset pin is not connected //U8G2_SSD1306_128X64_NONAME_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1306_128X64_NONAME_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 12, /* dc=*/ 4, /* reset=*/ 6); // Arduboy (Production, Kickstarter Edition) //U8G2_SSD1306_128X64_NONAME_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1306_128X64_NONAME_1_3W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* reset=*/ 8); //U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); //U8G2_SSD1306_128X64_NONAME_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* reset=*/ 8); //U8G2_SSD1306_128X64_NONAME_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // All Boards without Reset of the Display //U8G2_SSD1306_128X64_NONAME_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ 16, /* data=*/ 17, /* reset=*/ U8X8_PIN_NONE); // ESP32 Thing, pure SW emulated I2C //U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ 16, /* data=*/ 17); // ESP32 Thing, HW I2C with pin remapping //U8G2_SSD1306_128X64_NONAME_1_6800 u8g2(U8G2_R0, 13, 11, 2, 3, 4, 5, 6, A4, /*enable=*/ 7, /*cs=*/ 10, /*dc=*/ 9, /*reset=*/ 8); //U8G2_SSD1306_128X64_NONAME_1_8080 u8g2(U8G2_R0, 13, 11, 2, 3, 4, 5, 6, A4, /*enable=*/ 7, /*cs=*/ 10, /*dc=*/ 9, /*reset=*/ 8); //U8G2_SSD1306_128X64_VCOMH0_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // same as the NONAME variant, but maximizes setContrast() range //U8G2_SH1106_128X64_NONAME_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SH1106_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); //U8G2_SH1106_128X64_VCOMH0_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // same as the NONAME variant, but maximizes setContrast() range //U8G2_SSD1306_128X32_UNIVISION_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ 21, /* data=*/ 20, /* reset=*/ U8X8_PIN_NONE); // Adafruit Feather M0 Basic Proto + FeatherWing OLED //U8G2_SSD1306_128X32_UNIVISION_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // Adafruit Feather ESP8266/32u4 Boards + FeatherWing OLED //U8G2_SSD1306_128X32_UNIVISION_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // Adafruit ESP8266/32u4/ARM Boards + FeatherWing OLED //U8G2_SSD1306_128X32_UNIVISION_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ SCL, /* data=*/ SDA); // pin remapping with ESP8266 HW I2C //U8G2_SSD1306_64X48_ER_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // EastRising 0.66"" OLED breakout board, Uno: A4=SDA, A5=SCL, 5V powered //U8G2_SSD1306_64X32_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); //U8G2_SSD1306_64X32_1F_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); //U8G2_SSD1306_96X16_ER_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // EastRising 0.69"" OLED //U8G2_SSD1322_NHD_256X64_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Enable U8G2_16BIT in u8g2.h //U8G2_SSD1322_NHD_256X64_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Enable U8G2_16BIT in u8g2.h //U8G2_SSD1325_NHD_128X64_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1325_NHD_128X64_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1327_SEEED_96X96_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // Seeedstudio Grove OLED 96x96 //U8G2_SSD1327_SEEED_96X96_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // Seeedstudio Grove OLED 96x96 //U8G2_SSD1329_128X96_NONAME_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1329_128X96_NONAME_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1305_128X32_NONAME_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1305_128X32_NONAME_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1309_128X64_NONAME0_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1309_128X64_NONAME0_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1309_128X64_NONAME2_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_SSD1309_128X64_NONAME2_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_LD7032_60X32_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 11, /* data=*/ 12, /* cs=*/ 9, /* dc=*/ 10, /* reset=*/ 8); // SW SPI Nano Board //U8G2_LD7032_60X32_1_4W_SW_I2C u8g2(U8G2_R0, /* clock=*/ 11, /* data=*/ 12, /* reset=*/ U8X8_PIN_NONE); // NOT TESTED! //U8G2_UC1701_EA_DOGS102_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_UC1701_EA_DOGS102_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_PCD8544_84X48_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Nokia 5110 Display //U8G2_PCD8544_84X48_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Nokia 5110 Display //U8G2_PCF8812_96X65_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Could be also PCF8814 //U8G2_PCF8812_96X65_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Could be also PCF8814 //U8G2_KS0108_128X64_1 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18, /*dc=*/ 17, /*cs0=*/ 14, /*cs1=*/ 15, /*cs2=*/ U8X8_PIN_NONE, /* reset=*/ U8X8_PIN_NONE); // Set R/W to low! //U8G2_KS0108_ERM19264_1 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18, /*dc=*/ 17, /*cs0=*/ 14, /*cs1=*/ 15, /*cs2=*/ 16, /* reset=*/ U8X8_PIN_NONE); // Set R/W to low! //U8G2_ST7920_192X32_1_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18, /*cs=*/ U8X8_PIN_NONE, /*dc=*/ 17, /*reset=*/ U8X8_PIN_NONE); //U8G2_ST7920_192X32_1_SW_SPI u8g2(U8G2_R0, /* clock=*/ 18 /* A4 */ , /* data=*/ 16 /* A2 */, /* CS=*/ 17 /* A3 */, /* reset=*/ U8X8_PIN_NONE); //U8G2_ST7920_128X64_1_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18 /* A4 */, /*cs=*/ U8X8_PIN_NONE, /*dc/rs=*/ 17 /* A3 */, /*reset=*/ 15 /* A1 */); // Remember to set R/W to 0 //U8G2_ST7920_128X64_1_SW_SPI u8g2(U8G2_R0, /* clock=*/ 18 /* A4 */ , /* data=*/ 16 /* A2 */, /* CS=*/ 17 /* A3 */, /* reset=*/ U8X8_PIN_NONE); //U8G2_ST7920_128X64_1_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* CS=*/ 10, /* reset=*/ 8); //U8G2_ST7920_128X64_1_HW_SPI u8g2(U8G2_R0, /* CS=*/ 10, /* reset=*/ 8); //U8G2_ST7565_EA_DOGM128_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_EA_DOGM128_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_64128N_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_64128N_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_EA_DOGM132_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ U8X8_PIN_NONE); // DOGM132 Shield //U8G2_ST7565_EA_DOGM132_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ U8X8_PIN_NONE); // DOGM132 Shield //U8G2_ST7565_ZOLEN_128X64_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_ZOLEN_128X64_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_LM6059_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Adafruit ST7565 GLCD //U8G2_ST7565_LM6059_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // Adafruit ST7565 GLCD //U8G2_ST7565_ERC12864_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_ERC12864_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_NHD_C12832_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_NHD_C12832_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_NHD_C12864_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7565_NHD_C12864_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7567_PI_132X64_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 7, /* dc=*/ 9, /* reset=*/ 8); // Pax Instruments Shield, LCD_BL=6 //U8G2_ST7567_PI_132X64_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 7, /* dc=*/ 9, /* reset=*/ 8); // Pax Instruments Shield, LCD_BL=6 //U8G2_ST7567_JLX12864_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 7, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7567_JLX12864_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 7, /* dc=*/ 9, /* reset=*/ 8); //U8G2_NT7534_TG12864R_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_NT7534_TG12864R_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_ST7588_JLX12864_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ 5); //U8G2_ST7588_JLX12864_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ 5); //U8G2_IST3020_ERC19264_1_6800 u8g2(U8G2_R0, 44, 43, 42, 41, 40, 39, 38, 37, /*enable=*/ 28, /*cs=*/ 32, /*dc=*/ 30, /*reset=*/ 31); // Connect WR pin with GND //U8G2_IST3020_ERC19264_1_8080 u8g2(U8G2_R0, 44, 43, 42, 41, 40, 39, 38, 37, /*enable=*/ 29, /*cs=*/ 32, /*dc=*/ 30, /*reset=*/ 31); // Connect RD pin with 3.3V //U8G2_IST3020_ERC19264_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_LC7981_160X80_1_6800 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // Connect RW with GND //U8G2_LC7981_160X160_1_6800 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // Connect RW with GND //U8G2_LC7981_240X128_1_6800 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // Connect RW with GND //U8G2_SED1520_122X32_1 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*dc=*/ A0, /*e1=*/ A3, /*e2=*/ A2, /* reset=*/ A4); // Set R/W to low! //U8G2_T6963_240X128_1_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 17, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // Connect RD with +5V, FS0 and FS1 with GND //U8G2_T6963_256X64_1_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 17, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // Connect RD with +5V, FS0 and FS1 with GND //U8G2_SED1330_240X128_1_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 17, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // Connect /RD = E with +5V, enable is /WR = RW, FG with GND, 14=Uno Pin A0 //U8G2_SED1330_240X128_1_6800 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 17, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // A0 is dc pin, /WR = RW = GND, enable is /RD = E //U8G2_RA8835_NHD_240X128_1_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 17, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // Connect /RD = E with +5V, enable is /WR = RW, FG with GND, 14=Uno Pin A0 //U8G2_RA8835_NHD_240X128_1_6800 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 17, /*cs=*/ 14, /*dc=*/ 15, /*reset=*/ 16); // A0 is dc pin, /WR = RW = GND, enable is /RD = E //U8G2_UC1601_128X32_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_UC1601_128X32_1_3W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* reset=*/ 8); //U8G2_UC1604_JLX19264_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_UC1604_JLX19264_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_UC1608_ERC24064_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // SW SPI, Due ERC24064-1 Test Setup //U8G2_UC1608_ERC240120_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); //U8G2_UC1608_240X128_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // SW SPI, Due ERC24064-1 Test Setup //U8G2_UC1610_EA_DOGXL160_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ U8X8_PIN_NONE); //U8G2_UC1610_EA_DOGXL160_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ U8X8_PIN_NONE); //U8G2_UC1611_EA_DOGM240_1_2ND_HW_I2C u8g2(U8G2_R0, /* reset=*/ 8); // Due, 2nd I2C, DOGM240 Test Board //U8G2_UC1611_EA_DOGM240_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // SW SPI, Due DOGXL240 Test Board //U8G2_UC1611_EA_DOGXL240_1_2ND_HW_I2C u8g2(U8G2_R0, /* reset=*/ 8); // Due, 2nd I2C, DOGXL240 Test Board //U8G2_UC1611_EA_DOGXL240_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // SW SPI, Due DOGXL240 Test Board //U8G2_UC1611_EW50850_1_8080 u8g2(U8G2_R0, 8, 9, 10, 11, 4, 5, 6, 7, /*enable=*/ 18, /*cs=*/ 3, /*dc=*/ 16, /*reset=*/ 16); // 240x160, Connect RD/WR1 pin with 3.3V, CS is aktive high //U8G2_UC1638_160X128_1_4W_HW_SPI u8g2(U8G2_R2, /* cs=*/ 2, /* dc=*/ 3, /* reset=*/ 4); //U8G2_SSD1606_172X72_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // eInk/ePaper Display //U8G2_SSD1607_200X200_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // eInk/ePaper Display, original LUT from embedded artists //U8G2_IL3820_296X128_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // WaveShare 2.9 inch eInk/ePaper Display, enable 16 bit mode for this display! //U8G2_IL3820_V2_296X128_1_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8); // ePaper Display, lesser flickering and faster speed, enable 16 bit mode for this display! // End of constructor list void u8g2_prepare(void) { u8g2.setFont(u8g2_font_6x10_tf); u8g2.setFontRefHeightExtendedText(); u8g2.setDrawColor(1); u8g2.setFontPosTop(); u8g2.setFontDirection(0); } void u8g2_box_title(uint8_t a) { u8g2.drawStr( 10+a*2, 5, ""U8g2""); u8g2.drawStr( 10, 20, ""GraphicsTest""); u8g2.drawFrame(0,0,u8g2.getDisplayWidth(),u8g2.getDisplayHeight() ); } void u8g2_box_frame(uint8_t a) { u8g2.drawStr( 0, 0, ""drawBox""); u8g2.drawBox(5,10,20,10); u8g2.drawBox(10+a,15,30,7); u8g2.drawStr( 0, 30, ""drawFrame""); u8g2.drawFrame(5,10+30,20,10); u8g2.drawFrame(10+a,15+30,30,7); } void u8g2_disc_circle(uint8_t a) { u8g2.drawStr( 0, 0, ""drawDisc""); u8g2.drawDisc(10,18,9); u8g2.drawDisc(24+a,16,7); u8g2.drawStr( 0, 30, ""drawCircle""); u8g2.drawCircle(10,18+30,9); u8g2.drawCircle(24+a,16+30,7); } void u8g2_r_frame(uint8_t a) { u8g2.drawStr( 0, 0, ""drawRFrame/Box""); u8g2.drawRFrame(5, 10,40,30, a+1); u8g2.drawRBox(50, 10,25,40, a+1); } void u8g2_string(uint8_t a) { u8g2.setFontDirection(0); u8g2.drawStr(30+a,31, "" 0""); u8g2.setFontDirection(1); u8g2.drawStr(30,31+a, "" 90""); u8g2.setFontDirection(2); u8g2.drawStr(30-a,31, "" 180""); u8g2.setFontDirection(3); u8g2.drawStr(30,31-a, "" 270""); } void u8g2_line(uint8_t a) { u8g2.drawStr( 0, 0, ""drawLine""); u8g2.drawLine(7+a, 10, 40, 55); u8g2.drawLine(7+a*2, 10, 60, 55); u8g2.drawLine(7+a*3, 10, 80, 55); u8g2.drawLine(7+a*4, 10, 100, 55); } void u8g2_triangle(uint8_t a) { uint16_t offset = a; u8g2.drawStr( 0, 0, ""drawTriangle""); u8g2.drawTriangle(14,7, 45,30, 10,40); u8g2.drawTriangle(14+offset,7-offset, 45+offset,30-offset, 57+offset,10-offset); u8g2.drawTriangle(57+offset*2,10, 45+offset*2,30, 86+offset*2,53); u8g2.drawTriangle(10+offset,40+offset, 45+offset,30+offset, 86+offset,53+offset); } void u8g2_ascii_1() { char s[2] = "" ""; uint8_t x, y; u8g2.drawStr( 0, 0, ""ASCII page 1""); for( y = 0; y < 6; y++ ) { for( x = 0; x < 16; x++ ) { s[0] = y*16 + x + 32; u8g2.drawStr(x*7, y*10+10, s); } } } void u8g2_ascii_2() { char s[2] = "" ""; uint8_t x, y; u8g2.drawStr( 0, 0, ""ASCII page 2""); for( y = 0; y < 6; y++ ) { for( x = 0; x < 16; x++ ) { s[0] = y*16 + x + 160; u8g2.drawStr(x*7, y*10+10, s); } } } void u8g2_extra_page(uint8_t a) { u8g2.drawStr( 0, 0, ""Unicode""); u8g2.setFont(u8g2_font_unifont_t_symbols); u8g2.setFontPosTop(); u8g2.drawUTF8(0, 24, ""☀ ☁""); switch(a) { case 0: case 1: case 2: case 3: u8g2.drawUTF8(a*3, 36, ""☂""); break; case 4: case 5: case 6: case 7: u8g2.drawUTF8(a*3, 36, ""☔""); break; } } void u8g2_xor(uint8_t a) { uint8_t i; u8g2.drawStr( 0, 0, ""XOR""); u8g2.setFontMode(1); u8g2.setDrawColor(2); for( i = 0; i < 5; i++) { u8g2.drawBox(10+i*16, 18 + (i&1)*4, 21,31); } u8g2.drawStr( 5+a, 19, ""XOR XOR XOR XOR""); u8g2.setDrawColor(0); u8g2.drawStr( 5+a, 29, ""CLR CLR CLR CLR""); u8g2.setDrawColor(1); u8g2.drawStr( 5+a, 39, ""SET SET SET SET""); u8g2.setFontMode(0); } #define cross_width 24 #define cross_height 24 static const unsigned char cross_bits[] U8X8_PROGMEM = { 0x00, 0x18, 0x00, 0x00, 0x24, 0x00, 0x00, 0x24, 0x00, 0x00, 0x42, 0x00, 0x00, 0x42, 0x00, 0x00, 0x42, 0x00, 0x00, 0x81, 0x00, 0x00, 0x81, 0x00, 0xC0, 0x00, 0x03, 0x38, 0x3C, 0x1C, 0x06, 0x42, 0x60, 0x01, 0x42, 0x80, 0x01, 0x42, 0x80, 0x06, 0x42, 0x60, 0x38, 0x3C, 0x1C, 0xC0, 0x00, 0x03, 0x00, 0x81, 0x00, 0x00, 0x81, 0x00, 0x00, 0x42, 0x00, 0x00, 0x42, 0x00, 0x00, 0x42, 0x00, 0x00, 0x24, 0x00, 0x00, 0x24, 0x00, 0x00, 0x18, 0x00, }; #define cross_fill_width 24 #define cross_fill_height 24 static const unsigned char cross_fill_bits[] U8X8_PROGMEM = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x18, 0x64, 0x00, 0x26, 0x84, 0x00, 0x21, 0x08, 0x81, 0x10, 0x08, 0x42, 0x10, 0x10, 0x3C, 0x08, 0x20, 0x00, 0x04, 0x40, 0x00, 0x02, 0x80, 0x00, 0x01, 0x80, 0x18, 0x01, 0x80, 0x18, 0x01, 0x80, 0x00, 0x01, 0x40, 0x00, 0x02, 0x20, 0x00, 0x04, 0x10, 0x3C, 0x08, 0x08, 0x42, 0x10, 0x08, 0x81, 0x10, 0x84, 0x00, 0x21, 0x64, 0x00, 0x26, 0x18, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; #define cross_block_width 14 #define cross_block_height 14 static const unsigned char cross_block_bits[] U8X8_PROGMEM = { 0xFF, 0x3F, 0x01, 0x20, 0x01, 0x20, 0x01, 0x20, 0x01, 0x20, 0x01, 0x20, 0xC1, 0x20, 0xC1, 0x20, 0x01, 0x20, 0x01, 0x20, 0x01, 0x20, 0x01, 0x20, 0x01, 0x20, 0xFF, 0x3F, }; void u8g2_bitmap_overlay(uint8_t a) { uint8_t frame_size = 28; u8g2.drawStr(0, 0, ""Bitmap overlay""); u8g2.drawStr(0, frame_size + 12, ""Solid / transparent""); u8g2.setBitmapMode(false /* solid */); u8g2.drawFrame(0, 10, frame_size, frame_size); u8g2.drawXBMP(2, 12, cross_width, cross_height, cross_bits); if(a & 4) u8g2.drawXBMP(7, 17, cross_block_width, cross_block_height, cross_block_bits); u8g2.setBitmapMode(true /* transparent*/); u8g2.drawFrame(frame_size + 5, 10, frame_size, frame_size); u8g2.drawXBMP(frame_size + 7, 12, cross_width, cross_height, cross_bits); if(a & 4) u8g2.drawXBMP(frame_size + 12, 17, cross_block_width, cross_block_height, cross_block_bits); } void u8g2_bitmap_modes(uint8_t transparent) { const uint8_t frame_size = 24; u8g2.drawBox(0, frame_size * 0.5, frame_size * 5, frame_size); u8g2.drawStr(frame_size * 0.5, 50, ""Black""); u8g2.drawStr(frame_size * 2, 50, ""White""); u8g2.drawStr(frame_size * 3.5, 50, ""XOR""); if(!transparent) { u8g2.setBitmapMode(false /* solid */); u8g2.drawStr(0, 0, ""Solid bitmap""); } else { u8g2.setBitmapMode(true /* transparent*/); u8g2.drawStr(0, 0, ""Transparent bitmap""); } u8g2.setDrawColor(0);// Black u8g2.drawXBMP(frame_size * 0.5, 24, cross_width, cross_height, cross_bits); u8g2.setDrawColor(1); // White u8g2.drawXBMP(frame_size * 2, 24, cross_width, cross_height, cross_bits); u8g2.setDrawColor(2); // XOR u8g2.drawXBMP(frame_size * 3.5, 24, cross_width, cross_height, cross_bits); } uint8_t draw_state = 0; void draw(void) { u8g2_prepare(); switch(draw_state >> 3) { case 0: u8g2_box_title(draw_state&7); break; case 1: u8g2_box_frame(draw_state&7); break; case 2: u8g2_disc_circle(draw_state&7); break; case 3: u8g2_r_frame(draw_state&7); break; case 4: u8g2_string(draw_state&7); break; case 5: u8g2_line(draw_state&7); break; case 6: u8g2_triangle(draw_state&7); break; case 7: u8g2_ascii_1(); break; case 8: u8g2_ascii_2(); break; case 9: u8g2_extra_page(draw_state&7); break; case 10: u8g2_xor(draw_state&7); break; case 11: u8g2_bitmap_modes(0); break; case 12: u8g2_bitmap_modes(1); break; case 13: u8g2_bitmap_overlay(draw_state&7); break; } } void setup(void) { /* U8g2 Project: SSD1306 Test Board */ //pinMode(10, OUTPUT); //pinMode(9, OUTPUT); //digitalWrite(10, 0); //digitalWrite(9, 0); /* U8g2 Project: T6963 Test Board */ //pinMode(18, OUTPUT); //digitalWrite(18, 1); /* U8g2 Project: KS0108 Test Board */ //pinMode(16, OUTPUT); //digitalWrite(16, 0); u8g2.begin(); //u8g2.setFlipMode(0); } void loop(void) { // picture loop u8g2.firstPage(); do { draw(); } while( u8g2.nextPage() ); // increase the state draw_state++; if ( draw_state >= 14*8 ) draw_state = 0; // delay between each page delay(150); } ",12428,False,2458.080856129858,median "/**************************************************************************************************************************** Async_ConfigOnSwitch.ino For ESP8266 / ESP32 boards ESPAsync_WiFiManager is a library for the ESP8266/Arduino platform, using (ESP)AsyncWebServer to enable easy configuration and reconfiguration of WiFi credentials using a Captive Portal. Modified from 1. Tzapu (https://github.com/tzapu/WiFiManager) 2. Ken Taylor (https://github.com/kentaylor) 3. Alan Steremberg (https://github.com/alanswx/ESPAsyncWiFiManager) 4. Khoi Hoang (https://github.com/khoih-prog/ESP_WiFiManager) Built by Khoi Hoang https://github.com/khoih-prog/ESPAsync_WiFiManager Licensed under MIT license *****************************************************************************************************************************/ /**************************************************************************************************************************** This example will open a configuration portal when no WiFi configuration has been previously entered or when a button is pushed. It is the easiest scenario for configuration but requires a pin and a button on the ESP8266 device. The Flash button is convenient for this on NodeMCU devices. Also in this example a password is required to connect to the configuration portal network. This is inconvenient but means that only those who know the password or those already connected to the target WiFi network can access the configuration portal and the WiFi network credentials will be sent from the browser over an encrypted connection and can not be read by observers. *****************************************************************************************************************************/ #if !( defined(ESP8266) || defined(ESP32) ) #error This code is intended to run on the ESP8266 or ESP32 platform! Please check your Tools->Board setting. #endif #define ESP_ASYNC_WIFIMANAGER_VERSION_MIN_TARGET ""ESPAsync_WiFiManager v1.9.1"" // Use from 0 to 4. Higher number, more debugging messages and memory usage. #define _ESPASYNC_WIFIMGR_LOGLEVEL_ 3 //For ESP32, To use ESP32 Dev Module, QIO, Flash 4MB/80MHz, Upload 921600 //Ported to ESP32 #ifdef ESP32 #include #include #include // From v1.1.1 #include WiFiMulti wifiMulti; // LittleFS has higher priority than SPIFFS #if ( ARDUINO_ESP32C3_DEV ) // Currently, ESP32-C3 only supporting SPIFFS and EEPROM. Will fix to support LittleFS #define USE_LITTLEFS false #define USE_SPIFFS true #else #define USE_LITTLEFS true #define USE_SPIFFS false #endif #if USE_LITTLEFS // Use LittleFS #include ""FS.h"" // The library has been merged into esp32 core release 1.0.6 #include // https://github.com/lorol/LITTLEFS FS* filesystem = &LITTLEFS; #define FileFS LITTLEFS #define FS_Name ""LittleFS"" #elif USE_SPIFFS #include FS* filesystem = &SPIFFS; #define FileFS SPIFFS #define FS_Name ""SPIFFS"" #else // Use FFat #include FS* filesystem = &FFat; #define FileFS FFat #define FS_Name ""FFat"" #endif ////// #define ESP_getChipId() ((uint32_t)ESP.getEfuseMac()) #define LED_BUILTIN 2 #define LED_ON HIGH #define LED_OFF LOW #else #include //https://github.com/esp8266/Arduino //needed for library #include // From v1.1.0 #include ESP8266WiFiMulti wifiMulti; #define USE_LITTLEFS true #if USE_LITTLEFS #include FS* filesystem = &LittleFS; #define FileFS LittleFS #define FS_Name ""LittleFS"" #else FS* filesystem = &SPIFFS; #define FileFS SPIFFS #define FS_Name ""SPIFFS"" #endif ////// #define ESP_getChipId() (ESP.getChipId()) #define LED_ON LOW #define LED_OFF HIGH #endif #ifdef ESP32 //See file .../hardware/espressif/esp32/variants/(esp32|doitESP32devkitV1)/pins_arduino.h #define LED_BUILTIN 2 // Pin D2 mapped to pin GPIO2/ADC12 of ESP32, control on-board LED #define LED_BUILTIN 2 // Pin D2 mapped to pin GPIO2/ADC12 of ESP32, control on-board LED #define PIN_D0 0 // Pin D0 mapped to pin GPIO0/BOOT/ADC11/TOUCH1 of ESP32 #define PIN_D1 1 // Pin D1 mapped to pin GPIO1/TX0 of ESP32 #define PIN_D2 2 // Pin D2 mapped to pin GPIO2/ADC12/TOUCH2 of ESP32 #define PIN_D3 3 // Pin D3 mapped to pin GPIO3/RX0 of ESP32 #define PIN_D4 4 // Pin D4 mapped to pin GPIO4/ADC10/TOUCH0 of ESP32 #define PIN_D5 5 // Pin D5 mapped to pin GPIO5/SPISS/VSPI_SS of ESP32 #define PIN_D6 6 // Pin D6 mapped to pin GPIO6/FLASH_SCK of ESP32 #define PIN_D7 7 // Pin D7 mapped to pin GPIO7/FLASH_D0 of ESP32 #define PIN_D8 8 // Pin D8 mapped to pin GPIO8/FLASH_D1 of ESP32 #define PIN_D9 9 // Pin D9 mapped to pin GPIO9/FLASH_D2 of ESP32 #define PIN_D10 10 // Pin D10 mapped to pin GPIO10/FLASH_D3 of ESP32 #define PIN_D11 11 // Pin D11 mapped to pin GPIO11/FLASH_CMD of ESP32 #define PIN_D12 12 // Pin D12 mapped to pin GPIO12/HSPI_MISO/ADC15/TOUCH5/TDI of ESP32 #define PIN_D13 13 // Pin D13 mapped to pin GPIO13/HSPI_MOSI/ADC14/TOUCH4/TCK of ESP32 #define PIN_D14 14 // Pin D14 mapped to pin GPIO14/HSPI_SCK/ADC16/TOUCH6/TMS of ESP32 #define PIN_D15 15 // Pin D15 mapped to pin GPIO15/HSPI_SS/ADC13/TOUCH3/TDO of ESP32 #define PIN_D16 16 // Pin D16 mapped to pin GPIO16/TX2 of ESP32 #define PIN_D17 17 // Pin D17 mapped to pin GPIO17/RX2 of ESP32 #define PIN_D18 18 // Pin D18 mapped to pin GPIO18/VSPI_SCK of ESP32 #define PIN_D19 19 // Pin D19 mapped to pin GPIO19/VSPI_MISO of ESP32 #define PIN_D21 21 // Pin D21 mapped to pin GPIO21/SDA of ESP32 #define PIN_D22 22 // Pin D22 mapped to pin GPIO22/SCL of ESP32 #define PIN_D23 23 // Pin D23 mapped to pin GPIO23/VSPI_MOSI of ESP32 #define PIN_D24 24 // Pin D24 mapped to pin GPIO24 of ESP32 #define PIN_D25 25 // Pin D25 mapped to pin GPIO25/ADC18/DAC1 of ESP32 #define PIN_D26 26 // Pin D26 mapped to pin GPIO26/ADC19/DAC2 of ESP32 #define PIN_D27 27 // Pin D27 mapped to pin GPIO27/ADC17/TOUCH7 of ESP32 #define PIN_D32 32 // Pin D32 mapped to pin GPIO32/ADC4/TOUCH9 of ESP32 #define PIN_D33 33 // Pin D33 mapped to pin GPIO33/ADC5/TOUCH8 of ESP32 #define PIN_D34 34 // Pin D34 mapped to pin GPIO34/ADC6 of ESP32 //Only GPIO pin < 34 can be used as output. Pins >= 34 can be only inputs //See .../cores/esp32/esp32-hal-gpio.h/c //#define digitalPinIsValid(pin) ((pin) < 40 && esp32_gpioMux[(pin)].reg) //#define digitalPinCanOutput(pin) ((pin) < 34 && esp32_gpioMux[(pin)].reg) //#define digitalPinToRtcPin(pin) (((pin) < 40)?esp32_gpioMux[(pin)].rtc:-1) //#define digitalPinToAnalogChannel(pin) (((pin) < 40)?esp32_gpioMux[(pin)].adc:-1) //#define digitalPinToTouchChannel(pin) (((pin) < 40)?esp32_gpioMux[(pin)].touch:-1) //#define digitalPinToDacChannel(pin) (((pin) == 25)?0:((pin) == 26)?1:-1) #define PIN_D35 35 // Pin D35 mapped to pin GPIO35/ADC7 of ESP32 #define PIN_D36 36 // Pin D36 mapped to pin GPIO36/ADC0/SVP of ESP32 #define PIN_D39 39 // Pin D39 mapped to pin GPIO39/ADC3/SVN of ESP32 #define PIN_RX0 3 // Pin RX0 mapped to pin GPIO3/RX0 of ESP32 #define PIN_TX0 1 // Pin TX0 mapped to pin GPIO1/TX0 of ESP32 #define PIN_SCL 22 // Pin SCL mapped to pin GPIO22/SCL of ESP32 #define PIN_SDA 21 // Pin SDA mapped to pin GPIO21/SDA of ESP32 #else //PIN_D0 can't be used for PWM/I2C #define PIN_D0 16 // Pin D0 mapped to pin GPIO16/USER/WAKE of ESP8266. This pin is also used for Onboard-Blue LED. PIN_D0 = 0 => LED ON #define PIN_D1 5 // Pin D1 mapped to pin GPIO5 of ESP8266 #define PIN_D2 4 // Pin D2 mapped to pin GPIO4 of ESP8266 #define PIN_D3 0 // Pin D3 mapped to pin GPIO0/FLASH of ESP8266 #define PIN_D4 2 // Pin D4 mapped to pin GPIO2/TXD1 of ESP8266 #define LED_BUILTIN 2 // Pin D4 mapped to pin GPIO2/TXD1 of ESP8266, NodeMCU and WeMoS, control on-board LED #define PIN_D5 14 // Pin D5 mapped to pin GPIO14/HSCLK of ESP8266 #define PIN_D6 12 // Pin D6 mapped to pin GPIO12/HMISO of ESP8266 #define PIN_D7 13 // Pin D7 mapped to pin GPIO13/RXD2/HMOSI of ESP8266 #define PIN_D8 15 // Pin D8 mapped to pin GPIO15/TXD2/HCS of ESP8266 //Don't use pins GPIO6 to GPIO11 as already connected to flash, etc. Use them can crash the program //GPIO9(D11/SD2) and GPIO11 can be used only if flash in DIO mode ( not the default QIO mode) #define PIN_D11 9 // Pin D11/SD2 mapped to pin GPIO9/SDD2 of ESP8266 #define PIN_D12 10 // Pin D12/SD3 mapped to pin GPIO10/SDD3 of ESP8266 #define PIN_SD2 9 // Pin SD2 mapped to pin GPIO9/SDD2 of ESP8266 #define PIN_SD3 10 // Pin SD3 mapped to pin GPIO10/SDD3 of ESP8266 #define PIN_D9 3 // Pin D9 /RX mapped to pin GPIO3/RXD0 of ESP8266 #define PIN_D10 1 // Pin D10/TX mapped to pin GPIO1/TXD0 of ESP8266 #define PIN_RX 3 // Pin RX mapped to pin GPIO3/RXD0 of ESP8266 #define PIN_TX 1 // Pin RX mapped to pin GPIO1/TXD0 of ESP8266 #define LED_PIN 16 // Pin D0 mapped to pin GPIO16 of ESP8266. This pin is also used for Onboard-Blue LED. PIN_D0 = 0 => LED ON #endif //USE_ESP32 #ifdef ESP32 /* Trigger for inititating config mode is Pin D3 and also flash button on NodeMCU Flash button is convenient to use but if it is pressed it will stuff up the serial port device driver until the computer is rebooted on windows machines. */ #if ( USING_ESP32_S2 || USING_ESP32_C3 ) const int TRIGGER_PIN = PIN_D3; // Pin D3 mapped to pin GPIO03/ADC1-2/TOUCH3 of ESP32-S2 /* Alternative trigger pin. Needs to be connected to a button to use this pin. It must be a momentary connection not connected permanently to ground. Either trigger pin will work. */ const int TRIGGER_PIN2 = PIN_D4; // Pin D4 mapped to pin GPIO04/ADC1_3/TOUCH4 of ESP32-S2 #else const int TRIGGER_PIN = PIN_D0; // Pin D0 mapped to pin GPIO0/BOOT/ADC11/TOUCH1 of ESP32 /* Alternative trigger pin. Needs to be connected to a button to use this pin. It must be a momentary connection not connected permanently to ground. Either trigger pin will work. */ const int TRIGGER_PIN2 = PIN_D25; // Pin D25 mapped to pin GPIO25/ADC18/DAC1 of ESP32 #endif #else /* Trigger for inititating config mode is Pin D3 and also flash button on NodeMCU Flash button is convenient to use but if it is pressed it will stuff up the serial port device driver until the computer is rebooted on windows machines. */ const int TRIGGER_PIN = PIN_D3; // D3 on NodeMCU and WeMos. /* Alternative trigger pin. Needs to be connected to a button to use this pin. It must be a momentary connection not connected permanently to ground. Either trigger pin will work. */ const int TRIGGER_PIN2 = PIN_D7; // D7 on NodeMCU and WeMos. #endif // SSID and PW for Config Portal String ssid = ""ESP_"" + String(ESP_getChipId(), HEX); String password; // SSID and PW for your Router String Router_SSID; String Router_Pass; // From v1.1.1 // You only need to format the filesystem once //#define FORMAT_FILESYSTEM true #define FORMAT_FILESYSTEM false #define MIN_AP_PASSWORD_SIZE 8 #define SSID_MAX_LEN 32 //From v1.0.10, WPA2 passwords can be up to 63 characters long. #define PASS_MAX_LEN 64 typedef struct { char wifi_ssid[SSID_MAX_LEN]; char wifi_pw [PASS_MAX_LEN]; } WiFi_Credentials; typedef struct { String wifi_ssid; String wifi_pw; } WiFi_Credentials_String; #define NUM_WIFI_CREDENTIALS 2 // Assuming max 49 chars #define TZNAME_MAX_LEN 50 #define TIMEZONE_MAX_LEN 50 typedef struct { WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS]; char TZ_Name[TZNAME_MAX_LEN]; // ""America/Toronto"" char TZ[TIMEZONE_MAX_LEN]; // ""EST5EDT,M3.2.0,M11.1.0"" uint16_t checksum; } WM_Config; WM_Config WM_config; #define CONFIG_FILENAME F(""/wifi_cred.dat"") ////// // Indicates whether ESP has WiFi credentials saved from previous session, or double reset detected bool initialConfig = false; // Use false if you don't like to display Available Pages in Information Page of Config Portal // Comment out or use true to display Available Pages in Information Page of Config Portal // Must be placed before #include #define USE_AVAILABLE_PAGES true // From v1.0.10 to permit disable/enable StaticIP configuration in Config Portal from sketch. Valid only if DHCP is used. // You'll loose the feature of dynamically changing from DHCP to static IP, or vice versa // You have to explicitly specify false to disable the feature. //#define USE_STATIC_IP_CONFIG_IN_CP false // Use false to disable NTP config. Advisable when using Cellphone, Tablet to access Config Portal. // See Issue 23: On Android phone ConfigPortal is unresponsive (https://github.com/khoih-prog/ESP_WiFiManager/issues/23) #define USE_ESP_WIFIMANAGER_NTP true // Just use enough to save memory. On ESP8266, can cause blank ConfigPortal screen // if using too much memory #define USING_AFRICA false #define USING_AMERICA true #define USING_ANTARCTICA false #define USING_ASIA false #define USING_ATLANTIC false #define USING_AUSTRALIA false #define USING_EUROPE false #define USING_INDIAN false #define USING_PACIFIC false #define USING_ETC_GMT false // Use true to enable CloudFlare NTP service. System can hang if you don't have Internet access while accessing CloudFlare // See Issue #21: CloudFlare link in the default portal (https://github.com/khoih-prog/ESP_WiFiManager/issues/21) #define USE_CLOUDFLARE_NTP false // New in v1.0.11 #define USING_CORS_FEATURE true ////// // Use USE_DHCP_IP == true for dynamic DHCP IP, false to use static IP which you have to change accordingly to your network #if (defined(USE_STATIC_IP_CONFIG_IN_CP) && !USE_STATIC_IP_CONFIG_IN_CP) // Force DHCP to be true #if defined(USE_DHCP_IP) #undef USE_DHCP_IP #endif #define USE_DHCP_IP true #else // You can select DHCP or Static IP here #define USE_DHCP_IP true //#define USE_DHCP_IP false #endif #if ( USE_DHCP_IP ) // Use DHCP #warning Using DHCP IP IPAddress stationIP = IPAddress(0, 0, 0, 0); IPAddress gatewayIP = IPAddress(192, 168, 2, 1); IPAddress netMask = IPAddress(255, 255, 255, 0); #else // Use static IP #warning Using static IP #ifdef ESP32 IPAddress stationIP = IPAddress(192, 168, 2, 232); #else IPAddress stationIP = IPAddress(192, 168, 2, 186); #endif IPAddress gatewayIP = IPAddress(192, 168, 2, 1); IPAddress netMask = IPAddress(255, 255, 255, 0); #endif #define USE_CONFIGURABLE_DNS true IPAddress dns1IP = gatewayIP; IPAddress dns2IP = IPAddress(8, 8, 8, 8); #define USE_CUSTOM_AP_IP false IPAddress APStaticIP = IPAddress(192, 168, 100, 1); IPAddress APStaticGW = IPAddress(192, 168, 100, 1); IPAddress APStaticSN = IPAddress(255, 255, 255, 0); #include //https://github.com/khoih-prog/ESPAsync_WiFiManager #define HTTP_PORT 80 /////////////////////////////////////////// // New in v1.4.0 /****************************************** * // Defined in ESPAsync_WiFiManager.h typedef struct { IPAddress _ap_static_ip; IPAddress _ap_static_gw; IPAddress _ap_static_sn; } WiFi_AP_IPConfig; typedef struct { IPAddress _sta_static_ip; IPAddress _sta_static_gw; IPAddress _sta_static_sn; #if USE_CONFIGURABLE_DNS IPAddress _sta_static_dns1; IPAddress _sta_static_dns2; #endif } WiFi_STA_IPConfig; ******************************************/ WiFi_AP_IPConfig WM_AP_IPconfig; WiFi_STA_IPConfig WM_STA_IPconfig; void initAPIPConfigStruct(WiFi_AP_IPConfig &in_WM_AP_IPconfig) { in_WM_AP_IPconfig._ap_static_ip = APStaticIP; in_WM_AP_IPconfig._ap_static_gw = APStaticGW; in_WM_AP_IPconfig._ap_static_sn = APStaticSN; } void initSTAIPConfigStruct(WiFi_STA_IPConfig &in_WM_STA_IPconfig) { in_WM_STA_IPconfig._sta_static_ip = stationIP; in_WM_STA_IPconfig._sta_static_gw = gatewayIP; in_WM_STA_IPconfig._sta_static_sn = netMask; #if USE_CONFIGURABLE_DNS in_WM_STA_IPconfig._sta_static_dns1 = dns1IP; in_WM_STA_IPconfig._sta_static_dns2 = dns2IP; #endif } void displayIPConfigStruct(WiFi_STA_IPConfig in_WM_STA_IPconfig) { LOGERROR3(F(""stationIP =""), in_WM_STA_IPconfig._sta_static_ip, "", gatewayIP ="", in_WM_STA_IPconfig._sta_static_gw); LOGERROR1(F(""netMask =""), in_WM_STA_IPconfig._sta_static_sn); #if USE_CONFIGURABLE_DNS LOGERROR3(F(""dns1IP =""), in_WM_STA_IPconfig._sta_static_dns1, "", dns2IP ="", in_WM_STA_IPconfig._sta_static_dns2); #endif } void configWiFi(WiFi_STA_IPConfig in_WM_STA_IPconfig) { #if USE_CONFIGURABLE_DNS // Set static IP, Gateway, Subnetmask, DNS1 and DNS2. New in v1.0.5 WiFi.config(in_WM_STA_IPconfig._sta_static_ip, in_WM_STA_IPconfig._sta_static_gw, in_WM_STA_IPconfig._sta_static_sn, in_WM_STA_IPconfig._sta_static_dns1, in_WM_STA_IPconfig._sta_static_dns2); #else // Set static IP, Gateway, Subnetmask, Use auto DNS1 and DNS2. WiFi.config(in_WM_STA_IPconfig._sta_static_ip, in_WM_STA_IPconfig._sta_static_gw, in_WM_STA_IPconfig._sta_static_sn); #endif } /////////////////////////////////////////// uint8_t connectMultiWiFi() { #if ESP32 // For ESP32, this better be 0 to shorten the connect time. // For ESP32-S2/C3, must be > 500 #if ( USING_ESP32_S2 || USING_ESP32_C3 ) #define WIFI_MULTI_1ST_CONNECT_WAITING_MS 500L #else // For ESP32 core v1.0.6, must be >= 500 #define WIFI_MULTI_1ST_CONNECT_WAITING_MS 800L #endif #else // For ESP8266, this better be 2200 to enable connect the 1st time #define WIFI_MULTI_1ST_CONNECT_WAITING_MS 2200L #endif #define WIFI_MULTI_CONNECT_WAITING_MS 500L uint8_t status; WiFi.mode(WIFI_STA); LOGERROR(F(""ConnectMultiWiFi with :"")); if ( (Router_SSID != """") && (Router_Pass != """") ) { LOGERROR3(F(""* Flash-stored Router_SSID = ""), Router_SSID, F("", Router_Pass = ""), Router_Pass ); LOGERROR3(F(""* Add SSID = ""), Router_SSID, F("", PW = ""), Router_Pass ); wifiMulti.addAP(Router_SSID.c_str(), Router_Pass.c_str()); } for (uint8_t i = 0; i < NUM_WIFI_CREDENTIALS; i++) { // Don't permit NULL SSID and password len < MIN_AP_PASSWORD_SIZE (8) if ( (String(WM_config.WiFi_Creds[i].wifi_ssid) != """") && (strlen(WM_config.WiFi_Creds[i].wifi_pw) >= MIN_AP_PASSWORD_SIZE) ) { LOGERROR3(F(""* Additional SSID = ""), WM_config.WiFi_Creds[i].wifi_ssid, F("", PW = ""), WM_config.WiFi_Creds[i].wifi_pw ); } } LOGERROR(F(""Connecting MultiWifi..."")); //WiFi.mode(WIFI_STA); #if !USE_DHCP_IP // New in v1.4.0 configWiFi(WM_STA_IPconfig); ////// #endif int i = 0; status = wifiMulti.run(); delay(WIFI_MULTI_1ST_CONNECT_WAITING_MS); while ( ( i++ < 20 ) && ( status != WL_CONNECTED ) ) { status = wifiMulti.run(); if ( status == WL_CONNECTED ) break; else delay(WIFI_MULTI_CONNECT_WAITING_MS); } if ( status == WL_CONNECTED ) { LOGERROR1(F(""WiFi connected after time: ""), i); LOGERROR3(F(""SSID:""), WiFi.SSID(), F("",RSSI=""), WiFi.RSSI()); LOGERROR3(F(""Channel:""), WiFi.channel(), F("",IP address:""), WiFi.localIP() ); } else { LOGERROR(F(""WiFi not connected"")); #if ESP8266 ESP.reset(); #else ESP.restart(); #endif } return status; } void toggleLED() { //toggle state digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); } #if USE_ESP_WIFIMANAGER_NTP void printLocalTime() { #if ESP8266 static time_t now; now = time(nullptr); if ( now > 1451602800 ) { Serial.print(""Local Date/Time: ""); Serial.print(ctime(&now)); } #else struct tm timeinfo; getLocalTime( &timeinfo ); // Valid only if year > 2000. // You can get from timeinfo : tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec if (timeinfo.tm_year > 100 ) { Serial.print(""Local Date/Time: ""); Serial.print( asctime( &timeinfo ) ); } #endif } #endif void heartBeatPrint() { #if USE_ESP_WIFIMANAGER_NTP printLocalTime(); #else static int num = 1; if (WiFi.status() == WL_CONNECTED) Serial.print(F(""H"")); // H means connected to WiFi else Serial.print(F(""F"")); // F means not connected to WiFi if (num == 80) { Serial.println(); num = 1; } else if (num++ % 10 == 0) { Serial.print(F("" "")); } #endif } void check_WiFi() { if ( (WiFi.status() != WL_CONNECTED) ) { Serial.println(F(""\\nWiFi lost. Call connectMultiWiFi in loop"")); connectMultiWiFi(); } } void check_status() { static ulong checkstatus_timeout = 0; static ulong LEDstatus_timeout = 0; static ulong checkwifi_timeout = 0; static ulong current_millis; #define WIFICHECK_INTERVAL 1000L #if USE_ESP_WIFIMANAGER_NTP #define HEARTBEAT_INTERVAL 60000L #else #define HEARTBEAT_INTERVAL 10000L #endif #define LED_INTERVAL 2000L current_millis = millis(); // Check WiFi every WIFICHECK_INTERVAL (1) seconds. if ((current_millis > checkwifi_timeout) || (checkwifi_timeout == 0)) { check_WiFi(); checkwifi_timeout = current_millis + WIFICHECK_INTERVAL; } if ((current_millis > LEDstatus_timeout) || (LEDstatus_timeout == 0)) { // Toggle LED at LED_INTERVAL = 2s toggleLED(); LEDstatus_timeout = current_millis + LED_INTERVAL; } // Print hearbeat every HEARTBEAT_INTERVAL (10) seconds. if ((current_millis > checkstatus_timeout) || (checkstatus_timeout == 0)) { heartBeatPrint(); checkstatus_timeout = current_millis + HEARTBEAT_INTERVAL; } } int calcChecksum(uint8_t* address, uint16_t sizeToCalc) { uint16_t checkSum = 0; for (uint16_t index = 0; index < sizeToCalc; index++) { checkSum += * ( ( (byte*) address ) + index); } return checkSum; } bool loadConfigData() { File file = FileFS.open(CONFIG_FILENAME, ""r""); LOGERROR(F(""LoadWiFiCfgFile "")); memset((void *) &WM_config, 0, sizeof(WM_config)); // New in v1.4.0 memset((void *) &WM_STA_IPconfig, 0, sizeof(WM_STA_IPconfig)); ////// if (file) { file.readBytes((char *) &WM_config, sizeof(WM_config)); // New in v1.4.0 file.readBytes((char *) &WM_STA_IPconfig, sizeof(WM_STA_IPconfig)); ////// file.close(); LOGERROR(F(""OK"")); if ( WM_config.checksum != calcChecksum( (uint8_t*) &WM_config, sizeof(WM_config) - sizeof(WM_config.checksum) ) ) { LOGERROR(F(""WM_config checksum wrong"")); return false; } // New in v1.4.0 displayIPConfigStruct(WM_STA_IPconfig); ////// return true; } else { LOGERROR(F(""failed"")); return false; } } void saveConfigData() { File file = FileFS.open(CONFIG_FILENAME, ""w""); LOGERROR(F(""SaveWiFiCfgFile "")); if (file) { WM_config.checksum = calcChecksum( (uint8_t*) &WM_config, sizeof(WM_config) - sizeof(WM_config.checksum) ); file.write((uint8_t*) &WM_config, sizeof(WM_config)); displayIPConfigStruct(WM_STA_IPconfig); // New in v1.4.0 file.write((uint8_t*) &WM_STA_IPconfig, sizeof(WM_STA_IPconfig)); ////// file.close(); LOGERROR(F(""OK"")); } else { LOGERROR(F(""failed"")); } } void setup() { //set led pin as output pinMode(LED_BUILTIN, OUTPUT); pinMode(TRIGGER_PIN, INPUT_PULLUP); pinMode(TRIGGER_PIN2, INPUT_PULLUP); Serial.begin(115200); while (!Serial); delay(200); Serial.print(F(""\\nStarting Async_ConfigOnSwitch using "")); Serial.print(FS_Name); Serial.print(F("" on "")); Serial.println(ARDUINO_BOARD); Serial.println(ESP_ASYNC_WIFIMANAGER_VERSION); if ( String(ESP_ASYNC_WIFIMANAGER_VERSION) < ESP_ASYNC_WIFIMANAGER_VERSION_MIN_TARGET ) { Serial.print(""Warning. Must use this example on Version later than : ""); Serial.println(ESP_ASYNC_WIFIMANAGER_VERSION_MIN_TARGET); } Serial.setDebugOutput(false); if (FORMAT_FILESYSTEM) FileFS.format(); // Format FileFS if not yet #ifdef ESP32 if (!FileFS.begin(true)) #else if (!FileFS.begin()) #endif { #ifdef ESP8266 FileFS.format(); #endif Serial.println(F(""SPIFFS/LittleFS failed! Already tried formatting."")); if (!FileFS.begin()) { // prevents debug info from the library to hide err message. delay(100); #if USE_LITTLEFS Serial.println(F(""LittleFS failed!. Please use SPIFFS or EEPROM. Stay forever"")); #else Serial.println(F(""SPIFFS failed!. Please use LittleFS or EEPROM. Stay forever"")); #endif while (true) { delay(1); } } } unsigned long startedAt = millis(); // New in v1.4.0 initAPIPConfigStruct(WM_AP_IPconfig); initSTAIPConfigStruct(WM_STA_IPconfig); ////// digitalWrite(LED_BUILTIN, LED_ON); // turn the LED on by making the voltage LOW to tell us we are in configuration mode. //Local intialization. Once its business is done, there is no need to keep it around // Use this to default DHCP hostname to ESP8266-XXXXXX or ESP32-XXXXXX //ESPAsync_WiFiManager ESPAsync_wifiManager(&webServer, &dnsServer); // Use this to personalize DHCP hostname (RFC952 conformed) AsyncWebServer webServer(HTTP_PORT); #if ( USING_ESP32_S2 || USING_ESP32_C3 ) ESPAsync_WiFiManager ESPAsync_wifiManager(&webServer, NULL, ""AsyncConfigOnSwitch""); #else DNSServer dnsServer; ESPAsync_WiFiManager ESPAsync_wifiManager(&webServer, &dnsServer, ""AsyncConfigOnSwitch""); #endif ESPAsync_wifiManager.setDebugOutput(true); // Use only to erase stored WiFi Credentials //resetSettings(); //ESPAsync_wifiManager.resetSettings(); #if USE_CUSTOM_AP_IP //set custom ip for portal // New in v1.4.0 ESPAsync_wifiManager.setAPStaticIPConfig(WM_AP_IPconfig); ////// #endif ESPAsync_wifiManager.setMinimumSignalQuality(-1); // From v1.0.10 only // Set config portal channel, default = 1. Use 0 => random channel from 1-13 ESPAsync_wifiManager.setConfigPortalChannel(0); ////// #if !USE_DHCP_IP // Set (static IP, Gateway, Subnetmask, DNS1 and DNS2) or (IP, Gateway, Subnetmask). New in v1.0.5 // New in v1.4.0 ESPAsync_wifiManager.setSTAStaticIPConfig(WM_STA_IPconfig); ////// #endif // New from v1.1.1 #if USING_CORS_FEATURE ESPAsync_wifiManager.setCORSHeader(""Your Access-Control-Allow-Origin""); #endif // We can't use WiFi.SSID() in ESP32as it's only valid after connected. // SSID and Password stored in ESP32 wifi_ap_record_t and wifi_config_t are also cleared in reboot // Have to create a new function to store in EEPROM/SPIFFS for this purpose Router_SSID = ESPAsync_wifiManager.WiFi_SSID(); Router_Pass = ESPAsync_wifiManager.WiFi_Pass(); //Remove this line if you do not want to see WiFi password printed Serial.println(""ESP Self-Stored: SSID = "" + Router_SSID + "", Pass = "" + Router_Pass); // SSID to uppercase ssid.toUpperCase(); password = ""My"" + ssid; bool configDataLoaded = false; // From v1.1.0, Don't permit NULL password if ( (Router_SSID != """") && (Router_Pass != """") ) { LOGERROR3(F(""* Add SSID = ""), Router_SSID, F("", PW = ""), Router_Pass); wifiMulti.addAP(Router_SSID.c_str(), Router_Pass.c_str()); ESPAsync_wifiManager.setConfigPortalTimeout(120); //If no access point name has been previously entered disable timeout. Serial.println(F(""Got ESP Self-Stored Credentials. Timeout 120s for Config Portal"")); } if (loadConfigData()) { configDataLoaded = true; ESPAsync_wifiManager.setConfigPortalTimeout(120); //If no access point name has been previously entered disable timeout. Serial.println(F(""Got stored Credentials. Timeout 120s for Config Portal"")); #if USE_ESP_WIFIMANAGER_NTP if ( strlen(WM_config.TZ_Name) > 0 ) { LOGERROR3(F(""Current TZ_Name =""), WM_config.TZ_Name, F("", TZ = ""), WM_config.TZ); #if ESP8266 configTime(WM_config.TZ, ""pool.ntp.org""); #else //configTzTime(WM_config.TZ, ""pool.ntp.org"" ); configTzTime(WM_config.TZ, ""time.nist.gov"", ""0.pool.ntp.org"", ""1.pool.ntp.org""); #endif } else { Serial.println(F(""Current Timezone is not set. Enter Config Portal to set."")); } #endif } else { // Enter CP only if no stored SSID on flash and file Serial.println(F(""Open Config Portal without Timeout: No stored Credentials."")); initialConfig = true; } if (initialConfig) { Serial.print(F(""Starting configuration portal @ "")); #if USE_CUSTOM_AP_IP Serial.print(APStaticIP); #else Serial.print(F(""192.168.4.1"")); #endif Serial.print(F("", SSID = "")); Serial.print(ssid); Serial.print(F("", PWD = "")); Serial.println(password); digitalWrite(LED_BUILTIN, LED_ON); // Turn led on as we are in configuration mode. //sets timeout in seconds until configuration portal gets turned off. //If not specified device will remain in configuration mode until //switched off via webserver or device is restarted. //ESPAsync_wifiManager.setConfigPortalTimeout(600); // Starts an access point if (!ESPAsync_wifiManager.startConfigPortal((const char *) ssid.c_str(), password.c_str())) Serial.println(F(""Not connected to WiFi but continuing anyway."")); else { Serial.println(F(""WiFi connected...yeey :)"")); } // Stored for later usage, from v1.1.0, but clear first memset(&WM_config, 0, sizeof(WM_config)); for (uint8_t i = 0; i < NUM_WIFI_CREDENTIALS; i++) { String tempSSID = ESPAsync_wifiManager.getSSID(i); String tempPW = ESPAsync_wifiManager.getPW(i); if (strlen(tempSSID.c_str()) < sizeof(WM_config.WiFi_Creds[i].wifi_ssid) - 1) strcpy(WM_config.WiFi_Creds[i].wifi_ssid, tempSSID.c_str()); else strncpy(WM_config.WiFi_Creds[i].wifi_ssid, tempSSID.c_str(), sizeof(WM_config.WiFi_Creds[i].wifi_ssid) - 1); if (strlen(tempPW.c_str()) < sizeof(WM_config.WiFi_Creds[i].wifi_pw) - 1) strcpy(WM_config.WiFi_Creds[i].wifi_pw, tempPW.c_str()); else strncpy(WM_config.WiFi_Creds[i].wifi_pw, tempPW.c_str(), sizeof(WM_config.WiFi_Creds[i].wifi_pw) - 1); // Don't permit NULL SSID and password len < MIN_AP_PASSWORD_SIZE (8) if ( (String(WM_config.WiFi_Creds[i].wifi_ssid) != """") && (strlen(WM_config.WiFi_Creds[i].wifi_pw) >= MIN_AP_PASSWORD_SIZE) ) { LOGERROR3(F(""* Add SSID = ""), WM_config.WiFi_Creds[i].wifi_ssid, F("", PW = ""), WM_config.WiFi_Creds[i].wifi_pw ); wifiMulti.addAP(WM_config.WiFi_Creds[i].wifi_ssid, WM_config.WiFi_Creds[i].wifi_pw); } } #if USE_ESP_WIFIMANAGER_NTP String tempTZ = ESPAsync_wifiManager.getTimezoneName(); if (strlen(tempTZ.c_str()) < sizeof(WM_config.TZ_Name) - 1) strcpy(WM_config.TZ_Name, tempTZ.c_str()); else strncpy(WM_config.TZ_Name, tempTZ.c_str(), sizeof(WM_config.TZ_Name) - 1); const char * TZ_Result = ESPAsync_wifiManager.getTZ(WM_config.TZ_Name); if (strlen(TZ_Result) < sizeof(WM_config.TZ) - 1) strcpy(WM_config.TZ, TZ_Result); else strncpy(WM_config.TZ, TZ_Result, sizeof(WM_config.TZ_Name) - 1); if ( strlen(WM_config.TZ_Name) > 0 ) { LOGERROR3(F(""Saving current TZ_Name =""), WM_config.TZ_Name, F("", TZ = ""), WM_config.TZ); #if ESP8266 configTime(WM_config.TZ, ""pool.ntp.org""); #else //configTzTime(WM_config.TZ, ""pool.ntp.org"" ); configTzTime(WM_config.TZ, ""time.nist.gov"", ""0.pool.ntp.org"", ""1.pool.ntp.org""); #endif } else { LOGERROR(F(""Current Timezone Name is not set. Enter Config Portal to set."")); } #endif // New in v1.4.0 ESPAsync_wifiManager.getSTAStaticIPConfig(WM_STA_IPconfig); ////// saveConfigData(); } digitalWrite(LED_BUILTIN, LED_OFF); // Turn led off as we are not in configuration mode. startedAt = millis(); if (!initialConfig) { // Load stored data, the addAP ready for MultiWiFi reconnection if (!configDataLoaded) loadConfigData(); for (uint8_t i = 0; i < NUM_WIFI_CREDENTIALS; i++) { // Don't permit NULL SSID and password len < MIN_AP_PASSWORD_SIZE (8) if ( (String(WM_config.WiFi_Creds[i].wifi_ssid) != """") && (strlen(WM_config.WiFi_Creds[i].wifi_pw) >= MIN_AP_PASSWORD_SIZE) ) { LOGERROR3(F(""* Add SSID = ""), WM_config.WiFi_Creds[i].wifi_ssid, F("", PW = ""), WM_config.WiFi_Creds[i].wifi_pw ); wifiMulti.addAP(WM_config.WiFi_Creds[i].wifi_ssid, WM_config.WiFi_Creds[i].wifi_pw); } } if ( WiFi.status() != WL_CONNECTED ) { Serial.println(F(""ConnectMultiWiFi in setup"")); connectMultiWiFi(); } } Serial.print(F(""After waiting "")); Serial.print((float) (millis() - startedAt) / 1000); Serial.print(F("" secs more in setup(), connection result is "")); if (WiFi.status() == WL_CONNECTED) { Serial.print(F(""connected. Local IP: "")); Serial.println(WiFi.localIP()); } else Serial.println(ESPAsync_wifiManager.getStatus(WiFi.status())); } void loop() { // is configuration portal requested? if ((digitalRead(TRIGGER_PIN) == LOW) || (digitalRead(TRIGGER_PIN2) == LOW)) { Serial.println(F(""\\nConfiguration portal requested."")); digitalWrite(LED_BUILTIN, LED_ON); // turn the LED on by making the voltage LOW to tell us we are in configuration mode. //Local intialization. Once its business is done, there is no need to keep it around // Use this to default DHCP hostname to ESP8266-XXXXXX or ESP32-XXXXXX //ESPAsync_WiFiManager ESPAsync_wifiManager(&webServer, &dnsServer); // Use this to personalize DHCP hostname (RFC952 conformed) AsyncWebServer webServer(HTTP_PORT); #if ( USING_ESP32_S2 || USING_ESP32_C3 ) ESPAsync_WiFiManager ESPAsync_wifiManager(&webServer, NULL, ""ConfigOnSwitch""); #else DNSServer dnsServer; ESPAsync_WiFiManager ESPAsync_wifiManager(&webServer, &dnsServer, ""ConfigOnSwitch""); #endif ESPAsync_wifiManager.setMinimumSignalQuality(-1); // From v1.0.10 only // Set config portal channel, default = 1. Use 0 => random channel from 1-13 ESPAsync_wifiManager.setConfigPortalChannel(0); ////// //set custom ip for portal //ESPAsync_wifiManager.setAPStaticIPConfig(IPAddress(192, 168, 100, 1), IPAddress(192, 168, 100, 1), IPAddress(255, 255, 255, 0)); #if !USE_DHCP_IP #if USE_CONFIGURABLE_DNS // Set static IP, Gateway, Subnetmask, DNS1 and DNS2. New in v1.0.5 ESPAsync_wifiManager.setSTAStaticIPConfig(stationIP, gatewayIP, netMask, dns1IP, dns2IP); #else // Set static IP, Gateway, Subnetmask, Use auto DNS1 and DNS2. ESPAsync_wifiManager.setSTAStaticIPConfig(stationIP, gatewayIP, netMask); #endif #endif // New from v1.1.1 #if USING_CORS_FEATURE ESPAsync_wifiManager.setCORSHeader(""Your Access-Control-Allow-Origin""); #endif //Check if there is stored WiFi router/password credentials. //If not found, device will remain in configuration mode until switched off via webserver. Serial.println(F(""Opening configuration portal. "")); Router_SSID = ESPAsync_wifiManager.WiFi_SSID(); Router_Pass = ESPAsync_wifiManager.WiFi_Pass(); //Remove this line if you do not want to see WiFi password printed Serial.println(""ESP Self-Stored: SSID = "" + Router_SSID + "", Pass = "" + Router_Pass); // From v1.1.0, Don't permit NULL password if ( (Router_SSID != """") && (Router_Pass != """") ) { LOGERROR3(F(""* Add SSID = ""), Router_SSID, F("", PW = ""), Router_Pass); wifiMulti.addAP(Router_SSID.c_str(), Router_Pass.c_str()); ESPAsync_wifiManager.setConfigPortalTimeout(120); //If no access point name has been previously entered disable timeout. Serial.println(F(""Got ESP Self-Stored Credentials. Timeout 120s for Config Portal"")); } else if (loadConfigData()) { ESPAsync_wifiManager.setConfigPortalTimeout(120); //If no access point name has been previously entered disable timeout. Serial.println(F(""Got stored Credentials. Timeout 120s for Config Portal"")); } else { // Enter CP only if no stored SSID on flash and file Serial.println(F(""Open Config Portal without Timeout: No stored Credentials."")); initialConfig = true; } //Starts an access point //and goes into a blocking loop awaiting configuration if (!ESPAsync_wifiManager.startConfigPortal((const char *) ssid.c_str(), password.c_str())) { Serial.println(F(""Not connected to WiFi but continuing anyway."")); } else { //if you get here you have connected to the WiFi Serial.println(F(""connected...yeey :)"")); Serial.print(F(""Local IP: "")); Serial.println(WiFi.localIP()); } // Only clear then save data if CP entered and with new valid Credentials // No CP => stored getSSID() = """" if ( String(ESPAsync_wifiManager.getSSID(0)) != """" && String(ESPAsync_wifiManager.getSSID(1)) != """" ) { // Stored for later usage, from v1.1.0, but clear first memset(&WM_config, 0, sizeof(WM_config)); for (uint8_t i = 0; i < NUM_WIFI_CREDENTIALS; i++) { String tempSSID = ESPAsync_wifiManager.getSSID(i); String tempPW = ESPAsync_wifiManager.getPW(i); if (strlen(tempSSID.c_str()) < sizeof(WM_config.WiFi_Creds[i].wifi_ssid) - 1) strcpy(WM_config.WiFi_Creds[i].wifi_ssid, tempSSID.c_str()); else strncpy(WM_config.WiFi_Creds[i].wifi_ssid, tempSSID.c_str(), sizeof(WM_config.WiFi_Creds[i].wifi_ssid) - 1); if (strlen(tempPW.c_str()) < sizeof(WM_config.WiFi_Creds[i].wifi_pw) - 1) strcpy(WM_config.WiFi_Creds[i].wifi_pw, tempPW.c_str()); else strncpy(WM_config.WiFi_Creds[i].wifi_pw, tempPW.c_str(), sizeof(WM_config.WiFi_Creds[i].wifi_pw) - 1); // Don't permit NULL SSID and password len < MIN_AP_PASSWORD_SIZE (8) if ( (String(WM_config.WiFi_Creds[i].wifi_ssid) != """") && (strlen(WM_config.WiFi_Creds[i].wifi_pw) >= MIN_AP_PASSWORD_SIZE) ) { LOGERROR3(F(""* Add SSID = ""), WM_config.WiFi_Creds[i].wifi_ssid, F("", PW = ""), WM_config.WiFi_Creds[i].wifi_pw ); wifiMulti.addAP(WM_config.WiFi_Creds[i].wifi_ssid, WM_config.WiFi_Creds[i].wifi_pw); } } #if USE_ESP_WIFIMANAGER_NTP String tempTZ = ESPAsync_wifiManager.getTimezoneName(); if (strlen(tempTZ.c_str()) < sizeof(WM_config.TZ_Name) - 1) strcpy(WM_config.TZ_Name, tempTZ.c_str()); else strncpy(WM_config.TZ_Name, tempTZ.c_str(), sizeof(WM_config.TZ_Name) - 1); const char * TZ_Result = ESPAsync_wifiManager.getTZ(WM_config.TZ_Name); if (strlen(TZ_Result) < sizeof(WM_config.TZ) - 1) strcpy(WM_config.TZ, TZ_Result); else strncpy(WM_config.TZ, TZ_Result, sizeof(WM_config.TZ_Name) - 1); if ( strlen(WM_config.TZ_Name) > 0 ) { LOGERROR3(F(""Saving current TZ_Name =""), WM_config.TZ_Name, F("", TZ = ""), WM_config.TZ); #if ESP8266 configTime(WM_config.TZ, ""pool.ntp.org""); #else //configTzTime(WM_config.TZ, ""pool.ntp.org"" ); configTzTime(WM_config.TZ, ""time.nist.gov"", ""0.pool.ntp.org"", ""1.pool.ntp.org""); #endif } else { LOGERROR(F(""Current Timezone Name is not set. Enter Config Portal to set."")); } #endif // New in v1.4.0 ESPAsync_wifiManager.getSTAStaticIPConfig(WM_STA_IPconfig); ////// saveConfigData(); } digitalWrite(LED_BUILTIN, LED_OFF); // Turn led off as we are not in configuration mode. } // put your main code here, to run repeatedly check_status(); } ",12196,False,2037.4038927875165,median "/**************************************************************************************************************************** Async_ConfigOnSwitch.ino For ESP8266 / ESP32 boards ESPAsync_WiFiManager is a library for the ESP8266/Arduino platform, using (ESP)AsyncWebServer to enable easy configuration and reconfiguration of WiFi credentials using a Captive Portal. Modified from 1. Tzapu (https://github.com/tzapu/WiFiManager) 2. Ken Taylor (https://github.com/kentaylor) 3. Alan Steremberg (https://github.com/alanswx/ESPAsyncWiFiManager) 4. Khoi Hoang (https://github.com/khoih-prog/ESP_WiFiManager) Built by Khoi Hoang https://github.com/khoih-prog/ESPAsync_WiFiManager Licensed under MIT license *****************************************************************************************************************************/ /**************************************************************************************************************************** This example will open a configuration portal when no WiFi configuration has been previously entered or when a button is pushed. It is the easiest scenario for configuration but requires a pin and a button on the ESP8266 device. The Flash button is convenient for this on NodeMCU devices. Also in this example a password is required to connect to the configuration portal network. This is inconvenient but means that only those who know the password or those already connected to the target WiFi network can access the configuration portal and the WiFi network credentials will be sent from the browser over an encrypted connection and can not be read by observers. *****************************************************************************************************************************/ #if !( defined(ESP8266) || defined(ESP32) ) #error This code is intended to run on the ESP8266 or ESP32 platform! Please check your Tools->Board setting. #endif #define ESP_ASYNC_WIFIMANAGER_VERSION_MIN_TARGET ""ESPAsync_WiFiManager v1.9.2"" // Use from 0 to 4. Higher number, more debugging messages and memory usage. #define _ESPASYNC_WIFIMGR_LOGLEVEL_ 3 //For ESP32, To use ESP32 Dev Module, QIO, Flash 4MB/80MHz, Upload 921600 //Ported to ESP32 #ifdef ESP32 #include #include #include // From v1.1.1 #include WiFiMulti wifiMulti; // LittleFS has higher priority than SPIFFS #if ( ARDUINO_ESP32C3_DEV ) // Currently, ESP32-C3 only supporting SPIFFS and EEPROM. Will fix to support LittleFS #define USE_LITTLEFS false #define USE_SPIFFS true #else #define USE_LITTLEFS true #define USE_SPIFFS false #endif #if USE_LITTLEFS // Use LittleFS #include ""FS.h"" // The library has been merged into esp32 core release 1.0.6 #include // https://github.com/lorol/LITTLEFS FS* filesystem = &LITTLEFS; #define FileFS LITTLEFS #define FS_Name ""LittleFS"" #elif USE_SPIFFS #include FS* filesystem = &SPIFFS; #define FileFS SPIFFS #define FS_Name ""SPIFFS"" #else // Use FFat #include FS* filesystem = &FFat; #define FileFS FFat #define FS_Name ""FFat"" #endif ////// #define ESP_getChipId() ((uint32_t)ESP.getEfuseMac()) #define LED_BUILTIN 2 #define LED_ON HIGH #define LED_OFF LOW #else #include //https://github.com/esp8266/Arduino //needed for library #include // From v1.1.0 #include ESP8266WiFiMulti wifiMulti; #define USE_LITTLEFS true #if USE_LITTLEFS #include FS* filesystem = &LittleFS; #define FileFS LittleFS #define FS_Name ""LittleFS"" #else FS* filesystem = &SPIFFS; #define FileFS SPIFFS #define FS_Name ""SPIFFS"" #endif ////// #define ESP_getChipId() (ESP.getChipId()) #define LED_ON LOW #define LED_OFF HIGH #endif #ifdef ESP32 //See file .../hardware/espressif/esp32/variants/(esp32|doitESP32devkitV1)/pins_arduino.h #define LED_BUILTIN 2 // Pin D2 mapped to pin GPIO2/ADC12 of ESP32, control on-board LED #define LED_BUILTIN 2 // Pin D2 mapped to pin GPIO2/ADC12 of ESP32, control on-board LED #define PIN_D0 0 // Pin D0 mapped to pin GPIO0/BOOT/ADC11/TOUCH1 of ESP32 #define PIN_D1 1 // Pin D1 mapped to pin GPIO1/TX0 of ESP32 #define PIN_D2 2 // Pin D2 mapped to pin GPIO2/ADC12/TOUCH2 of ESP32 #define PIN_D3 3 // Pin D3 mapped to pin GPIO3/RX0 of ESP32 #define PIN_D4 4 // Pin D4 mapped to pin GPIO4/ADC10/TOUCH0 of ESP32 #define PIN_D5 5 // Pin D5 mapped to pin GPIO5/SPISS/VSPI_SS of ESP32 #define PIN_D6 6 // Pin D6 mapped to pin GPIO6/FLASH_SCK of ESP32 #define PIN_D7 7 // Pin D7 mapped to pin GPIO7/FLASH_D0 of ESP32 #define PIN_D8 8 // Pin D8 mapped to pin GPIO8/FLASH_D1 of ESP32 #define PIN_D9 9 // Pin D9 mapped to pin GPIO9/FLASH_D2 of ESP32 #define PIN_D10 10 // Pin D10 mapped to pin GPIO10/FLASH_D3 of ESP32 #define PIN_D11 11 // Pin D11 mapped to pin GPIO11/FLASH_CMD of ESP32 #define PIN_D12 12 // Pin D12 mapped to pin GPIO12/HSPI_MISO/ADC15/TOUCH5/TDI of ESP32 #define PIN_D13 13 // Pin D13 mapped to pin GPIO13/HSPI_MOSI/ADC14/TOUCH4/TCK of ESP32 #define PIN_D14 14 // Pin D14 mapped to pin GPIO14/HSPI_SCK/ADC16/TOUCH6/TMS of ESP32 #define PIN_D15 15 // Pin D15 mapped to pin GPIO15/HSPI_SS/ADC13/TOUCH3/TDO of ESP32 #define PIN_D16 16 // Pin D16 mapped to pin GPIO16/TX2 of ESP32 #define PIN_D17 17 // Pin D17 mapped to pin GPIO17/RX2 of ESP32 #define PIN_D18 18 // Pin D18 mapped to pin GPIO18/VSPI_SCK of ESP32 #define PIN_D19 19 // Pin D19 mapped to pin GPIO19/VSPI_MISO of ESP32 #define PIN_D21 21 // Pin D21 mapped to pin GPIO21/SDA of ESP32 #define PIN_D22 22 // Pin D22 mapped to pin GPIO22/SCL of ESP32 #define PIN_D23 23 // Pin D23 mapped to pin GPIO23/VSPI_MOSI of ESP32 #define PIN_D24 24 // Pin D24 mapped to pin GPIO24 of ESP32 #define PIN_D25 25 // Pin D25 mapped to pin GPIO25/ADC18/DAC1 of ESP32 #define PIN_D26 26 // Pin D26 mapped to pin GPIO26/ADC19/DAC2 of ESP32 #define PIN_D27 27 // Pin D27 mapped to pin GPIO27/ADC17/TOUCH7 of ESP32 #define PIN_D32 32 // Pin D32 mapped to pin GPIO32/ADC4/TOUCH9 of ESP32 #define PIN_D33 33 // Pin D33 mapped to pin GPIO33/ADC5/TOUCH8 of ESP32 #define PIN_D34 34 // Pin D34 mapped to pin GPIO34/ADC6 of ESP32 //Only GPIO pin < 34 can be used as output. Pins >= 34 can be only inputs //See .../cores/esp32/esp32-hal-gpio.h/c //#define digitalPinIsValid(pin) ((pin) < 40 && esp32_gpioMux[(pin)].reg) //#define digitalPinCanOutput(pin) ((pin) < 34 && esp32_gpioMux[(pin)].reg) //#define digitalPinToRtcPin(pin) (((pin) < 40)?esp32_gpioMux[(pin)].rtc:-1) //#define digitalPinToAnalogChannel(pin) (((pin) < 40)?esp32_gpioMux[(pin)].adc:-1) //#define digitalPinToTouchChannel(pin) (((pin) < 40)?esp32_gpioMux[(pin)].touch:-1) //#define digitalPinToDacChannel(pin) (((pin) == 25)?0:((pin) == 26)?1:-1) #define PIN_D35 35 // Pin D35 mapped to pin GPIO35/ADC7 of ESP32 #define PIN_D36 36 // Pin D36 mapped to pin GPIO36/ADC0/SVP of ESP32 #define PIN_D39 39 // Pin D39 mapped to pin GPIO39/ADC3/SVN of ESP32 #define PIN_RX0 3 // Pin RX0 mapped to pin GPIO3/RX0 of ESP32 #define PIN_TX0 1 // Pin TX0 mapped to pin GPIO1/TX0 of ESP32 #define PIN_SCL 22 // Pin SCL mapped to pin GPIO22/SCL of ESP32 #define PIN_SDA 21 // Pin SDA mapped to pin GPIO21/SDA of ESP32 #else //PIN_D0 can't be used for PWM/I2C #define PIN_D0 16 // Pin D0 mapped to pin GPIO16/USER/WAKE of ESP8266. This pin is also used for Onboard-Blue LED. PIN_D0 = 0 => LED ON #define PIN_D1 5 // Pin D1 mapped to pin GPIO5 of ESP8266 #define PIN_D2 4 // Pin D2 mapped to pin GPIO4 of ESP8266 #define PIN_D3 0 // Pin D3 mapped to pin GPIO0/FLASH of ESP8266 #define PIN_D4 2 // Pin D4 mapped to pin GPIO2/TXD1 of ESP8266 #define LED_BUILTIN 2 // Pin D4 mapped to pin GPIO2/TXD1 of ESP8266, NodeMCU and WeMoS, control on-board LED #define PIN_D5 14 // Pin D5 mapped to pin GPIO14/HSCLK of ESP8266 #define PIN_D6 12 // Pin D6 mapped to pin GPIO12/HMISO of ESP8266 #define PIN_D7 13 // Pin D7 mapped to pin GPIO13/RXD2/HMOSI of ESP8266 #define PIN_D8 15 // Pin D8 mapped to pin GPIO15/TXD2/HCS of ESP8266 //Don't use pins GPIO6 to GPIO11 as already connected to flash, etc. Use them can crash the program //GPIO9(D11/SD2) and GPIO11 can be used only if flash in DIO mode ( not the default QIO mode) #define PIN_D11 9 // Pin D11/SD2 mapped to pin GPIO9/SDD2 of ESP8266 #define PIN_D12 10 // Pin D12/SD3 mapped to pin GPIO10/SDD3 of ESP8266 #define PIN_SD2 9 // Pin SD2 mapped to pin GPIO9/SDD2 of ESP8266 #define PIN_SD3 10 // Pin SD3 mapped to pin GPIO10/SDD3 of ESP8266 #define PIN_D9 3 // Pin D9 /RX mapped to pin GPIO3/RXD0 of ESP8266 #define PIN_D10 1 // Pin D10/TX mapped to pin GPIO1/TXD0 of ESP8266 #define PIN_RX 3 // Pin RX mapped to pin GPIO3/RXD0 of ESP8266 #define PIN_TX 1 // Pin RX mapped to pin GPIO1/TXD0 of ESP8266 #define LED_PIN 16 // Pin D0 mapped to pin GPIO16 of ESP8266. This pin is also used for Onboard-Blue LED. PIN_D0 = 0 => LED ON #endif //USE_ESP32 #ifdef ESP32 /* Trigger for inititating config mode is Pin D3 and also flash button on NodeMCU Flash button is convenient to use but if it is pressed it will stuff up the serial port device driver until the computer is rebooted on windows machines. */ #if ( USING_ESP32_S2 || USING_ESP32_C3 ) const int TRIGGER_PIN = PIN_D3; // Pin D3 mapped to pin GPIO03/ADC1-2/TOUCH3 of ESP32-S2 /* Alternative trigger pin. Needs to be connected to a button to use this pin. It must be a momentary connection not connected permanently to ground. Either trigger pin will work. */ const int TRIGGER_PIN2 = PIN_D4; // Pin D4 mapped to pin GPIO04/ADC1_3/TOUCH4 of ESP32-S2 #else const int TRIGGER_PIN = PIN_D0; // Pin D0 mapped to pin GPIO0/BOOT/ADC11/TOUCH1 of ESP32 /* Alternative trigger pin. Needs to be connected to a button to use this pin. It must be a momentary connection not connected permanently to ground. Either trigger pin will work. */ const int TRIGGER_PIN2 = PIN_D25; // Pin D25 mapped to pin GPIO25/ADC18/DAC1 of ESP32 #endif #else /* Trigger for inititating config mode is Pin D3 and also flash button on NodeMCU Flash button is convenient to use but if it is pressed it will stuff up the serial port device driver until the computer is rebooted on windows machines. */ const int TRIGGER_PIN = PIN_D3; // D3 on NodeMCU and WeMos. /* Alternative trigger pin. Needs to be connected to a button to use this pin. It must be a momentary connection not connected permanently to ground. Either trigger pin will work. */ const int TRIGGER_PIN2 = PIN_D7; // D7 on NodeMCU and WeMos. #endif // SSID and PW for Config Portal String ssid = ""ESP_"" + String(ESP_getChipId(), HEX); String password; // SSID and PW for your Router String Router_SSID; String Router_Pass; // From v1.1.1 // You only need to format the filesystem once //#define FORMAT_FILESYSTEM true #define FORMAT_FILESYSTEM false #define MIN_AP_PASSWORD_SIZE 8 #define SSID_MAX_LEN 32 //From v1.0.10, WPA2 passwords can be up to 63 characters long. #define PASS_MAX_LEN 64 typedef struct { char wifi_ssid[SSID_MAX_LEN]; char wifi_pw [PASS_MAX_LEN]; } WiFi_Credentials; typedef struct { String wifi_ssid; String wifi_pw; } WiFi_Credentials_String; #define NUM_WIFI_CREDENTIALS 2 // Assuming max 49 chars #define TZNAME_MAX_LEN 50 #define TIMEZONE_MAX_LEN 50 typedef struct { WiFi_Credentials WiFi_Creds [NUM_WIFI_CREDENTIALS]; char TZ_Name[TZNAME_MAX_LEN]; // ""America/Toronto"" char TZ[TIMEZONE_MAX_LEN]; // ""EST5EDT,M3.2.0,M11.1.0"" uint16_t checksum; } WM_Config; WM_Config WM_config; #define CONFIG_FILENAME F(""/wifi_cred.dat"") ////// // Indicates whether ESP has WiFi credentials saved from previous session, or double reset detected bool initialConfig = false; // Use false if you don't like to display Available Pages in Information Page of Config Portal // Comment out or use true to display Available Pages in Information Page of Config Portal // Must be placed before #include #define USE_AVAILABLE_PAGES true // From v1.0.10 to permit disable/enable StaticIP configuration in Config Portal from sketch. Valid only if DHCP is used. // You'll loose the feature of dynamically changing from DHCP to static IP, or vice versa // You have to explicitly specify false to disable the feature. //#define USE_STATIC_IP_CONFIG_IN_CP false // Use false to disable NTP config. Advisable when using Cellphone, Tablet to access Config Portal. // See Issue 23: On Android phone ConfigPortal is unresponsive (https://github.com/khoih-prog/ESP_WiFiManager/issues/23) #define USE_ESP_WIFIMANAGER_NTP true // Just use enough to save memory. On ESP8266, can cause blank ConfigPortal screen // if using too much memory #define USING_AFRICA false #define USING_AMERICA true #define USING_ANTARCTICA false #define USING_ASIA false #define USING_ATLANTIC false #define USING_AUSTRALIA false #define USING_EUROPE false #define USING_INDIAN false #define USING_PACIFIC false #define USING_ETC_GMT false // Use true to enable CloudFlare NTP service. System can hang if you don't have Internet access while accessing CloudFlare // See Issue #21: CloudFlare link in the default portal (https://github.com/khoih-prog/ESP_WiFiManager/issues/21) #define USE_CLOUDFLARE_NTP false // New in v1.0.11 #define USING_CORS_FEATURE true ////// // Use USE_DHCP_IP == true for dynamic DHCP IP, false to use static IP which you have to change accordingly to your network #if (defined(USE_STATIC_IP_CONFIG_IN_CP) && !USE_STATIC_IP_CONFIG_IN_CP) // Force DHCP to be true #if defined(USE_DHCP_IP) #undef USE_DHCP_IP #endif #define USE_DHCP_IP true #else // You can select DHCP or Static IP here #define USE_DHCP_IP true //#define USE_DHCP_IP false #endif #if ( USE_DHCP_IP ) // Use DHCP #warning Using DHCP IP IPAddress stationIP = IPAddress(0, 0, 0, 0); IPAddress gatewayIP = IPAddress(192, 168, 2, 1); IPAddress netMask = IPAddress(255, 255, 255, 0); #else // Use static IP #warning Using static IP #ifdef ESP32 IPAddress stationIP = IPAddress(192, 168, 2, 232); #else IPAddress stationIP = IPAddress(192, 168, 2, 186); #endif IPAddress gatewayIP = IPAddress(192, 168, 2, 1); IPAddress netMask = IPAddress(255, 255, 255, 0); #endif #define USE_CONFIGURABLE_DNS true IPAddress dns1IP = gatewayIP; IPAddress dns2IP = IPAddress(8, 8, 8, 8); #define USE_CUSTOM_AP_IP false IPAddress APStaticIP = IPAddress(192, 168, 100, 1); IPAddress APStaticGW = IPAddress(192, 168, 100, 1); IPAddress APStaticSN = IPAddress(255, 255, 255, 0); #include //https://github.com/khoih-prog/ESPAsync_WiFiManager #define HTTP_PORT 80 /////////////////////////////////////////// // New in v1.4.0 /****************************************** * // Defined in ESPAsync_WiFiManager.h typedef struct { IPAddress _ap_static_ip; IPAddress _ap_static_gw; IPAddress _ap_static_sn; } WiFi_AP_IPConfig; typedef struct { IPAddress _sta_static_ip; IPAddress _sta_static_gw; IPAddress _sta_static_sn; #if USE_CONFIGURABLE_DNS IPAddress _sta_static_dns1; IPAddress _sta_static_dns2; #endif } WiFi_STA_IPConfig; ******************************************/ WiFi_AP_IPConfig WM_AP_IPconfig; WiFi_STA_IPConfig WM_STA_IPconfig; void initAPIPConfigStruct(WiFi_AP_IPConfig &in_WM_AP_IPconfig) { in_WM_AP_IPconfig._ap_static_ip = APStaticIP; in_WM_AP_IPconfig._ap_static_gw = APStaticGW; in_WM_AP_IPconfig._ap_static_sn = APStaticSN; } void initSTAIPConfigStruct(WiFi_STA_IPConfig &in_WM_STA_IPconfig) { in_WM_STA_IPconfig._sta_static_ip = stationIP; in_WM_STA_IPconfig._sta_static_gw = gatewayIP; in_WM_STA_IPconfig._sta_static_sn = netMask; #if USE_CONFIGURABLE_DNS in_WM_STA_IPconfig._sta_static_dns1 = dns1IP; in_WM_STA_IPconfig._sta_static_dns2 = dns2IP; #endif } void displayIPConfigStruct(WiFi_STA_IPConfig in_WM_STA_IPconfig) { LOGERROR3(F(""stationIP =""), in_WM_STA_IPconfig._sta_static_ip, "", gatewayIP ="", in_WM_STA_IPconfig._sta_static_gw); LOGERROR1(F(""netMask =""), in_WM_STA_IPconfig._sta_static_sn); #if USE_CONFIGURABLE_DNS LOGERROR3(F(""dns1IP =""), in_WM_STA_IPconfig._sta_static_dns1, "", dns2IP ="", in_WM_STA_IPconfig._sta_static_dns2); #endif } void configWiFi(WiFi_STA_IPConfig in_WM_STA_IPconfig) { #if USE_CONFIGURABLE_DNS // Set static IP, Gateway, Subnetmask, DNS1 and DNS2. New in v1.0.5 WiFi.config(in_WM_STA_IPconfig._sta_static_ip, in_WM_STA_IPconfig._sta_static_gw, in_WM_STA_IPconfig._sta_static_sn, in_WM_STA_IPconfig._sta_static_dns1, in_WM_STA_IPconfig._sta_static_dns2); #else // Set static IP, Gateway, Subnetmask, Use auto DNS1 and DNS2. WiFi.config(in_WM_STA_IPconfig._sta_static_ip, in_WM_STA_IPconfig._sta_static_gw, in_WM_STA_IPconfig._sta_static_sn); #endif } /////////////////////////////////////////// uint8_t connectMultiWiFi() { #if ESP32 // For ESP32, this better be 0 to shorten the connect time. // For ESP32-S2/C3, must be > 500 #if ( USING_ESP32_S2 || USING_ESP32_C3 ) #define WIFI_MULTI_1ST_CONNECT_WAITING_MS 500L #else // For ESP32 core v1.0.6, must be >= 500 #define WIFI_MULTI_1ST_CONNECT_WAITING_MS 800L #endif #else // For ESP8266, this better be 2200 to enable connect the 1st time #define WIFI_MULTI_1ST_CONNECT_WAITING_MS 2200L #endif #define WIFI_MULTI_CONNECT_WAITING_MS 500L uint8_t status; //WiFi.mode(WIFI_STA); LOGERROR(F(""ConnectMultiWiFi with :"")); if ( (Router_SSID != """") && (Router_Pass != """") ) { LOGERROR3(F(""* Flash-stored Router_SSID = ""), Router_SSID, F("", Router_Pass = ""), Router_Pass ); LOGERROR3(F(""* Add SSID = ""), Router_SSID, F("", PW = ""), Router_Pass ); wifiMulti.addAP(Router_SSID.c_str(), Router_Pass.c_str()); } for (uint8_t i = 0; i < NUM_WIFI_CREDENTIALS; i++) { // Don't permit NULL SSID and password len < MIN_AP_PASSWORD_SIZE (8) if ( (String(WM_config.WiFi_Creds[i].wifi_ssid) != """") && (strlen(WM_config.WiFi_Creds[i].wifi_pw) >= MIN_AP_PASSWORD_SIZE) ) { LOGERROR3(F(""* Additional SSID = ""), WM_config.WiFi_Creds[i].wifi_ssid, F("", PW = ""), WM_config.WiFi_Creds[i].wifi_pw ); } } LOGERROR(F(""Connecting MultiWifi..."")); //WiFi.mode(WIFI_STA); #if !USE_DHCP_IP // New in v1.4.0 configWiFi(WM_STA_IPconfig); ////// #endif int i = 0; status = wifiMulti.run(); delay(WIFI_MULTI_1ST_CONNECT_WAITING_MS); while ( ( i++ < 20 ) && ( status != WL_CONNECTED ) ) { status = WiFi.status(); if ( status == WL_CONNECTED ) break; else delay(WIFI_MULTI_CONNECT_WAITING_MS); } if ( status == WL_CONNECTED ) { LOGERROR1(F(""WiFi connected after time: ""), i); LOGERROR3(F(""SSID:""), WiFi.SSID(), F("",RSSI=""), WiFi.RSSI()); LOGERROR3(F(""Channel:""), WiFi.channel(), F("",IP address:""), WiFi.localIP() ); } else { LOGERROR(F(""WiFi not connected"")); #if ESP8266 ESP.reset(); #else ESP.restart(); #endif } return status; } void toggleLED() { //toggle state digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); } #if USE_ESP_WIFIMANAGER_NTP void printLocalTime() { #if ESP8266 static time_t now; now = time(nullptr); if ( now > 1451602800 ) { Serial.print(""Local Date/Time: ""); Serial.print(ctime(&now)); } #else struct tm timeinfo; getLocalTime( &timeinfo ); // Valid only if year > 2000. // You can get from timeinfo : tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec if (timeinfo.tm_year > 100 ) { Serial.print(""Local Date/Time: ""); Serial.print( asctime( &timeinfo ) ); } #endif } #endif void heartBeatPrint() { #if USE_ESP_WIFIMANAGER_NTP printLocalTime(); #else static int num = 1; if (WiFi.status() == WL_CONNECTED) Serial.print(F(""H"")); // H means connected to WiFi else Serial.print(F(""F"")); // F means not connected to WiFi if (num == 80) { Serial.println(); num = 1; } else if (num++ % 10 == 0) { Serial.print(F("" "")); } #endif } void check_WiFi() { if ( (WiFi.status() != WL_CONNECTED) ) { Serial.println(F(""\\nWiFi lost. Call connectMultiWiFi in loop"")); connectMultiWiFi(); } } void check_status() { static ulong checkstatus_timeout = 0; static ulong LEDstatus_timeout = 0; static ulong checkwifi_timeout = 0; static ulong current_millis; #define WIFICHECK_INTERVAL 1000L #if USE_ESP_WIFIMANAGER_NTP #define HEARTBEAT_INTERVAL 60000L #else #define HEARTBEAT_INTERVAL 10000L #endif #define LED_INTERVAL 2000L current_millis = millis(); // Check WiFi every WIFICHECK_INTERVAL (1) seconds. if ((current_millis > checkwifi_timeout) || (checkwifi_timeout == 0)) { check_WiFi(); checkwifi_timeout = current_millis + WIFICHECK_INTERVAL; } if ((current_millis > LEDstatus_timeout) || (LEDstatus_timeout == 0)) { // Toggle LED at LED_INTERVAL = 2s toggleLED(); LEDstatus_timeout = current_millis + LED_INTERVAL; } // Print hearbeat every HEARTBEAT_INTERVAL (10) seconds. if ((current_millis > checkstatus_timeout) || (checkstatus_timeout == 0)) { heartBeatPrint(); checkstatus_timeout = current_millis + HEARTBEAT_INTERVAL; } } int calcChecksum(uint8_t* address, uint16_t sizeToCalc) { uint16_t checkSum = 0; for (uint16_t index = 0; index < sizeToCalc; index++) { checkSum += * ( ( (byte*) address ) + index); } return checkSum; } bool loadConfigData() { File file = FileFS.open(CONFIG_FILENAME, ""r""); LOGERROR(F(""LoadWiFiCfgFile "")); memset((void *) &WM_config, 0, sizeof(WM_config)); // New in v1.4.0 memset((void *) &WM_STA_IPconfig, 0, sizeof(WM_STA_IPconfig)); ////// if (file) { file.readBytes((char *) &WM_config, sizeof(WM_config)); // New in v1.4.0 file.readBytes((char *) &WM_STA_IPconfig, sizeof(WM_STA_IPconfig)); ////// file.close(); LOGERROR(F(""OK"")); if ( WM_config.checksum != calcChecksum( (uint8_t*) &WM_config, sizeof(WM_config) - sizeof(WM_config.checksum) ) ) { LOGERROR(F(""WM_config checksum wrong"")); return false; } // New in v1.4.0 displayIPConfigStruct(WM_STA_IPconfig); ////// return true; } else { LOGERROR(F(""failed"")); return false; } } void saveConfigData() { File file = FileFS.open(CONFIG_FILENAME, ""w""); LOGERROR(F(""SaveWiFiCfgFile "")); if (file) { WM_config.checksum = calcChecksum( (uint8_t*) &WM_config, sizeof(WM_config) - sizeof(WM_config.checksum) ); file.write((uint8_t*) &WM_config, sizeof(WM_config)); displayIPConfigStruct(WM_STA_IPconfig); // New in v1.4.0 file.write((uint8_t*) &WM_STA_IPconfig, sizeof(WM_STA_IPconfig)); ////// file.close(); LOGERROR(F(""OK"")); } else { LOGERROR(F(""failed"")); } } void setup() { //set led pin as output pinMode(LED_BUILTIN, OUTPUT); pinMode(TRIGGER_PIN, INPUT_PULLUP); pinMode(TRIGGER_PIN2, INPUT_PULLUP); Serial.begin(115200); while (!Serial); delay(200); Serial.print(F(""\\nStarting Async_ConfigOnSwitch using "")); Serial.print(FS_Name); Serial.print(F("" on "")); Serial.println(ARDUINO_BOARD); Serial.println(ESP_ASYNC_WIFIMANAGER_VERSION); if ( String(ESP_ASYNC_WIFIMANAGER_VERSION) < ESP_ASYNC_WIFIMANAGER_VERSION_MIN_TARGET ) { Serial.print(""Warning. Must use this example on Version later than : ""); Serial.println(ESP_ASYNC_WIFIMANAGER_VERSION_MIN_TARGET); } Serial.setDebugOutput(false); if (FORMAT_FILESYSTEM) FileFS.format(); // Format FileFS if not yet #ifdef ESP32 if (!FileFS.begin(true)) #else if (!FileFS.begin()) #endif { #ifdef ESP8266 FileFS.format(); #endif Serial.println(F(""SPIFFS/LittleFS failed! Already tried formatting."")); if (!FileFS.begin()) { // prevents debug info from the library to hide err message. delay(100); #if USE_LITTLEFS Serial.println(F(""LittleFS failed!. Please use SPIFFS or EEPROM. Stay forever"")); #else Serial.println(F(""SPIFFS failed!. Please use LittleFS or EEPROM. Stay forever"")); #endif while (true) { delay(1); } } } unsigned long startedAt = millis(); // New in v1.4.0 initAPIPConfigStruct(WM_AP_IPconfig); initSTAIPConfigStruct(WM_STA_IPconfig); ////// digitalWrite(LED_BUILTIN, LED_ON); // turn the LED on by making the voltage LOW to tell us we are in configuration mode. //Local intialization. Once its business is done, there is no need to keep it around // Use this to default DHCP hostname to ESP8266-XXXXXX or ESP32-XXXXXX //ESPAsync_WiFiManager ESPAsync_wifiManager(&webServer, &dnsServer); // Use this to personalize DHCP hostname (RFC952 conformed) AsyncWebServer webServer(HTTP_PORT); #if ( USING_ESP32_S2 || USING_ESP32_C3 ) ESPAsync_WiFiManager ESPAsync_wifiManager(&webServer, NULL, ""AsyncConfigOnSwitch""); #else DNSServer dnsServer; ESPAsync_WiFiManager ESPAsync_wifiManager(&webServer, &dnsServer, ""AsyncConfigOnSwitch""); #endif ESPAsync_wifiManager.setDebugOutput(true); // Use only to erase stored WiFi Credentials //resetSettings(); //ESPAsync_wifiManager.resetSettings(); #if USE_CUSTOM_AP_IP //set custom ip for portal // New in v1.4.0 ESPAsync_wifiManager.setAPStaticIPConfig(WM_AP_IPconfig); ////// #endif ESPAsync_wifiManager.setMinimumSignalQuality(-1); // From v1.0.10 only // Set config portal channel, default = 1. Use 0 => random channel from 1-13 ESPAsync_wifiManager.setConfigPortalChannel(0); ////// #if !USE_DHCP_IP // Set (static IP, Gateway, Subnetmask, DNS1 and DNS2) or (IP, Gateway, Subnetmask). New in v1.0.5 // New in v1.4.0 ESPAsync_wifiManager.setSTAStaticIPConfig(WM_STA_IPconfig); ////// #endif // New from v1.1.1 #if USING_CORS_FEATURE ESPAsync_wifiManager.setCORSHeader(""Your Access-Control-Allow-Origin""); #endif // We can't use WiFi.SSID() in ESP32as it's only valid after connected. // SSID and Password stored in ESP32 wifi_ap_record_t and wifi_config_t are also cleared in reboot // Have to create a new function to store in EEPROM/SPIFFS for this purpose Router_SSID = ESPAsync_wifiManager.WiFi_SSID(); Router_Pass = ESPAsync_wifiManager.WiFi_Pass(); //Remove this line if you do not want to see WiFi password printed Serial.println(""ESP Self-Stored: SSID = "" + Router_SSID + "", Pass = "" + Router_Pass); // SSID to uppercase ssid.toUpperCase(); password = ""My"" + ssid; bool configDataLoaded = false; // From v1.1.0, Don't permit NULL password if ( (Router_SSID != """") && (Router_Pass != """") ) { LOGERROR3(F(""* Add SSID = ""), Router_SSID, F("", PW = ""), Router_Pass); wifiMulti.addAP(Router_SSID.c_str(), Router_Pass.c_str()); ESPAsync_wifiManager.setConfigPortalTimeout(120); //If no access point name has been previously entered disable timeout. Serial.println(F(""Got ESP Self-Stored Credentials. Timeout 120s for Config Portal"")); } if (loadConfigData()) { configDataLoaded = true; ESPAsync_wifiManager.setConfigPortalTimeout(120); //If no access point name has been previously entered disable timeout. Serial.println(F(""Got stored Credentials. Timeout 120s for Config Portal"")); #if USE_ESP_WIFIMANAGER_NTP if ( strlen(WM_config.TZ_Name) > 0 ) { LOGERROR3(F(""Current TZ_Name =""), WM_config.TZ_Name, F("", TZ = ""), WM_config.TZ); #if ESP8266 configTime(WM_config.TZ, ""pool.ntp.org""); #else //configTzTime(WM_config.TZ, ""pool.ntp.org"" ); configTzTime(WM_config.TZ, ""time.nist.gov"", ""0.pool.ntp.org"", ""1.pool.ntp.org""); #endif } else { Serial.println(F(""Current Timezone is not set. Enter Config Portal to set."")); } #endif } else { // Enter CP only if no stored SSID on flash and file Serial.println(F(""Open Config Portal without Timeout: No stored Credentials."")); initialConfig = true; } if (initialConfig) { Serial.print(F(""Starting configuration portal @ "")); #if USE_CUSTOM_AP_IP Serial.print(APStaticIP); #else Serial.print(F(""192.168.4.1"")); #endif Serial.print(F("", SSID = "")); Serial.print(ssid); Serial.print(F("", PWD = "")); Serial.println(password); digitalWrite(LED_BUILTIN, LED_ON); // Turn led on as we are in configuration mode. //sets timeout in seconds until configuration portal gets turned off. //If not specified device will remain in configuration mode until //switched off via webserver or device is restarted. //ESPAsync_wifiManager.setConfigPortalTimeout(600); // Starts an access point if (!ESPAsync_wifiManager.startConfigPortal((const char *) ssid.c_str(), password.c_str())) Serial.println(F(""Not connected to WiFi but continuing anyway."")); else { Serial.println(F(""WiFi connected...yeey :)"")); } // Stored for later usage, from v1.1.0, but clear first memset(&WM_config, 0, sizeof(WM_config)); for (uint8_t i = 0; i < NUM_WIFI_CREDENTIALS; i++) { String tempSSID = ESPAsync_wifiManager.getSSID(i); String tempPW = ESPAsync_wifiManager.getPW(i); if (strlen(tempSSID.c_str()) < sizeof(WM_config.WiFi_Creds[i].wifi_ssid) - 1) strcpy(WM_config.WiFi_Creds[i].wifi_ssid, tempSSID.c_str()); else strncpy(WM_config.WiFi_Creds[i].wifi_ssid, tempSSID.c_str(), sizeof(WM_config.WiFi_Creds[i].wifi_ssid) - 1); if (strlen(tempPW.c_str()) < sizeof(WM_config.WiFi_Creds[i].wifi_pw) - 1) strcpy(WM_config.WiFi_Creds[i].wifi_pw, tempPW.c_str()); else strncpy(WM_config.WiFi_Creds[i].wifi_pw, tempPW.c_str(), sizeof(WM_config.WiFi_Creds[i].wifi_pw) - 1); // Don't permit NULL SSID and password len < MIN_AP_PASSWORD_SIZE (8) if ( (String(WM_config.WiFi_Creds[i].wifi_ssid) != """") && (strlen(WM_config.WiFi_Creds[i].wifi_pw) >= MIN_AP_PASSWORD_SIZE) ) { LOGERROR3(F(""* Add SSID = ""), WM_config.WiFi_Creds[i].wifi_ssid, F("", PW = ""), WM_config.WiFi_Creds[i].wifi_pw ); wifiMulti.addAP(WM_config.WiFi_Creds[i].wifi_ssid, WM_config.WiFi_Creds[i].wifi_pw); } } #if USE_ESP_WIFIMANAGER_NTP String tempTZ = ESPAsync_wifiManager.getTimezoneName(); if (strlen(tempTZ.c_str()) < sizeof(WM_config.TZ_Name) - 1) strcpy(WM_config.TZ_Name, tempTZ.c_str()); else strncpy(WM_config.TZ_Name, tempTZ.c_str(), sizeof(WM_config.TZ_Name) - 1); const char * TZ_Result = ESPAsync_wifiManager.getTZ(WM_config.TZ_Name); if (strlen(TZ_Result) < sizeof(WM_config.TZ) - 1) strcpy(WM_config.TZ, TZ_Result); else strncpy(WM_config.TZ, TZ_Result, sizeof(WM_config.TZ_Name) - 1); if ( strlen(WM_config.TZ_Name) > 0 ) { LOGERROR3(F(""Saving current TZ_Name =""), WM_config.TZ_Name, F("", TZ = ""), WM_config.TZ); #if ESP8266 configTime(WM_config.TZ, ""pool.ntp.org""); #else //configTzTime(WM_config.TZ, ""pool.ntp.org"" ); configTzTime(WM_config.TZ, ""time.nist.gov"", ""0.pool.ntp.org"", ""1.pool.ntp.org""); #endif } else { LOGERROR(F(""Current Timezone Name is not set. Enter Config Portal to set."")); } #endif // New in v1.4.0 ESPAsync_wifiManager.getSTAStaticIPConfig(WM_STA_IPconfig); ////// saveConfigData(); } digitalWrite(LED_BUILTIN, LED_OFF); // Turn led off as we are not in configuration mode. startedAt = millis(); if (!initialConfig) { // Load stored data, the addAP ready for MultiWiFi reconnection if (!configDataLoaded) loadConfigData(); for (uint8_t i = 0; i < NUM_WIFI_CREDENTIALS; i++) { // Don't permit NULL SSID and password len < MIN_AP_PASSWORD_SIZE (8) if ( (String(WM_config.WiFi_Creds[i].wifi_ssid) != """") && (strlen(WM_config.WiFi_Creds[i].wifi_pw) >= MIN_AP_PASSWORD_SIZE) ) { LOGERROR3(F(""* Add SSID = ""), WM_config.WiFi_Creds[i].wifi_ssid, F("", PW = ""), WM_config.WiFi_Creds[i].wifi_pw ); wifiMulti.addAP(WM_config.WiFi_Creds[i].wifi_ssid, WM_config.WiFi_Creds[i].wifi_pw); } } if ( WiFi.status() != WL_CONNECTED ) { Serial.println(F(""ConnectMultiWiFi in setup"")); connectMultiWiFi(); } } Serial.print(F(""After waiting "")); Serial.print((float) (millis() - startedAt) / 1000); Serial.print(F("" secs more in setup(), connection result is "")); if (WiFi.status() == WL_CONNECTED) { Serial.print(F(""connected. Local IP: "")); Serial.println(WiFi.localIP()); } else Serial.println(ESPAsync_wifiManager.getStatus(WiFi.status())); } void loop() { // is configuration portal requested? if ((digitalRead(TRIGGER_PIN) == LOW) || (digitalRead(TRIGGER_PIN2) == LOW)) { Serial.println(F(""\\nConfiguration portal requested."")); digitalWrite(LED_BUILTIN, LED_ON); // turn the LED on by making the voltage LOW to tell us we are in configuration mode. //Local intialization. Once its business is done, there is no need to keep it around // Use this to default DHCP hostname to ESP8266-XXXXXX or ESP32-XXXXXX //ESPAsync_WiFiManager ESPAsync_wifiManager(&webServer, &dnsServer); // Use this to personalize DHCP hostname (RFC952 conformed) AsyncWebServer webServer(HTTP_PORT); #if ( USING_ESP32_S2 || USING_ESP32_C3 ) ESPAsync_WiFiManager ESPAsync_wifiManager(&webServer, NULL, ""ConfigOnSwitch""); #else DNSServer dnsServer; ESPAsync_WiFiManager ESPAsync_wifiManager(&webServer, &dnsServer, ""ConfigOnSwitch""); #endif ESPAsync_wifiManager.setMinimumSignalQuality(-1); // From v1.0.10 only // Set config portal channel, default = 1. Use 0 => random channel from 1-13 ESPAsync_wifiManager.setConfigPortalChannel(0); ////// //set custom ip for portal //ESPAsync_wifiManager.setAPStaticIPConfig(IPAddress(192, 168, 100, 1), IPAddress(192, 168, 100, 1), IPAddress(255, 255, 255, 0)); #if !USE_DHCP_IP #if USE_CONFIGURABLE_DNS // Set static IP, Gateway, Subnetmask, DNS1 and DNS2. New in v1.0.5 ESPAsync_wifiManager.setSTAStaticIPConfig(stationIP, gatewayIP, netMask, dns1IP, dns2IP); #else // Set static IP, Gateway, Subnetmask, Use auto DNS1 and DNS2. ESPAsync_wifiManager.setSTAStaticIPConfig(stationIP, gatewayIP, netMask); #endif #endif // New from v1.1.1 #if USING_CORS_FEATURE ESPAsync_wifiManager.setCORSHeader(""Your Access-Control-Allow-Origin""); #endif //Check if there is stored WiFi router/password credentials. //If not found, device will remain in configuration mode until switched off via webserver. Serial.println(F(""Opening configuration portal. "")); Router_SSID = ESPAsync_wifiManager.WiFi_SSID(); Router_Pass = ESPAsync_wifiManager.WiFi_Pass(); //Remove this line if you do not want to see WiFi password printed Serial.println(""ESP Self-Stored: SSID = "" + Router_SSID + "", Pass = "" + Router_Pass); // From v1.1.0, Don't permit NULL password if ( (Router_SSID != """") && (Router_Pass != """") ) { LOGERROR3(F(""* Add SSID = ""), Router_SSID, F("", PW = ""), Router_Pass); wifiMulti.addAP(Router_SSID.c_str(), Router_Pass.c_str()); ESPAsync_wifiManager.setConfigPortalTimeout(120); //If no access point name has been previously entered disable timeout. Serial.println(F(""Got ESP Self-Stored Credentials. Timeout 120s for Config Portal"")); } else if (loadConfigData()) { ESPAsync_wifiManager.setConfigPortalTimeout(120); //If no access point name has been previously entered disable timeout. Serial.println(F(""Got stored Credentials. Timeout 120s for Config Portal"")); } else { // Enter CP only if no stored SSID on flash and file Serial.println(F(""Open Config Portal without Timeout: No stored Credentials."")); initialConfig = true; } //Starts an access point //and goes into a blocking loop awaiting configuration if (!ESPAsync_wifiManager.startConfigPortal((const char *) ssid.c_str(), password.c_str())) { Serial.println(F(""Not connected to WiFi but continuing anyway."")); } else { //if you get here you have connected to the WiFi Serial.println(F(""connected...yeey :)"")); Serial.print(F(""Local IP: "")); Serial.println(WiFi.localIP()); } // Only clear then save data if CP entered and with new valid Credentials // No CP => stored getSSID() = """" if ( String(ESPAsync_wifiManager.getSSID(0)) != """" && String(ESPAsync_wifiManager.getSSID(1)) != """" ) { // Stored for later usage, from v1.1.0, but clear first memset(&WM_config, 0, sizeof(WM_config)); for (uint8_t i = 0; i < NUM_WIFI_CREDENTIALS; i++) { String tempSSID = ESPAsync_wifiManager.getSSID(i); String tempPW = ESPAsync_wifiManager.getPW(i); if (strlen(tempSSID.c_str()) < sizeof(WM_config.WiFi_Creds[i].wifi_ssid) - 1) strcpy(WM_config.WiFi_Creds[i].wifi_ssid, tempSSID.c_str()); else strncpy(WM_config.WiFi_Creds[i].wifi_ssid, tempSSID.c_str(), sizeof(WM_config.WiFi_Creds[i].wifi_ssid) - 1); if (strlen(tempPW.c_str()) < sizeof(WM_config.WiFi_Creds[i].wifi_pw) - 1) strcpy(WM_config.WiFi_Creds[i].wifi_pw, tempPW.c_str()); else strncpy(WM_config.WiFi_Creds[i].wifi_pw, tempPW.c_str(), sizeof(WM_config.WiFi_Creds[i].wifi_pw) - 1); // Don't permit NULL SSID and password len < MIN_AP_PASSWORD_SIZE (8) if ( (String(WM_config.WiFi_Creds[i].wifi_ssid) != """") && (strlen(WM_config.WiFi_Creds[i].wifi_pw) >= MIN_AP_PASSWORD_SIZE) ) { LOGERROR3(F(""* Add SSID = ""), WM_config.WiFi_Creds[i].wifi_ssid, F("", PW = ""), WM_config.WiFi_Creds[i].wifi_pw ); wifiMulti.addAP(WM_config.WiFi_Creds[i].wifi_ssid, WM_config.WiFi_Creds[i].wifi_pw); } } #if USE_ESP_WIFIMANAGER_NTP String tempTZ = ESPAsync_wifiManager.getTimezoneName(); if (strlen(tempTZ.c_str()) < sizeof(WM_config.TZ_Name) - 1) strcpy(WM_config.TZ_Name, tempTZ.c_str()); else strncpy(WM_config.TZ_Name, tempTZ.c_str(), sizeof(WM_config.TZ_Name) - 1); const char * TZ_Result = ESPAsync_wifiManager.getTZ(WM_config.TZ_Name); if (strlen(TZ_Result) < sizeof(WM_config.TZ) - 1) strcpy(WM_config.TZ, TZ_Result); else strncpy(WM_config.TZ, TZ_Result, sizeof(WM_config.TZ_Name) - 1); if ( strlen(WM_config.TZ_Name) > 0 ) { LOGERROR3(F(""Saving current TZ_Name =""), WM_config.TZ_Name, F("", TZ = ""), WM_config.TZ); #if ESP8266 configTime(WM_config.TZ, ""pool.ntp.org""); #else //configTzTime(WM_config.TZ, ""pool.ntp.org"" ); configTzTime(WM_config.TZ, ""time.nist.gov"", ""0.pool.ntp.org"", ""1.pool.ntp.org""); #endif } else { LOGERROR(F(""Current Timezone Name is not set. Enter Config Portal to set."")); } #endif // New in v1.4.0 ESPAsync_wifiManager.getSTAStaticIPConfig(WM_STA_IPconfig); ////// saveConfigData(); } digitalWrite(LED_BUILTIN, LED_OFF); // Turn led off as we are not in configuration mode. } // put your main code here, to run repeatedly check_status(); } ",12196,False,2037.0085061332015,median "u_offset1 = -TYPE ; behaviour offset is determined by next structure element ; all following objects ""inherit"" from defined Objectstruct ; all vars after ""NEXT_OBJECT"" can be different for each of the objects ; ; all definitions with the same name must be at the same structure position struct DragonObjectStruct ds Y_POS,1 ; current position ds X_POS,1 ds CURRENT_LIST,2 ; current list vectorlist ds DDRA,1 ds SCALE,1 ; scale to position the object ds BEHAVIOUR,2 ds TYPE,1 ; enemy type ds ANGLE,2 ; if angle base, angle in degree *2 ds PREVIOUS_OBJECT,2 ; positive = start of list ds NEXT_OBJECT,2 ; positive = end of list ds DRAGON_COUNTER,1 ; how many times was I hit? ds CHILD_1, 2 ds CHILD_2, 2 ds filler, 0 ; #noDoubleWarn end struct ; struct DragonChildObjectStruct ds Y_POS,1 ; current position ds X_POS,1 ds CURRENT_LIST,2 ; current list vectorlist ds DDRA,1 ds SCALE,1 ; scale to position the object ds BEHAVIOUR,2 ds TYPE,1 ; enemy type ds ANGLE,2 ; if angle base, angle in degree *2 ds PREVIOUS_OBJECT,2 ; positive = start of list ds NEXT_OBJECT,2 ; positive = end of list ds ANGLE_OFFSET,2 ; two byte for easier adding ds DRAGON, 2 ; my parent - I have to tell him when I die ds SCALE_OFFSET, 1 ds filler, 0 ; #noDoubleWarn end struct ; struct XObjectStruct ds Y_POS,1 ; current position ds X_POS,1 ds CURRENT_LIST,2 ; current list vectorlist ds DDRA,1 ds SCALE,1 ; scale to position the object ds BEHAVIOUR,2 ds TYPE,1 ; enemy type ds ANGLE,2 ; if angle base, angle in degree *2 ds PREVIOUS_OBJECT,2 ; positive = start of list ds NEXT_OBJECT,2 ; positive = end of list ds ANIM_COUNTER,1 ; with what value does the animation get updated ds TICK_COUNTER,1 ; after how many rounds the movement updates (0 = each, 1 = every second etc) ds SCALE_DELTA,1 ; with what value does the movement get updated (1-4)? ds filler, 2 ; #noDoubleWarn end struct ; struct ShotObjectStruct ds Y_POS,1 ; current position ds X_POS,1 ds CURRENT_LIST,2 ; current list vectorlist ds DDRA,1 ds SCALE,1 ; scale to position the object ds BEHAVIOUR,2 ds TYPE,1 ; enemy type ds ANGLE,2 ; if angle base, angle in degree *2 ds PREVIOUS_OBJECT,2 ; positive = start of list ds NEXT_OBJECT,2 ; positive = end of list ds filler, 1 ; #noDoubleWarn ds TICK_COUNTER,1 ; after how many rounds the movement updates (0 = each, 1 = every second etc) ds SCALE_DELTA,1 ; with what value does the movement get updated (1-4)? ds filler, 2 ; #noDoubleWarn end struct ; struct HunterObjectStruct ds Y_POS,1 ; current position ds X_POS,1 ds CURRENT_LIST,2 ; current list vectorlist ds DDRA,1 ds SCALE,1 ; scale to position the object ds BEHAVIOUR,2 ds TYPE,1 ; enemy type ds ANGLE,2 ; if angle base, angle in degree *2 ds PREVIOUS_OBJECT,2 ; positive = start of list ds NEXT_OBJECT,2 ; positive = end of list ds filler, 1 ; #noDoubleWarn ds TICK_COUNTER,1 ; after how many rounds the movement updates (0 = each, 1 = every second etc) ds SCALE_DELTA,1 ; with what value does the movement get updated (1-4)? ds filler, 2 ; #noDoubleWarn end struct ; struct BomberObjectStruct ds Y_POS,1 ; current position ds X_POS,1 ds CURRENT_LIST,2 ; current list vectorlist ds DDRA,1 ds SCALE,1 ; scale to position the object ds BEHAVIOUR,2 ds TYPE,1 ; enemy type ds ANGLE,2 ; if angle base, angle in degree *2 ds PREVIOUS_OBJECT,2 ; positive = start of list ds NEXT_OBJECT,2 ; positive = end of list ds ANIM_COUNTER,1 ; with what value does the animation get updated ds ANGLE_TICK_COUNTER,1 ; after how many rounds the movement updates (0 = each, 1 = every second etc) ds SHOT_COUNTER_RESET,1 ; after how many ticks will the counter be resetd next time ds SHOT_COUNTER,1 ; after how many ticks do I shoot again? ds ANGLE_DELTA, 1 ; add to angle each countdown ds filler, 0 ; #noDoubleWarn end struct ; struct StarletObjectStruct ds Y_POS,1 ; current position ds X_POS,1 ds CURRENT_LIST,2 ; current list vectorlist ds DDRA,1 ds SCALE,1 ; scale to position the object ds BEHAVIOUR,2 ds TYPE,1 ; enemy type ds ANGLE,2 ; if angle base, angle in degree *2 ds PREVIOUS_OBJECT,2 ; positive = start of list ds NEXT_OBJECT,2 ; positive = end of list ds ANIM_COUNTER,1 ; jmp to current draw routine ds SCORE_COUNTER, 1 ; next time I spawn a bonus score ds SCORE_COUNT, 1 ; what is the current bonus score (2-255) ds I_AM_STAR_NO, 1 ; what number of star am I (0-2) ds filler, 0 ; #noDoubleWarn end struct ; struct ExplosionObjectStruct ds Y_POS,1 ; current position ds X_POS,1 ds CURRENT_LIST,2 ; current list vectorlist ds DDRA,1 ds SCALE,1 ; scale to position the object ds BEHAVIOUR,2 ds TYPE,1 ; enemy type ds ANGLE,2 ; if angle base, angle in degree *2 ds PREVIOUS_OBJECT,2 ; positive = start of list ds NEXT_OBJECT,2 ; positive = end of list ds EXPLOSION_SCALE,1 ds filler, 4 ; #noDoubleWarn end struct ; struct ScoreObjectStruct ds Y_POS,1 ; current position ds X_POS,1 ds CURRENT_LIST,2 ; current list vectorlist ds DDRA,1 ds SCALE,1 ; scale to position the object ds BEHAVIOUR,2 ds TYPE,1 ; enemy type ds ANGLE,2 ; if angle base, angle in degree *2 ds PREVIOUS_OBJECT,2 ; positive = start of list ds NEXT_OBJECT,2 ; positive = end of list ds SCORE_COUNTDOWN,1 ; how long will I be displayed (countdon to zero) ds filler, 4 ; #noDoubleWarn end struct ; struct ScoreXObjectStruct ds Y_POS,1 ; current position ds X_POS,1 ds SCORE_POINTER_1,2 ; current list vectorlist of first score digit ds DDRA,1 ds SCALE,1 ; scale to position the object ds BEHAVIOUR,2 ds TYPE,1 ; enemy type ds ANGLE,2 ; if angle base, angle in degree *2 ds PREVIOUS_OBJECT,2 ; positive = start of list ds NEXT_OBJECT,2 ; positive = end of list ds SCORE_COUNTDOWN,1 ; how long will I be displayed (countdon to zero) DS SCORE_POINTER_2,2 ; current list vectorlist of second score digit DS SCORE_POINTER_3,2 ; current list vectorlist of third score digit ds filler, 0 ; #noDoubleWarn end struct ; struct TimerObjectStruct ds Y_POS,1 ; current position ds X_POS,1 ds CURRENT_LIST,2 ; current list vectorlist of first score digit ds DDRA,1 ds SCALE,1 ; scale to position the object ds BEHAVIOUR,2 ds TYPE,1 ; enemy type ds ANGLE,2 ; if angle base, angle in degree *2 ds PREVIOUS_OBJECT,2 ; positive = start of list ds NEXT_OBJECT,2 ; positive = end of list ds SECOND_COUNTER,1 ; initialized with 50 again and again and countdown ds filler, 4 ; #noDoubleWarn end struct code ; all behaviour routines leave ; with u pointed to the next object structure ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; GENERAL Object functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SET_U_FREE macro ldy list_empty_head ; set u free, as new free head sty NEXT_OBJECT,u ; load to u the next linked list element stu list_empty_head leau ,x ; x contains always next object - even if next is the ""null"" (return-) object pulu d,x,y,pc ; (D = y,x, X = vectorlist, Y = DDRA+Scale) endm ; in u pointer to the object that must be removed ; destroys x, y ; sets u to pointer of next object in linked list removeObject: ;#isfunction ; since often called from ""in move"" we disable the move! ldd #0 std VIA_t1_cnt_lo ; disable ramping _ZERO_VECTOR_BEAM leau u_offset1,u ; u -> pointer object strutire (correction of offset) ldx NEXT_OBJECT,u ; x pointer to next objext bpl was_last_re ; if positive than object in ROM space - therefor LAST ldy PREVIOUS_OBJECT,u ; y pointer to previous object bpl was_first_re ; if positive than object in ROM space - therefor first stx NEXT_OBJECT,y ; set next object as previous next sty PREVIOUS_OBJECT,x ; set previous object as next previous SET_U_FREE was_first_re sty PREVIOUS_OBJECT,x ; clear previous' object of next object stx list_objects_head ; set next object as head SET_U_FREE was_last_re: ldy PREVIOUS_OBJECT,u ; y pointer to previous object bpl was_last_and_first_re ; if positive than object in ROM space - therefor first stx NEXT_OBJECT,y ; clear last objects next object sty list_objects_tail ; set last object as tail SET_U_FREE ; clear both was_last_and_first_re: stx list_objects_head ; the ""null"" object (ROM) is in x, store it to head stx list_objects_tail ; and tail SET_U_FREE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; new list object to U ; leaves with flags set to result ; (positive = not successfull) ROM ; negative = successfull RAM ; destroys d, u , x newObject ;#isfunction ldu list_empty_head bpl cs_done_no ; we don't have any spare objects -> go out ; set the new empty head ldd NEXT_OBJECT,u std list_empty_head ; load last of current object list ldx list_objects_tail ; of our new object, that last object is the previous stx PREVIOUS_OBJECT,u bpl no_next_no ; the last object was 0, so we do net set a next there ; of the last object, the new object is the next object stu NEXT_OBJECT,x bra was_not_only_no no_next_no: stu list_objects_head ; if there was no last, than also no first -> therefor set new object as head was_not_only_no: ; the next object of our current object is null, since we are last ldd #PC_MAIN std NEXT_OBJECT,u ; our new object is the new tail stu list_objects_tail cs_done_no rts ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; SPECIFIC Object functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ****************************** ***** OBJECT X *************** ****************************** ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; X SPAWN ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; in x pointer to new object structure that should be filled with object ; data spawnX: ; #isfunction bitb #ALLOW_X bne spx_allowed clr spawn_timer ; check spawn next round again jmp returnSpawnNotAllowed spx_allowed: bsr newObject bpl cs_done_no leax ,u ; pointer to new object PLAY_SFX SpawnX_Sound ; copy and initialze new enemy lda #TYPE_X sta TYPE, x lda X_add_delay sta TICK_COUNTER, x lda X_addi sta SCALE_DELTA, x ldd #xBehaviour std BEHAVIOUR,x lda #X_ANIM_DELAY ; anim reset sta ANIM_COUNTER, x ldd #enemyXList_0 ; vectorlist std CURRENT_LIST,x lda #$ff sta DDRA,x ; performance dummy lda #SPAWN_MAX_SCALE sta SCALE,x ; start with max scale (for xEnemy) lda my_random2 anda #%01111111 ; in a random number between 0 - 127 tfr a, b clra MY_LSL_D ; double it tfr d,u leau d,u leau d,u ; u = 0 - 720 -> spawning angle of our new enemy stu ANGLE,x ; store current angle of object ldd #circle leau d,u ; u pointer to spwan angle coordinates ldd ,u std Y_POS,x ; save start pos rts ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; behaviours control (action) and draw all objects ; each object type has an individual behaviour ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; values are set from ""u"" list as: ; pulu pc,d,x,y ; (D = y,x, X = vectorlist, Y = DDRA+Scale) xBehaviour ;#isfunction ; do the scaling sty VIA_DDR_a ; also stores to scale :-() VIA_t1_cnt_lo ; to timer t1 (lo) ; start the move to ; following calcs can be done within that move MY_MOVE_TO_D_START lda SCALE+u_offset1,u ; load current scale to a - for later calcs dec TICK_COUNTER+u_offset1, u ; see if wee need calc at all, compare tick counter with below zero bpl no_scale_update_xb ; if not, scale will not be updated ldb X_add_delay ; otherwise reset the delay counter for scale update (this is global now, should I use that from the structure?) stb TICK_COUNTER+u_offset1, u ; store it suba SCALE_DELTA+u_offset1, u ; and actually descrease the scale with the ""decrease"" value bcs die_xb ; if below zero, than base reaches cmpa #BASE_SCALE+3 ; if lower base scale, than also dead bhi base_not_reached ; if we reached the base - ; a) moveto was SMALL - finished anyway ; b) not interested in move - nothing will be drawn anymore! ; MY_MOVE_TO_B_END die_xb ; cancle move jmp gameOver ; if base was hit -> game over base_not_reached: sta SCALE+u_offset1,u ; store the calculated scale (used next round) no_scale_update_xb: dec ANIM_COUNTER+u_offset1, u ; see if wee need calc at all, compare tick counter with below zero bpl no_anim_update_xb ; if not, scale will not be updated lda #X_ANIM_DELAY ; anim reset sta ANIM_COUNTER+u_offset1, u ldd CURRENT_LIST+u_offset1,u addd #(enemyXList_1-enemyXList_0) cmpd #(enemyXList_3+(enemyXList_1-enemyXList_0)) bne not_last_anim_xb ldd #enemyXList_0 not_last_anim_xb: std CURRENT_LIST+u_offset1,u no_anim_update_xb: ldu NEXT_OBJECT+u_offset1,u ; preload next user stack lda #6 sta VIA_t1_cnt_lo ; to timer t1 (lo= lda #$5f ; intensity MY_MOVE_TO_B_END ; end a move to _INTENSITY_A jsr myDraw_VL_mode _ZERO_VECTOR_BEAM pulu d,x,y,pc ; (D = y,x, X = vectorlist, Y = DDRA+Scale) ****************************** ***** OBJECT HUNTER ********** ****************************** ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Hunter SPAWN ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; in x pointer to new object structure that should be filled with object ; data spawnHunter: ; #isfunction bitb #ALLOW_HUNTER bne sph_allowed clr spawn_timer ; check spawn next round again jmp returnSpawnNotAllowed sph_allowed: jsr newObject lbpl cs_done_no leax ,u ; pointer to new object PLAY_SFX SpawnHunter_Sound ; copy and initialze new enemy lda #TYPE_HUNTER sta TYPE, x lda Hunter_add_delay sta TICK_COUNTER, x lda Hunter_addi sta SCALE_DELTA, x ldd #hunterBehaviour std BEHAVIOUR,x lda #$ff sta DDRA,x ; performance dummy lda #SPAWN_MAX_SCALE sta SCALE,x ; start with max scale (for xEnemy) ldb my_random2 andb #%01111111 ; in a random number between 0 - 127 clra cmpd #120 blt noMax_dh subd #120 ; following calculates the correct angle vectorlist for the hunter noMax_dh MY_LSL_D ; double it tfr d,u leau d,u leau d,u ; u = 0 - 720 -> spawning angle of our new enemy leau 31,u ; u = 0 - 720 -> spawning angle of our new enemy tfr u,d MY_LSR_D MY_LSR_D MY_LSR_D MY_LSR_D MY_LSR_D ; angle / 32 MY_LSL_D ; *2 ldu #HunterList leau d,u ldu ,u stu CURRENT_LIST,x MY_LSL_D ; *2 MY_LSL_D ; *2 MY_LSL_D ; *2 MY_LSL_D ; *2 tfr d,u stu ANGLE,x ; store current angle of object ldd #circle leau d,u ; u pointer to spwan angle coordinates ldd ,u std Y_POS,x ; save start pos rts ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; behaviours control (action) and draw all objects ; each object type has an individual behaviour ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; values are set from ""u"" list as: ; pulu pc,d,x,y ; (D = y,x, X = vectorlist, Y = DDRA+Scale) hunterBehaviour ;#isfunction ; do the scaling sty VIA_DDR_a ; also stores to scale :-() VIA_t1_cnt_lo ; to timer t1 (lo) ; start the move to ; following calcs can be done within that move MY_MOVE_TO_D_START lda SCALE+u_offset1,u ; load current scale to a - for later calcs dec TICK_COUNTER+u_offset1, u ; see if wee need calc at all, compare tick counter with below zero bpl no_scale_update_hb ; if not, scale will not be updated ldb Hunter_add_delay ; otherwise reset the delay counter for scale update (this is global now, should I use that from the structure?) stb TICK_COUNTER+u_offset1, u ; store it suba SCALE_DELTA+u_offset1, u ; and actually descrease the scale with the ""decrease"" value bcs die_hb ; if below zero, than base reaches cmpa #BASE_SCALE+3 ; if lower base scale, than also dead bhi base_not_reached_hb ; bcc base_not_reached ; if the decreas generated an overflow - than we reached the base (scale below zero) ; if we reached the base - ; a) moveto was SMALL - finished anyway ; b) not interested in move - nothing will be drawn anymore! ; MY_MOVE_TO_B_END die_hb ; cancle move jmp gameOver ; if base was hit -> game over base_not_reached_hb: sta SCALE+u_offset1,u ; store the calculated scale (used next round) no_scale_update_hb: ldu NEXT_OBJECT+u_offset1,u ; preload next user stack ldy ,x++ ; load offset of vector list draw leay >(unloop_start_addressSub+LENGTH_OF_HEADER),y ; lda #$5f ; intensity MY_MOVE_TO_B_END ; end a move to _INTENSITY_A jsr entry_optimized_draw_mvlc_unloop ldd #$cc98 sta