public override void Run() { var tinyFont = new TinyFont(); ISenseHatDisplay display = SenseHat.Display; while (true) { SenseHat.Sensors.HumiditySensor.Update(); if (SenseHat.Sensors.Temperature.HasValue) { int temperature = (int)Math.Round(SenseHat.Sensors.Temperature.Value); string text = temperature.ToString(); if (text.Length > 2) { // Too long to fit the display! text = "**"; } display.Clear(); tinyFont.Write(display, text, Colors.White); display.Update(); // Sleep quite some time; the temperature usually change quite slowly... Sleep(TimeSpan.FromSeconds(5)); } else { // Rapid update until there is a temperature reading. Sleep(TimeSpan.FromSeconds(0.5)); } } }
public async Task LogAction(double obj) { await Task.Run(() => { var tinyFont = new TinyFont(); ISenseHatDisplay display = _senseHat.Display; double humidityValue = obj; int humidity = (int)Math.Round(humidityValue); string text = humidity.ToString(); if (text.Length > 2) { // Too long to fit the display! text = "**"; } display.Clear(); Color color; color = GetTextColor(humidity); tinyFont.Write(display, text, color); display.Update(); }); }
public override void Run() { var tinyFont = new TinyFont(); Cpu cpu = new Cpu(); double temp_calibrated; ISenseHatDisplay display = SenseHat.Display; TemperatureUnit unit = TemperatureUnit.Celcius; // The wanted temperature unit. string unitText = GetUnitText(unit); // Get the unit as a string. while (true) { SenseHat.Sensors.HumiditySensor.Update(); if (SenseHat.Sensors.Temperature.HasValue) { double temperatureValue = ConvertTemperatureValue(unit, SenseHat.Sensors.Temperature.Value); double?cpu_temp = cpu.GetTemperature(); if (cpu_temp != null) { temp_calibrated = temperatureValue - (((double)cpu_temp - temperatureValue) / 0.79); } else { temp_calibrated = temperatureValue; } int temperature = (int)Math.Round((double)temp_calibrated); string text = temperature.ToString(); if (text.Length > 2) { // Too long to fit the display! text = "**"; } display.Clear(); tinyFont.Write(display, text, Color.Blue); display.Update(); SetScreenText?.Invoke($"{temperatureValue:0.0} {unitText}"); // Update the MainPage (if it's utilized; i.e. not null). // Sleep quite some time; the temperature usually change quite slowly... Sleep(TimeSpan.FromSeconds(5)); } else { // Rapid update until there is a temperature reading. Sleep(TimeSpan.FromSeconds(0.5)); } } }
private void MakePostBuildAdjustments(TinyFont font) { checked { foreach (RangeAdjustments adjustments in _postBuildAdjustments) { for (int i = adjustments.Start; i <= adjustments.End; i++) { CharacterInfo info = font.GetCharacterInfo(i); info.MarginLeft += (sbyte)adjustments.LeftMargin; info.MarginRight += (sbyte)adjustments.RightMargin; } } IDictionary <ushort, int> mapping = _builder.GetAssignedGlyphCharacters(); foreach (GlyphRangeAdjustments adjustments in _postBuildGlyphAdjustments) { for (ushort i = adjustments.Start; i <= adjustments.End; i++) { CharacterInfo info = font.GetCharacterInfo(mapping[i]); info.MarginLeft += (sbyte)adjustments.LeftMargin; info.MarginRight += (sbyte)adjustments.RightMargin; } } font.Metrics.Ascent += _adjustAscent; if (font.Metrics.Ascent < 0) { throw new ArgumentException("Font cannot have negative ascent."); } font.Metrics.Descent += _adjustDescent; if (font.Metrics.Descent < 0) { throw new ArgumentException("Font cannot have negative descent."); } font.Metrics.ExternalLeading += _adjustExternalLeading; if (font.Metrics.ExternalLeading < 0) { throw new ArgumentException("Font cannot have negative external leading."); } font.Metrics.InternalLeading += _adjustInternalLeading; if (font.Metrics.InternalLeading < 0) { throw new ArgumentException("Font cannot have negative internal leading."); } } }
public override void Run() { temperaturestate = true; var tinyFont = new TinyFont(); ISenseHatDisplay display = SenseHat.Display; TemperatureUnit unit = TemperatureUnit.Celcius; //we want celcius :v string unitText = GetUnitText(unit); while (temperaturestate == true) { SenseHat.Sensors.HumiditySensor.Update(); if (SenseHat.Sensors.Temperature.HasValue) { double temperatureValue = ConvertTemperatureValue(unit, SenseHat.Sensors.Temperature.Value); int temperature = (int)Math.Round(temperatureValue); string text = temperature.ToString(); if (text.Length > 2) { // too long to display :'v text = "**"; } display.Clear(); tinyFont.Write(display, text, Colors.White); display.Update(); SetScreenText?.Invoke($"{temperatureValue:0:1} {unitText}"); Sleep(TimeSpan.FromSeconds(2)); temperaturestate = false; } else { //rapid update until value is available Sleep(TimeSpan.FromSeconds(0.5)); } ActionRunner.Run(senseHat => HomeSelector.GetAction(senseHat, SetScreenText)); } }
private void state(string text, ISenseHat _senseHat) { var tinyFont = new TinyFont(); ISenseHatDisplay display = _senseHat.Display; if (text.Length > 2) { // Too long to fit the display! text = "**"; } display.Clear(); tinyFont.Write(display, text, Colors.White); display.Update(); }
public void Write(string text, Color color, DisplayDirection rotation = DisplayDirection.Deg0) { SenseHat.Display.Reset(); SenseHat.Display.Direction = rotation; if (text.Length > 2) { // Too long to fit the display! text = text.Substring(0, 2); } var tinyFont = new TinyFont(); SenseHat.Display.Clear(); tinyFont.Write(SenseHat.Display, text, color); SenseHat.Display.Update(); }
public override void Run() { pressurestate = true; var tinyFont = new TinyFont(); ISenseHatDisplay display = SenseHat.Display; while (pressurestate == true) { SenseHat.Sensors.PressureSensor.Update(); if (SenseHat.Sensors.Pressure.HasValue) { double pressurevalue = SenseHat.Sensors.Pressure.Value; int pressure = (int)Math.Round(pressurevalue / 1000); string text = pressure.ToString(); if (text.Length > 2) { // too long to display :'v text = "**"; } display.Clear(); tinyFont.Write(display, text, Colors.IndianRed); display.Update(); SetScreenText?.Invoke($"{pressure:0:1}"); Sleep(TimeSpan.FromSeconds(2)); pressurestate = false; } else { Sleep(TimeSpan.FromSeconds(0.5)); } ActionRunner.Run(senseHat => HomeSelector.GetAction(senseHat, SetScreenText)); } }
public override void Run() { humiditystate = true; var tinyFont = new TinyFont(); ISenseHatDisplay display = SenseHat.Display; while (humiditystate == true) { SenseHat.Sensors.HumiditySensor.Update(); if (SenseHat.Sensors.Humidity.HasValue) { double humidityValue = SenseHat.Sensors.Humidity.Value; int humidity = (int)Math.Round(humidityValue); string text = humidity.ToString(); if (text.Length > 2) { text = "**"; } display.Clear(); tinyFont.Write(display, text, Colors.Blue); display.Update(); SetScreenText?.Invoke($"{humidityValue:0:1}"); Sleep(TimeSpan.FromSeconds(2)); humiditystate = false; } else { Sleep(TimeSpan.FromSeconds(0.5)); } ActionRunner.Run(senseHat => HomeSelector.GetAction(senseHat, SetScreenText)); } }
/// <summary> /// Creates new TinyFont based on the rules from <see cref="TinyDefinition"/>. /// </summary> /// <param name="definition">Definition rules for font.</param> /// <returns>An instance of <see cref="TinyFont"/>.</returns> protected TinyFont ConvertWithState(TinyDefinition definition) { if (_builder == null) { _builder = new TinyFontBuilder(); _builder.GlyphTransform = _transform; #if TERKA_FEATURES _builder.OpenTypeCompiler = new Terka.FontBuilder.OpenTypeCompiler(); #endif } Type[] type = new Type[1]; object[] parameter = new object[1]; foreach (TinyCommandBase command in definition) { if (command != null) { type[0] = command.GetType(); parameter[0] = command; MethodInfo processMethod = typeof(TFConvert).GetMethod("Process", BindingFlags.NonPublic | BindingFlags.Instance, null, type, null); if (processMethod != null) { processMethod.Invoke(this, parameter); } } } if (_noDefaultImport == false) { Process(new SetDefaultCharacter()); } TinyFont font = _builder.Build(); MakePostBuildAdjustments(font); return(font); }
// timer callbacks for states changing private void Timer_Tick1(object send, object e) { if (!appInitialized) // check initialization status in case crashing { return; } if (inTimerTick) // check if it is in processing { return; } inTimerTick = true; // start processing tinyFont = new TinyFont(); Boolean oldKSC = keyStateChanged; keyStateChanged = senseHat.Joystick.Update(); // check if any button is pressed if (keyStateChanged && !oldKSC) // de-bounce duplicate key presses { HandleButtons(); } cycleCount++; switch (currentState) { case States.STARTUP: StartupState(); break; case States.LIGHT_SHOW_1: LightShow1State(); break; case States.GET_FORECAST: GetForecastState(); break; case States.ASK_TEMP: AskTempState(); break; case States.ASK_FORECAST: AskForecastState(); break; case States.LIGHT_SHOW_2: LightShow2State(); break; case States.MONITOR_DAY: MonitorDayState(); break; case States.MONITOR_NIGHT: MonitorNightState(); break; case States.WEATHER_ERROR: WeatherErrorState(); break; } inTimerTick = false; // end processing }
private async Task <List <string> > TheWholeThing(int theIndexNumberWhichIsCool) { StorageFile file = await storageFolder.CreateFileAsync(fileName, CreationCollisionOption.OpenIfExists); ISenseHat senseHat = await SenseHatFactory.GetSenseHat().ConfigureAwait(false); ISenseHatDisplay display = senseHat.Display; var exceptionSave = new List <string>(); //Connect to the senseHat & Clear the display var tinyFont = new TinyFont(); string myText = theIndexNumberWhichIsCool.ToString(); if (myText.Length > 2) { myText = myText.Substring(0, 2); } for (int i = 0; i < 5; ++i) { display.Clear(); tinyFont.Write(display, myText, Windows.UI.Colors.Green); display.Update(); //_waitEvent.Wait(TimeSpan.FromMilliseconds(100)); display.Clear(); //display.Update(); //_waitEvent.Wait(TimeSpan.FromMilliseconds(200)); } //Reading Temperature CustomData myTemperatureReading = new CustomData { value = "", timestamp = "", dataType = "te", sensorID = sensorID }; senseHat.Sensors.HumiditySensor.Update(); for (int i = 0; i <= 3; ++i) { if (senseHat.Sensors.Temperature.HasValue) { myTemperatureReading.timestamp = getTimeNow().ToString(timeStampFormat); var ttt = senseHat.Sensors.Temperature.Value; myTemperatureReading.value = ttt.ToString(); break; } //else _waitEvent.Wait(TimeSpan.FromMilliseconds(100)); } string temperatureReadingString = JsonConvert.SerializeObject(myTemperatureReading); //Read Acceleration CustomData myAccelerationReading = new CustomData { value = "", timestamp = "", dataType = "ac", sensorID = sensorID }; senseHat.Sensors.ImuSensor.Update(); for (int i = 0; i <= 3; ++i) { if (senseHat.Sensors.Acceleration.HasValue) { myAccelerationReading.timestamp = getTimeNow().ToString(timeStampFormat); myAccelerationReading.value = senseHat.Sensors.Acceleration.Value.ToString(); break; } //else _waitEvent.Wait(TimeSpan.FromMilliseconds(100)); } string accelerationReadingString = JsonConvert.SerializeObject(myAccelerationReading); //send data to Azure var message = new Message(Encoding.ASCII.GetBytes(temperatureReadingString)); try { await DeviceClient.SendEventAsync(message); } catch { Debug.WriteLine("Sending temperature data to cloud failed."); await FileIO.AppendTextAsync(file, temperatureReadingString); exceptionSave.Add(temperatureReadingString); } message = new Message(Encoding.ASCII.GetBytes(accelerationReadingString)); try { await DeviceClient.SendEventAsync(message); } catch { Debug.WriteLine("Sending acceleration data to cloud failed."); await FileIO.AppendTextAsync(file, accelerationReadingString); exceptionSave.Add(accelerationReadingString); } //Reading using (IRandomAccessStream textStream = await file.OpenReadAsync()) { using (DataReader textReader = new DataReader(textStream)) { uint textLength = (uint)textStream.Size; await textReader.LoadAsync(textLength); Debug.WriteLine(textReader.ReadString(textLength)); } } return(exceptionSave); }
private static void DumpFont(TinyDefinition definition, TinyFont font, TextWriter textWriter) { }
private static void Main(string[] args) { Console.InputEncoding = Encoding.UTF8; Console.OutputEncoding = Encoding.UTF8; try { Line = CommandLineHelper.Parse <CommandLine>(args); } catch { Line = new CommandLine { ShowHelp = true }; } if (Line != null) { if (Line.ShowHelp || Line.IsValid == false) { Line.WriteHelp(Console.Out); } else { TinyDefinition definition = new TinyDefinition(); TextReader definitionReader; try { // separate try catch block for file issues for compatibility reasons definitionReader = new StreamReader(Line.InputFile, Encoding.UTF8, true); } catch { Console.WriteLine("Cannot open '{0}'!", Line.InputFile); return; } try { definition.Load(definitionReader); } catch (Exception e) { // the TFConvert exception messages correspond to the native error strings Console.WriteLine(e.Message); return; } try { definition.Validate(); } catch (KeyNotFoundException) { // currently the only required command Console.WriteLine("SelectFont command not found in .FNTDEF file"); return; } definitionReader.Close(); TinyFont font = TFConvert.Convert(definition); DumpFont(definition, font, Console.Out); try { font.Save(Line.OutputFile); } catch { Console.WriteLine("Cannot open '{0}' for writing!", Line.OutputFile); return; } } } }