public static void ShowKloutSplashScreen() { tftBacklight.SetPulse(0, 0); var background = new VirtualFrame(40960, 32, @"SD\Bitmaps\KLOUTSplashScreen.bin"); background.Width = 160; background.Height = 128; vm.Copy(background); tft.Refresh(); BreatheTFT(BreatheInPulses); background.Dispose(); background = null; Debug.GC(true); Thread.Sleep(2000); }
public void Print(VirtualFrame background, string message, int x, int y, int Width, int Height) { VirtualFrame spriteCharFrame = null; var characterCount = 0; long frameSize = 0; bool hasPeriod = false; int digitsAfterPeriod = 0; foreach (Char c in message) { characterCount++; var path = GetPathFromCharacter(c); if (characterCount == 1) { frameSize = GetFrameSize(path); spriteCharFrame = new VirtualFrame(frameSize, 4, path); spriteCharFrame.Height = Height; spriteCharFrame.Width = Width; spriteCharFrame.xOffset = x; spriteCharFrame.yOffset = y; } else { spriteCharFrame.ConnectExistingStream(path); } Merge(background, spriteCharFrame); spriteCharFrame.xOffset += Width; path = null; Debug.GC(true); if (characterCount >= MaxMessageLength) { break; } if (c == '.') { hasPeriod = true; continue; } if (hasPeriod) { digitsAfterPeriod++; } if (hasPeriod && (digitsAfterPeriod >= MaxCharactersAfterPeriod)) { break; } } spriteCharFrame.Dispose(); spriteCharFrame = null; Debug.GC(true); }
//protected string ToHex(byte value) { // var hex = new Char[2]; // hex[0] = ToNibble((byte)(value >> 4)); // hex[1] = ToNibble((byte)(value & 0x0F)); // return new string(hex); //} //protected Char ToNibble(byte value) { // if (value >= 0 && value <= 9) { // return (Char)('0' + value); // } // return (Char)('A' + value - 10); //} public VirtualFrame Merge(VirtualFrame background, VirtualFrame sprite) { if (sprite.Width > background.Width || sprite.Width > Width || sprite.Height > background.Height || sprite.Height > Height || sprite.BytesPerPixel != BytesPerPixel || sprite.BytesPerPixel != background.BytesPerPixel) { throw new IndexOutOfRangeException("sprite"); } var xStartPixels = xOffset + sprite.xOffset; if (xStartPixels > Width) return this; var yStartPixels = yOffset + sprite.yOffset; if (yStartPixels > Height) return this; var xEndPixels = xStartPixels + sprite.Width; if (xEndPixels > Width) xEndPixels = Width; var yEndPixels = yStartPixels + sprite.Height; if (yEndPixels > Height) yEndPixels = Height; var spriteWidthBytes = (xEndPixels - xStartPixels) * BytesPerPixel; var address = (yStartPixels * GetWidthInBytes()) + (xStartPixels * BytesPerPixel); var step = GetWidthInBytes(); if (sprite.TransparentColor == Solid) { var spriteLine = 0; while(yStartPixels < yEndPixels) { sprite.ReadVM(spriteLine, 0, spriteWidthBytes); base.WriteVM(address, sprite.Buffer, spriteWidthBytes); address += step; spriteLine += spriteWidthBytes; yStartPixels++; } } else { var spriteAddress = 0; for (; yStartPixels < yEndPixels; yStartPixels++) { var w = xEndPixels - xStartPixels; for (var x = 0; x < w; x++) { var pixelHigh = sprite.ReadVM(spriteAddress++); var pixelLow = sprite.ReadVM(spriteAddress++); short color = pixelHigh; color <<= 8; color |= (short)pixelLow; if (color == TransparentColor) { // Not yet implemented. Same as solid. base.WriteVM(address++, pixelHigh); base.WriteVM(address++, pixelLow); } else { base.WriteVM(address++, pixelHigh); base.WriteVM(address++, pixelLow); } } address += (step - spriteWidthBytes); } } return this; }
public void Print(VirtualFrame background, string message, int x, int y, int Width, int Height) { VirtualFrame spriteCharFrame = null; var characterCount = 0; long frameSize = 0; bool hasPeriod = false; int digitsAfterPeriod = 0; foreach (Char c in message) { characterCount++; var path = GetPathFromCharacter(c); if (characterCount == 1) { frameSize = GetFrameSize(path); spriteCharFrame = new VirtualFrame(frameSize, 4, path); spriteCharFrame.Height = Height; spriteCharFrame.Width = Width; spriteCharFrame.xOffset = x; spriteCharFrame.yOffset = y; } else { spriteCharFrame.ConnectExistingStream(path); } Merge(background, spriteCharFrame); spriteCharFrame.xOffset += Width; path = null; Debug.GC(true); if (characterCount >= MaxMessageLength) break; if (c == '.') { hasPeriod = true; continue; } if (hasPeriod) digitsAfterPeriod++; if (hasPeriod && (digitsAfterPeriod >= MaxCharactersAfterPeriod)) break; } spriteCharFrame.Dispose(); spriteCharFrame = null; Debug.GC(true); }
public static void ShowTime() { BreatheTFT(BreatheOutPulses); var background = new VirtualFrame(40960, 32, @"SD\Bitmaps\KloutBackground.bin"); background.Width = 160; background.Height = 128; vm.IsReadOnly = false; vm.Copy(background); DisplayKloutOrKlockIcon(background, "clock"); DisplayKloutOrKlock(background, "KLOCK"); vm.BitmapDirectory = @"SD\DigitsS\"; vm.MaxCharactersAfterPeriod = 2; vm.MaxMessageLength = 10; vm.Print(background, GetDate(), 7, 35 + 4, 15, 21); vm.BitmapDirectory = @"SD\DigitsM\"; vm.MaxCharactersAfterPeriod = 2; vm.MaxMessageLength = 5; vm.Print(background, GetTime(), 0, 64 + 11, 32, 42); tft.Refresh(); BreatheTFT(BreatheInPulses); background.Dispose(); background = null; Debug.GC(true); }
/// <summary> /// Configures the application from the 'resources.txt' file place on the microSD card. /// See the 'SD Card Resources' folder for a sample to start with. /// </summary> private static void InitializeResources() { var resourceLoader = new SDResourceLoader(); try { resourceLoader.Load(); } catch (IOException e) { PowerState.RebootDevice(false); } _key = (string)resourceLoader.Strings["key"]; _user = (string)resourceLoader.Strings["user"]; _host = (string)resourceLoader.Strings["host"]; _port = int.Parse((string)resourceLoader.Strings["port"]); _timeZone = int.Parse((string)resourceLoader.Strings["timeZone"]); _ntpServers = (string)resourceLoader.Strings["ntpServers"]; _dst = int.Parse((string)resourceLoader.Strings["dst"]); resourceLoader.Dispose(); vm = new VirtualFrame(40960, 16, VirtualMemoryFilename); vm.IsReadOnly = false; tft = new AdaFruitST7735(Pins.GPIO_PIN_D9, Pins.GPIO_PIN_D7, Pins.GPIO_PIN_D8, speedKHz: 40000, vm: vm); tft.Orientation = AdaFruitST7735.ScreenOrientation.Landscape; Debug.GC(true); }
public static void DisplayKloutKPI(VirtualFrame background, string filename) { var sprite = new VirtualFrame(8960, 16, @"SD\Bitmaps\" + filename + ".bin"); sprite.Width = 160; sprite.Height = 28; sprite.xOffset = 0; sprite.yOffset = 35; vm.Merge(background, sprite); sprite.Dispose(); sprite = null; Debug.GC(true); }
public static void DisplayKloutOrKlock(VirtualFrame background, string filename) { var sprite = new VirtualFrame(7548, 16, @"SD\Bitmaps\" + filename + ".bin"); sprite.Width = 111; sprite.Height = 34; sprite.xOffset = 44; sprite.yOffset = 0; vm.Merge(background, sprite); sprite.Dispose(); sprite = null; Debug.GC(true); }
public static void DisplayKloutOrKlockIcon(VirtualFrame background, string icon) { var sprite = new VirtualFrame(4950, 16, @"SD\Bitmaps\" + icon + ".bin"); sprite.Width = 48; sprite.Height = 34; sprite.xOffset = 0; sprite.yOffset = 0; vm.Merge(background, sprite); sprite.Dispose(); sprite = null; Debug.GC(true); }
public static void DisplayPositiveNegativeIcon(VirtualFrame background, string icon) { var sprite = new VirtualFrame(4800, 16, @"SD\Bitmaps\" + icon + ".bin"); sprite.Width = 40; sprite.Height = 60; sprite.xOffset = 0; sprite.yOffset = 64 + 2; vm.Merge(background, sprite); sprite.Dispose(); sprite = null; Debug.GC(true); }
public static void DisplayKloutClass(VirtualFrame background, string kloutClass) { var sprite = new VirtualFrame(6720, 16, @"SD\Bitmaps\" + kloutClass + ".bin"); sprite.Width = 160; sprite.Height = 21; sprite.xOffset = 0; sprite.yOffset = 64 + 21; vm.Merge(background, sprite); sprite.Dispose(); sprite = null; Debug.GC(true); }
public static void EraseKloutData(VirtualFrame background) { var sprite = new VirtualFrame(20480, 16, @"SD\Bitmaps\KloutDataEraser.bin"); sprite.Width = 160; sprite.Height = 64; sprite.xOffset = 0; sprite.yOffset = 64; vm.Merge(background, sprite); sprite.Dispose(); sprite = null; Debug.GC(true); }
public static void DisplayKloutDataPoint(VirtualFrame background, string kpi, float value, bool showArrow = false) { DisplayKloutKPI(background, kpi); EraseKloutData(background); string displayValue; if ((float) System.Math.Round(value) == 0f) { displayValue = " -- "; showArrow = false; } else if (value >= 1000000f) { value = (float) System.Math.Round(value / 1000000f); displayValue = value.ToString() + "M"; } else if (value >= 1000f) { value = (float)System.Math.Round(value / 1000f); displayValue = value.ToString() + "K"; } else { displayValue = System.Math.Round(value).ToString(); } int xOffset = 0; if (showArrow) { xOffset += 40; if (value < 0f) { DisplayPositiveNegativeIcon(background, "neg"); } else { DisplayPositiveNegativeIcon(background, "pos"); } } if (xOffset == 0) { xOffset = (160 - (displayValue.Length * 40)) / 2; } vm.Print(background, displayValue, xOffset, 64 + 2, 40, 60); tft.Refresh(); }
public static void ShowKlout() { BreatheTFT(BreatheOutPulses); var background = new VirtualFrame(40960, 32, @"SD\Bitmaps\KloutBackground.bin"); background.Width = 160; background.Height = 128; vm.IsReadOnly = false; vm.Copy(background); vm.BitmapDirectory = @"SD\DigitsL\"; vm.MaxCharactersAfterPeriod = 1; vm.MaxMessageLength = 4; DisplayKloutOrKlockIcon(background, "KloutLogo"); DisplayKloutOrKlock(background, "KLOUT"); DisplayKloutKPI(background, "Class"); DisplayKloutClass(background, _kclass); tft.Refresh(); BreatheTFT(BreatheInPulses); DisplayKloutDataPoint(background, "KloutScore", _kscore); DisplayKloutDataPoint(background, "Network", _networkScore); DisplayKloutDataPoint(background, "Amplification", _amplificationScore); DisplayKloutDataPoint(background, "TrueReach", _trueReach); DisplayKloutDataPoint(background, "Influencers", _influencers); DisplayKloutDataPoint(background, "Influencees", _influencees); DisplayKloutDataPoint(background, "Topics", _topicsCount); DisplayKloutDataPoint(background, "Delta1Day", _delta1Day, true); DisplayKloutDataPoint(background, "Delta5Days", _delta5Day, true); background.Dispose(); background = null; Debug.GC(true); }
//protected string ToHex(byte value) { // var hex = new Char[2]; // hex[0] = ToNibble((byte)(value >> 4)); // hex[1] = ToNibble((byte)(value & 0x0F)); // return new string(hex); //} //protected Char ToNibble(byte value) { // if (value >= 0 && value <= 9) { // return (Char)('0' + value); // } // return (Char)('A' + value - 10); //} public VirtualFrame Merge(VirtualFrame background, VirtualFrame sprite) { if (sprite.Width > background.Width || sprite.Width > Width || sprite.Height > background.Height || sprite.Height > Height || sprite.BytesPerPixel != BytesPerPixel || sprite.BytesPerPixel != background.BytesPerPixel) { throw new IndexOutOfRangeException("sprite"); } var xStartPixels = xOffset + sprite.xOffset; if (xStartPixels > Width) { return(this); } var yStartPixels = yOffset + sprite.yOffset; if (yStartPixels > Height) { return(this); } var xEndPixels = xStartPixels + sprite.Width; if (xEndPixels > Width) { xEndPixels = Width; } var yEndPixels = yStartPixels + sprite.Height; if (yEndPixels > Height) { yEndPixels = Height; } var spriteWidthBytes = (xEndPixels - xStartPixels) * BytesPerPixel; var address = (yStartPixels * GetWidthInBytes()) + (xStartPixels * BytesPerPixel); var step = GetWidthInBytes(); if (sprite.TransparentColor == Solid) { var spriteLine = 0; while (yStartPixels < yEndPixels) { sprite.ReadVM(spriteLine, 0, spriteWidthBytes); base.WriteVM(address, sprite.Buffer, spriteWidthBytes); address += step; spriteLine += spriteWidthBytes; yStartPixels++; } } else { var spriteAddress = 0; for (; yStartPixels < yEndPixels; yStartPixels++) { var w = xEndPixels - xStartPixels; for (var x = 0; x < w; x++) { var pixelHigh = sprite.ReadVM(spriteAddress++); var pixelLow = sprite.ReadVM(spriteAddress++); short color = pixelHigh; color <<= 8; color |= (short)pixelLow; if (color == TransparentColor) { // Not yet implemented. Same as solid. base.WriteVM(address++, pixelHigh); base.WriteVM(address++, pixelLow); } else { base.WriteVM(address++, pixelHigh); base.WriteVM(address++, pixelLow); } } address += (step - spriteWidthBytes); } } return(this); }