Subversion Repositories group.electronics

Rev

Rev 185 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 185 Rev 186
Line 54... Line 54...
54
            this.vccstate = vccstate;
54
            this.vccstate = vccstate;
55
            this.i2caddr = i2caddr;
55
            this.i2caddr = i2caddr;
56
            this.i2c = i2c;
56
            this.i2c = i2c;
57
 
57
 
58
            
58
            
59
            for (int i = 0; i < (LCD_WIDTH * LCD_HEIGHT / 8); i++) {
59
            for (int t = 0; t < (LCD_WIDTH * LCD_HEIGHT / 8); t++) {
60
                buffer[i] = new byte();
60
                buffer[t] = new byte();
61
                buffer[i] = 0xff;
61
                buffer[t] = 0x00;
62
            }
62
            }
-
 
63
 
-
 
64
 
63
        }
65
        }
64
 
66
 
65
        public void init() {
67
        public void init() {
66
            // Init sequence
68
            // Init sequence
67
 
69
 
Line 110... Line 112...
110
            oled_command(DISPLAYON);
112
            oled_command(DISPLAYON);
111
 
113
 
112
        }
114
        }
113
 
115
 
114
        public void display() {
116
        public void display() {
115
            oled_command(COLUMNADDR);
117
            oled_command(COLUMNADDR);           
116
            oled_command(0x00);         // Column start address
118
            oled_command(0x00);         // Column start address
117
            oled_command(LCD_WIDTH - 1);  // Column end address
119
            oled_command(LCD_WIDTH - 1);  // Column end address
-
 
120
            
-
 
121
 
118
 
122
 
119
            oled_command(PAGEADDR);
123
            oled_command(PAGEADDR);
120
            oled_command(0x00); // Page start address
124
            oled_command(0x00); // Page start address
121
            oled_command(7);    // Page end address (7 for 64 pixels)
125
            oled_command(7);    // Page end address (7 for 64 pixels)
122
 
126
 
-
 
127
            // 1024 -  388ms
-
 
128
            //   16 - 1190ms
-
 
129
 
123
            const int BYTES_TO_SEND = 1024;
130
            const int BYTES_TO_SEND = 1024;
124
 
131
 
125
            for (int i = 0; i < (LCD_WIDTH * LCD_HEIGHT / 8); i++) {
132
            for (int i = 0; i < (LCD_WIDTH * LCD_HEIGHT / 8); i++) {
126
                byte[] data = new byte[BYTES_TO_SEND + 1];
133
                byte[] data = new byte[BYTES_TO_SEND + 1];
127
                data[0] = 0x40;
134
                data[0] = 0x40;
Line 130... Line 137...
130
                    i++;
137
                    i++;
131
                }
138
                }
132
                i--;
139
                i--;
133
                i2c.WriteI2cData(i2cUtils.addressToWrite(this.i2caddr), data, BYTES_TO_SEND + 1);
140
                i2c.WriteI2cData(i2cUtils.addressToWrite(this.i2caddr), data, BYTES_TO_SEND + 1);
134
            }
141
            }
-
 
142
            
135
        }
143
        }
136
 
144
 
137
        public int oled_command(byte c) {
145
        public int oled_command(byte c) {
138
            byte[] data = { 0x00, c };            
146
            byte[] data = { 0x00, c };
-
 
147
            
139
            i2c.WriteI2cData(i2cUtils.addressToWrite(this.i2caddr), data, 2); ;
148
            i2c.WriteI2cData(i2cUtils.addressToWrite(this.i2caddr), data, 2); ;
140
            //data[0] = c;
149
            
141
            //i2c.WriteI2cData((byte)this.i2caddr, data, 1);
-
 
142
            return 0;
150
            return 0;
143
        }
151
        }
144
    }
152
    }
145
 
153
 
146
    public class BmpImage {
154
    public class BmpImage {
Line 340... Line 348...
340
            this.height = bmp.Height;
348
            this.height = bmp.Height;
341
            this.bitdata = new BitArray[this.height];
349
            this.bitdata = new BitArray[this.height];
342
 
350
 
343
            for (int y = 0; y < this.height; y++) {
351
            for (int y = 0; y < this.height; y++) {
344
                this.bitdata[y] = new BitArray(this.width);
352
                this.bitdata[y] = new BitArray(this.width);
345
                for (int x = 0; x < this.height; x++) {
353
                for (int x = 0; x < this.width; x++) {
346
                    Color c = bmp.GetPixel(x, y);
354
                    Color c = bmp.GetPixel(x, y);
347
                    
355
                    
348
                    if (c.GetBrightness() == 0)
356
                    if (c.GetBrightness() == 0)
349
                        this.bitdata[y].Set(x, false);
357
                        this.bitdata[y].Set(x, false);
350
                    else
358
                    else
Line 605... Line 613...
605
            int y = 0;
613
            int y = 0;
606
 
614
 
607
            for (y = 0; y < bit.height; y++) {
615
            for (y = 0; y < bit.height; y++) {
608
                for (x = 0; x < bit.width; x++) {
616
                for (x = 0; x < bit.width; x++) {
609
                    if (bit.bitdata[y].Get(x)) {
617
                    if (bit.bitdata[y].Get(x)) {
-
 
618
                        if (oy + y > this.height -1  || ox + x > this.width)
-
 
619
                            return;
610
                        this.bitdata[oy + y].Set(ox + x, true);
620
                        this.bitdata[oy + y].Set(ox + x, true);
611
                    }
621
                    }
612
                }
622
                }
613
            }
623
            }
614
        }
624
        }
Line 653... Line 663...
653
            if (size % 8 != 0) {
663
            if (size % 8 != 0) {
654
                Console.WriteLine("toByteArray only supports mod 8 array (size: {0}, misalinged by {1})", size, size % 8);
664
                Console.WriteLine("toByteArray only supports mod 8 array (size: {0}, misalinged by {1})", size, size % 8);
655
                return null;
665
                return null;
656
            }
666
            }
657
 
667
 
-
 
668
            BitArray data = new BitArray(width * height);
-
 
669
            int i = 0;
658
            for (int y = 0; y < ba.Length; y++) {
670
            for (int y = 0; y < ba.Length; y += 8) {
659
                byte[] bytes = new byte[ba[0].Length / 8];
671
                for (int x = 0; x < width; x++) {
660
                ba[y].CopyTo(bytes, 0);
672
                    for (int j = 0; j < 8; j++) {
661
                for (int i = 0; i < bytes.Length; i++) {
673
                        data.Set(i, ba[y+j].Get(x));
662
                    buffer[y * bytes.Length + i] = bytes[i];
674
                        i++;
-
 
675
                    }
663
                }
676
                }
664
            }
677
            }
665
 
-
 
-
 
678
            data.CopyTo(buffer, 0);
666
            return buffer;
679
            return buffer;
667
        }
680
        }
668
 
681
 
669
        /// <summary>
682
        /// <summary>
670
        /// Rotates a matrix by provided degrees. Note that the size of the
683
        /// Rotates a matrix by provided degrees. Note that the size of the