|
|
|
@ -75,6 +75,26 @@ void Display7Segment::setLitSegments(unsigned char segs) {
|
|
|
|
|
prevSegments = segs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned char Display7Segment::segmentsForNumericDigit(unsigned char val, bool dp) {
|
|
|
|
|
unsigned char ret = 0;
|
|
|
|
|
if (val == 0) { ret = 0x7e; }
|
|
|
|
|
else if (val == 1) { ret = 0x30; }
|
|
|
|
|
else if (val == 2) { ret = 0x6d; }
|
|
|
|
|
else if (val == 3) { ret = 0x79; }
|
|
|
|
|
else if (val == 4) { ret = 0x33; }
|
|
|
|
|
else if (val == 5) { ret = 0x5b; }
|
|
|
|
|
else if (val == 6) { ret = 0x5f; }
|
|
|
|
|
else if (val == 7) { ret = 0x70; }
|
|
|
|
|
else if (val == 8) { ret = 0x7f; }
|
|
|
|
|
else if (val == 9) { ret = 0x73; }
|
|
|
|
|
|
|
|
|
|
if (dp) {
|
|
|
|
|
ret |= 0x80;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Display7Segment::drawContents( TQPainter *p )
|
|
|
|
|
{
|
|
|
|
|
// Draw all segments
|
|
|
|
@ -453,4 +473,149 @@ void Display7Segment::drawSegment(const TQPoint &pos, char segmentNo, TQPainter
|
|
|
|
|
#undef DARK
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Display7SegmentArray::Display7SegmentArray( TQWidget *parent, const char *name )
|
|
|
|
|
: TQFrame( parent, name ),
|
|
|
|
|
m_numberOfDigits(0),
|
|
|
|
|
m_segmentStyle(Flat)
|
|
|
|
|
{
|
|
|
|
|
init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Display7SegmentArray::~Display7SegmentArray() {
|
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
|
|
// Delete displays
|
|
|
|
|
for (i=0; i < m_numberOfDigits; i++) {
|
|
|
|
|
delete m_displayArray[i];
|
|
|
|
|
}
|
|
|
|
|
delete m_displayArray;
|
|
|
|
|
m_displayArray = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Display7SegmentArray::init() {
|
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
|
|
// Set up grid layout
|
|
|
|
|
m_layout = new TQGridLayout(this, 1, m_numberOfDigits);
|
|
|
|
|
m_layout->setAutoAdd(true);
|
|
|
|
|
|
|
|
|
|
// Allocate display array
|
|
|
|
|
m_displayArray = (Display7Segment**)malloc(sizeof(Display7Segment*) * m_numberOfDigits);
|
|
|
|
|
|
|
|
|
|
// Create displays
|
|
|
|
|
for (i=0; i < m_numberOfDigits; i++) {
|
|
|
|
|
m_displayArray[i] = new Display7Segment(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setSizePolicy(TQSizePolicy(TQSizePolicy::Minimum, TQSizePolicy::Minimum));
|
|
|
|
|
|
|
|
|
|
// Set up displays
|
|
|
|
|
for (i=0; i < m_numberOfDigits; i++) {
|
|
|
|
|
m_displayArray[i]->setBackgroundColor(TQt::black);
|
|
|
|
|
m_displayArray[i]->setPaletteForegroundColor(TQColor(0, 255, 64));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The LED display can work one of two ways
|
|
|
|
|
#if 0
|
|
|
|
|
// Separated segments
|
|
|
|
|
for (i=0; i < m_numberOfDigits; i++) {
|
|
|
|
|
m_displayArray[i]->setFrameStyle(TQFrame::Box | TQFrame::Raised);
|
|
|
|
|
}
|
|
|
|
|
setFrameStyle(TQFrame::NoFrame);
|
|
|
|
|
#else
|
|
|
|
|
// Combined segments
|
|
|
|
|
for (i=0; i < m_numberOfDigits; i++) {
|
|
|
|
|
m_displayArray[i]->setFrameStyle(TQFrame::NoFrame);
|
|
|
|
|
}
|
|
|
|
|
setBackgroundColor(TQt::black);
|
|
|
|
|
setFrameStyle(TQFrame::Box | TQFrame::Raised);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Display7SegmentArray::setNumberOfDigits(unsigned int count) {
|
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
|
|
if (m_numberOfDigits != count) {
|
|
|
|
|
// Delete displays
|
|
|
|
|
if (m_displayArray) {
|
|
|
|
|
for (i=0; i < m_numberOfDigits; i++) {
|
|
|
|
|
delete m_displayArray[i];
|
|
|
|
|
}
|
|
|
|
|
delete m_displayArray;
|
|
|
|
|
m_displayArray = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Destroy layout
|
|
|
|
|
if (m_layout) {
|
|
|
|
|
delete m_layout;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set display count
|
|
|
|
|
m_numberOfDigits = count;
|
|
|
|
|
|
|
|
|
|
// Reinitialize
|
|
|
|
|
init();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Display7SegmentArray::setSegmentStyle(SegmentStyle s) {
|
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
|
|
m_segmentStyle = s;
|
|
|
|
|
for (i=0; i < m_numberOfDigits; i++) {
|
|
|
|
|
m_displayArray[i]->setSegmentStyle((Display7Segment::SegmentStyle)m_segmentStyle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Display7SegmentArray::SegmentStyle Display7SegmentArray::segmentStyle() const {
|
|
|
|
|
return m_segmentStyle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Display7SegmentArray::setValue(double value, int maxDecimalLength, bool forceMinDecimalLength) {
|
|
|
|
|
bool dp;
|
|
|
|
|
unsigned int i;
|
|
|
|
|
TQString displayString = TQString("%1").arg(value);
|
|
|
|
|
if (maxDecimalLength >= 0) {
|
|
|
|
|
int decPos = displayString.find(".");
|
|
|
|
|
if (decPos >= 0) {
|
|
|
|
|
int decLen = (displayString.length() - 1) - decPos;
|
|
|
|
|
if (decLen > maxDecimalLength) {
|
|
|
|
|
displayString.truncate(displayString.length() - (decLen - maxDecimalLength));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (forceMinDecimalLength) {
|
|
|
|
|
if (decPos < 0) {
|
|
|
|
|
displayString.append(".");
|
|
|
|
|
decPos = displayString.length() - 1;
|
|
|
|
|
}
|
|
|
|
|
for (int i = displayString.length(); i < decPos + maxDecimalLength + 1; i++) {
|
|
|
|
|
displayString.append("0");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
int last_char = displayString.length();
|
|
|
|
|
int current_char = (last_char - (int)m_numberOfDigits);
|
|
|
|
|
if (displayString.contains(".")) {
|
|
|
|
|
current_char--;
|
|
|
|
|
}
|
|
|
|
|
for (i=0; i < m_numberOfDigits; i++) {
|
|
|
|
|
if (current_char < 0) {
|
|
|
|
|
m_displayArray[i]->setLitSegments(0x0);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
dp = false;
|
|
|
|
|
if (current_char < (displayString.length() - 1)) {
|
|
|
|
|
if (displayString[current_char + 1] == '.') {
|
|
|
|
|
dp = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (displayString[current_char] == '.') {
|
|
|
|
|
current_char++;
|
|
|
|
|
}
|
|
|
|
|
m_displayArray[i]->setLitSegments(Display7Segment::segmentsForNumericDigit(TQString(displayString[current_char]).toInt(NULL, 10), dp));
|
|
|
|
|
}
|
|
|
|
|
current_char++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#include "sevensegment.moc"
|