void LCD_drag(Lcd *x, Point pt, short button_down) { Rect r; short slider; Atom aList[2]; short way; EnterCallback(); #ifdef debug post("¥LCD_drag - start"); #endif r = x->lcd_box.b_rect; if (x->local) { if (button_down) { LCD_MoveTo(x,(long)(x->lcd_where.h),(long)(x->lcd_where.v)); LCD_LineTo(x,(long)(pt.h-r.left),(long)(pt.v-r.top)); } else x->lcd_shiftClick = false; } LCD_posToRC(x,pt); SETLONG(&aList[0],(long)(pt.h-r.left)); SETLONG(&aList[1],(long)(pt.v-r.top)); /* lockouts added by DDZ 12/14/92 */ way = lockout_set(1); outlet_list(x->lcd_outlet,0L,2,aList); lockout_set(way); ExitCallback(); }
void LCD_click(Lcd *x, Point where, short modifiers) { short i; Rect r; Atom aList[2]; short way; EnterCallback(); #ifdef debug post("¥LCD_click - start"); #endif r = x->lcd_box.b_rect; x->lcd_shiftClick = modifiers&shiftKey; if (x->local) LCD_MoveTo(x,(long)(where.h-r.left),(long)(where.v-r.top)); LCD_posToRC(x,where); wind_drag((void *)LCD_drag,x,where); SETLONG(&aList[0],(long)(where.h-r.left)); SETLONG(&aList[1],(long)(where.v-r.top)); /* lockouts added by DDZ 12/14/92 */ way = lockout_set(1); outlet_list(x->lcd_outlet,0L,2,aList); lockout_set(way); ExitCallback(); } /* ms_click */
static void CalibrateCore( MENU_Event_t event, uint8_t *cal ) { if ( event == MENU_EVENT_SELECT ) { memcpy( &cal[ 1 ], &gADC[ 1 ], 5 ); return; } if ( event == MENU_EVENT_INIT ) { LCD_Clear(); } LCD_MoveTo( 0, 0 ); LCD_Printf( "C %02x %02x %02x %02x %02x", cal[ 4 ], cal[ 1 ], cal[ 2 ], cal[ 3 ], cal[ 5 ]); LCD_MoveTo( 0, 1 ); LCD_Printf( "L %02x %02x %02x %02x %02x", gADC[ 4 ], gADC[ 1 ], gADC[ 2 ], gADC[ 3 ], gADC[ 5 ]); } // CalibrateCore
void LCD_PutChar( char ch ) { if (( gX >= gNumCols ) || ( ch == '\n' )) { gX = 0; gY++; if ( gY >= gNumLines ) { gY = 0; } LCD_MoveTo( gX, gY ); } if ( ch != '\n' ) { LCD_HAL_Write( LCD_RS_DATA, ch ); LCD_HAL_Delay( 1 ); gX++; } } // LCD_PutChar
void LCD_doLineTo(Lcd *x, Symbol *s, short argc, Atom *argv) { PaletteHandle pH; RGBColor fColor; GrafPort *gp; RgnHandle cur; long deltaX, deltaY; EnterCallback(); deltaX = argv->a_w.w_long; deltaY = (argv+1)->a_w.w_long; #ifdef debug post("LineTo"); #endif gp = patcher_setport(x->lcd_box.b_patcher); if (gp) { if (!box_nodraw((void *)x)) { cur = NewRgn(); GetClip(cur); SetClip(x->lcd_region); setUpPalette(x,&fColor,&pH); LCD_MoveTo(x,(long)(x->lcd_where.h),(long)(x->lcd_where.v)); LineTo(x->lcd_box.b_rect.left+1+(short)deltaX,x->lcd_box.b_rect.top+1+(short)deltaY); x->lcd_where.h = (short)deltaX; x->lcd_where.v = (short)deltaY; restorePalette(x,&fColor,&pH); SetClip(cur); DisposeRgn(cur); } SetPort(gp); } ExitCallback(); }
int main( void ) { int i; int led = 0; uint16_t prevSwitches = 0; InitHardware(); InitADC(); InitMotors(); eeprom_read_block( &gMemParam, &gEEParam, sizeof( gMemParam )); if ( gMemParam.thresh_hi == 0xFF ) { gMemParam.thresh_hi = 0x80; } if ( gMemParam.thresh_lo == 0xFF ) { gMemParam.thresh_lo = 0x10; } #if CFG_LOG_USE_STDIO fdevopen( UART0_PutCharStdio, UART0_GetCharStdio ); LogInit( stdout ); #endif // The first handle opened for read goes to stdin, and the first handle // opened for write goes to stdout. So u0 is stdin, stdout, and stderr Log( "*****\n" ); Log( "***** Line Maze program\n" ); Log( "*****\n" ); LCD_Init( 2, 16 ); LCD_Printf( " SRS Sample Bot " ); LCD_MoveTo( 0, 1 ); LCD_Printf( "Second line" ); Log( "\n" ); MENU_Init( gTopMenu ); LED_OFF( GREEN ); while( 1 ) { uint16_t switches; uint8_t pinc; uint8_t pind; int8_t error; LED_TOGGLE( GREEN ); led++; if ( led >= 6 ) { led = 0; } error = GetLineError(); if ( MENU_IsActive() ) { MENU_Event( MENU_EVENT_TIMER ); } else { if ( MENU_IsModified() ) { eeprom_write_block( &gMemParam, &gEEParam, sizeof( gMemParam )); MENU_ClearModified(); LCD_Clear(); LCD_Printf( "EEPROM Updated\n" ); Log( "EEPROM Updated\n" ); ms_spin( 1000 ); } //switches = EXP_TransferWord( ~( 1 << ( led + 2 )), EXP_OUT_LED_MASK ); switches = EXP_TransferWord( 0, 0 ); Log( "SW:%04x ", switches ); if ( switches != prevSwitches ) { LCD_Clear(); prevSwitches = switches; } for ( i = 0; i < 8; i++ ) { Log( "%02x ", gLineADC[ i ]); } //Log( "C: %02x\n", PINC ); switch (( switches & 0xF0 ) >> 4 ) { case 0: { LCD_MoveTo( 0, 0 ); LCD_Printf( " SRS Sample Bot " ); LCD_MoveTo( 0, 1 ); LCD_Printf( "Second line" ); break; } case 1: { LCD_MoveTo( 0, 0 ); LCD_Printf( "Joy: %c%c%c%c%c", (( switches & 0x4000 ) == 0 ) ? 'L' : ' ', (( switches & 0x2000 ) == 0 ) ? 'R' : ' ', (( switches & 0x0800 ) == 0 ) ? 'U' : ' ', (( switches & 0x0400 ) == 0 ) ? 'D' : ' ', (( switches & 0x1000 ) == 0 ) ? 'X' : ' ' ); LCD_MoveTo( 0, 1 ); LCD_Printf( "S1:%d S2:%d S3:%d", ( switches & 0x0200 ) == 0, ( switches & 0x0100 ) == 0, ( PIND & ( 1 << 6 )) == 0 ); break; } case 2: { LCD_MoveTo( 0, 0 ); LCD_Printf( "L %02x %02x %02x %02x %02x", gLineADC[ 0 ], gLineADC[ 1 ], gLineADC[ 2 ], gLineADC[ 3 ], gLineADC[ 4 ] ); LCD_MoveTo( 0, 1 ); LCD_Printf( "E %02x %02x %3d B %02x", gADC[ 0 ], gADC[ 7 ], error, gADC[ 6 ] ); break; } default: { LCD_MoveTo( 0, 0 ); LCD_Printf( "Setting: %d", ( switches & 0xF0 ) >> 4 ); break; } } pinc = PINC; pind = PIND; Log( " QL:%d%d QR:%d%d EC-L:%d EC-R:%d Err:%2d L:%5b H:%5b\n", ( ENCODER_L_A_PIN & ENCODER_L_A_MASK ) != 0, ( ENCODER_L_B_PIN & ENCODER_L_B_MASK ) != 0, ( ENCODER_R_A_PIN & ENCODER_R_A_MASK ) != 0, ( ENCODER_R_B_PIN & ENCODER_R_B_MASK ) != 0, gEncoderCountL, gEncoderCountR, error, gLowMask, gHighMask ); } // Tick rate is 100/sec so waiting for 50 waits for 1/2 sec for ( i = 0; i < 50; i++ ) { WaitForTimer0Rollover(); CheckSwitches(); #if 1 if ( UART0_IsCharAvailable() ) { char ch = UART0_GetChar(); if ( ch == ' ' ) { DebugKey(); } else { Log( "Read: '%c'\n", ch ); } } #endif } } return 0; }
int main(void) { int i; int led = 0; uint16_t prevSwitches = 0; InitHardware(); LogInit( printfFunc ); // The first handle opened for read goes to stdin, and the first handle // opened for write goes to stdout. So u0 is stdin, stdout, and stderr Log( "*****\n" ); Log( "***** Flash-LED program - 2\n" ); Log( "*****\n" ); Log( "SPCR = 0x%02x\n", SPCR ); LCD_Init(); LCD_Printf( " SRS Sample Bot " ); LCD_MoveTo( 0, 1 ); LCD_Printf( "Second line" ); Log( "\n" ); LED_OFF( GREEN ); while( 1 ) { uint16_t switches; uint8_t pinc; uint8_t pind; LED_TOGGLE( GREEN ); led++; if ( led >= 6 ) { led = 0; } //switches = EXP_TransferWord( ~( 1 << ( led + 2 )), EXP_OUT_LED_MASK ); switches = EXP_TransferWord( ~0, EXP_OUT_LED_MASK ); Log( "SW:%04x ", switches ); if ( switches != prevSwitches ) { LCD_Clear(); prevSwitches = switches; } // Read the ADC for ( i = 0; i < 8; i++ ) { gADC[ i ] = a2d_8( i ); Log( "%02x ", gADC[ i ]); } //Log( "C: %02x\n", PINC ); switch (( switches & 0xF0 ) >> 4 ) { case 0: { LCD_MoveTo( 0, 0 ); LCD_Printf( " SRS Sample Bot " ); LCD_MoveTo( 0, 1 ); LCD_Printf( "Second line" ); break; } case 1: { LCD_MoveTo( 0, 0 ); LCD_Printf( "Joy: %c%c%c%c%c", (( switches & 0x4000 ) == 0 ) ? 'L' : ' ', (( switches & 0x2000 ) == 0 ) ? 'R' : ' ', (( switches & 0x0800 ) == 0 ) ? 'U' : ' ', (( switches & 0x0400 ) == 0 ) ? 'D' : ' ', (( switches & 0x1000 ) == 0 ) ? 'X' : ' ' ); LCD_MoveTo( 0, 1 ); LCD_Printf( "S1:%d S2:%d S3:%d", ( switches & 0x0200 ) == 0, ( switches & 0x0100 ) == 0, ( PIND & ( 1 << 6 )) == 0 ); break; } case 2: { LCD_MoveTo( 0, 0 ); LCD_Printf( "L %02x %02x %02x %02x %02x", gADC[ 4 ], gADC[ 1 ], gADC[ 2 ], gADC[ 3 ], gADC[ 5 ] ); LCD_MoveTo( 0, 1 ); LCD_Printf( "E %02x %02x B %02x", gADC[ 0 ], gADC[ 7 ], gADC[ 6 ] ); break; } default: { LCD_MoveTo( 0, 0 ); LCD_Printf( "Setting: %d", ( switches & 0xF0 ) >> 4 ); break; } } pinc = PINC; pind = PIND; Log( " QL:%d%d QR:%d%d EC-L:%d EC-R:%d\n", ( ENCODER_L_A_PIN & ENCODER_L_A_MASK ) != 0, ( ENCODER_L_B_PIN & ENCODER_L_B_MASK ) != 0, ( ENCODER_R_A_PIN & ENCODER_R_A_MASK ) != 0, ( ENCODER_R_B_PIN & ENCODER_R_B_MASK ) != 0, gEncoderCountL, gEncoderCountR ); // Tick rate is 100/sec so waiting for 50 waits for 1/2 sec for ( i = 0; i < 50; i++ ) { WaitForTimer0Rollover(); #if 1 if ( UART0_IsCharAvailable() ) { char ch = UART0_GetChar(); if ( ch == ' ' ) { DebugKey(); } else { Log( "Read: '%c'\n", ch ); } } #endif } } return 0; }
void MENU_Draw( void ) { char *s; char fmtStr[ 10 ]; uint16_t val = 0; uint16_t maxVal = 0; int16_t ival = 0; int16_t maxIVal = 0; uint8_t maxLen; uint8_t valLen; MENU_MemItem_t item; uint8_t signedVal = 0; if ( !MENU_IsActive() ) { return; } if ( MENU_IsEditing() ) { MENU_GetItem( gMenuStack[ gMenuStackTop ], &item ); } else { // By only drawing when we're not editing, we reduce flicker LCD_Clear(); // First of all, draw the title of the containing menu MENU_GetItem( gMenuStack[ gMenuStackTop - 1 ], &item ); LCD_PutStr_P( item.name ); // Now draw the currently selected item LCD_MoveTo( 0, 1 ); MENU_GetItem( gMenuStack[ gMenuStackTop ], &item ); LCD_PutStr_P( item.name ); } switch ( item.type ) { case MENU_TYPE_BYTE: { if ( MENU_IsEditing() ) { val = gMenuEditVal.uintVal; } else { val = *item.val.byteVal.bytePtr; } maxVal = item.val.byteVal.maxVal; break; } case MENU_TYPE_UINT: { if ( MENU_IsEditing() ) { val = gMenuEditVal.uintVal; } else { val = *item.val.uintVal.uintPtr; } maxVal = item.val.uintVal.maxVal; break; } case MENU_TYPE_INT: { signedVal = 1; if ( MENU_IsEditing() ) { ival = gMenuEditVal.intVal; } else { ival = *item.val.intVal.intPtr; } maxIVal = item.val.intVal.maxVal; break; } default: { return; } } if ( signedVal ) { snprintf( fmtStr, sizeof( fmtStr ), "%d", maxIVal ); maxLen = strlen( fmtStr ); snprintf( fmtStr, sizeof( fmtStr ), "%d", ival ); } else { snprintf( fmtStr, sizeof( fmtStr ), "%u", maxVal ); maxLen = strlen( fmtStr ); snprintf( fmtStr, sizeof( fmtStr ), "%u", val ); } LCD_MoveTo( LCD_NumCols() - maxLen - 2, LCD_NumLines() - 1 ); LCD_PutChar( MENU_IsEditing() ? '[' : ' ' ); valLen = strlen( fmtStr ); while ( maxLen > valLen ) { LCD_PutChar( ' ' ); maxLen--; } s = fmtStr; while ( valLen > 0 ) { LCD_PutChar( *s++ ); valLen--; } LCD_PutChar( MENU_IsEditing() ? ']' : ' ' ); } // MENU_Draw
int main(void) { InitTimer(); InitUART(); LED_DDR |= LED_MASK; LCD_Init( CFG_LCD_NUM_LINES, CFG_LCD_NUM_COLUMNS ); LCD_PutStr( "LCD Test\n" ); LCD_PutStr( ">Line 2<\n" ); fdevopen( UART0_PutCharStdio, UART0_GetCharStdio ); printf( "*****\n" ); printf( "***** LCD Test program\n" ); printf( "*****\n" ); DDRB &= ~SW_ALL; PORTB |= SW_ALL; while( 1 ) { LED_PORT |= LED_MASK; ms_spin( 100 ); LED_PORT &= ~LED_MASK; ms_spin( 100 ); LED_PORT |= LED_MASK; ms_spin( 100 ); LED_PORT &= ~LED_MASK; ms_spin( 700 ); LCD_MoveTo(0,1); uint8_t pinb = PINB; if ( pinb & SW_A ) { printf("A is high "); LCD_PutChar('a'); } else { printf("A is low "); LCD_PutChar('A'); } if ( pinb & SW_B ) { printf("B is high "); LCD_PutChar('b'); } else { printf("B is low "); LCD_PutChar('B'); } if ( pinb & SW_C ) { printf("C is high\n"); LCD_PutChar('c'); } else { printf("C is low\n"); LCD_PutChar('C'); } } return 0; }