Subversion Repositories group.electronics

Rev

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

Rev 183 Rev 184
Line 41... Line 41...
41
        public const int SETCOMPINS = 0xDA;
41
        public const int SETCOMPINS = 0xDA;
42
        public const int SETVCOMDETECT = 0xDB;
42
        public const int SETVCOMDETECT = 0xDB;
43
        public const int SETDISPLAYCLOCKDIV = 0xD5;
43
        public const int SETDISPLAYCLOCKDIV = 0xD5;
44
        public const int SETPRECHARGE = 0xD9;
44
        public const int SETPRECHARGE = 0xD9;
45
 
45
 
46
        public static byte[] buffer = new byte[Oled.LCD_WIDTH / 8 * Oled.LCD_HEIGHT];
46
        public byte[] buffer = new byte[Oled.LCD_WIDTH / 8 * Oled.LCD_HEIGHT];
47
 
47
 
48
        public int vccstate { get; set; }
48
        public int vccstate { get; set; }
49
        public int i2caddr { get; set; }
49
        public byte i2caddr { get; set; }
50
 
50
 
51
        public i2cmaster i2c { get; set; }
51
        public i2cmaster i2c { get; set; }
52
 
52
 
53
        public Oled(int vccstate, int i2caddr, i2cmaster i2c) {
53
        public Oled(int vccstate, byte i2caddr, i2cmaster i2c) {
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
 
-
 
58
            
-
 
59
            for (int i = 0; i < (LCD_WIDTH * LCD_HEIGHT / 8); i++) {
-
 
60
                buffer[i] = new byte();
-
 
61
                buffer[i] = 0x00;
-
 
62
            }
57
        }
63
        }
58
 
64
 
59
        public void init() {
65
        public void init() {
60
            // Init sequence
66
            // Init sequence
-
 
67
 
61
            oled_command(DISPLAYOFF);
68
            oled_command(DISPLAYOFF);
62
            oled_command(SETDISPLAYCLOCKDIV);
69
            oled_command(SETDISPLAYCLOCKDIV);
63
            oled_command(0x80); // Suggested ratio
70
            oled_command(0x80); // Suggested ratio
64
 
71
 
65
            oled_command(SETMULTIPLEX);
72
            oled_command(SETMULTIPLEX);
Line 118... Line 125...
118
                for (int j = 0; j < 16; j++) {
125
                for (int j = 0; j < 16; j++) {
119
                    data[j] = buffer[i];
126
                    data[j] = buffer[i];
120
                    i++;
127
                    i++;
121
                }
128
                }
122
                i--;
129
                i--;
123
                i2c.WriteI2cData((byte)this.i2caddr, data, 16);
130
                i2c.WriteI2cData(i2cUtils.addressToWrite(this.i2caddr), data, 16);
124
            }
131
            }
125
        }
132
        }
126
 
133
 
127
        public int oled_command(byte c) {
134
        public int oled_command(byte c) {
128
            byte control = 0x00;
-
 
129
            byte[] data = { control };
135
            byte[] data = { 0x00, c };            
130
            i2c.WriteI2cData((byte)this.i2caddr, data, 1);
136
            i2c.WriteI2cData(i2cUtils.addressToWrite(this.i2caddr), data, 2); ;
131
            data[0] = c;
137
            //data[0] = c;
132
            i2c.WriteI2cData((byte)this.i2caddr, data, 1);
138
            //i2c.WriteI2cData((byte)this.i2caddr, data, 1);
133
            return 0;
139
            return 0;
134
        }
140
        }
135
    }
141
    }
136
 
142
 
137
    public class BmpImage {
143
    public class BmpImage {