Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SET key functionality #109

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>electronic-leadscrew</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>
31 changes: 31 additions & 0 deletions els-f280049c/ControlPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,44 @@ void ControlPanel :: setMessage( const Uint16 *message )
this->message = message;
}

void ControlPanel :: increaseBrightness()
{
++brightness;

if (brightness == 5) brightness = 8;

setBrightness(brightness);
}

void ControlPanel :: decreaseBrightness()
{
--brightness;

if(brightness == 7) brightness = 4;

setBrightness(brightness);
}

void ControlPanel :: setBrightness( Uint16 brightness )
// Because of the screwy way the TM1638 controls brightness in steps of 1/16,
// 2/16, 4/16, 10/16, 11/16, 12/16, 13/16, and 14/16,
// there are really only five distinct levels.
// Limit brightness value sent to control panel to 1, 2, 3, 4, or 8.
// 0 = off.
// 5, 6, and 7 are indistinguishable from 4.
{
if (brightness == 0) brightness = 1;

if( brightness > 8 ) brightness = 8;

this->brightness = brightness;
}

Uint16 ControlPanel :: getBrightness(void)
{
return this->brightness;
}

void ControlPanel :: refresh()
{
configureSpiBus();
Expand Down
46 changes: 44 additions & 2 deletions els-f280049c/ControlPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@
#include "F28x_Project.h"
#include "SPIBus.h"

// Seven segment display segment mapping:
//
// MSb 7 6 5 4 3 2 1 0 x x x x x x x x LSb
//
// 7
// 2 6
// 1
// 3 5
// 4
// 0

#define ZERO 0b1111110000000000 // 0
#define ONE 0b0110000000000000 // 1
Expand All @@ -44,32 +54,60 @@
#define POINT 0b0000000100000000 // .
#define BLANK 0b0000000000000000

// Some lowercase letters have to be the same as the
// uppercase letter.
#define LETTER_A 0b1110111000000000
#define LETTER_a 0b1111101000000000
#define LETTER_B 0b0011111000000000
#define LETTER_b 0b0011111000000000
#define LETTER_C 0b1001110000000000
#define LETTER_c 0b0011001000000000
#define LETTER_D 0b0111101000000000
#define LETTER_d 0b0111101000000000
#define LETTER_E 0b1001111000000000
#define LETTER_e 0b1001111000000000
#define LETTER_F 0b1000111000000000
#define LETTER_f 0b1000111000000000
#define LETTER_G 0b1011110000000000
#define LETTER_g 0b1011110000000000
#define LETTER_H 0b0110111000000000
#define LETTER_h 0b0010111000000000
#define LETTER_I 0b0000110000000000
#define LETTER_i 0b0010000000000000
#define LETTER_J 0b0111100000000000
#define LETTER_j 0b0111100000000000
#define LETTER_K 0b1010111000000000
#define LETTER_k 0b1010111000000000
#define LETTER_L 0b0001110000000000
#define LETTER_l 0b0001110000000000
#define LETTER_M 0b1010100000000000
#define LETTER_m 0b1010100000000000
#define LETTER_N 0b1110110000000000
#define LETTER_n 0b0010101000000000
#define LETTER_O 0b1111110000000000
#define LETTER_o 0b0011101000000000
#define LETTER_P 0b1100111000000000
#define LETTER_p 0b1100111000000000
#define LETTER_Q 0b1110011000000000
#define LETTER_q 0b1110011000000000
#define LETTER_R 0b1100110000000000
#define LETTER_r 0b0000101000000000
#define LETTER_S 0b1011011000000000
#define LETTER_s 0b1011011000000000
#define LETTER_T 0b0001111000000000
#define LETTER_t 0b0001111000000000
#define LETTER_U 0b0111110000000000
#define LETTER_u 0b0011100000000000
#define LETTER_V 0b0111010000000000
#define LETTER_v 0b0111010000000000
#define LETTER_W 0b0101010000000000
#define LETTER_w 0b0101010000000000
#define LETTER_X 0b0110110000000000
#define LETTER_x 0b0110110000000000
#define LETTER_Y 0b0111011000000000
#define LETTER_y 0b0111011000000000
#define LETTER_Z 0b1101001000000000
#define LETTER_z 0b1101001000000000

#define DASH 0b0000001000000000

Expand Down Expand Up @@ -165,6 +203,7 @@ class ControlPanel
void configureSpiBus(void);
bool isValidKeyState(KEY_REG);
bool isStable(KEY_REG);
void setBrightness(Uint16 x);

public:
ControlPanel(SPIBus *spiBus);
Expand All @@ -187,8 +226,11 @@ class ControlPanel
// set a message that overrides the display, 8 characters required
void setMessage(const Uint16 *message);

// set a brightness value, 0 (off) to 8 (max)
void setBrightness(Uint16 brightness);
Uint16 getBrightness(void);

void increaseBrightness(void);

void decreaseBrightness(void);

// refresh the hardware display
void refresh(void);
Expand Down
12 changes: 12 additions & 0 deletions els-f280049c/Debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,25 @@ Debug :: Debug( void )

void Debug :: initHardware( void )
{
// Initialize GPIO
// Doesn't work if put after EALLOW
InitGpio();

// set up GPIO pins as output for debugging
EALLOW;

GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 0;
GpioCtrlRegs.GPADIR.bit.GPIO2 = 1;
GpioDataRegs.GPACLEAR.bit.GPIO2 = 1;

GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 0;
GpioCtrlRegs.GPADIR.bit.GPIO3 = 1;
GpioDataRegs.GPACLEAR.bit.GPIO3 = 1;

// LED4 on LAUNCHXL (red)
GpioCtrlRegs.GPAMUX2.bit.GPIO23 = 0;
GpioCtrlRegs.GPADIR.bit.GPIO23 = 1;
GpioDataRegs.GPACLEAR.bit.GPIO23 = 1;

EDIS;
}
28 changes: 28 additions & 0 deletions els-f280049c/Debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@

class Debug
{
private:
Uint16 heartbeatCount;

public:
Debug(void);
void initHardware(void);
Expand All @@ -42,6 +45,8 @@ class Debug
// analyzer pin 2
void begin2( void );
void end2( void );

void heartbeat( void );
};


Expand All @@ -65,5 +70,28 @@ inline void Debug :: end2( void )
GpioDataRegs.GPACLEAR.bit.GPIO3 = 1;
}

inline void Debug :: heartbeat( void )
{
++heartbeatCount;

if (heartbeatCount > 50)
{
heartbeatCount = 1;
}

if (heartbeatCount == 15)
{
// Turn off red LED and turn on green LED
GpioDataRegs.GPASET.bit.GPIO23 = 1;
GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1;
}

if (heartbeatCount == 1)
{
// Turn on red LED and turn off green LED
GpioDataRegs.GPACLEAR.bit.GPIO23 = 1;
GpioDataRegs.GPBSET.bit.GPIO34 = 1;
}
}

#endif // __DEBUG_H
Loading