libmoglk libMoGlk
A library to drive Matrix Orbital's GLK graphic LCD

Browse the code

Differences between 38 and 39 on /.
Number of edited files: 7 (0 added, 0 deleted and 7 modified)
Author: ematech
Log message:
Tried to make it work but still not functionnal
Segfaults like hell
Date: 2010-09-26 02:39:19

Added file(s) Deleted file(s) Modified file(s)

 

Old New Code
25 25

                                        
26 26
pixel: pixel.cc
27 27
	$(CC) $(CFLAGS) -I ../../src -c -o pixel.o pixel.cc
28  
	$(CC) $(CFLAGS) -L ../../src -static -o pixel pixel.o -lmoglk
  28
	$(CC) $(CFLAGS) -L ../../build/default -static -o pixel pixel.o -lmoglk -D_GNU_SOURCE -lccext2 -pthread -lccgnu2 -ldl -lrt -lpthread -fPIC 
29 29

                                        
30 30
clean:
31 31
	rm pixel.o
32 32

                                        

 

Old New Code
21 21
#include "../../src/moglk.h"
22 22
#include "ematech.h"
23 23
#include <iostream>
  24
using namespace moglk;
24 25

                                        
25 26
int main(void)
26 27
{
27  
	char port[] = "/dev/ttyUSB0";
28  
	unsigned long int speed = 19200;
29  

                                    
30  
	moglk lcd;
31  
	int check = lcd.init(port,speed);
32  
	if (check > 0)
33  
	{
  28
	Moglk lcd("/dev/ttyUSB0");
34 29
        lcd.clearScreen();
35 30

                                        
36 31
        unsigned char x = 0;
53 48
            i++;
54 49
        };
55 50

                                        
56  
	}
57  
	else
58  
	{
59  
        std::cerr << "libmoglk exited with code " << check << std::endl;
60  
	}
61 51
}
62 52

                                        

 

Old New Code
27 27

                                        
28 28
// Namespaces
29 29
using namespace std;
  30
using namespace ost;
30 31

                                        
31 32
// Debug
32 33
//#define NDEBUG
33 34

                                        
34 35
//TODO: Autodetect device
35 36
//FIXME: Use a portable serial I/O library
  37
