Skip to content

Commit

Permalink
fix negative polarity backlight stages
Browse files Browse the repository at this point in the history
Now if your backlight's polarity is Negative, it's will send "0", if backlight if on, and "1" if backlight if off
  • Loading branch information
arthour-terghazaryan committed May 19, 2017
1 parent 715d15e commit a7c13da
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Sources/LCDI2C/HD44780.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ class LCDI2C{
// Supporting Properties
private var temp = [String:UInt8]() // Temp data

private var clockData: UInt8{
return ((polarity.rawValue & (temp["backlight"] ?? 1)) << bl) | (0 << e)
public var clockData: UInt8{
var backlightBit = temp["bl"] ?? 1
if polarity == .Negative{
backlightBit = ~backlightBit & 1
}
return backlightBit << bl
}

init(address: UInt8, width: UInt8, height: UInt8, rs: UInt8 = 0, rw: UInt8 = 1, e: UInt8 = 2, bl: UInt8 = 3, polarity: Polarity = .Positive) throws {
Expand All @@ -68,7 +72,7 @@ class LCDI2C{
self.bl = bl
self.e = e
self.polarity = polarity
self.temp["backlight"] = 1
self.temp["bl"] = 1
self.device = try I2CBusDevice(portNumber: 1)
initDisplay()
}
Expand Down

1 comment on commit a7c13da

@iyumeg
Copy link
Owner

@iyumeg iyumeg commented on a7c13da May 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now if your backlight's polarity is Negative, it's will send "0", if backlight is on, and "1" if backlight is off

Sorry for mistakes.

Please sign in to comment.