Quad RGB sensor with SPI output drive, I2C display interface & analogue inputs / UI for various LED types
Dependencies: MCP23S17 PCF8574 TextLCD eeprom mbed-dev
Diff: main.cpp
- Revision:
- 11:729eb224dce6
- Parent:
- 10:efe8585f7fa4
- Child:
- 12:eab1bc88fe68
--- a/main.cpp Thu Oct 13 15:56:00 2016 +0000 +++ b/main.cpp Fri Nov 04 11:56:39 2016 +0000 @@ -34,7 +34,12 @@ //-------------------------------------- - +#define NEWBUTTON 0x80 +#define UPBUTTON 0x04 +#define DOWNBUTTON 0x01 +#define LEFTBUTTON 0x03 +#define RIGHTBUTTON 0x02 +#define TICKBUTTON 0x05 void SelectSensorPort(uint8_t SensorID); @@ -63,6 +68,11 @@ DigitalIn ModeSwitch2(p29); DigitalIn ModeSwitch3(p30); +//buttons +DigitalIn Button1(p22); +DigitalIn Button2(p23); +DigitalIn Button3(p24); +DigitalIn Button4(p8); //------------------------------------------------------------------------------- @@ -157,7 +167,7 @@ NOTUSED, 15, //sensor 15 }; */ - +/* char Config[32]={ //RGB, 0, //sensor 0 , uses 3 outputs - 0,1,2 GREEN_YELLOW, 0, //sensor 0 , uses 2 outputs - 0,1 GREEN_YELLOW, 2, //sensor 1 , uses 2 outputs - 2,3 @@ -176,29 +186,37 @@ NOTUSED, 15, //sensor 14 NOTUSED, 15, //sensor 15 }; +*/ -/* char Config[32]={ //RGB, 0, //sensor 0 , uses 3 outputs - 0,1,2 - STD_RED, 0, //sensor 0 , uses 3 outputs - 0,1,2 - STD_GREEN, 1, //sensor 1 - STD_RED, 2, //sensor 2 - STD_GREEN, 3, //sensor 3 - STD_RED, 4, //sensor 4 - STD_GREEN, 5, //sensor 5 - STD_RED, 6, //sensor 6 + STD_RED, 0, //sensor 0 , uses 3 outputs - 0,1,2 + STD_GREEN, 1, //sensor 1 + STD_BLUE, 2, //sensor 2 + STD_YELLOW, 3, //sensor 3 + GREEN_YELLOW, 4, //sensor 4 + RGB, 5, //sensor 5 + STD_RED, 6, //sensor 6 STD_GREEN, 7, //sensor 7 - STD_RED, 8, //sensor 8 - STD_GREEN, 9, //sensor 9 - STD_RED, 10, //sensor 10 - STD_GREEN, 11, //sensor 11 - STD_RED, 12, //sensor 12 - STD_GREEN, 13, //sensor 13 - STD_RED, 14, //sensor 14 - STD_GREEN, 15, //sensor 15 + STD_RED, 8, //sensor 8 + STD_RED, 9, //sensor 9 + STD_RED, 10, //sensor 10 + STD_RED, 11, //sensor 11 + STD_RED, 12, //sensor 12 + STD_RED, 13, //sensor 13 + STD_RED, 14, //sensor 14 + RGB, 15, //sensor 15 }; -*/ + //new config trpe +//each LED type is defined here +#define NOTUSED 0 +#define STD_RED 1 +#define STD_GREEN 2 +#define STD_BLUE 3 +#define STD_YELLOW 4 +#define GREEN_YELLOW 5 +#define RGB 6 char LEDState[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; //current detected LED states @@ -211,6 +229,21 @@ uint8_t ConfigureSensor; +uint8_t DisplayScreen = 0; +uint8_t DisplaySensorType; +uint8_t ButtonState = 0; + +char LEDTypes[7][6+1]={ + "SPARE ", //0 + "RED ", //1 + "GREEN ", //2 + "BLUE ", //3 + "YELLOW", //4 + "GN/YEL", //5 + "RGB " + }; //6 + + //------------TSC Stuff---------------- int sensor_addr = 41 << 1; @@ -349,6 +382,50 @@ return Result; } + +uint8_t GetButtonState(void) +{ + uint8_t ButtonStateNew = 0; + if (Button1 == 1) + { + ButtonStateNew = 1; + } + + if (Button2 == 1) + { + ButtonStateNew = 2; + } + + if (Button3 == 1) + { + ButtonStateNew = 3; + } + if (Button4 == 1) + { + ButtonStateNew = 4; + } + + if(ButtonStateNew != 0) + { + if(ButtonState == 0) + { + ButtonState = (ButtonStateNew | NEWBUTTON); + } + else + { + ButtonState = ButtonStateNew; + } + } + else + { + ButtonState = 0; + } + + + return ButtonState; +} + + void InitOutputs(void) { // Set all 8 Port A bits to output direction @@ -743,6 +820,80 @@ } } } + + +void HandleDisplay(void) +{ + uint8_t CurrentButton =0; + /* + #define NEWBUTTON 0x80 +#define UPBUTTON 0x01 +#define DOWNBUTTON 0x02 +#define LEFTBUTTON 0x03 +#define RIGHTBUTTON 0x04 +#define TICKBUTTON 0x05 +*/ + CurrentButton = GetButtonState(); + + //------------------- select the sensor ---------------- + if (CurrentButton == (UPBUTTON | NEWBUTTON)) + { + DisplayScreen++; + if (DisplayScreen == 17) + { + DisplayScreen = 0; + } + } + else + { + if (CurrentButton == (DOWNBUTTON | NEWBUTTON)) + { + DisplayScreen--; + if (DisplayScreen == 255) + { + DisplayScreen = 16; + } + } + } + + + //------------------- select the sensor type ---------------- + DisplaySensorType = Config[(DisplayScreen-1)*2]; + + if (CurrentButton == (RIGHTBUTTON | NEWBUTTON)) + { + if (DisplaySensorType < 6) + { + DisplaySensorType++; + Config[(DisplayScreen-1)*2] = DisplaySensorType; + } + } + else + { + if (CurrentButton == (LEFTBUTTON | NEWBUTTON)) + { + if (DisplaySensorType > 0) + { + DisplaySensorType--; + Config[(DisplayScreen-1)*2] = DisplaySensorType; + } + } + } + + + + //show current config setting + DisplaySensorType = Config[(DisplayScreen-1)*2]; + + if (DisplayScreen !=0) + { + lcd.locate(0, 0); + lcd.printf("Sensor %02i %s", DisplayScreen, LEDTypes[DisplaySensorType]); + lcd.locate(0, 1); + lcd.printf(" "); + } +} + int main() @@ -782,8 +933,11 @@ if (SensorNumber == GetModeSwitch()) { - UpdateDisplay(); - ShowLeds(SensorResult); + if (DisplayScreen == 0) + { + UpdateDisplay(); + ShowLeds(SensorResult); + } } } //end if @@ -796,7 +950,8 @@ lcd.locate(0, 1); lcd.printf("%02i ",GetModeSwitch() ); } - } + } + } //end for @@ -807,7 +962,7 @@ //{ // OutputDataB = 0x8000; //} - + HandleDisplay(); //Handle Comms HandleRS485(); } //while(1)