With another Card the board freeze. The freezing Card is FAT32 with 3 folders. The other card is FAT and empty.
using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using GTI = Gadgeteer.Interfaces;
using Microsoft.SPOT.Hardware;
using Gadgeteer.Modules.GHIElectronics;
using Gadgeteer.Modules.Seeed;
namespace HyperionGadgeteer
{
public partial class Program
{
// Définission des variable globales
Font baseFont = Resources.GetFont(Resources.FontResources.NinaB);
Font baseFontSmall = Resources.GetFont(Resources.FontResources.small);
GTI.I2CBus MyI2C;
bool RunningTest = true;
int I2C_timeout = 100;
int bitShift = 0;
long ValueToWrite = 255;
byte[] ByteToWrite = new byte[1];
byte[] ByteRead = new byte[1];
ushort PHILLIPS_PFC8574A_ADDRESS = 0x38;
int PHILLIPS_PFC8574A_CLOCK_IN_kHz = 100;
// This method is run when the mainboard is powered up or reset.
void ProgramStarted()
{
/*******************************************************************************************
Modules added in the Program.gadgeteer designer view are used by typing
their name followed by a period, e.g. button. or camera.
Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.:
button.ButtonPressed +=<tab><tab>
If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.:
GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
timer.Tick +=<tab><tab>
timer.Start();
*******************************************************************************************/
// Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
Debug.Print("Program Started");
GT.Socket socket = GT.Socket.GetSocket(5, true, MyExtender, null);
MyI2C = new GTI.I2CBus(socket, PHILLIPS_PFC8574A_ADDRESS, PHILLIPS_PFC8574A_CLOCK_IN_kHz, null);
ShowHyperionInfo();
// Définitions des timers
GT.Timer TimerOR8 = new GT.Timer(250); // every 0.5 seconds (500ms)
// Définition des Handlers
TimerOR8.Tick += new GT.Timer.TickEventHandler(TimerOR8_Tick);
MySDCard.SDCardMounted += new SDCard.SDCardMountedEventHandler(MySDCard_SDCardMounted);
MySDCard.SDCardUnmounted += new SDCard.SDCardUnmountedEventHandler(MySDCard_SDCardUnmounted);
MyButton.ButtonPressed += new GTM.GHIElectronics.Button.ButtonEventHandler(MyButton_ButtonPressed);
// Démarrage des timers
TimerOR8.Start();
//Initialisation des relais à l'état éteint;
ByteToWrite[0] = (byte)ValueToWrite;
MyI2C.Write(ByteToWrite, I2C_timeout);
MyI2C.Read(ByteRead, I2C_timeout);
//ShowRelayState();
}
void ShowRelayState()
{
MyOledDisplay.SimpleGraphics.Clear();
string RelayResult;
RelayResult = IsSet(ByteRead[0], 0).ToString() + " " + IsSet(ByteRead[0], 1).ToString() + " " + IsSet(ByteRead[0], 2).ToString() + " " + IsSet(ByteRead[0], 3).ToString() + " " + IsSet(ByteRead[0], 4).ToString() + " " + IsSet(ByteRead[0], 5).ToString() + " " + IsSet(ByteRead[0], 6).ToString() + " " + IsSet(ByteRead[0], 7).ToString();
MyOledDisplay.SimpleGraphics.DisplayText(RelayResult, baseFont, GT.Color.Purple, 15, 75);
}
int IsSet(long ba, int bit)
{
long mask = 1L << bit;
if ((ba & mask) != 0)
{
return 1;
}
else
{
return 0;
}
}
void Set(ref long ba, int bit)
{
ba |= 1L << bit;
}
void Clear(ref long ba, int bit)
{
long mask = 1L << bit;
mask = ~mask;
ba &= mask;
}
void ShowHyperionInfo()
{
MyOledDisplay.SimpleGraphics.DisplayText("Inertia Systemes", baseFont, GT.Color.Blue, 15, 15);
MyOledDisplay.SimpleGraphics.DisplayText("Hyperion P.A.S.", baseFont, GT.Color.White, 15, 30);
MyOledDisplay.SimpleGraphics.DisplayText("Version 2012.02.19", baseFontSmall, GT.Color.White, 15, 45);
}
#region EventHandler
void TimerOR8_Tick(GT.Timer timer)
{
if (RunningTest)
{
ValueToWrite = 255;
Clear(ref ValueToWrite, bitShift);
ByteToWrite[0] = (byte)ValueToWrite;
MyI2C.Write(ByteToWrite, I2C_timeout);
MyI2C.Read(ByteRead, I2C_timeout);
//ShowRelayState();
if (bitShift < 7)
{
bitShift += 1;
}
else
{
bitShift = 0;
}
}
//throw new NotImplementedException();
}
void MyButton_ButtonPressed(GTM.GHIElectronics.Button sender, GTM.GHIElectronics.Button.ButtonState state)
{
if (RunningTest)
{
RunningTest = false;
}
else
{
RunningTest = true;
}
//throw new NotImplementedException();
}
void MySDCard_SDCardMounted(SDCard sender, GT.StorageDevice SDCard)
{
Debug.Print("\r\nAn SD card has been inserted.");
if (sender.IsCardInserted)
{
Debug.Print("The IsCardInserted property correctly says that the SD Card is inserted.");
}
else
{
Debug.Print("*** The IsCardInserted property incorrectly claims that the SD card is not inserted.");
}
if (sender.IsCardMounted)
{
Debug.Print("The IsCardMounted property correctly says that the SD Card is mounted.");
}
else
{
Debug.Print("*** The IsCardMounted property incorrectly claims that the SD card is not mounted.");
}
Debug.Print("\r\nUsing the SDCard parameter of the SDCardMounted event, the directory of the SD card root is:");
string[] root = SDCard.ListRootDirectoryFiles();
foreach (string fileName in root)
{
Debug.Print(" " + fileName);
}
Debug.Print("\r\nUsing the GetStorageDevice call, the directory of the SD card root is:");
string[] root2 = sender.GetStorageDevice().ListRootDirectoryFiles();
foreach (string fileName in root2)
{
Debug.Print(" " + fileName);
}
Debug.Print("\r\nPlease remove the SD card to finish the test.");
}
void MySDCard_SDCardUnmounted(SDCard sender)
{
Debug.Print("\r\nAn SD card has been removed.");
if (!sender.IsCardInserted)
{
Debug.Print("The IsCardInserted property correctly says that the SD Card is not inserted.");
}
else
{
Debug.Print("*** The IsCardInserted property incorrectly claims that the SD card is inserted.");
}
if (!sender.IsCardMounted)
{
Debug.Print("The IsCardMounted property correctly says that the SD Card is not mounted.");
}
else
{
Debug.Print("*** The IsCardMounted property incorrectly claims that the SD card is mounted.");
}
Debug.Print("\r\nEnd of SD_Card test.");
}
#endregion
}
}