newest version

Committer:
Alix955
Date:
Fri Dec 07 13:07:08 2018 +0000
Revision:
9:ca8090c7868e
Parent:
8:df979097cc71
updated;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
noutram 0:6f9f2e93a0be 1 #include "mbed.h"
Alix955 9:ca8090c7868e 2 #include "ntp-client/NTPClient.h"
Alix955 9:ca8090c7868e 3 #include "TCPServer.h"
Alix955 9:ca8090c7868e 4 #include "TCPSocket.h"
Alix955 9:ca8090c7868e 5 #include <iostream>
Alix955 9:ca8090c7868e 6 #include <string>
Alix955 9:ca8090c7868e 7 #include "EthernetInterface.h"
noutram 0:6f9f2e93a0be 8 #include "sample_hardware.hpp"
Alix955 9:ca8090c7868e 9
Alix955 9:ca8090c7868e 10
noutram 0:6f9f2e93a0be 11
noutram 0:6f9f2e93a0be 12 #define RED_DONE 1
noutram 0:6f9f2e93a0be 13 #define YELLOW_DONE 2
noutram 0:6f9f2e93a0be 14
Alix955 9:ca8090c7868e 15 #define IP "10.0.0.10"
Alix955 9:ca8090c7868e 16 #define NETMASK "255.0.0.0"
Alix955 9:ca8090c7868e 17 #define GATEWAY "10.0.0.1"
Alix955 9:ca8090c7868e 18
Alix955 9:ca8090c7868e 19
noutram 0:6f9f2e93a0be 20 //Digital outputs
noutram 0:6f9f2e93a0be 21 DigitalOut onBoardLED(LED1);
noutram 0:6f9f2e93a0be 22 DigitalOut redLED(PE_15);
noutram 0:6f9f2e93a0be 23 DigitalOut yellowLED(PB_10);
noutram 0:6f9f2e93a0be 24 DigitalOut greenLED(PB_11);
noutram 0:6f9f2e93a0be 25
noutram 0:6f9f2e93a0be 26 //Inputs
noutram 0:6f9f2e93a0be 27 DigitalIn onBoardSwitch(USER_BUTTON);
noutram 0:6f9f2e93a0be 28 DigitalIn SW2(PE_14);
Alix955 9:ca8090c7868e 29
noutram 0:6f9f2e93a0be 30 //Serial pc(USBTX, USBRX);
noutram 2:24eb98cf2376 31 AnalogIn adcIn(PA_0);
noutram 0:6f9f2e93a0be 32
noutram 5:58ba1a6dbf60 33 //Environmental Sensor driver
noutram 5:58ba1a6dbf60 34 #ifdef BME
noutram 5:58ba1a6dbf60 35 BME280 sensor(D14, D15);
noutram 5:58ba1a6dbf60 36 #else
noutram 5:58ba1a6dbf60 37 BMP280 sensor(D14, D15);
noutram 5:58ba1a6dbf60 38 #endif
noutram 3:768d30157488 39
noutram 8:df979097cc71 40 //LCD Driver (provided via mbed repository)
noutram 8:df979097cc71 41 //RS D9
noutram 8:df979097cc71 42 //E D8
noutram 8:df979097cc71 43 //D7,6,4,2 are the 4 bit for d4-7
noutram 8:df979097cc71 44 TextLCD lcd(D9, D8, D7, D6, D4, D2); // rs, e, d4-d7
noutram 8:df979097cc71 45
Alix955 9:ca8090c7868e 46
noutram 8:df979097cc71 47 //SD Card
noutram 8:df979097cc71 48 SDBlockDevice sd(PB_5, D12, D13, D10); // mosi, miso, sclk, cs
noutram 8:df979097cc71 49
Alix955 9:ca8090c7868e 50
Alix955 9:ca8090c7868e 51
Alix955 9:ca8090c7868e 52
noutram 0:6f9f2e93a0be 53 //POWER ON SELF TEST
noutram 0:6f9f2e93a0be 54 void post()
noutram 0:6f9f2e93a0be 55 {
noutram 0:6f9f2e93a0be 56 //POWER ON TEST (POT)
noutram 5:58ba1a6dbf60 57 puts("**********STARTING POWER ON SELF TEST (POST)**********");
noutram 5:58ba1a6dbf60 58
noutram 5:58ba1a6dbf60 59 //Test LEDs
noutram 3:768d30157488 60 puts("ALL LEDs should be blinking");
noutram 0:6f9f2e93a0be 61 for (unsigned int n=0; n<10; n++) {
noutram 0:6f9f2e93a0be 62 redLED = 1;
noutram 0:6f9f2e93a0be 63 yellowLED = 1;
noutram 0:6f9f2e93a0be 64 greenLED = 1;
noutram 0:6f9f2e93a0be 65 wait(0.05);
noutram 0:6f9f2e93a0be 66 redLED = 0;
noutram 0:6f9f2e93a0be 67 yellowLED = 0;
noutram 0:6f9f2e93a0be 68 greenLED = 0;
noutram 0:6f9f2e93a0be 69 wait(0.05);
noutram 3:768d30157488 70 }
noutram 3:768d30157488 71
noutram 3:768d30157488 72 //Output the switch states (hold them down to test)
Alix955 9:ca8090c7868e 73 printf("SW2: %d\n\r", SW2.read());
noutram 7:d0e445a97c60 74 printf("USER: %d\n\r", onBoardSwitch.read());
noutram 3:768d30157488 75
noutram 3:768d30157488 76 //Output the ADC
noutram 3:768d30157488 77 printf("ADC: %f\n\r", adcIn.read());
noutram 5:58ba1a6dbf60 78
noutram 5:58ba1a6dbf60 79 //Read Sensors (I2C)
noutram 5:58ba1a6dbf60 80 float temp = sensor.getTemperature();
noutram 5:58ba1a6dbf60 81 float pressure = sensor.getPressure();
noutram 5:58ba1a6dbf60 82 #ifdef BME
noutram 5:58ba1a6dbf60 83 float humidity = sensor.getHumidity();
noutram 5:58ba1a6dbf60 84 #endif
noutram 5:58ba1a6dbf60 85
noutram 5:58ba1a6dbf60 86 //Display in PuTTY
noutram 5:58ba1a6dbf60 87 printf("Temperature: %5.1f\n", temp);
noutram 5:58ba1a6dbf60 88 printf("Pressure: %5.1f\n", pressure);
noutram 5:58ba1a6dbf60 89 #ifdef BME
noutram 5:58ba1a6dbf60 90 printf("Pressure: %5.1f\n", humidity);
noutram 5:58ba1a6dbf60 91 #endif
noutram 5:58ba1a6dbf60 92
noutram 8:df979097cc71 93 //Display on LCD
noutram 8:df979097cc71 94 redLED = 1;
noutram 8:df979097cc71 95 lcd.cls();
noutram 8:df979097cc71 96 lcd.printf("LCD TEST...");
noutram 8:df979097cc71 97 wait(0.5);
noutram 8:df979097cc71 98 redLED = 0;
noutram 8:df979097cc71 99
noutram 8:df979097cc71 100 //Network test (if BOTH switches are held down)
Alix955 9:ca8090c7868e 101 // networktest();
noutram 8:df979097cc71 102
noutram 5:58ba1a6dbf60 103 puts("**********POST END**********");
noutram 5:58ba1a6dbf60 104
noutram 4:d884f14069c6 105 }
noutram 4:d884f14069c6 106
noutram 4:d884f14069c6 107 void errorCode(ELEC350_ERROR_CODE err)
noutram 4:d884f14069c6 108 {
noutram 6:d95616e645bb 109 switch (err) {
noutram 6:d95616e645bb 110 case OK:
noutram 6:d95616e645bb 111 greenLED = 1;
noutram 6:d95616e645bb 112 wait(1.0);
noutram 6:d95616e645bb 113 greenLED = 0;
noutram 6:d95616e645bb 114 return;
noutram 6:d95616e645bb 115 case FATAL:
noutram 6:d95616e645bb 116 while(1) {
noutram 6:d95616e645bb 117 redLED = 1;
noutram 6:d95616e645bb 118 wait(0.1);
noutram 6:d95616e645bb 119 redLED = 0;
noutram 6:d95616e645bb 120 wait(0.1);
noutram 6:d95616e645bb 121 }
noutram 6:d95616e645bb 122 };
noutram 0:6f9f2e93a0be 123 }