Project Embedded Systems E-ict Denayer

Dependencies:   BSP_DISCO_F746NG F7_Ethernet LCD_DISCO_F746NG TS_DISCO_F746NG mbed-rtos mbed

Committer:
Ayrton_L
Date:
Sat Jan 21 23:05:11 2017 +0000
Revision:
0:16bcf70d262e
Child:
1:a2f7adf6db3d
First up

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Ayrton_L 0:16bcf70d262e 1 #include "main.h"
Ayrton_L 0:16bcf70d262e 2
Ayrton_L 0:16bcf70d262e 3 // regel 68: enum schrijven voor IP/netmask... en vergelijken binnen main
Ayrton_L 0:16bcf70d262e 4
Ayrton_L 0:16bcf70d262e 5 uint32_t ul_ResetDisplay( )
Ayrton_L 0:16bcf70d262e 6 {
Ayrton_L 0:16bcf70d262e 7 display.Clear( LCD_COLOR_WHITE );
Ayrton_L 0:16bcf70d262e 8 display.SetBackColor( LCD_COLOR_WHITE );
Ayrton_L 0:16bcf70d262e 9 display.SetTextColor( LCD_COLOR_BLACK );
Ayrton_L 0:16bcf70d262e 10 return 0;
Ayrton_L 0:16bcf70d262e 11 }
Ayrton_L 0:16bcf70d262e 12
Ayrton_L 0:16bcf70d262e 13 uint32_t ul_CheckDHCP( struct Network x_DynNetwork ) //while lus, iedere seconde eens checken of er geen verandering is
Ayrton_L 0:16bcf70d262e 14 {
Ayrton_L 0:16bcf70d262e 15 if( Eth.init( ) == 0 )
Ayrton_L 0:16bcf70d262e 16 {
Ayrton_L 0:16bcf70d262e 17 char c_NewIP[16];
Ayrton_L 0:16bcf70d262e 18 Eth.connect( );
Ayrton_L 0:16bcf70d262e 19 strncpy( c_NewIP, Eth.getIPAddress( ), 16 );
Ayrton_L 0:16bcf70d262e 20 if( strcmp( x_DynNetwork.c_IPAddress, c_NewIP ) == false )
Ayrton_L 0:16bcf70d262e 21 {
Ayrton_L 0:16bcf70d262e 22 strncpy( x_DynNetwork.c_IPAddress, c_NewIP, 16 );
Ayrton_L 0:16bcf70d262e 23 strncpy( x_DynNetwork.c_MACAddress, Eth.getMACAddress( ), 16 );
Ayrton_L 0:16bcf70d262e 24 strncpy( x_DynNetwork.c_Netmask, Eth.getNetworkMask( ), 16 );
Ayrton_L 0:16bcf70d262e 25 strncpy( x_DynNetwork.c_Gateway, Eth.getGateway( ), 16 );
Ayrton_L 0:16bcf70d262e 26 }
Ayrton_L 0:16bcf70d262e 27 return 0;
Ayrton_L 0:16bcf70d262e 28 }
Ayrton_L 0:16bcf70d262e 29 else
Ayrton_L 0:16bcf70d262e 30 {
Ayrton_L 0:16bcf70d262e 31 display.DisplayStringAt( 0, 10, ( uint8_t * )"DHCP: FAILED: ", LEFT_MODE );
Ayrton_L 0:16bcf70d262e 32 return 1;
Ayrton_L 0:16bcf70d262e 33 }
Ayrton_L 0:16bcf70d262e 34 }
Ayrton_L 0:16bcf70d262e 35
Ayrton_L 0:16bcf70d262e 36 uint32_t ul_CheckInternet( )
Ayrton_L 0:16bcf70d262e 37 {
Ayrton_L 0:16bcf70d262e 38 return 0;
Ayrton_L 0:16bcf70d262e 39 }
Ayrton_L 0:16bcf70d262e 40
Ayrton_L 0:16bcf70d262e 41 uint32_t ul_CreateMenu( )
Ayrton_L 0:16bcf70d262e 42 {
Ayrton_L 0:16bcf70d262e 43 //480x272
Ayrton_L 0:16bcf70d262e 44 display.DrawRect( 0, 0, 125, 68);
Ayrton_L 0:16bcf70d262e 45 display.DisplayStringAt( 2, 34, ( uint8_t * )"DYNAMIC", LEFT_MODE );
Ayrton_L 0:16bcf70d262e 46 display.DrawRect( 0, 68, 125, 68);
Ayrton_L 0:16bcf70d262e 47 display.DisplayStringAt( 2, 102, ( uint8_t * )"STATIC", LEFT_MODE );
Ayrton_L 0:16bcf70d262e 48 return 0;
Ayrton_L 0:16bcf70d262e 49 }
Ayrton_L 0:16bcf70d262e 50
Ayrton_L 0:16bcf70d262e 51 uint32_t ul_ShowDynamicMenu( struct Network x_DynNetwork )
Ayrton_L 0:16bcf70d262e 52 {
Ayrton_L 0:16bcf70d262e 53 ul_ResetDisplay( );
Ayrton_L 0:16bcf70d262e 54 ul_CreateMenu( );
Ayrton_L 0:16bcf70d262e 55 display.SetFont( &Font16 );
Ayrton_L 0:16bcf70d262e 56 display.DisplayStringAt( 130, 10, ( uint8_t * )"IP address: ", LEFT_MODE );
Ayrton_L 0:16bcf70d262e 57 display.DisplayStringAt( 270, 10, ( uint8_t * )&x_DynNetwork.c_IPAddress, LEFT_MODE );
Ayrton_L 0:16bcf70d262e 58 display.DisplayStringAt( 130, 30, ( uint8_t * )"MAC Address: ", LEFT_MODE );
Ayrton_L 0:16bcf70d262e 59 display.DisplayStringAt( 270, 30, ( uint8_t * )&x_DynNetwork.c_MACAddress, LEFT_MODE );
Ayrton_L 0:16bcf70d262e 60 display.DisplayStringAt( 130, 50, ( uint8_t * )"Netmask: ", LEFT_MODE );
Ayrton_L 0:16bcf70d262e 61 display.DisplayStringAt( 270, 50, ( uint8_t * )&x_DynNetwork.c_Netmask, LEFT_MODE );
Ayrton_L 0:16bcf70d262e 62 display.DisplayStringAt( 130, 70, ( uint8_t * )"Gateway: ", LEFT_MODE );
Ayrton_L 0:16bcf70d262e 63 display.DisplayStringAt( 270, 70, ( uint8_t * )&x_DynNetwork.c_Gateway, LEFT_MODE );
Ayrton_L 0:16bcf70d262e 64 return 0;
Ayrton_L 0:16bcf70d262e 65 }
Ayrton_L 0:16bcf70d262e 66
Ayrton_L 0:16bcf70d262e 67 uint32_t ul_ShowStaticMenu( )
Ayrton_L 0:16bcf70d262e 68 {
Ayrton_L 0:16bcf70d262e 69 ul_ResetDisplay( );
Ayrton_L 0:16bcf70d262e 70 ul_CreateMenu( );
Ayrton_L 0:16bcf70d262e 71 display.DrawRect( 125, 0, 125, 68);
Ayrton_L 0:16bcf70d262e 72 display.DisplayStringAt( 130, 34, ( uint8_t * )"IP", LEFT_MODE );
Ayrton_L 0:16bcf70d262e 73 display.DrawRect( 125, 68, 125, 68);
Ayrton_L 0:16bcf70d262e 74 display.DisplayStringAt( 130, 102, ( uint8_t * )"Gateway", LEFT_MODE );
Ayrton_L 0:16bcf70d262e 75 display.DrawRect( 125, 136, 125, 68);
Ayrton_L 0:16bcf70d262e 76 display.DisplayStringAt( 130, 170, ( uint8_t * )"Netmask", LEFT_MODE );
Ayrton_L 0:16bcf70d262e 77 return 0;
Ayrton_L 0:16bcf70d262e 78 }
Ayrton_L 0:16bcf70d262e 79
Ayrton_L 0:16bcf70d262e 80 void v_TouchThread( void const *args )
Ayrton_L 0:16bcf70d262e 81 {
Ayrton_L 0:16bcf70d262e 82 TS_StateTypeDef Touch_State;
Ayrton_L 0:16bcf70d262e 83
Ayrton_L 0:16bcf70d262e 84 Touch.Init( 420, 272 );
Ayrton_L 0:16bcf70d262e 85
Ayrton_L 0:16bcf70d262e 86 while( 1 )
Ayrton_L 0:16bcf70d262e 87 {
Ayrton_L 0:16bcf70d262e 88 Touch.GetState( &Touch_State );
Ayrton_L 0:16bcf70d262e 89 if( ( Touch_State.touchDetected )&& ( Touch_State.touchX[0] < 125 )&& ( Touch_State.touchY[0] < 69 ) )
Ayrton_L 0:16bcf70d262e 90 {
Ayrton_L 0:16bcf70d262e 91 b_Dynamic = true;
Ayrton_L 0:16bcf70d262e 92 }
Ayrton_L 0:16bcf70d262e 93 else if( ( Touch_State.touchDetected )&& ( Touch_State.touchX[0] < 125 )&& ( Touch_State.touchY[0] > 68 )&& ( Touch_State.touchY[0] < 137 ) )
Ayrton_L 0:16bcf70d262e 94 {
Ayrton_L 0:16bcf70d262e 95 b_Dynamic = false;
Ayrton_L 0:16bcf70d262e 96 }
Ayrton_L 0:16bcf70d262e 97 else if( ( Touch_State.touchDetected )&& ( Touch_State.touchX[0] > 125 )&& ( Touch_State.touchY[0] < 68 )&& ( b_Dynamic == false) ) //button for static IP
Ayrton_L 0:16bcf70d262e 98 {
Ayrton_L 0:16bcf70d262e 99
Ayrton_L 0:16bcf70d262e 100 }
Ayrton_L 0:16bcf70d262e 101 }
Ayrton_L 0:16bcf70d262e 102 }
Ayrton_L 0:16bcf70d262e 103
Ayrton_L 0:16bcf70d262e 104 int main( )
Ayrton_L 0:16bcf70d262e 105 {
Ayrton_L 0:16bcf70d262e 106 struct Network x_DynNetwork;
Ayrton_L 0:16bcf70d262e 107
Ayrton_L 0:16bcf70d262e 108 ul_ResetDisplay( );
Ayrton_L 0:16bcf70d262e 109 ul_CreateMenu( );
Ayrton_L 0:16bcf70d262e 110 Thread t_Touch( v_TouchThread );
Ayrton_L 0:16bcf70d262e 111 t_Touch.set_priority( osPriorityNormal );
Ayrton_L 0:16bcf70d262e 112
Ayrton_L 0:16bcf70d262e 113 if( b_Dynamic == true )
Ayrton_L 0:16bcf70d262e 114 {
Ayrton_L 0:16bcf70d262e 115 if( ul_CheckDHCP( x_DynNetwork ) == 0 )
Ayrton_L 0:16bcf70d262e 116 {
Ayrton_L 0:16bcf70d262e 117 ul_ShowDynamicMenu( x_DynNetwork );
Ayrton_L 0:16bcf70d262e 118 ul_CheckInternet( );
Ayrton_L 0:16bcf70d262e 119 }
Ayrton_L 0:16bcf70d262e 120 }
Ayrton_L 0:16bcf70d262e 121 else if( b_Dynamic == false )
Ayrton_L 0:16bcf70d262e 122 {
Ayrton_L 0:16bcf70d262e 123 ul_ShowStaticMenu( );
Ayrton_L 0:16bcf70d262e 124 }
Ayrton_L 0:16bcf70d262e 125 return 0;
Ayrton_L 0:16bcf70d262e 126 }