namespace moglk {
36 38
Moglk::Moglk(const char *device_ptr)
37 39
{
38 40
  Port *serial_port = NULL;
39 41
  try {
40  
	serial_port = new Port("/dev/ttyUSB0");
  42
	serial_port = new Port(device_ptr);
41 43
  } catch (Port::xError *e) {
42 44
	cout << "Port Error; aborting" << endl;
43 45
	::exit(1);
108 110

                                        
109 111
void Moglk::send(int * message_ptr)
110 112
{
111  
        unsigned int n = 0;
  113
    unsigned int n = 0;
112 114
	int value = *(message_ptr + n);
113 115

                                        
114 116
	while (value != EOF)
390 392
	int message[] = {CMD_INIT,
391 393
                         CMD_CLEAR_SCREEN,
392 394
                         EOF};
  395

                                    
  396

                                    
  397

                                    
393 398
	send(&message[0]);
394 399

                                        
395 400
} /* clearScreen() */
2652 2657
    upload(data_ptr);
2653 2658

                                        
2654 2659
} /* uploadFs */
  2660
}
2655 2661

                                        

 

Old New Code
563 563

                                        
564 564
#include "port.h"
565 565

                                        
566  
//Namespaces
567  
#ifdef	CCXX_NAMESPACES
568  
using namespace std;
569  
using namespace ost;
570  
#endif
571  

                                    
572 566
// Class definitions
573  
class Moglk
574  
{
575  
	public:
576  
        Moglk(const char * device_ptr = "/dev/ttyS0");
577  
        ~Moglk();
  567
namespace moglk {
  568
    class Moglk
  569
    {
  570
    	public:
  571
            Moglk(const char * device_ptr = "/dev/ttyS0");
  572
            ~Moglk();
578 573

                                        
579  
        //int autodetect(void);
  574
            //int autodetect(void);
580 575

                                        
581  
        //int autodetectPort(void);
  576
            //int autodetectPort(void);
582 577

                                        
583  
        bool setBaudRate(unsigned long int baud_rate = 19200);
  578
            bool setBaudRate(unsigned long int baud_rate = 19200);
584 579

                                        
585  
        void setFlowControl(bool state = 0,
586  
                            unsigned char full = 0,
587  
                            unsigned char empty = 0);
  580
            void setFlowControl(bool state = 0,
  581
                                unsigned char full = 0,
  582
                                unsigned char empty = 0);
588 583

                                        
589  
        void display(const char text[],
590  
                     unsigned char font = 0,
591  
                     unsigned char x = 255,
592  
                     unsigned char y = 255);
  584
            void display(const char text[],
  585
                         unsigned char font = 0,
  586
                         unsigned char x = 255,
  587
                         unsigned char y = 255);
593 588

                                        
594  
        void goHome(void);
  589
            void goHome(void);
595 590

                                        
596  
        void setFont(unsigned char id = 1,
597  
                     unsigned char lm = 0,
598  
                     unsigned char tm = 0,
599  
                     unsigned char csp = 0,
600  
                     unsigned char lsp = 1,
601  
                     unsigned char srow = 64);
  591
            void setFont(unsigned char id = 1,
  592
                         unsigned char lm = 0,
  593
                         unsigned char tm = 0,
  594
                         unsigned char csp = 0,
  595
                         unsigned char lsp = 1,
  596
                         unsigned char srow = 64);
602 597

                                        
603  
        void setFontMetrics(unsigned char lm = 0,
604  
                            unsigned char tm = 0,
605  
                            unsigned char csp = 0,
606  
                            unsigned char lsp = 1,
607  
                            unsigned char srow = 64);
  598
            void setFontMetrics(unsigned char lm = 0,
  599
                                unsigned char tm = 0,
  600
                                unsigned char csp = 0,
  601
                                unsigned char lsp = 1,
  602
                                unsigned char srow = 64);
608 603

                                        
609  
        void setBoxSpace(bool mode = 1);
  604
            void setBoxSpace(bool mode = 1);
610 605

                                        
611  
        void setAutoScroll(bool mode = 1);
  606
            void setAutoScroll(bool mode = 1);
612 607

                                        
613  
        void setCursor(unsigned char x,
614  
                       unsigned char y,
615  
                       bool mode = 0);
  608
            void setCursor(unsigned char x,
  609
                           unsigned char y,
  610
                           bool mode = 0);
616 611

                                        
617  
        void drawMemBmp(unsigned char id = 1,
618  
                        unsigned char x = 0,
619  
                        unsigned char y = 0);
  612
            void drawMemBmp(unsigned char id = 1,
  613
                            unsigned char x = 0,
  614
                            unsigned char y = 0);
620 615

                                        
621  
        void setDrawingColor(bool color = 1);
  616
            void setDrawingColor(bool color = 1);
622 617

                                        
623  
        void drawPixel(unsigned char x,
624  
                       unsigned char y,
625  
                       bool color = 1);
626  

                                    
627  
        bool drawLine(unsigned char x1,
628  
                      unsigned char y1,
629  
                      unsigned char x2 = 255,
630  
                      unsigned char y2 = 255,
631  
                      bool color = 1);
632  

                                    
633  
        void drawRectangle(unsigned char x1,
634  
                           unsigned char y1,
635  
                           unsigned char x2,
636  
                           unsigned char y2,
637  
                           bool mode = 0,
  618
            void drawPixel(unsigned char x,
  619
                           unsigned char y,
638 620
                           bool color = 1);
639 621

                                        
640  
        bool initBarGraph(unsigned char x1,
  622
            bool drawLine(unsigned char x1,
641 623
                          unsigned char y1,
642  
                          unsigned char x2,
643  
                          unsigned char y2,
644  
                          unsigned char type = 0,
645  
                          unsigned char id = 0);
  624
                          unsigned char x2 = 255,
  625
                          unsigned char y2 = 255,
  626
                          bool color = 1);
646 627

                                        
647  
        bool drawBarGraph(unsigned char value,
648  
                          unsigned char id = 0);
  628
            void drawRectangle(unsigned char x1,
  629
                               unsigned char y1,
  630
                               unsigned char x2,
  631
                               unsigned char y2,
  632
                               bool mode = 0,
  633
                               bool color = 1);
649 634

                                        
650  
        bool initStripChart(unsigned char x1,
651  
                            unsigned char y1,
652  
                            unsigned char x2,
653  
                            unsigned char y2,
654  
                            unsigned char id = 0);
  635
            bool initBarGraph(unsigned char x1,
  636
                              unsigned char y1,
  637
                              unsigned char x2,
  638
                              unsigned char y2,
  639
                              unsigned char type = 0,
  640
                              unsigned char id = 0);
655 641

                                        
656  
        bool shiftStripChart(bool direction = 0,
657  
                             unsigned char id =0);
  642
            bool drawBarGraph(unsigned char value,
  643
                              unsigned char id = 0);
658 644

                                        
659  
        bool setGpo(unsigned char id,
660  
                    bool state);
  645
            bool initStripChart(unsigned char x1,
  646
                                unsigned char y1,
  647
                                unsigned char x2,
  648
                                unsigned char y2,
  649
                                unsigned char id = 0);
661 650

                                        
662  
        bool setLed(unsigned char id,
663  
                    unsigned char state);
  651
            bool shiftStripChart(bool direction = 0,
  652
                                 unsigned char id =0);
664 653

                                        
665  
        bool ledYellow(unsigned char id);
  654
            bool setGpo(unsigned char id,
  655
                        bool state);
666 656

                                        
667  
        bool ledGreen(unsigned char id);
  657
            bool setLed(unsigned char id,
  658
                        unsigned char state);
668 659

                                        
669  
        bool ledRed(unsigned char id);
  660
            bool ledYellow(unsigned char id);
670 661

                                        
671  
        bool ledOff(unsigned char id);
  662
            bool ledGreen(unsigned char id);
672 663

                                        
673  
        bool startupGpo(unsigned char id,
674  
                        bool state);
  664
            bool ledRed(unsigned char id);
675 665

                                        
676  
        void setAutoTxKey(bool state);
  666
            bool ledOff(unsigned char id);
677 667

                                        
678  
        void clearKeyBuffer(void);
  668
            bool startupGpo(unsigned char id,
  669
                            bool state);
679 670

                                        
680  
        void setDebounce(unsigned char time);
  671
            void setAutoTxKey(bool state);
681 672

                                        
682  
        void setAutoRepeat(bool mode);
  673
            void clearKeyBuffer(void);
683 674

                                        
684  
        void autoRepeatOff(void);
  675
            void setDebounce(unsigned char time);
685 676

                                        
686  
        void clearScreen(void);
  677
            void setAutoRepeat(bool mode);
687 678

                                        
688  
        bool setBacklight(bool state = 1,
689  
                          unsigned char time = 0);
  679
            void autoRepeatOff(void);
690 680

                                        
691  
        void setBrightness(unsigned char value = 255);
  681
            void clearScreen(void);
692 682

                                        
693  
        void setDefaultBrightness(unsigned char value = 255);
  683
            bool setBacklight(bool state = 1,
  684
                              unsigned char time = 0);
694 685

                                        
695  
        void setContrast(unsigned char value = 128);
  686
            void setBrightness(unsigned char value = 255);
696 687

                                        
697  
        void setDefaultContrast(unsigned char value = 128);
  688
            void setDefaultBrightness(unsigned char value = 255);
698 689

                                        
699  
        void wipeFs(void);
  690
            void setContrast(unsigned char value = 128);
700 691

                                        
701  
        unsigned short int getFreeSpace(void);
  692
            void setDefaultContrast(unsigned char value = 128);
702 693

                                        
703  
        void setRemember(bool mode = 1);
  694
            void wipeFs(void);
704 695

                                        
705  
        void setCustomerData(const char * data);
  696
            unsigned short int getFreeSpace(void);
706 697

                                        
707  
        void getCustomerData(unsigned char * data);
  698
            void setRemember(bool mode = 1);
708 699

                                        
709  
        unsigned char getVersion(void);
  700
            void setCustomerData(const char * data);
710 701

                                        
711  
        unsigned char getModuleType(void);
  702
            void getCustomerData(unsigned char * data);
712 703

                                        
713  
        void getDirectory(void);
  704
            unsigned char getVersion(void);
714 705

                                        
715  
        void deleteFile(bool type,
716  
                        unsigned char id);
  706
            unsigned char getModuleType(void);
717 707

                                        
718  
        int * downloadFile(bool type,
719  
                           unsigned char id,
720  
                           int * file_ptr);
  708
            void getDirectory(void);
721 709

                                        
722  
        int * dumpFs(int * file_ptr);
  710
            void deleteFile(bool type,
  711
                            unsigned char id);
723 712

                                        
724  
        int * dumpSettings(int * file_ptr);
  713
            int * downloadFile(bool type,
  714
                               unsigned char id,
  715
                               int * file_ptr);
725 716

                                        
726  
        void moveFile(bool old_type,
727  
                      unsigned char old_id,
728  
                      bool new_type,
729  
                      unsigned char new_id);
  717
            int * dumpFs(int * file_ptr);
730 718

                                        
731  
        void setLock(std::bitset<8> level);
  719
            int * dumpSettings(int * file_ptr);
732 720

                                        
733  
        void setDefaultLock(std::bitset<8> level);
  721
            void moveFile(bool old_type,
  722
                          unsigned char old_id,
  723
                          bool new_type,
  724
                          unsigned char new_id);
734 725

                                        
735  
        unsigned char pollKey(void);
  726
            void setLock(std::bitset<8> level);
736 727

                                        
737  
        void setCustomKeyCodes(unsigned char kup_top,
738  
                               unsigned char kup_up,
739  
                               unsigned char kup_right,
740  
                               unsigned char kup_left,
741  
                               unsigned char kup_center,
742  
                               unsigned char kup_bottom,
743  
                               unsigned char kup_down,
744  
                               unsigned char kdown_top,
745  
                               unsigned char kdown_up,
746  
                               unsigned char kdown_right,
747  
                               unsigned char kdown_left,
748  
                               unsigned char kdown_center,
749  
                               unsigned char kdown_bottom,
750  
                               unsigned char kdown_down);
  728
            void setDefaultLock(std::bitset<8> level);
751 729

                                        
752  
        void drawBmp(unsigned char x,
753  
                     unsigned char y,
754  
                     unsigned char width,
755  
                     unsigned char height,
756  
                     int * data);
  730
            unsigned char pollKey(void);
757 731

                                        
758  
        void uploadFont(unsigned char id,
759  
                        unsigned int size,
760  
                        char * data_ptr);
  732
            void setCustomKeyCodes(unsigned char kup_top,
  733
                                   unsigned char kup_up,
  734
                                   unsigned char kup_right,
  735
                                   unsigned char kup_left,
  736
                                   unsigned char kup_center,
  737
                                   unsigned char kup_bottom,
  738
                                   unsigned char kup_down,
  739
                                   unsigned char kdown_top,
  740
                                   unsigned char kdown_up,
  741
                                   unsigned char kdown_right,
  742
                                   unsigned char kdown_left,
  743
                                   unsigned char kdown_center,
  744
                                   unsigned char kdown_bottom,
  745
                                   unsigned char kdown_down);
761 746

                                        
762  
        void uploadBmp(unsigned char id,
763  
                       unsigned int size,
764  
                       char * data_ptr);
  747
            void drawBmp(unsigned char x,
  748
                         unsigned char y,
  749
                         unsigned char width,
  750
                         unsigned char height,
  751
                         int * data);
765 752

                                        
766  
        void uploadFs(unsigned int size,
767  
                      char * data_ptr);
  753
            void uploadFont(unsigned char id,
  754
                            unsigned int size,
  755
                            char * data_ptr);
768 756

                                        
769  
	private:
770  
	Port *serial_port;
771  
        unsigned long int autodetectBaudRate(char * device_ptr = "/dev/ttyS0");
772  
        void transmit(int * data_ptr);
773  
        bool receive(unsigned char * data_ptr);
774  
        bool receiveFile(int * file_ptr);
  757
            void uploadBmp(unsigned char id,
  758
                           unsigned int size,
  759
                           char * data_ptr);
775 760

                                        
776  
        bool upload(char * data_ptr);
  761
            void uploadFs(unsigned int size,
  762
                          char * data_ptr);
777 763

                                        
778  
	void send(int * message_ptr);
  764
    	private:
  765
        	Port *serial_port;
  766
            unsigned long int autodetectBaudRate(char * device_ptr = "/dev/ttyS0");
  767
            void transmit(int * data_ptr);
  768
            bool receive(unsigned char * data_ptr);
  769
            bool receiveFile(int * file_ptr);
779 770

                                        
780  
}; /* Moglk */
  771
            bool upload(char * data_ptr);
781 772

                                        
  773
        	void send(int * message_ptr);
  774
    };
  775
} /* Moglk */
  776

                                    
782 777
#endif /* #ifndef _MOGLK_H */
783 778

                                        

 

Old New Code
25 25
#endif
26 26

                                        
27 27
using namespace std;
  28
using namespace ost;
28 29

                                        
29 30
Port::Port(const char *device,
30  
	   int priority,
  31
           int priority,
31 32
           int stacksize) :
32 33
  TTYSession( device, priority, stacksize ) {
33 34

                                        
34  
  cout << "PORT: Creating serial port" << endl;
  35
  cout << "PORT: Creating serial port : " << device << endl;
35 36

                                        
36 37
  if (!(*this)) {
37 38
	throw xError();
38 39

                                        

 

Old New Code
25 25
// Headers
26 26
#include <cc++/common.h>	//GNU Common C++
27 27

                                        
28  
// Namespaces
29  
#ifdef	CCXX_NAMESPACES
30  
using namespace std;
31  
using namespace ost;
32  
#endif
33  

                                    
34 28
// Class definitions
35  
class Port : public TTYSession
  29
class Port : public ost::TTYSession
36 30
{
37 31
	public:
38 32
        Port(const char * device_ptr,
39 33

                                        

 

Old New Code
6 6
    conf.check_cfg(atleast_pkgconfig_version='0.0.0')
7 7
    conf.check_cfg(package='libccgnu2', atleast_version='0.0.0')
8 8
    conf.check_cfg(package='libccgnu2', args='--cflags --libs')
  9
    conf.check_cfg(package='libccext2', atleast_version='0.0.0')
  10
    conf.check_cfg(package='libccext2', args='--cflags --libs')
9 11
    pango_version = conf.check_cfg(modversion='libccgnu2')
10 12
def build(bld):
11  
    tgen = bld.new_task_gen('cxx', 'shlib')
12  
    tgen.source = 'moglk.cpp port.cpp'
13  
    tgen.target = 'libmoglk'
14  
    tgen.includes = '.'
15  
    tgen.install_path = '${SOME_PATH}/lib'
16  
    tgen.ccflags = '-O2 -Wall'
17  
    tgen.uselib = 'MOGLK'
  13
    shlib = bld.new_task_gen('cxx', 'shlib')
  14
    stlib = bld.new_task_gen('cxx', 'staticlib')
  15
    shlib.source = 'moglk.cpp port.cpp'
  16
    shlib.target = 'moglk'
  17
    shlib.includes = '.'
  18
    shlib.install_path = '${SOME_PATH}/lib'
  19
    shlib.ccflags = '-O2 -Wall'
  20
#    shlib.linkflags = '-D_GNU_SOURCE -pthread -lccext2 -lccgnu2 -ldl -lrt -lpthread -fPIC'
  21
    stlib.source = 'moglk.cpp port.cpp'
  22
    stlib.target = 'moglk'
  23
    stlib.includes = '.'
  24
    stlib.install_path = '${SOME_PATH}/lib'
  25
    stlib.ccflags = '-O2 -Wall'
  26
#    stlib.linkflags = '-D_GNU_SOURCE -pthread -lccext2 -lccgnu2 -ldl -lrt -lpthread -fPIC'
  27

                                    
  28

                                    
18 29