Germanwings co-pilot’s home town stunned as health details emerge – Guardian

Germanwings co-pilot’s home town stunned as health details emerge – Guardian 28 March 2015 

http://www.theguardian.com/world/2015/mar/27/germanwings-co-pilots-home-town-remains-stunned-as-background-begins-to-emerge

For a year before embarking on a career as a pilot, Andreas Lubitz worked in his local branch of Burger King, serving up french fries. The restaurant – on a busy A3 junction – is a few kilometres outside the small German city of Montabaur where Lubitz grew up. The branch manager, Detlef Aldolf, described Lubitz on Friday as dependable and inconspicuous. He earned €400 (£290) a month, he said, and quit his part-time job to join Lufthansa.

In 2009, however, Aldolf said Lubitz abruptly reappeared. Lufthansa had sent him on a training course, initially in Bremen and then in Phoenix, Arizona, in the US. “I asked him how it was. He replied: ‘Too much stress. I’m going to take a break’,” Aldolf said. The manager added that Lubitz didn’t formulate this stress as depression. But, he said, the future pilot seemed overwhelmed.

For 24 hours French and German investigators had been at a loss: why would a 27-year-old co-pilot deliberately fly his plane with 150 people on board into the French Alps? This, certainly, is where the black box pointed. By Friday there were uncomfortable answers. Lubitz had a history of psychological problems, which he had apparently been concealing from his colleagues and bosses.

State prosecutors in Düsseldorf said medical documents had been retrieved from his flat there, which suggested that treatment for an unspecified illness was ongoing. Investigators found a torn-up current medical certificate. It was dated the day of the crash. “The assumption is that the deceased hid his illness from his employer and his professional circles,” prosecutors said, without specifying whether the illness was mental or physical. They added that no suicide note had been found. Nor were there indications of a “political or religious background”.

Citing police sources, the German media said that Lubitz had broken off his pilot training several times. At one point the Lufthansa flight school in Phoenix designated the man later left in sole charge of Germanwings flight 4U9525 from Barcelona to Düsseldorf as “not fit to fly”. He spent a year-and-a-half receiving psychiatric treatment. In 2009 he was diagnosed with a “severe depressive episode”, according to the German newspaper Bild.

Throughout this difficult period it appeared Lubitz was getting regular medical help. A special coding “SIC” was entered into his pilot’s licence, which means “Specific Regular Medical Examination”, according to Germany’s Federal Aviation Office. It is unclear, though, if this treatment was for episodes of depressive illness or some other complaint. Mental health professionals have urged caution until all the facts are known.

On Thursday, prosecutors in France gave details of the final moments of flight 4U9525, travelling from Barcelona to Düsseldorf. For eight minutes, during which the cockpit voice recorder revealed Lubitz said nothing but was breathing normally, the 27-year-old ignored captain Patrick Sondheimer hammering on the cockpit door and did not respond to increasingly urgent radio calls from air traffic controllers and nearby aircraft. At approximately 10.40am the aircraft smashed into the side of a mountain near the picturesque mountain village of Seyne-les-Alpes.

“The air disaster was so devastating that we have not found a single body intact. We have found parts of bodies and biological matter that are currently undergoing post mortem examinations,” Colonel Patrick Touron, deputy director of the Institute for Criminal Research at the National Gendarmerie, told a press conference near the crash zone on Friday.

“We have sent out an urgent medical-legal team to start identification and we have a team working on the site to recuperate the bodies, parts of bodies or biological matter, depending on the circumstances, so we can proceed with the identification of the victims,” he added.

While the full picture surrounding Lubitz’s mental state is unclear, these are terrible times for Lufthansa. The airline’s chief executive, Carsten Spohr, insisted this week that Lubitz was fine to fly at the time of the disaster. He was, Spohr said, “100% fit”. Now, this assertion will come to haunt the airline amid further claims – so far unproven – that Lubitz was suffering emotional problems, too, with his girlfriend of seven years. Aldolf said he had chatted with her at Burger King in Heligenroth, where Lubitz worked, and which he listed on his now-deleted Facebook profile.

As of Friday, all German airlines including Lufthansa have introduced a new two-person cockpit rule, seemingly to prevent the horror of flight 4U9525 from ever being repeated. It is an admission that procedures failed to anticipate what a determined and troubled individual might do, when given a small window of opportunity.

Neighbours, though, condemned any rush to judgment. They said it was too early to blame Lubitz or to extrapolate what may happened above the Alps from his apparent secret backstory. “I’m shocked. But it’s not proven yet that he killed 149 people,” Johannes Rossbach said. “The other black box hasn’t been found and evaluated. I won’t believe this until it has been properly investigated.” Of Lubitz, he said: “He seemed friendly and polite. We simply said hello.”

Germanwings co-pilot Andreas Lubitz ‘wanted to make everyone remember him’

Rossbach lives two doors down from Lubitz’s home in Am Spiessweiher, in the sleepy southern part of Montabaur. The pilot lived with his parents some of the time as well as at his small flat in Düsseldorf. The two-storey house is a model of order. Large, it has a pleasant balcony. The garden is immaculately tended. It has daffodils, ornamental shrubs, and a perfectly trimmed hedge. Someone has stacked the garden gnomes neatly by the back shed.

Lubitz’s father is a banker; his mother an organist who plays at the local evangelical church. He has a younger brother. On Friday the white shutters were drawn, with no one at home. Police had earlier removed papers and a computer. The Lubitzs appear to come from the more prosperous end of the German middle class; unusually for a town this size – it has 13,000 people – Montabaur has a high-speed rail connection to the banking mega-hub of Frankfurt. Many commute.

A short walk from Am Spiessweiher is a grassy field surrounded by pine trees. It is here Lubitz learned to fly. Age 14 he joined the local LSC Westerweld flying club, which boasts a small hangar, a control tower, and a couple of gliders. There are around 100 members, 20 of them teenagers. According to Ernst Müller, novices fly at just 300 metres in a postcard-like rectangle. The view over Montabaur’s yellow-painted baroque castle is terrific, he said. Lubitz last visited at Christmas, Müller said, adding: “The club attracts a wide section of society. We have doctors, dentists and workers.”

Younger residents grumble that there isn’t much to do in Montabaur, which they dub boring. The nearest nightlife is in Koblenz, they add. Sibila Zaccaron said that Lubitz was a regular at her ice-cream bar, La Galleria, on the city’s cobbled main street. She said she saw him frequently with his blonde girlfriend, adding that he came in for the last time a month ago with his mother. She served him a cappuccino; his favourite ice-cream a lurid green.

“He was a sympathetic guy. He didn’t seem depressed. He had a nice girlfriend,” she said. The town was in a state of shock, she said, adding: “Everybody here knows each other. It’s a small place.” Opposite the bar is the city’s town hall. It has a plaque commemorating Jewish residents murdered in the Holocaust as well as a map of Brackley, Montabaur’s English twin town. Officials inside did not want to comment.

Lubitz attended the Mons-Tabor-Gymnasium or grammar school, a 15-minute walk from his home. He graduated with a diploma, the German Abitur, in 2007. Friends said Lubitz was known for being a “sporting type” who was frequently out jogging and took his exercise pretty seriously. Between 2010 and 2013 he took part in Lufthansa’s half-marathon in Frankfurt, clocking up a time on his last run of 1 hour and 37 minutes. He was a member of the city’s only health club, Fit-Up, in the centre of town, and on the first floor above a budget supermarket.

His Facebook page yields few further clues beyond an interest in flying and electronic music. His social life appears to have taken place largely in Koblenz. His likes include a disco there, the Agostea Nachtarena, a local bowling alley and a climbing wall. His favourite music acts include Paul Kalkbrenner, a German electronic producer, and David Guetta, a French DJ. There are signs too of a sense of humour. Lubitz favourites a website called “When Men Are Alone” or “Wenn Männer Allein Sind”. It isn’t a forum for singles but a light-hearted platform where men can post daft videos of themselves mucking about with chainsaws, or looking after babies badly.

Back at Burger King, Aldolf said the whole tragic story was nothing less than an unfathomable disaster. “I’m totally shocked,” he said. ‘I can’t believe it. Nobody would have expected him to do something this evil.”

.END

Leave a comment

Filed under Electronics DIY Project

那是花花! – 越南女童

fafa_2015mar2901

越南女童愛犬走失 走過狗肉攤驚叫痛哭:「那是花花」- ETtoday 2015年03月26日

http://www.ettoday.net/news/20150326/484596.htm

近日在社群網站上瘋傳一張照片,一名越南女童蹲在地上哭紅雙眼、一手觸摸著地上遭屠宰的狗。據了解,這名5歲女童飼養三年的愛狗「花花」意外走丟,幾日後她行經狗肉攤時,看到一隻遭屠宰的狗,正是她走失的愛狗。照片意外被拍下後在社群網站瘋傳,讓網友痛喊「這殘忍的一刻為什麼要讓小女孩承受!」

根據《THANHNIEN NEWS》報導,這張照片的拍攝時間和地點都無法確認,但應該是在越南北方的鄉村拍下的。據了解,這名女童的愛犬走丟後,她非常傷心,也花了很多時間去找,但都沒有結果。在幾天後,這名女童行經狗肉攤時,卻在地上看到一隻狗,一眼就認出是愛犬,讓她放聲痛喊,

「那是花花」!接著跑過去蹲在地上,邊摸著花花邊痛哭。

這張照片在社群網站瘋傳後,引發網友熱烈討論,有人表示越南北方還存有吃狗肉的習慣,但這件事對於5歲小女孩過於殘忍;也有網友痛斥,屠宰狗肉本來就該被禁止,如果不根除這樣悲傷的事只會不斷發生而已!


餵食好心人去世 20流浪貓狗靈堂送別 – 蘋果日報 2015年03月29日

得人恩果千年記,動物們也有這份靈性。墨西哥一名女子經常餵食流浪貓狗,在她逝世後,

有20隻貓狗不約而同現身靈堂似要送別恩人,並一路守護靈柩直至恩人火化為止。

蘇亞雷斯(Margarita Suarez)生前經常在所住的梅里達市(Merida)餵食流浪貓狗,幫助至少20隻動物,可是她本月初病情轉差,隨後遷往另一城市與女兒同住,可惜最終不敵病魔離世。

蘇亞雷斯的女兒本月15日為媽媽設靈,赫見很多貓狗尾隨靈柩,像列隊護送靈柩送至靈堂似的,牠們抵達靈堂後,默默躺下守候,當她知道殯葬館無飼養任何寵物後,才知道這些貓狗是來報恩。

她表示,貓狗在喪禮當天都神情哀傷,直至棺木火化後才陸續離開。

英國《都市報》/澳洲9news網


香港的另類服務行業 – 高慧然 蘋果日報 2015年03月29日

一轉眼,我隻小貓鹹爺過身已一年多。這一年,他的骨灰一直被供奉在寵物靈堂,跟其他貓貓狗狗作伴。這天我去探望他,順便告訴加拿大的朋友。朋友聽了嘖嘖稱奇,「香港居然有這等服務行業?」

是啊,論生意頭腦,香港人真是一流,轉數又快。只要可以搵到錢,他們甚麼行業都樂意開拓。香港養寵物的人越來越多,不少人視寵物為家人,甚至孩子。所以,處理寵物的身後事,在有心人眼中,是一條財路。看回舊單,

小貓獨立火化及一份紀念品索價一千九百多港幣,小貓靈位年費也近兩千。

但是,對寵物主人來說,這筆錢卻花得心甘情願。他們記掛自己的寵物時,可隨時上去探望。

寵物靈位通常位於工廈,面積小小的,四面牆釘上層架與木格便可以營業了。裏面永遠坐着位女員工,朝九晚七。有趣的是,每一次那女人總是強調自己是義工,是因為熱愛寵物所以每天坐在那兒的。大約是生意人的禁忌,心理上不能克服利用寵物主人對寵物的愛去賺錢。這種顧忌實在大可不必。商業社會,在商言商,時間和精力有價,有人願賣,有人願買,你情我願,何樂不為?

其實我很欣慰香港有這樣的服務行業,寵物靈堂,見證了香港的文明。只有在尊重生命的地方,動物才能

活得快樂,死得有尊嚴

.END

Leave a comment

Filed under Electronics DIY Project

FongSegmentLed03 refactoring notes

Begin FongSegmentLed03::testSegmentLed(). >>

+++ Current segmentLed number = 0
+++ Current spiSlaveSelectNum = 7
+++ Current spiSsPinNum = 7
+++ Current digiOutPinNum = 15
+++ Current arduinoPinNum = 42

SegmentLed test selection

0 = Change segmentLedNum. >>>>

SegmentLed Test Select = ? >>>>

SegmentLed Test Select = 0 >>>>

*** Select SegmentLedNum, …
0 = SegmentLed 0
1 = SegmentLed 1
2 = SegmentLed 2
3 = SegmentLed 3
4 = SegmentLed 4
5 = SegmentLed 5
6 = SegmentLed 6
7 = SegmentLed 7
8 = SegmentLed 8
9 = SegmentLed 9
a = SegmentLed 10
b = SegmentLed 11
c = SegmentLed 12
d = SegmentLed 13
Enter SegmentLed num, …

+++ Current segmentLed num = 12
+++ Current spiSlaveSelectNum = 19
+++ Current spiSsPinNum = 19
+++ Current digiOutPinNum = 27
+++ Current arduinoPinNum = 38

SegmentLed test selection

0 = Change segmentLedNum. >>>>
1 = Test segmentLed 7 segment mode. >>>>

+++ Current segmentLed = 12

+++ Current spiSlaveSelectNum = 19


// *** FongSegmentLed03.cpp *******

// ********************************************************************
// FongSegmentLed03 – TL Fong 2015mar29hkt1628
// ********************************************************************

#include <FongSegmentLed03.h>

// *** Constructors ***********************************************************

FongSegmentLed03::FongSegmentLed03(int8_t initNum, int8_t testNum): FongSpi03(initNum, testNum)
{
Serial.println(F(“\nBegin FongSegmentLed03::FongSegmentLed03(), … >>>>>>>>>”));

if (initNum <= InitNum0)
initSegmentLed();

if (testNum <= TestNum8)
{
beep();
testSegmentLed();
}

Serial.println(F(“End FongSegmentLed03::FongSegmentLed03(), … >>>>>>>>>”));
}

// *** Init functions *********************************************************

void FongSegmentLed03::initSegmentLed()
{
Serial.println(F(“\n\nBegin FongSegmentLed03::initSegmentLed(). >>”));

int8_t segmentLedNum;

_segmentLedConfigArrayArray[SegmentLedNum0][SpiSlaveNumIndex] = SpiSlaveNum7;
_segmentLedConfigArrayArray[SegmentLedNum0][DecodeModeNumIndex] = SevenSegmentMode;

_segmentLedConfigArrayArray[SegmentLedNum1][SpiSlaveNumIndex] = SpiSlaveNum8;
_segmentLedConfigArrayArray[SegmentLedNum1][DecodeModeNumIndex] = SevenSegmentMode;

_segmentLedConfigArrayArray[SegmentLedNum2][SpiSlaveNumIndex] = SpiSlaveNum9;
_segmentLedConfigArrayArray[SegmentLedNum2][DecodeModeNumIndex] = DotMatrixMode;

_segmentLedConfigArrayArray[SegmentLedNum3][SpiSlaveNumIndex] = SpiSlaveNum10;
_segmentLedConfigArrayArray[SegmentLedNum3][DecodeModeNumIndex] = DotMatrixMode;

_segmentLedConfigArrayArray[SegmentLedNum4][SpiSlaveNumIndex] = SpiSlaveNum11;
_segmentLedConfigArrayArray[SegmentLedNum4][DecodeModeNumIndex] = SevenSegmentMode;

_segmentLedConfigArrayArray[SegmentLedNum5][SpiSlaveNumIndex] = SpiSlaveNum12;
_segmentLedConfigArrayArray[SegmentLedNum5][DecodeModeNumIndex] = DotMatrixMode;

_segmentLedConfigArrayArray[SegmentLedNum6][SpiSlaveNumIndex] = SpiSlaveNum13;
_segmentLedConfigArrayArray[SegmentLedNum6][DecodeModeNumIndex] = DotMatrixMode;

_segmentLedConfigArrayArray[SegmentLedNum7][SpiSlaveNumIndex] = SpiSlaveNum14;
_segmentLedConfigArrayArray[SegmentLedNum7][DecodeModeNumIndex] = DotMatrixMode;

_segmentLedConfigArrayArray[SegmentLedNum8][SpiSlaveNumIndex] = SpiSlaveNum15;
_segmentLedConfigArrayArray[SegmentLedNum8][DecodeModeNumIndex] = DotMatrixMode;

_segmentLedConfigArrayArray[SegmentLedNum9][SpiSlaveNumIndex] = SpiSlaveNum16;
_segmentLedConfigArrayArray[SegmentLedNum9][DecodeModeNumIndex] = DotMatrixMode;

_segmentLedConfigArrayArray[SegmentLedNum10][SpiSlaveNumIndex] = SpiSlaveNum17;
_segmentLedConfigArrayArray[SegmentLedNum10][DecodeModeNumIndex] = DotMatrixMode;

_segmentLedConfigArrayArray[SegmentLedNum11][SpiSlaveNumIndex] = SpiSlaveNum18;
_segmentLedConfigArrayArray[SegmentLedNum11][DecodeModeNumIndex] = DotMatrixMode;

_segmentLedConfigArrayArray[SegmentLedNum12][SpiSlaveNumIndex] = SpiSlaveNum19;
_segmentLedConfigArrayArray[SegmentLedNum12][DecodeModeNumIndex] = DotMatrixMode;

_segmentLedConfigArrayArray[SegmentLedNum13][SpiSlaveNumIndex] = SpiSlaveNum20;
_segmentLedConfigArrayArray[SegmentLedNum13][DecodeModeNumIndex] = DotMatrixMode;

_segmentLedValueArray[SegmentLedNum0][Digit0Index] = Digit7Num;

for (int8_t i = SegmentLedNum0; i <= SegmentLedNum13; i++)
{
initMax7219SevenSegmentMode(i);
}

_segmentLedNum = DefaultSegmentLedNum;

Serial.println(F(“End FongSegmentLed03::initSegmentLed(). >>\n”));
}

void FongSegmentLed03::initMax7219SevenSegmentMode(int8_t segmentLedNum)
{
writeSegmentLed(segmentLedNum, DisplayTestRegAdd, NormalDisplayOnMode);
writeSegmentLed(segmentLedNum, DecodeModeRegAdd, AllDigitsDecodeMode); // <<< Bcode decode
writeSegmentLed(segmentLedNum, ScanLimitRegAdd, Scan8Digits);
writeSegmentLed(segmentLedNum, IntensityRegAdd, DisplayIntensityLevel7);
writeSegmentLed(segmentLedNum, ShutDownRegAdd, EnableShutDownMode);
}

void FongSegmentLed03::initMax7219DotMatrixMode(int8_t segmentLedNum)
{
writeSegmentLed(segmentLedNum, DisplayTestRegAdd, NormalDisplayOnMode);
writeSegmentLed(segmentLedNum, DecodeModeRegAdd, AllDigitsNoDecodeMode); // <<< Nodecode
writeSegmentLed(segmentLedNum, ScanLimitRegAdd, Scan8Digits);
writeSegmentLed(segmentLedNum, IntensityRegAdd, DisplayIntensityLevel7);
writeSegmentLed(segmentLedNum, ShutDownRegAdd, EnableShutDownMode);
}

void FongSegmentLed03::testMax7219SevenSegmentMode(int8_t segmentLedNum)
{
writeSegmentLed(segmentLedNum, Digit0RegAdd, Digit7Num);
writeSegmentLed(segmentLedNum, Digit1RegAdd, Digit6Num);
writeSegmentLed(segmentLedNum, Digit2RegAdd, Digit5Num);
writeSegmentLed(segmentLedNum, Digit3RegAdd, Digit4Num);
writeSegmentLed(segmentLedNum, Digit4RegAdd, Digit3Num);
writeSegmentLed(segmentLedNum, Digit5RegAdd, Digit2Num);
writeSegmentLed(segmentLedNum, Digit6RegAdd, Digit1Num);
writeSegmentLed(segmentLedNum, Digit7RegAdd, Digit0Num);

startUpSegmentLed(segmentLedNum);
delay(500);

testDisplayOnSegmentLed(segmentLedNum);
delay(500);

normalDisplayOnSegmentLed(segmentLedNum);
delay(500);

blinkSegmentLed(segmentLedNum, MilliSeconds100, MilliSeconds100, FourTimes);
delay(500);

startUpSegmentLed(segmentLedNum);

for (int8_t i = Digit7RegAdd; i >= Digit0RegAdd; i–)
{
blankSegmentLedDigit(segmentLedNum, i);
delay(500);
}
}

void FongSegmentLed03::testMax7219DotMatrixMode(int8_t segmentLedNum)
{
writeSegmentLed(segmentLedNum, Digit0RegAdd, AllDotsOn);
writeSegmentLed(segmentLedNum, Digit1RegAdd, AllDotsOn);
writeSegmentLed(segmentLedNum, Digit2RegAdd, AllDotsOn);
writeSegmentLed(segmentLedNum, Digit3RegAdd, AllDotsOn);
writeSegmentLed(segmentLedNum, Digit4RegAdd, AllDotsOff);
writeSegmentLed(segmentLedNum, Digit5RegAdd, AllDotsOff);
writeSegmentLed(segmentLedNum, Digit6RegAdd, AllDotsOff);
writeSegmentLed(segmentLedNum, Digit7RegAdd, AllDotsOff);

startUpSegmentLed(segmentLedNum);
delay(500);

testDisplayOnSegmentLed(segmentLedNum);
delay(500);

normalDisplayOnSegmentLed(segmentLedNum);
delay(500);

blinkSegmentLed(segmentLedNum, MilliSeconds100, MilliSeconds100, FourTimes);
delay(500);

startUpSegmentLed(segmentLedNum);

for (int8_t i = Digit7RegAdd; i >= Digit0RegAdd; i–)
{
blankSegmentLedDigit(segmentLedNum, i);
delay(500);
}

writeSegmentLed(segmentLedNum, ShutDownRegAdd, EnableShutDownMode);
}

void FongSegmentLed03::writeSegmentLed(int8_t segmentLedNum, int8_t RegAddress, byte writeDataByte)
{
int8_t spiSlaveNum = getSpiSlaveSelectNum(segmentLedNum);
spiTransferTwoByte(spiSlaveNum, RegAddress, writeDataByte);
delay(Max7219OperationDelayTime);
}

int8_t FongSegmentLed03::getSpiSlaveSelectNum(int8_t segmentLedNum)
{
int8_t spiSlaveNum = _segmentLedConfigArrayArray[segmentLedNum][SpiSlaveNumIndex];
return spiSlaveNum;
}

void FongSegmentLed03::startUpSegmentLed(int8_t segmentLedNum)
{
writeSegmentLed(segmentLedNum, ShutDownRegAdd, DisableShutDownMode);
}

void FongSegmentLed03::shutDownSegmentLed(int8_t segmentLedNum)
{
writeSegmentLed(segmentLedNum, ShutDownRegAdd, EnableShutDownMode);
}

void FongSegmentLed03::testDisplayOnSegmentLed(int8_t segmentLedNum)
{
writeSegmentLed(segmentLedNum, DisplayTestRegAdd, TestDisplayOnMode);
}

void FongSegmentLed03::normalDisplayOnSegmentLed(int8_t segmentLedNum)
{
writeSegmentLed(segmentLedNum, DisplayTestRegAdd, NormalDisplayOnMode);
}

void FongSegmentLed03::blinkSegmentLed(int8_t segmentLedNum, int8_t onTime, \
int8_t offTime, int8_t blinkCount)
{
for (int8_t i = 0; i < 4; i++)
{
startUpSegmentLed(segmentLedNum);
delay(100);
shutDownSegmentLed(segmentLedNum);
delay(100);
}
}

void FongSegmentLed03::blankSegmentLedDigit(int8_t segmentLedNum, int8_t digitNumRegAdd)
{
writeSegmentLed(segmentLedNum, digitNumRegAdd, CharBlankNum);
}

// *** Test and menu functions ************************************************

void FongSegmentLed03::testSegmentLed()
{
char selectChar;
int8_t spiSlaveSelectNum;
int8_t spiSsPinNum;
int8_t digiOutPinNum;
int8_t arduinoPinNum;

// int8_t segmentLedNum;

// segmentLedNum = SegmentLedNum0; // <<< default !!!

Serial.println(F(“Begin FongSegmentLed03::testSegmentLed(). >>”));

Serial.print(F(“\n+++ Current segmentLed number = “));
Serial.print(_segmentLedNum);

_spiSlaveSelectNum = getSpiSlaveSelectNum(_segmentLedNum);
Serial.print(F(“\n+++ Current spiSlaveSelectNum = “));
Serial.print(_spiSlaveSelectNum);

spiSsPinNum = spiSlaveNumToSpiSsPinNumArray[_spiSlaveSelectNum];
Serial.print(F(“\n+++ Current spiSsPinNum = “));
Serial.print(spiSsPinNum);

digiOutPinNum = spiSsPinNumToDigiOutPinNumArray[spiSsPinNum];
Serial.print(F(“\n+++ Current digiOutPinNum = “));
Serial.print(digiOutPinNum);

arduinoPinNum = _digiOutPinNumArray[digiOutPinNum];
Serial.print(F(“\n+++ Current arduinoPinNum = “));
Serial.print(arduinoPinNum);

printSegmentLedTestSelectMenu();
selectChar = askSegmentLedTestSelectChar(“SegmentLed Test Select”);

while (selectChar != ‘x’)
{
exeSegmentLedTestSelectFunction(_segmentLedNum, selectChar);

Serial.print(F(“\n+++ Current segmentLed = “));
Serial.print(_segmentLedNum);

_spiSlaveSelectNum = getSpiSlaveSelectNum(_segmentLedNum);
Serial.print(F(“\n+++ Current spiSlaveSelectNum = “));
Serial.print(_spiSlaveSelectNum);

printSegmentLedTestSelectMenu();
selectChar = askSegmentLedTestSelectChar(“SegmentLed Port Test Select”);
}

Serial.println(F(“End FongSegmentLed03::testSegmentLed(). >>”));
}

void FongSegmentLed03::printSegmentLedTestSelectMenu()
{
printSegmentLedTestSelectMenu(FirstSelectNum, LastSelectNum);
}

char FongSegmentLed03::askSegmentLedTestSelectChar(String askString)
{
char selectChar;
char dummyChar;

// *** flush read buffer ***
while (Serial.available() > 0) {dummyChar = Serial.read();} // flush

// *** get user selection ***
Serial.print(F(“\n”));
Serial.print(askString);
Serial.println(F(” = ? >>>> “));

while (Serial.available() == false) {} // wait for char
selectChar = Serial.read();
Serial.print(F(“”));
Serial.print(askString);
Serial.print(F(” = “));
Serial.print(selectChar);
Serial.println(F(” >>>>”));
return selectChar;
}

int FongSegmentLed03::askSegmentLedNum()
{
char dummyReadChar;
char segmentLedChar;
int segmentLedNum;
int8_t spiSlaveSelectNum;
int8_t spiSsPinNum;
int8_t digiOutPinNum;
int8_t arduinoPinNum;

Serial.print(F(“\n*** Select SegmentLedNum, …”));
Serial.print(F(“\n 0 = SegmentLed 0″));
Serial.print(F(“\n 1 = SegmentLed 1″));
Serial.print(F(“\n 2 = SegmentLed 2″));
Serial.print(F(“\n 3 = SegmentLed 3″));
Serial.print(F(“\n 4 = SegmentLed 4″));
Serial.print(F(“\n 5 = SegmentLed 5″));
Serial.print(F(“\n 6 = SegmentLed 6″));
Serial.print(F(“\n 7 = SegmentLed 7″));
Serial.print(F(“\n 8 = SegmentLed 8″));
Serial.print(F(“\n 9 = SegmentLed 9″));
Serial.print(F(“\n a = SegmentLed 10″));
Serial.print(F(“\n b = SegmentLed 11″));
Serial.print(F(“\n c = SegmentLed 12″));
Serial.print(F(“\n d = SegmentLed 13″));

// *** flush read buffer ***
while (Serial.available() > 0) {dummyReadChar = Serial.read();} // flush

Serial.print(F(“\nEnter SegmentLed num, … \n”));

while (Serial.available() == false)
{
}
segmentLedChar = Serial.read();
segmentLedNum = segmentLedChar – ‘0’;

if ((segmentLedChar == ‘0’) || (segmentLedChar <= ‘9’))
segmentLedNum = segmentLedChar – ‘0’;
else if ((segmentLedChar == ‘a’) || (segmentLedChar <= ‘z’))
segmentLedNum = (segmentLedChar – ‘a’) + 10;
else
segmentLedNum = 0;

Serial.print(F(“\n+++ Current segmentLed num = “));
Serial.print(segmentLedNum);

spiSlaveSelectNum = getSpiSlaveSelectNum(segmentLedNum);
Serial.print(F(“\n+++ Current spiSlaveSelectNum = “));
Serial.print(spiSlaveSelectNum);

spiSsPinNum = spiSlaveNumToSpiSsPinNumArray[spiSlaveSelectNum];
Serial.print(F(“\n+++ Current spiSsPinNum = “));
Serial.print(spiSsPinNum);

digiOutPinNum = spiSsPinNumToDigiOutPinNumArray[spiSsPinNum];
Serial.print(F(“\n+++ Current digiOutPinNum = “));
Serial.print(digiOutPinNum);

arduinoPinNum = _digiOutPinNumArray[digiOutPinNum];
Serial.print(F(“\n+++ Current arduinoPinNum = “));
Serial.print(arduinoPinNum);

return segmentLedNum;
}

// *** Print select function menu *********************************************

void FongSegmentLed03::printSegmentLedTestSelectMenu(int8_t firstSelectNum, int8_t lastSelectNum)
{
const char menu0[] PROGMEM = “0 = Change segmentLedNum. >>>>”;
const char menu1[] PROGMEM = “1 = Test segmentLed 7 segment mode. >>>>”;
const char menu2[] PROGMEM = “2 = Test segmentLed dot matrix mode. >>>>”;
const char menu3[] PROGMEM = “3 = Test segmentLed 0 7 segment mode. >>>>”;
const char menu4[] PROGMEM = “4 = Test segmentLed 0 dot Matrix Mode. >>>>”;
const char menu5[] PROGMEM = “5 = Reserved. >>>>”;
const char menu6[] PROGMEM = “6 = Reserved. >>>>”;
const char menu7[] PROGMEM = “7 = Reserved. >>>>”;
const char menu8[] PROGMEM = “8 = Reserved. >>>>”;
const char menu9[] PROGMEM = “9 = Reserved. >>>>”;
const char menu10[] PROGMEM = “a = Reserved. >>>>”;
const char menu11[] PROGMEM = “m = Menu. >>>>”;
const char menu12[] PROGMEM = “h = Help. >>>>”;
const char menu13[] PROGMEM = “x = Exit. >>>>”;

const char * const selectMenu[] PROGMEM = \
{menu0, menu1, menu2, menu3, menu4, \
menu5, menu6, menu7, menu8, menu9, \
menu10, menu11, menu12, menu13};

Serial.println(F(“\n### SegmentLed test selection ###”));
for (int8_t i = firstSelectNum; i <= lastSelectNum; i++)
{
Serial.println(selectMenu[i]);
}
}

// *** Execute selection function *********************************************

void FongSegmentLed03::exeSegmentLedTestSelectFunction(int8_t segmentLedNum, char selectChar)
{
byte writeByteArray[3];
byte readByteArray[3];
writeByteArray[1] = 0x00;
writeByteArray[2] = 0x00;
float adcResult;

if (selectChar == ‘0’)
{
_segmentLedNum = askSegmentLedNum();
selectChar = ‘m';
}
if (selectChar == ‘1’)
{
testMax7219SevenSegmentMode(_segmentLedNum);
}
if (selectChar == ‘2’)
{
testMax7219DotMatrixMode(_segmentLedNum);
}
else if (selectChar == ‘3’)
{
testMax7219SevenSegmentMode(SegmentLedNum0);
}
else if (selectChar == ‘4’)
{
testMax7219DotMatrixMode(SegmentLedNum0);
}
else if (selectChar == ‘5’)
{
}
else if (selectChar == ‘6’)
{
}
else if (selectChar == ‘7’)
{
}
else if (selectChar == ‘8’)
{
}
else if (selectChar == ‘9’)
{
}
else if (selectChar == ‘a’)
{
}
else if (selectChar == ‘b’)
{
}
else if (selectChar == ‘m’)
{
Serial.print(F(“\n+++ Current segmentLed num = “));
Serial.print(segmentLedNum);
printSegmentLedTestSelectMenu();
}
else if (selectChar == ‘h’)
{
Serial.print(“Sorry, no help available, …”);
}
else
{
Serial.print(“Sorry, no such option, …”);
}
}

// *** End ********************************************************************

.END

Leave a comment

Filed under Electronics DIY Project

FongSegmentLed03 refactoring notes

Begin FongSegmentLed03::FongSegmentLed03(), … >>>>>>>>>

Begin FongSegmentLed03::initSegmentLed(). >>
End FongSegmentLed03::initSegmentLed(). >>

Begin FongSegmentLed03::testSegmentLed(). >>

+++ Current segmentLed number = 0 +++

SegmentLed test selection

0 = Change segmentLedNum. >>>>
1 = Test segmentLed 7 segment mode. >>>>
2 = Test segmentLed dot matrix mode. >>>>
3 = Test segmentLed 0 7 segment mode. >>>>
4 = Test segmentLed 0 dot Matrix Mode. >>>>
5 = Reserved. >>>>
6 = Reserved. >>>>
7 = Reserved. >>>>
8 = Reserved. >>>>
9 = Reserved. >>>>
a = Reserved. >>>>
m = Menu. >>>>
h = Help. >>>>
x = Exit. >>>>

SegmentLed Test Select = ? >>>>
SegmentLed Test Select = 0 >>>>

*** Select SegmentLedNum, …
0 = SegmentLed 0
1 = SegmentLed 1
2 = SegmentLed 2
3 = SegmentLed 3
4 = SegmentLed 4
5 = SegmentLed 5
6 = SegmentLed 6
7 = SegmentLed 7
8 = SegmentLed 8
9 = SegmentLed 9
a = SegmentLed 10
b = SegmentLed 11
c = SegmentLed 12
d = SegmentLed 13
Enter SegmentLed num, …

+++ Current segmentLed num = 12
+++ Current segmentLed num = 0

SegmentLed test selection

0 = Change segmentLedNum. >>>>
1 = Test segmentLed 7 segment mode. >>>>
2 = Test segmentLed dot matrix mode. >>>>
3 = Test segmentLed 0 7 segment mode. >>>>
4 = Test segmentLed 0 dot Matrix Mode. >>>>
5 = Reserved. >>>>
6 = Reserved. >>>>
7 = Reserved. >>>>
8 = Reserved. >>>>
9 = Reserved. >>>>
a = Reserved. >>>>
m = Menu. >>>>
h = Help. >>>>
x = Exit. >>>>

+++ Current segmentLed port number = 12 +++
+++ Current spiSlaveSelectNum = 19 +++

SegmentLed test selection

0 = Change segmentLedNum. >>>>
1 = Test segmentLed 7 segment mode. >>>>
2 = Test segmentLed dot matrix mode. >>>>
3 = Test segmentLed 0 7 segment mode. >>>>
4 = Test segmentLed 0 dot Matrix Mode. >>>>
5 = Reserved. >>>>
6 = Reserved. >>>>
7 = Reserved. >>>>
8 = Reserved. >>>>
9 = Reserved. >>>>
a = Reserved. >>>>
m = Menu. >>>>
h = Help. >>>>
x = Exit. >>>>

SegmentLed Port Test Select = ? >>>>
SegmentLed Port Test Select = 1 >>>>
Sorry, no such option, …
+++ Current segmentLed port number = 12 +++
+++ Current spiSlaveSelectNum = 19 +++

SegmentLed test selection

0 = Change segmentLedNum. >>>>
1 = Test segmentLed 7 segment mode. >>>>
2 = Test segmentLed dot matrix mode. >>>>
3 = Test segmentLed 0 7 segment mode. >>>>
4 = Test segmentLed 0 dot Matrix Mode. >>>>
5 = Reserved. >>>>
6 = Reserved. >>>>
7 = Reserved. >>>>
8 = Reserved. >>>>
9 = Reserved. >>>>
a = Reserved. >>>>
m = Menu. >>>>
h = Help. >>>>
x = Exit. >>>>

SegmentLed Port Test Select = ? >>>>


// *** testFongDuino03v2015mar27hkt1032.ino ****
// ********************************************************************
// FongDuino03 tlfong01.com 201mar27
// ********************************************************************
#include “Arduino.h”
#include “HardwareSerial.h”
#include <SPI.h>
#include <FongDigiOut03.h>
#include <FongDigiControl03.h>
#include <FongHardSerial03.h>
#include <FongBlueToothBase03.h>
#include <FongSpi03.h>8
#include <FongAdc03.h>
#include <FongIox03.h>
#include <FongKeyPad03.h>
#include <FongSegmentLed03.h>

/*
#include <Wire.h>
#include <FongAnaIn02.h>
#include <FongEeprom02.h>
#include <FongI2c02.h>
#include <FongBlueToothConnect02.h>
#include <FongTest02.h>
*/

enum InitNum {InitNum0 = 0, InitNum1 = 1, InitNum2 = 2, InitNum3 = 3};
enum TestNum {TestNum0 = 0, TestNum1 = 1, TestNum2 = 2, TestNum3 = 3, \
TestNum4 = 4, TestNum5 = 5, TestNum6 = 6, TestNum7 = 7, \
TestNum8 = 8};

void setup()
{
Serial.begin(9600);
}

void loop()
{

// FongDigiOut03 fdo1(InitNum0, TestNum0); // 2015mar27 testing
// FongDigiControl03 fdc1(InitNum0, TestNum1); // 2015mar06 OK
// FongHardSerial03 fhs1(InitNum0, TestNum3); // 2015mar16 OK
// FongBlueToothBase03 fbtb1(InitNum0, TestNum4); // 2015mar16 OK
// FongSpi03 fspi1(InitNum0, TestNum4); // 2015mar26 testing

// FongAdc03 fadc1(InitNum0, TestNum5); // 2015mar16 OK
// FongIox03 fiox1(InitNum0, TestNum6); // 2015mar16 OK
// FongKeyPad03 fkp1(InitNum0, TestNum7); // 2015mar16 OK

FongSegmentLed03 fsl1(InitNum0, TestNum8); // 2015mar19 testing

// FongAnaIn02 fai1(InitNum0, TestNum0); // OK 2015jan22
// FongI2c02 fi2c1(InitNum0, TestNum7); // testing
// FongEeprom02 feep1(InitNum0, TestNum5); //To test later
// FongBlueToothConnect02 fbtc1(InitNum0, TestNum2); // To test later
// FongTest02 ft1(Init0, Test0); // To test later

while (true) { };
}

// *** End ***

Sketch uses 22,016 bytes (8%) of program storage space. Maximum is 253,952 bytes.
Global variables use 2,403 bytes (29%) of dynamic memory, leaving 5,789 bytes for local variables. Maximum is 8,192 bytes.


// *** FongSegmentLed03.h *******

// ********************************************************************
// FongSegmentLed03 – TL Fong 2015mar29hkt1627
// ********************************************************************

#ifndef FongSegmentLed03_h
#define FongSegmentLed03_h

#include <Arduino.h>
#include <FongSpi03.h>

/*
Spi Spi Dig Ard Spi Dev
Slv SS Out dui Sev Num
Num Pin Pin Pin

00 00 08 53 Adc 00
01 01 09 46 Adc 01

02 02 10 47 Iox 00
03 03 11 48 Iox 01
04 04 12 49 Iox 02

05 05 13 40 Iox 03
06 06 14 41 Iox 04

07 07 15 42 Led 00
08 08 16 43 Led 01
09 09 17 44 Led 02
10 10 18 45 Led 03

11 11 19 30 Led 04
12 12 20 31 Led 05
13 13 21 32 Led 06
14 14 22 33 Led 07
15 15 23 34 Led 08
16 16 24 35 Led 09
17 17 25 36 Led 10
18 18 26 37 Led 11
19 19 27 38 Led 12
20 20 28 39 Led 13
*/

class FongSegmentLed03: public FongSpi03
{
public:

// *** Constructors *******************************************************

FongSegmentLed03(int8_t initNum, int8_t testNum);

// *** Config enum ********************************************************

enum DelayTime {MilliSeconds100 = 100};
enum RepeatCount {Once = 1, Twice = 2, FourTimes = 4};
enum LogicVal {LowVal = false, HighVal = true};

enum SegmentLedNum {SegmentLedNum0 = 0, SegmentLedNum1 = 1, SegmentLedNum2 = 2, SegmentLedNum3 = 3, \
SegmentLedNum4 = 4, SegmentLedNum5 = 5, SegmentLedNum6 = 6, SegmentLedNum7 = 7,
SegmentLedNum8 = 8, SegmentLedNum9 = 9, SegmentLedNum10 = 10, SegmentLedNum11 = 11, \
SegmentLedNum12 = 12, SegmentLedNum13 = 13, TotalSegmentLedNum = 14};

enum SpiSlaveSelectPinNum { SpiSlaveSelectPinNum0 = 0, SpiSlaveSelectPinNum1 = 1, SpiSlaveSelectPinNum2 = 2, \
SpiSlaveSelectPinNum3 = 3, SpiSlaveSelectPinNum4 = 4, SpiSlaveSelectPinNum5 = 5, \
SpiSlaveSelectPinNum6 = 6, SpiSlaveSelectPinNum7 = 7, SpiSlaveSelectPinNum8 = 8, \
SpiSlaveSelectPinNum9 = 9, SpiSlaveSelectPinNum10 = 10, SpiSlaveSelectPinNum11 = 11, \
SpiSlaveSelectPinNum12 = 12, SpiSlaveSelectPinNum13 = 13, SpiSlaveSelectPinNum14 = 14, \
SpiSlaveSelectPinNum15 = 15, SpiSlaveSelectPinNum16 = 16, SpiSlaveSelectPinNum17 = 17, \
SpiSlaveSelectPinNum18 = 18, SpiSlaveSelectPinNum19 = 19, \
SpiSlaveSelectPinNum20 = 20, TotalSpiSlaveSelectPinNum = 21};

// enum SevenSegmentLedNum {FirstSevenSegmentLedNum = SegmentLedNum0, \
// LastSevenSegmentLedNum = SegmentLedNum1};

// enum DotMatrixSegmentLedNum {FirstDotMatrixLedNum = SegmentLedNum2, \
// LastDotMatrixLedNum = SegmentLedNum3};

// enum segmentLedType {SegmentLedType7 = 7, SegmentLedType16 = 16};

enum SegmentLedConfigArrayArrayIndex {SpiSlaveNumIndex = 0, DecodeModeNumIndex = 1, TotalConfigIndexNum = 2};
enum DecodeModeNum {NoDecodeMode = 0, BdecodeMode = 1};

int8_t _segmentLedConfigArrayArray[TotalSegmentLedNum][TotalConfigIndexNum];

// *** Init, test, and menu functions *************************************

enum InitNum {InitNum0 = 0, InitNum1 = 1, InitNum2 = 2, InitNum3 = 3};
enum TestNum {TestNum0 = 0, TestNum1 = 1, TestNum2 = 2, TestNum3 = 3, \
TestNum4 = 4, TestNum5 = 5, TestNum6 = 6, TestNum7 = 7, \
TestNum8 = 8};

void initSegmentLed();
void testSegmentLed();

enum MenuNum {FirstSelectNum = 0, LastSelectNum = 13, TotalSelectNum = 14};
void printSegmentLedTestSelectMenu(int8_t firstSelectNum, int8_t lastSelectNum);
void printSegmentLedTestSelectMenu();

char askSegmentLedTestSelectChar(String askString);

enum DefaultSegMentLedNum {DefaultSegmentLedNum = SegmentLedNum0};

int8_t _segmentLedNum;

int8_t _spiSlaveSelectNum;

int askSegmentLedNum();

void exeSegmentLedTestSelectFunction(int8_t segmentLed, char selectChar);

// *** MAX7219 Register Addresses *****************************************************

enum SegmentLedRegisterAddress { NoOpRegAdd = 0x0, \
Digit0RegAdd = 0x1, \
Digit1RegAdd = 0x2, \
Digit2RegAdd = 0x3, \
Digit3RegAdd = 0x4, \
Digit4RegAdd = 0x5, \
Digit5RegAdd = 0x6, \
Digit6RegAdd = 0x7, \
Digit7RegAdd = 0x8, \
DecodeModeRegAdd = 0x9, \
IntensityRegAdd = 0xa, \
ScanLimitRegAdd = 0xb, \
ShutDownRegAdd = 0xc, \
DisplayTestRegAdd = 0xf};

enum segmentLedValueArrayIndex {Digit0Index = 0, Digit1Index = 1, Digit2Index = 2, \
Digit3Index = 3, Digit4Index = 4, Digit5Index = 5, \
Digit6Index = 6, Digit7Index = 7, TotalDigitNumIndex = 8};

int8_t _segmentLedValueArray[TotalSegmentLedNum][TotalDigitNumIndex];

enum DigitNum { Digit0Num = 0, Digit1Num = 1, Digit2Num = 2, Digit3Num = 3, \
Digit4Num = 4, Digit5Num = 5, Digit6Num = 6, Digit7Num = 7, \
Digit8Num = 8, Digit9Num = 9, TotalDigitNum = 10};

enum DotMatrixNum {AllDotsOn = 0x11, AllDotsOff = 0x00};

enum CharNum { CharHyphenNum = 0xa, CharEnum = 0xb, CharHnum = 0xc, CharLnum = 0xd, \
CharPnum = 0xe, CharBlankNum = 0xf};

enum Max7219OperationDelayTime {Max7219OperationDelayTime = MilliSeconds100} ;

// *** MAX7219 functions *****************************************************

// *** MAX7219 config constants **********************************************

enum DisplayTestRegisterFormat {NormalDisplayOnMode = 0x00, TestDisplayOnMode = 0x01};

enum ShutdownRegisterFormat {DisableShutDownMode = 0x01, EnableShutDownMode = 0x00};

enum DecodeModeRegisterFormat {AllDigitsNoDecodeMode = 0x0, AllDigitsDecodeMode = 0xff, OnlyDigit0Decode = 0x01};

enum IntensityRegisterFormat {DisplayIntensityLevel0 = 0x0, DisplayIntensityLevel7 = 0x3, \
DisplayIntensityLevel5 = 0x7, DisplayIntensityLevel31 = 0xf};

enum ScanLimitRegisterFormat {Scan1Digit = 0x0, Scan2Digits = 0x1, \
Scan8Digits = 0x7};

enum SevenSegmentOrDotMatrixMode {SevenSegmentMode = 0, DotMatrixMode = 1};

// *** MAX7219 functions *****************************************************

void initMax7219SevenSegmentMode(int8_t segmentLedNum);
void initMax7219DotMatrixMode(int8_t segmentLedNum);

void testMax7219SevenSegmentMode(int8_t segmentLedNum);
void testMax7219DotMatrixMode(int8_t segmentLedNum);

void setSegmentLedMode(int8_t segmentLedNum, int8_t OperationMode);
void writeSegmentLed(int8_t segmentLedNum, int8_t segmentLedRegisterAddress, byte writeDataByte);

int8_t getSpiSlaveSelectNum(int8_t segmentLedNum);

void startUpSegmentLed(int8_t segmentLedNum);
void shutDownSegmentLed(int8_t segmentLedNum);

void testDisplayOnSegmentLed(int8_t segmentLedNum);
void normalDisplayOnSegmentLed(int8_t segmentLedNum);
void blinkSegmentLed(int8_t segmentLedNum, int8_t onTime, int8_t offTime, int8_t blinkCount);

void blankSegmentLedDigit(int8_t segmentLedNum, int8_t digitNumRegAdd);

private:
};

#endif

// *** End ********************************************************************


// *** FongSegmentLed03.cpp *******

// ********************************************************************
// FongSegmentLed03 – TL Fong 2015mar29hkt1628
// ********************************************************************

#include <FongSegmentLed03.h>

// *** Constructors ***********************************************************

FongSegmentLed03::FongSegmentLed03(int8_t initNum, int8_t testNum): FongSpi03(initNum, testNum)
{
Serial.println(F(“\nBegin FongSegmentLed03::FongSegmentLed03(), … >>>>>>>>>”));

if (initNum <= InitNum0)
initSegmentLed();

if (testNum <= TestNum8)
{
beep();
testSegmentLed();
}

Serial.println(F(“End FongSegmentLed03::FongSegmentLed03(), … >>>>>>>>>”));
}

// *** Init functions *********************************************************

void FongSegmentLed03::initSegmentLed()
{
Serial.println(F(“\n\nBegin FongSegmentLed03::initSegmentLed(). >>”));

int8_t segmentLedNum;

_segmentLedConfigArrayArray[SegmentLedNum0][SpiSlaveNumIndex] = SpiSlaveNum7;
_segmentLedConfigArrayArray[SegmentLedNum0][DecodeModeNumIndex] = SevenSegmentMode;

_segmentLedConfigArrayArray[SegmentLedNum1][SpiSlaveNumIndex] = SpiSlaveNum8;
_segmentLedConfigArrayArray[SegmentLedNum1][DecodeModeNumIndex] = SevenSegmentMode;

_segmentLedConfigArrayArray[SegmentLedNum2][SpiSlaveNumIndex] = SpiSlaveNum9;
_segmentLedConfigArrayArray[SegmentLedNum2][DecodeModeNumIndex] = DotMatrixMode;

_segmentLedConfigArrayArray[SegmentLedNum3][SpiSlaveNumIndex] = SpiSlaveNum10;
_segmentLedConfigArrayArray[SegmentLedNum3][DecodeModeNumIndex] = DotMatrixMode;

_segmentLedConfigArrayArray[SegmentLedNum4][SpiSlaveNumIndex] = SpiSlaveNum11;
_segmentLedConfigArrayArray[SegmentLedNum4][DecodeModeNumIndex] = SevenSegmentMode;

_segmentLedConfigArrayArray[SegmentLedNum5][SpiSlaveNumIndex] = SpiSlaveNum12;
_segmentLedConfigArrayArray[SegmentLedNum5][DecodeModeNumIndex] = DotMatrixMode;

_segmentLedConfigArrayArray[SegmentLedNum6][SpiSlaveNumIndex] = SpiSlaveNum13;
_segmentLedConfigArrayArray[SegmentLedNum6][DecodeModeNumIndex] = DotMatrixMode;

_segmentLedConfigArrayArray[SegmentLedNum7][SpiSlaveNumIndex] = SpiSlaveNum14;
_segmentLedConfigArrayArray[SegmentLedNum7][DecodeModeNumIndex] = DotMatrixMode;

_segmentLedConfigArrayArray[SegmentLedNum8][SpiSlaveNumIndex] = SpiSlaveNum15;
_segmentLedConfigArrayArray[SegmentLedNum8][DecodeModeNumIndex] = DotMatrixMode;

_segmentLedConfigArrayArray[SegmentLedNum9][SpiSlaveNumIndex] = SpiSlaveNum16;
_segmentLedConfigArrayArray[SegmentLedNum9][DecodeModeNumIndex] = DotMatrixMode;

_segmentLedConfigArrayArray[SegmentLedNum10][SpiSlaveNumIndex] = SpiSlaveNum17;
_segmentLedConfigArrayArray[SegmentLedNum10][DecodeModeNumIndex] = DotMatrixMode;

_segmentLedConfigArrayArray[SegmentLedNum11][SpiSlaveNumIndex] = SpiSlaveNum18;
_segmentLedConfigArrayArray[SegmentLedNum11][DecodeModeNumIndex] = DotMatrixMode;

_segmentLedConfigArrayArray[SegmentLedNum12][SpiSlaveNumIndex] = SpiSlaveNum19;
_segmentLedConfigArrayArray[SegmentLedNum12][DecodeModeNumIndex] = DotMatrixMode;

_segmentLedConfigArrayArray[SegmentLedNum13][SpiSlaveNumIndex] = SpiSlaveNum20;
_segmentLedConfigArrayArray[SegmentLedNum13][DecodeModeNumIndex] = DotMatrixMode;

_segmentLedValueArray[SegmentLedNum0][Digit0Index] = Digit7Num;

for (int8_t i = SegmentLedNum0; i <= SegmentLedNum13; i++)
{
initMax7219SevenSegmentMode(i);
}

_segmentLedNum = DefaultSegmentLedNum;

Serial.println(F(“End FongSegmentLed03::initSegmentLed(). >>\n”));
}

void FongSegmentLed03::initMax7219SevenSegmentMode(int8_t segmentLedNum)
{
writeSegmentLed(segmentLedNum, DisplayTestRegAdd, NormalDisplayOnMode);
writeSegmentLed(segmentLedNum, DecodeModeRegAdd, AllDigitsDecodeMode); // <<< Bcode decode
writeSegmentLed(segmentLedNum, ScanLimitRegAdd, Scan8Digits);
writeSegmentLed(segmentLedNum, IntensityRegAdd, DisplayIntensityLevel7);
writeSegmentLed(segmentLedNum, ShutDownRegAdd, EnableShutDownMode);
}

void FongSegmentLed03::initMax7219DotMatrixMode(int8_t segmentLedNum)
{
writeSegmentLed(segmentLedNum, DisplayTestRegAdd, NormalDisplayOnMode);
writeSegmentLed(segmentLedNum, DecodeModeRegAdd, AllDigitsNoDecodeMode); // <<< Nodecode
writeSegmentLed(segmentLedNum, ScanLimitRegAdd, Scan8Digits);
writeSegmentLed(segmentLedNum, IntensityRegAdd, DisplayIntensityLevel7);
writeSegmentLed(segmentLedNum, ShutDownRegAdd, EnableShutDownMode);
}

void FongSegmentLed03::testMax7219SevenSegmentMode(int8_t segmentLedNum)
{
writeSegmentLed(segmentLedNum, Digit0RegAdd, Digit7Num);
writeSegmentLed(segmentLedNum, Digit1RegAdd, Digit6Num);
writeSegmentLed(segmentLedNum, Digit2RegAdd, Digit5Num);
writeSegmentLed(segmentLedNum, Digit3RegAdd, Digit4Num);
writeSegmentLed(segmentLedNum, Digit4RegAdd, Digit3Num);
writeSegmentLed(segmentLedNum, Digit5RegAdd, Digit2Num);
writeSegmentLed(segmentLedNum, Digit6RegAdd, Digit1Num);
writeSegmentLed(segmentLedNum, Digit7RegAdd, Digit0Num);

startUpSegmentLed(segmentLedNum);
delay(500);

testDisplayOnSegmentLed(segmentLedNum);
delay(500);

normalDisplayOnSegmentLed(segmentLedNum);
delay(500);

blinkSegmentLed(segmentLedNum, MilliSeconds100, MilliSeconds100, FourTimes);
delay(500);

startUpSegmentLed(segmentLedNum);

for (int8_t i = Digit7RegAdd; i >= Digit0RegAdd; i–)
{
blankSegmentLedDigit(segmentLedNum, i);
delay(500);
}
}

void FongSegmentLed03::testMax7219DotMatrixMode(int8_t segmentLedNum)
{
writeSegmentLed(segmentLedNum, Digit0RegAdd, AllDotsOn);
writeSegmentLed(segmentLedNum, Digit1RegAdd, AllDotsOn);
writeSegmentLed(segmentLedNum, Digit2RegAdd, AllDotsOn);
writeSegmentLed(segmentLedNum, Digit3RegAdd, AllDotsOn);
writeSegmentLed(segmentLedNum, Digit4RegAdd, AllDotsOff);
writeSegmentLed(segmentLedNum, Digit5RegAdd, AllDotsOff);
writeSegmentLed(segmentLedNum, Digit6RegAdd, AllDotsOff);
writeSegmentLed(segmentLedNum, Digit7RegAdd, AllDotsOff);

startUpSegmentLed(segmentLedNum);
delay(500);

testDisplayOnSegmentLed(segmentLedNum);
delay(500);

normalDisplayOnSegmentLed(segmentLedNum);
delay(500);

blinkSegmentLed(segmentLedNum, MilliSeconds100, MilliSeconds100, FourTimes);
delay(500);

startUpSegmentLed(segmentLedNum);

for (int8_t i = Digit7RegAdd; i >= Digit0RegAdd; i–)
{
blankSegmentLedDigit(segmentLedNum, i);
delay(500);
}

writeSegmentLed(segmentLedNum, ShutDownRegAdd, EnableShutDownMode);
}

void FongSegmentLed03::writeSegmentLed(int8_t segmentLedNum, int8_t RegAddress, byte writeDataByte)
{
int8_t spiSlaveNum = getSpiSlaveSelectNum(segmentLedNum);
spiTransferTwoByte(spiSlaveNum, RegAddress, writeDataByte);
delay(Max7219OperationDelayTime);
}

int8_t FongSegmentLed03::getSpiSlaveSelectNum(int8_t segmentLedNum)
{
int8_t spiSlaveNum = _segmentLedConfigArrayArray[segmentLedNum][SpiSlaveNumIndex];
return spiSlaveNum;
}

void FongSegmentLed03::startUpSegmentLed(int8_t segmentLedNum)
{
writeSegmentLed(segmentLedNum, ShutDownRegAdd, DisableShutDownMode);
}

void FongSegmentLed03::shutDownSegmentLed(int8_t segmentLedNum)
{
writeSegmentLed(segmentLedNum, ShutDownRegAdd, EnableShutDownMode);
}

void FongSegmentLed03::testDisplayOnSegmentLed(int8_t segmentLedNum)
{
writeSegmentLed(segmentLedNum, DisplayTestRegAdd, TestDisplayOnMode);
}

void FongSegmentLed03::normalDisplayOnSegmentLed(int8_t segmentLedNum)
{
writeSegmentLed(segmentLedNum, DisplayTestRegAdd, NormalDisplayOnMode);
}

void FongSegmentLed03::blinkSegmentLed(int8_t segmentLedNum, int8_t onTime, \
int8_t offTime, int8_t blinkCount)
{
for (int8_t i = 0; i < 4; i++)
{
startUpSegmentLed(segmentLedNum);
delay(100);
shutDownSegmentLed(segmentLedNum);
delay(100);
}
}

void FongSegmentLed03::blankSegmentLedDigit(int8_t segmentLedNum, int8_t digitNumRegAdd)
{
writeSegmentLed(segmentLedNum, digitNumRegAdd, CharBlankNum);
}

// *** Test and menu functions ************************************************

void FongSegmentLed03::testSegmentLed()
{
char selectChar;
int8_t spiSlaveSelectNum;

// int8_t segmentLedNum;

// segmentLedNum = SegmentLedNum0; // <<< default !!!

Serial.println(F(“Begin FongSegmentLed03::testSegmentLed(). >>”));

Serial.print(F(“\n+++ Current segmentLed number = “));
Serial.print(_segmentLedNum);
Serial.print(F(” +++”));

printSegmentLedTestSelectMenu();
selectChar = askSegmentLedTestSelectChar(“SegmentLed Test Select”);

while (selectChar != ‘x’)
{
exeSegmentLedTestSelectFunction(_segmentLedNum, selectChar);

Serial.print(F(“\n+++ Current segmentLed port number = “));
Serial.print(_segmentLedNum);
Serial.print(F(” +++”));

_spiSlaveSelectNum = getSpiSlaveSelectNum(_segmentLedNum);

Serial.print(F(“\n+++ Current spiSlaveSelectNum = “));
Serial.print(_spiSlaveSelectNum);
Serial.print(F(” +++”));
printSegmentLedTestSelectMenu();
selectChar = askSegmentLedTestSelectChar(“SegmentLed Port Test Select”);
}

Serial.println(F(“End FongSegmentLed03::testSegmentLed(). >>”));
}

void FongSegmentLed03::printSegmentLedTestSelectMenu()
{
printSegmentLedTestSelectMenu(FirstSelectNum, LastSelectNum);
}

char FongSegmentLed03::askSegmentLedTestSelectChar(String askString)
{
char selectChar;
char dummyChar;

// *** flush read buffer ***
while (Serial.available() > 0) {dummyChar = Serial.read();} // flush

// *** get user selection ***
Serial.print(F(“\n”));
Serial.print(askString);
Serial.println(F(” = ? >>>> “));

while (Serial.available() == false) {} // wait for char
selectChar = Serial.read();
Serial.print(F(“”));
Serial.print(askString);
Serial.print(F(” = “));
Serial.print(selectChar);
Serial.println(F(” >>>>”));
return selectChar;
}

int FongSegmentLed03::askSegmentLedNum()
{
char dummyReadChar;
char segmentLedChar;
int segmentLedNum;

Serial.print(F(“\n*** Select SegmentLedNum, …”));
Serial.print(F(“\n 0 = SegmentLed 0″));
Serial.print(F(“\n 1 = SegmentLed 1″));
Serial.print(F(“\n 2 = SegmentLed 2″));
Serial.print(F(“\n 3 = SegmentLed 3″));
Serial.print(F(“\n 4 = SegmentLed 4″));
Serial.print(F(“\n 5 = SegmentLed 5″));
Serial.print(F(“\n 6 = SegmentLed 6″));
Serial.print(F(“\n 7 = SegmentLed 7″));
Serial.print(F(“\n 8 = SegmentLed 8″));
Serial.print(F(“\n 9 = SegmentLed 9″));
Serial.print(F(“\n a = SegmentLed 10″));
Serial.print(F(“\n b = SegmentLed 11″));
Serial.print(F(“\n c = SegmentLed 12″));
Serial.print(F(“\n d = SegmentLed 13″));

// *** flush read buffer ***
while (Serial.available() > 0) {dummyReadChar = Serial.read();} // flush

Serial.print(F(“\nEnter SegmentLed num, … \n”));

while (Serial.available() == false)
{
}
segmentLedChar = Serial.read();
segmentLedNum = segmentLedChar – ‘0’;

if ((segmentLedChar == ‘0’) || (segmentLedChar <= ‘9’))
segmentLedNum = segmentLedChar – ‘0’;
else if ((segmentLedChar == ‘a’) || (segmentLedChar <= ‘z’))
segmentLedNum = (segmentLedChar – ‘a’) + 10;
else
segmentLedNum = 0;

Serial.print(F(“\n+++ Current segmentLed num = “));
Serial.print(segmentLedNum);
return segmentLedNum;
}

// *** Print select function menu *********************************************

void FongSegmentLed03::printSegmentLedTestSelectMenu(int8_t firstSelectNum, int8_t lastSelectNum)
{
const char menu0[] PROGMEM = “0 = Change segmentLedNum. >>>>”;
const char menu1[] PROGMEM = “1 = Test segmentLed 7 segment mode. >>>>”;
const char menu2[] PROGMEM = “2 = Test segmentLed dot matrix mode. >>>>”;
const char menu3[] PROGMEM = “3 = Test segmentLed 0 7 segment mode. >>>>”;
const char menu4[] PROGMEM = “4 = Test segmentLed 0 dot Matrix Mode. >>>>”;
const char menu5[] PROGMEM = “5 = Reserved. >>>>”;
const char menu6[] PROGMEM = “6 = Reserved. >>>>”;
const char menu7[] PROGMEM = “7 = Reserved. >>>>”;
const char menu8[] PROGMEM = “8 = Reserved. >>>>”;
const char menu9[] PROGMEM = “9 = Reserved. >>>>”;
const char menu10[] PROGMEM = “a = Reserved. >>>>”;
const char menu11[] PROGMEM = “m = Menu. >>>>”;
const char menu12[] PROGMEM = “h = Help. >>>>”;
const char menu13[] PROGMEM = “x = Exit. >>>>”;

const char * const selectMenu[] PROGMEM = \
{menu0, menu1, menu2, menu3, menu4, \
menu5, menu6, menu7, menu8, menu9, \
menu10, menu11, menu12, menu13};

Serial.println(F(“\n### SegmentLed test selection ###”));
for (int8_t i = firstSelectNum; i <= lastSelectNum; i++)
{
Serial.println(selectMenu[i]);
}
}

// *** Execute selection function *********************************************

void FongSegmentLed03::exeSegmentLedTestSelectFunction(int8_t segmentLedNum, char selectChar)
{
byte writeByteArray[3];
byte readByteArray[3];
writeByteArray[1] = 0x00;
writeByteArray[2] = 0x00;
float adcResult;

if (selectChar == ‘0’)
{
_segmentLedNum = askSegmentLedNum();
selectChar = ‘m';
}
if (selectChar == ‘1’)
{
testMax7219SevenSegmentMode(_segmentLedNum);
}
if (selectChar == ‘2’)
{
testMax7219DotMatrixMode(_segmentLedNum);
}
else if (selectChar == ‘3’)
{
testMax7219SevenSegmentMode(SegmentLedNum0);
}
else if (selectChar == ‘4’)
{
testMax7219DotMatrixMode(SegmentLedNum0);
}
else if (selectChar == ‘5’)
{
}
else if (selectChar == ‘6’)
{
}
else if (selectChar == ‘7’)
{
}
else if (selectChar == ‘8’)
{
}
else if (selectChar == ‘9’)
{
}
else if (selectChar == ‘a’)
{
}
else if (selectChar == ‘b’)
{
}
else if (selectChar == ‘m’)
{
Serial.print(F(“\n+++ Current segmentLed num = “));
Serial.print(segmentLedNum);
printSegmentLedTestSelectMenu();
}
else if (selectChar == ‘h’)
{
Serial.print(“Sorry, no help available, …”);
}
else
{
Serial.print(“Sorry, no such option, …”);
}
}

// *** End ********************************************************************

.END

Leave a comment

Filed under Electronics DIY Project

FongSpi03 refactoring notes

*** Select SPI Slave Num, …
0 = Spi Slave Num 0
1 = Spi Slave Num 1
2 = Spi Slave Num 2
3 = Spi Slave Num 3
4 = Spi Slave Num 4
5 = Spi Slave Num 5
6 = Spi Slave Num 6
7 = Spi Slave Num 7
8 = Spi Slave Num 8
9 = Spi Slave Num 9
a = Spi Slave Num 10
b = Spi Slave Num 11
c = Spi Slave Num 12
d = Spi Slave Num 13
e = Spi Slave Num 14
f = Spi Slave Num 15
g = Spi Slave Num 16
h = Spi Slave Num 17
i = Spi Slave Num 18
j = Spi Slave Num 19
k = Spi Slave Num 20
Enter SPI slave number, …

+++ Current slave number = 19
Spi Test Select = ? >>>>
Spi Test Select = >>>>
Sorry, no such option, …
Spi Test Select = ? >>>>
Spi Test Select = 1 >>>>


// *** testFongDuino03v2015mar27hkt1032.ino ****
// ********************************************************************
// FongDuino03 tlfong01.com 201mar27
// ********************************************************************
#include “Arduino.h”
#include “HardwareSerial.h”
#include <SPI.h>
#include <FongDigiOut03.h>
#include <FongDigiControl03.h>
#include <FongHardSerial03.h>
#include <FongBlueToothBase03.h>
#include <FongSpi03.h>8
#include <FongAdc03.h>
#include <FongIox03.h>
#include <FongKeyPad03.h>
#include <FongSegmentLed03.h>

/*
#include <Wire.h>
#include <FongAnaIn02.h>
#include <FongEeprom02.h>
#include <FongI2c02.h>
#include <FongBlueToothConnect02.h>
#include <FongTest02.h>
*/

enum InitNum {InitNum0 = 0, InitNum1 = 1, InitNum2 = 2, InitNum3 = 3};
enum TestNum {TestNum0 = 0, TestNum1 = 1, TestNum2 = 2, TestNum3 = 3, \
TestNum4 = 4, TestNum5 = 5, TestNum6 = 6, TestNum7 = 7, \
TestNum8 = 8};

void setup()
{
Serial.begin(9600);
}

void loop()
{

// FongDigiOut03 fdo1(InitNum0, TestNum0); // 2015mar27 testing
// FongDigiControl03 fdc1(InitNum0, TestNum1); // 2015mar06 OK
// FongHardSerial03 fhs1(InitNum0, TestNum3); // 2015mar16 OK
// FongBlueToothBase03 fbtb1(InitNum0, TestNum4); // 2015mar16 OK

FongSpi03 fspi1(InitNum0, TestNum4); // 2015mar26 testing

// FongAdc03 fadc1(InitNum0, TestNum5); // 2015mar16 OK
// FongIox03 fiox1(InitNum0, TestNum6); // 2015mar16 OK
// FongKeyPad03 fkp1(InitNum0, TestNum7); // 2015mar16 OK

// FongSegmentLed03 fsl1(InitNum0, TestNum8); // 2015mar19 testing

// FongAnaIn02 fai1(InitNum0, TestNum0); // OK 2015jan22
// FongI2c02 fi2c1(InitNum0, TestNum7); // testing
// FongEeprom02 feep1(InitNum0, TestNum5); //To test later
// FongBlueToothConnect02 fbtc1(InitNum0, TestNum2); // To test later
// FongTest02 ft1(Init0, Test0); // To test later

while (true) { };
}

// *** End ***


// *** FongSpi03.h *******

// ********************************************************************
// FongSpi03 – TL Fong 2015mar29hkt1520
// ********************************************************************

#ifndef FongSpi03_h
#define FongSpi03_h

#include <Arduino.h>
#include <FongDigiControl03.h>
#include <SPI.h>

class FongSpi03: public FongDigiControl03
{
public:

// *** Constructors *******************************************************

FongSpi03(int8_t initNum, int8_t testNum);

int8_t _initNum;
int8_t _testNum;

enum InitNum {InitNum0 = 0, InitNum1 = 1, InitNum2 = 2, InitNum3 = 3};
enum TestNum {TestNum0 = 0, TestNum1 = 1, TestNum2 = 2, TestNum3 = 3, \
TestNum4 = 4, TestNum5 = 5, TestNum6 = 6};

// *** General enums ***

enum RepeatCount {RepeatOnce = 1, RepeatTwice = 2, RepeatFourTimes = 4, RepeatTenTimes = 10, \
RepeatOneHundredTimes = 100, RepeatOneThousandTimes = 1000, \
RepeatTenThousandTimes = 10000, Repeat100000Times = 100000, \
RepeatOneMillionTimes = 1000000, RepeatTenMillionTimes = 10000000};

// *** Init functions ***

enum spiSlaveNum { SpiSlaveNum0 = 0, SpiSlaveNum1 = 1, SpiSlaveNum2 = 2, SpiSlaveNum3 = 3, \
SpiSlaveNum4 = 4, SpiSlaveNum5 = 5, SpiSlaveNum6 = 6, SpiSlaveNum7 = 7, \
SpiSlaveNum8 = 8, SpiSlaveNum9 = 9, SpiSlaveNum10 = 10, \
SpiSlaveNum11 = 11, SpiSlaveNum12 = 12, SpiSlaveNum13 = 13, SpiSlaveNum14 = 14, \
SpiSlaveNum15 = 15, SpiSlaveNum16 = 16, SpiSlaveNum17 = 17, SpiSlaveNum18 = 18, \
SpiSlaveNum19 = 19, SpiSlaveNum20 = 20, \
FirstSpiSlaveNum = 0, LastSpiSlaveNum = 20, TotalSpiSlaveNum = 21};

int8_t spiSlaveNumToSpiSsPinNumArray[TotalSpiSlaveNum];

// *** adc channel number ***
enum ChannelNum1 { ChannelNum0 = 0, ChannelNum1 = 1, ChannelNum2 = 2, ChannelNum3 = 3, \
ChannelNum4 = 4, ChannelNum5 = 5, ChannelNum6 = 6, ChannelNum7 = 7, \
ChannelNum8 = 8, ChannelNum9 = 9, ChannelNum10 = 10, ChannelNum11 = 11, \
ChannelNum12 = 12, ChannelNum13 = 13, ChannelNum14 = 14, ChannelNum15 = 15};

enum ClodkDividerTimes {ClockDivider21Times = 21, ClockDivider42Times = 42, ClockDivider84Times = 84};

// *** Test functions ***

void initSpi(int8_t initNum, int8_t testNum);
void stopSpi(int8_t initNum, int8_t testNum);

enum MenuNum {FirstSelectNum = 0, LastSelectNum = 13, TotalSelectNum = 14};

void testSpi(int8_t initNum, int8_t testNum);
void printSpiSelectMenu(int8_t firstSelectNum, int8_t lastSelectNum, int8_t initNum, int8_t testNum);
void printSpiSelectMenu(int8_t initNum, int8_t testNum);
char askSpiSelectChar(String askString, int8_t initNum, int8_t testNum);
void exeSpiSelectFunction(char selectChar, int8_t initNum, int8_t testNum);

int8_t spiSlaveNum;

int askspiSlaveNum(int8_t initNum , int8_t testNum);
int8_t getSlaveSelectPin(int8_t spiSlaveNum);

byte xferOneByte(int8_t spiSlaveNum, byte writeByte);
void xferOneByte(int8_t spiSlaveNum, byte writeByte, unsigned long repeatNum);
void xferTwoByte(int8_t spiSlaveNum, byte writeByteArray[], byte readByteArray[]);
void xferThreeByte(int8_t spiSlaveNum, byte writeByteArray[], byte readByteArray[]);
void xferThreeByte(int8_t spiSlaveNum, byte writeByte0, \
byte writeByte1, byte writeByte2, byte readByteArray[]);
void xferThreeByte(int8_t spiSlaveNum, byte writeByte0, \
byte writeByte1, byte writeByte2);
byte xferThreeByteX(int8_t spiSlaveNum, byte writeByte0, \
byte writeByte1, byte writeByte2);
void testOneByteLoopback(int8_t spiSlaveNum);

void xferTwoByte(int8_t spiSlaveNum, byte writeByte0, byte writeByte1);
void spiTransferTwoByte(int8_t spiSlaveNum, byte writeByte0, byte writeByte1);

private:
};

#endif

// *** End ********************************************************************


// *** FongSpi03.cpp *******

// ********************************************************************
// FongSpi03 – TL Fong 2015feb22hkt1610
// ********************************************************************

#include <FongSpi03.h>

// *** Constructors ***********************************************************

FongSpi03::FongSpi03(int8_t initNum, int8_t testNum): FongDigiControl03(initNum, testNum)
{
// Serial.println(F(“\nBegin FongSpi03::FongSpi03(), … >>>>>>>>>”));

_initNum = initNum;
_testNum = testNum;

if (_initNum <= InitNum0)
initSpi(_initNum, _testNum);

if (_testNum <= TestNum4)
{
beep();
testSpi(_initNum, _testNum);
}

// Serial.println(F(“End FongSpi03::FongSpi03(), … >>>>>>>>>”));
}

// *** Init functions ***

void FongSpi03::initSpi(int8_t initNum, int8_t testNum)
{
// Serial.println(F(“\n\nBegin FongSpi03::initSpi(). >>”));

// Arduin Due Only !!!
// SPI.begin(SlaveSelectPinSlaveSelectPin0);
// SPI.begin(SlaveSelectPinSlaveSelectPin1);
// SPI.begin(SlaveSelectPinSlaveSelectPin2);
// SPI.setClockDivider(SlaveSelectPinSs0, ClockDivider84Times);
// SPI.setClockDivider(SlaveSelectPinSs1, ClockDivider84Times);
// SPI.setClockDivider(SlaveSelectPinSs2, ClockDivider84Times);
// SPI.setDataMode(SlaveSelectPinSs0, SPI_MODE0);
// SPI.setDataMode(SlaveSelectPinSs1, SPI_MODE0);
// SPI.setDataMode(SlaveSelectPinSs2, SPI_MODE0);

SPI.begin();

SPI.setClockDivider(SPI_CLOCK_DIV4); // too slow for ADC MCP3208 (2.5V cap leaks to 2.0V)

// SPI.setClockDivider(SPI_CLOCK_DIV8);
// SPI.setClockDivider(SPI_CLOCK_DIV128);
// SPI.setClockDivider(SPI_CLOCK_DIV16);
//SPI.setClockDivider(SPI_CLOCK_DIV4);

SPI.setDataMode(SPI_MODE0);
SPI.setBitOrder(MSBFIRST);

spiSlaveNumToSpiSsPinNumArray[0] = SpiSsPinNum0;
spiSlaveNumToSpiSsPinNumArray[1] = SpiSsPinNum1;
spiSlaveNumToSpiSsPinNumArray[2] = SpiSsPinNum2;
spiSlaveNumToSpiSsPinNumArray[3] = SpiSsPinNum3;
spiSlaveNumToSpiSsPinNumArray[4] = SpiSsPinNum4;
spiSlaveNumToSpiSsPinNumArray[5] = SpiSsPinNum5;
spiSlaveNumToSpiSsPinNumArray[6] = SpiSsPinNum6;
spiSlaveNumToSpiSsPinNumArray[7] = SpiSsPinNum7;
spiSlaveNumToSpiSsPinNumArray[8] = SpiSsPinNum8;
spiSlaveNumToSpiSsPinNumArray[9] = SpiSsPinNum9;
spiSlaveNumToSpiSsPinNumArray[10] = SpiSsPinNum10;
spiSlaveNumToSpiSsPinNumArray[11] = SpiSsPinNum11;
spiSlaveNumToSpiSsPinNumArray[12] = SpiSsPinNum12;
spiSlaveNumToSpiSsPinNumArray[13] = SpiSsPinNum13;
spiSlaveNumToSpiSsPinNumArray[14] = SpiSsPinNum14;
spiSlaveNumToSpiSsPinNumArray[15] = SpiSsPinNum15;
spiSlaveNumToSpiSsPinNumArray[16] = SpiSsPinNum16;
spiSlaveNumToSpiSsPinNumArray[17] = SpiSsPinNum17;
spiSlaveNumToSpiSsPinNumArray[18] = SpiSsPinNum18;
spiSlaveNumToSpiSsPinNumArray[19] = SpiSsPinNum19;

spiSlaveNum = 0;

// Serial.println(F(“End FongSpi03::initSpi(). >>\n”));
}

void FongSpi03::stopSpi(int8_t initNum, int8_t testNum)
{
Serial.println(F(“\n\nBegin FongSpi03::stopSpi(). >>”));

// Arduino Due Only!!!
// SPI.end(SlaveSelectPinSs0);
// SPI.end(SlaveSelectPinSs1);
// SPI.end(SlaveSelectPinSs2);

SPI.end();

Serial.println(F(“End FongSpi03::stopSpi(). >>\n”));
}

// *** Test functions *********************************************************

void FongSpi03::testSpi(int8_t initNum, int8_t testNum)
{
char selectChar;

Serial.println(F(“Begin FongSpi03::testSpi(). >>”));

Serial.print(F(“\n+++ Current slave number = “));
Serial.print(spiSlaveNum);

printSpiSelectMenu(initNum, testNum);
while (selectChar != ‘x’)
{
selectChar = askSpiSelectChar(“Spi Test Select”, initNum, testNum);
if (selectChar == ‘x’)
break;
else
{
exeSpiSelectFunction(selectChar, initNum, testNum);
selectChar = ‘m';
}
}

Serial.println(F(“End FongSpi03::testSpi(). >>”));
}

void FongSpi03::printSpiSelectMenu(int8_t initNum, int8_t testNum)
{
printSpiSelectMenu(FirstSelectNum, LastSelectNum, initNum, testNum);
}

char FongSpi03::askSpiSelectChar(String askString, int8_t initNum, int8_t testNum)
{
char selectChar;
char dummyChar;

// *** flush read buffer ***
while (Serial.available() > 0) {dummyChar = Serial.read();} // flush

// *** get user selection ***
Serial.print(F(“\n”));
Serial.print(askString);
Serial.println(F(” = ? >>>> “));

while (Serial.available() == false) {} // wait for char
selectChar = Serial.read();
Serial.print(F(“”));
Serial.print(askString);
Serial.print(F(” = “));
Serial.print(selectChar);
Serial.println(F(” >>>>”));
return selectChar;
}

// *** Ask SPI slave num ***

int FongSpi03::askspiSlaveNum(int8_t initNum , int8_t testNum)
{
char dummyReadChar;
char spiSlaveChar;
int spiSlaveNum;

Serial.print(F(“\n*** Select SPI Slave Num, …”));
Serial.print(F(“\n 0 = Spi Slave Num 0″));
Serial.print(F(“\n 1 = Spi Slave Num 1″));
Serial.print(F(“\n 2 = Spi Slave Num 2″));
Serial.print(F(“\n 3 = Spi Slave Num 3″));
Serial.print(F(“\n 4 = Spi Slave Num 4″));
Serial.print(F(“\n 5 = Spi Slave Num 5″));
Serial.print(F(“\n 6 = Spi Slave Num 6″));
Serial.print(F(“\n 7 = Spi Slave Num 7″));
Serial.print(F(“\n 8 = Spi Slave Num 8″));
Serial.print(F(“\n 9 = Spi Slave Num 9″));
Serial.print(F(“\n a = Spi Slave Num 10″));
Serial.print(F(“\n b = Spi Slave Num 11″));
Serial.print(F(“\n c = Spi Slave Num 12″));
Serial.print(F(“\n d = Spi Slave Num 13″));
Serial.print(F(“\n e = Spi Slave Num 14″));
Serial.print(F(“\n f = Spi Slave Num 15″));
Serial.print(F(“\n g = Spi Slave Num 16″));
Serial.print(F(“\n h = Spi Slave Num 17″));
Serial.print(F(“\n i = Spi Slave Num 18″));
Serial.print(F(“\n j = Spi Slave Num 19″));
Serial.print(F(“\n k = Spi Slave Num 20″));

// *** flush read buffer ***
while (Serial.available() > 0) {dummyReadChar = Serial.read();} // flush

Serial.print(F(“\nEnter SPI slave number, … \n”));

while (Serial.available() == false)
{
}
spiSlaveChar = Serial.read();

if ((spiSlaveChar == ‘0’) || (spiSlaveChar <= ‘9’))
spiSlaveNum = spiSlaveChar – ‘0’;
else if ((spiSlaveChar == ‘a’) || (spiSlaveChar <= ‘z’))
spiSlaveNum = (spiSlaveChar – ‘a’) + 10;
else
spiSlaveNum = 0;

Serial.print(F(“\n+++ Current slave number = “));
Serial.print(spiSlaveNum);

return spiSlaveNum;
}

// *** Transfer SPI bytes ***

byte FongSpi03::xferOneByte(int8_t spiSlaveNum, byte writeByte)
{
// Arduino Due Only!!!
// int8_t slaveSelectPin = getSlaveSelectPin(spiSlaveNum);
// byte readByte = SPI.transfer(slaveSelectPin, writeByte);

int8_t SpiSsPinNum = spiSlaveNumToSpiSsPinNumArray[spiSlaveNum];
enableSpiSlaveSelectPin(SpiSsPinNum);
byte readByte = SPI.transfer(writeByte);
disableSpiSlaveSelectPin(SpiSsPinNum);

return readByte;
}

void FongSpi03::xferOneByte(int8_t spiSlaveNum, byte writeByte, unsigned long repeatNum)
{
for (unsigned long i = 0; i < repeatNum; i++)
{
xferOneByte(spiSlaveNum, writeByte);
}
}

int8_t FongSpi03::getSlaveSelectPin(int8_t spiSlaveNum)
{
int8_t slaveSelectPin = spiSlaveNumToSpiSsPinNumArray[spiSlaveNum];

return slaveSelectPin;
}

void FongSpi03::xferTwoByte(int8_t spiSlaveNum, byte writeByteArray[], byte readByteArray[])
{
// Arduino Due Only!!!
// int8_t slaveSelectPin = getSlaveSelectPin(spiSlaveNum);
// readByteArray[0] = SPI.transfer(slaveSelectPin, writeByteArray[0], SPI_CONTINUE);
// readByteArray[1] = SPI.transfer(slaveSelectPin, writeByteArray[1], SPI_LAST);

int8_t SpiSsPinNum = spiSlaveNumToSpiSsPinNumArray[spiSlaveNum];
enableSpiSlaveSelectPin(SpiSsPinNum);
readByteArray[0] = SPI.transfer(writeByteArray[0]);
readByteArray[1] = SPI.transfer(writeByteArray[1]);
disableSpiSlaveSelectPin(SpiSsPinNum);
}

void FongSpi03::xferThreeByte(int8_t spiSlaveNum, byte writeByteArray[], byte readByteArray[])
{
// ARduino Due Only !!!
// int8_t slaveSelectPin = getSlaveSelectPin(spiSlaveNum);
// readByteArray[0] = SPI.transfer(slaveSelectPin, writeByteArray[0], SPI_CONTINUE);
// readByteArray[1] = SPI.transfer(slaveSelectPin, writeByteArray[1], SPI_CONTINUE);
// readByteArray[2] = SPI.transfer(slaveSelectPin, writeByteArray[2], SPI_LAST);

int8_t SpiSsPinNum = spiSlaveNumToSpiSsPinNumArray[spiSlaveNum];

enableSpiSlaveSelectPin(SpiSsPinNum);

readByteArray[0] = SPI.transfer(writeByteArray[0]);
readByteArray[1] = SPI.transfer(writeByteArray[1]);
readByteArray[2] = SPI.transfer(writeByteArray[2]);

disableSpiSlaveSelectPin(SpiSsPinNum);
}

void FongSpi03::xferThreeByte(int8_t spiSlaveNum, byte writeByte0, \
byte writeByte1, byte writeByte2, byte readByteArray[])
{
// Arduin Due Only !!!
// int8_t slaveSelectPin = getSlaveSelectPin(spiSlaveNum);
// readByteArray[0] = SPI.transfer(slaveSelectPin, writeByte0, SPI_CONTINUE);
// readByteArray[1] = SPI.transfer(slaveSelectPin, writeByte1, SPI_CONTINUE);
// readByteArray[2] = SPI.transfer(slaveSelectPin, writeByte2, SPI_LAST);

int8_t SpiSsPinNum = spiSlaveNumToSpiSsPinNumArray[spiSlaveNum];
enableSpiSlaveSelectPin(SpiSsPinNum);
readByteArray[0] = SPI.transfer(writeByte0);
readByteArray[1] = SPI.transfer(writeByte1);
readByteArray[2] = SPI.transfer(writeByte2);
disableSpiSlaveSelectPin(SpiSsPinNum);
}

void FongSpi03::xferThreeByte(int8_t spiSlaveNum, byte writeByte0, \
byte writeByte1, byte writeByte2)
{
byte dummyReadByte;

// ARduino Due Only !!!
// int8_t slaveSelectPin = getSlaveSelectPin(spiSlaveNum);
// dummyReadByte = SPI.transfer(slaveSelectPin, writeByte0, SPI_CONTINUE);
// dummyReadByte = SPI.transfer(slaveSelectPin, writeByte1, SPI_CONTINUE);
// dummyReadByte = SPI.transfer(slaveSelectPin, writeByte2, SPI_LAST);

int8_t slaveSelectPin = spiSlaveNumToSpiSsPinNumArray[spiSlaveNum];

int8_t SpiSsPinNum = spiSlaveNumToSpiSsPinNumArray[spiSlaveNum];
enableSpiSlaveSelectPin(SpiSsPinNum);
dummyReadByte = SPI.transfer(writeByte0);
dummyReadByte = SPI.transfer(writeByte1);
dummyReadByte = SPI.transfer(writeByte2);
disableSpiSlaveSelectPin(SpiSsPinNum);
}

byte FongSpi03::xferThreeByteX(int8_t spiSlaveNum, byte writeByte0, \
byte writeByte1, byte writeByte2)
{
byte readByte;

// Arduino Due Only!!
// int8_t slaveSelectPin = getSlaveSelectPin(spiSlaveNum);
// readByte = SPI.transfer(slaveSelectPin, writeByte0, SPI_CONTINUE);
// readByte = SPI.transfer(slaveSelectPin, writeByte1, SPI_CONTINUE);
// readByte = SPI.transfer(slaveSelectPin, writeByte2, SPI_LAST);

int8_t SpiSsPinNum = spiSlaveNumToSpiSsPinNumArray[spiSlaveNum];
enableSpiSlaveSelectPin(SpiSsPinNum);
readByte = SPI.transfer(writeByte0);
readByte = SPI.transfer(writeByte1);
readByte = SPI.transfer(writeByte2);
disableSpiSlaveSelectPin(SpiSsPinNum);

return readByte;
}

void FongSpi03::xferTwoByte(int8_t spiSlaveNum, byte writeByte0, byte writeByte1)
{
byte dummyReadByte;

// int8_t slaveSelectPin = spiSlaveNumToSpiSsPinNumArray[spiSlaveNum];

int8_t SpiSsPinNum = spiSlaveNumToSpiSsPinNumArray[spiSlaveNum];

enableSpiSlaveSelectPin(SpiSsPinNum);
dummyReadByte = SPI.transfer(writeByte0);
dummyReadByte = SPI.transfer(writeByte1);
disableSpiSlaveSelectPin(SpiSsPinNum);
}

void FongSpi03::spiTransferTwoByte(int8_t spiSlaveNum, byte writeByte0, byte writeByte1)
{
xferTwoByte(spiSlaveNum, writeByte0, writeByte1);
}

void FongSpi03::testOneByteLoopback(int8_t spiSlaveNum)
{
byte writeByte = 0x55;
byte readByte;

Serial.print(F(“Write byte = “));
Serial.println(writeByte, HEX);

readByte = xferOneByte(spiSlaveNum, writeByte);

Serial.print(F(“Read byte = “));
Serial.println(readByte, HEX);
}

// *** Print select menu ***

void FongSpi03::printSpiSelectMenu(int8_t firstSelectNum, int8_t lastSelectNum, int8_t initNum, int8_t testNum)
{
const char menu0[] PROGMEM = “0 = Change spi slave num.”;
const char menu1[] PROGMEM = “1 = Repeat send char.”;
const char menu2[] PROGMEM = “2 = Test Spi loopback.”;
const char menu3[] PROGMEM = “3 = Blink all Spi slave select pins.”;
const char menu4[] PROGMEM = “4 = Reserved.”;
const char menu5[] PROGMEM = “5 = Reserved.”;
const char menu6[] PROGMEM = “6 = Reserved.”;
const char menu7[] PROGMEM = “7 = Reserved.”;
const char menu8[] PROGMEM = “8 = Reserved.”;
const char menu9[] PROGMEM = “9 = Reserved.”;
const char menu10[] PROGMEM = “a = Reserved.”;
const char menu11[] PROGMEM = “m = Menu.”;
const char menu12[] PROGMEM = “h = Help.”;
const char menu13[] PROGMEM = “x = Exit.”;

const char * const selectMenu[] PROGMEM = \
{menu0, menu1, menu2, menu3, menu4, \
menu5, menu6, menu7, menu8, menu9, \
menu10, menu11, menu12, menu13};

Serial.println(F(“\n### Spi test selection ###”));
for (int8_t i = firstSelectNum; i <= lastSelectNum; i++)
{
Serial.println(selectMenu[i]);
}
}

// *** Execute selection function *********************************************

void FongSpi03::exeSpiSelectFunction(char selectChar, int8_t initNum, int8_t testNum)
{
byte writeByteArray[3];
byte readByteArray[3];
writeByteArray[1] = 0x00;
writeByteArray[2] = 0x00;
float adcResult;
int8_t spiSsPinNum;

if (selectChar == ‘0’)
{
spiSlaveNum = askspiSlaveNum(_initNum, _testNum);
selectChar = ‘m';
}
else if (selectChar == ‘1’)
{
// xferOneByte(spiSlaveNum, ‘x’, RepeatTenMillionTimes);
// xferOneByte(spiSlaveNum, 0x55, RepeatOneMillionTimes);
// xferOneByte(Slave1, ‘x’, Repeat1000000Times);
// xferOneByte(Slave2, ‘x’, Repeat1000000Times);
// xferOneByte(Slave3, ‘x’, Repeat1000000Times);

xferOneByte(spiSlaveNum, 0x55, RepeatTenThousandTimes);

selectChar = ‘m';
}
else if (selectChar == ‘2’)
{
testOneByteLoopback(spiSlaveNum);
selectChar = ‘m';
}

else if (selectChar == ‘3’)
{
for (int8_t i = FirstSpiSlaveNum; i <= LastSpiSlaveNum; i++)
{
spiSsPinNum = spiSlaveNumToSpiSsPinNumArray[spiSlaveNum];

enableSpiSlaveSelectPin(i);
delay(100);
disableSpiSlaveSelectPin(i);
delay(100);
enableSpiSlaveSelectPin(i);
delay(100);
disableSpiSlaveSelectPin(i);
delay(100);
enableSpiSlaveSelectPin(i);
}
selectChar = ‘m';
}

else if (selectChar == ‘m’)
{
Serial.print(F(“\n+++ Current slave number = “));
Serial.print(spiSlaveNum);
printSpiSelectMenu(initNum, testNum);
}
else if (selectChar == ‘h’)
{
Serial.print(“Sorry, no help available, …”);
}
else
{
Serial.print(“Sorry, no such option, …”);
}
// selectChar = ‘m';
}

// *** End ********************************************************************

.END

Leave a comment

Filed under Electronics DIY Project

FongDigiControl03 refactoring notes

// *** testFongDuino03v2015mar27hkt1032.ino ****
// ********************************************************************
// FongDuino03 tlfong01.com 201mar27
// ********************************************************************
#include “Arduino.h”
#include “HardwareSerial.h”
#include <SPI.h>
#include <FongDigiOut03.h>
#include <FongDigiControl03.h>
#include <FongHardSerial03.h>
#include <FongBlueToothBase03.h>
#include <FongSpi03.h>8
#include <FongAdc03.h>
#include <FongIox03.h>
#include <FongKeyPad03.h>
#include <FongSegmentLed03.h>

/*
#include <Wire.h>
#include <FongAnaIn02.h>
#include <FongEeprom02.h>
#include <FongI2c02.h>
#include <FongBlueToothConnect02.h>
#include <FongTest02.h>
*/

enum InitNum {InitNum0 = 0, InitNum1 = 1, InitNum2 = 2, InitNum3 = 3};
enum TestNum {TestNum0 = 0, TestNum1 = 1, TestNum2 = 2, TestNum3 = 3, \
TestNum4 = 4, TestNum5 = 5, TestNum6 = 6, TestNum7 = 7, \
TestNum8 = 8};

void setup()
{
Serial.begin(9600);
}

void loop()
{

// FongDigiOut03 fdo1(InitNum0, TestNum0); // 2015mar27 testing

FongDigiControl03 fdc1(InitNum0, TestNum1); // 2015mar06 OK

// FongHardSerial03 fhs1(InitNum0, TestNum3); // 2015mar16 OK
// FongBlueToothBase03 fbtb1(InitNum0, TestNum4); // 2015mar16 OK

// FongSpi03 fspi1(InitNum0, TestNum4); // 2015mar26 testing

// FongAdc03 fadc1(InitNum0, TestNum5); // 2015mar16 OK
// FongIox03 fiox1(InitNum0, TestNum6); // 2015mar16 OK
// FongKeyPad03 fkp1(InitNum0, TestNum7); // 2015mar16 OK

// FongSegmentLed03 fsl1(InitNum0, TestNum8); // 2015mar19 testing

// FongAnaIn02 fai1(InitNum0, TestNum0); // OK 2015jan22
// FongI2c02 fi2c1(InitNum0, TestNum7); // testing
// FongEeprom02 feep1(InitNum0, TestNum5); //To test later
// FongBlueToothConnect02 fbtc1(InitNum0, TestNum2); // To test later
// FongTest02 ft1(Init0, Test0); // To test later

while (true) { };
}

// *** End ***


Begin FongDigiControl03::testDigiControl(), … >>>>
+++ Current Psu Num = 0 +++
+++ Current Btm Num = 0 +++
+++ Current Spi Select Pin Num = 0 +++

DigiControl Test Select Menu

0 = FongDigiOut03::testDigiOut(). >>>>
1 = Change Psu num. >>>>
2 = Change Btm num. >>>>
3 = Change Spi Select Pin num. >>>>
4 = Switch Off PSU. >>>>
5 = Switch On PSU >>>>
6 = Enable BlueTooth AT command mode. >>>>
7 = Enable BlueTooth wireless command mode.. >>>>
8 = Enable Spi Select Pin. >>>>
9 = Disable Spi Select Pin. >>>>
a = Test all Psu, Btm, and Spi Slave Select pins. >>>>
m = Reserved. >>>>
h = Help. >>>>
x = Exit. >>>>

DigitalControl Test Select = ?

DigitalControl Test Select = a

Sorry, no help available, …

+++ Current Psu Num = 0 +++
+++ Current Btm Num = 0 +++
+++ Current Spi Select Pin Num = 0 +++

DigiControl Test Select Menu

0 = FongDigiOut03::testDigiOut(). >>>>
1 = Change Psu num. >>>>
2 = Change Btm num. >>>>
3 = Change Spi Select Pin num. >>>>
4 = Switch Off PSU. >>>>
5 = Switch On PSU >>>>
6 = Enable BlueTooth AT command mode. >>>>
7 = Enable BlueTooth wireless command mode.. >>>>
8 = Enable Spi Select Pin. >>>>
9 = Disable Spi Select Pin. >>>>
a = Test all Psu, Btm, and Spi Slave Select pins. >>>>
m = Reserved. >>>>
h = Help. >>>>
x = Exit. >>>>

DigitalControl Test Select = ?

DigitalControl Test Select = a

Sorry, no help available, …

+++ Current Psu Num = 0 +++
+++ Current Btm Num = 0 +++
+++ Current Spi Select Pin Num = 0 +++

DigiControl Test Select Menu

0 = FongDigiOut03::testDigiOut(). >>>>
1 = Change Psu num. >>>>
2 = Change Btm num. >>>>
3 = Change Spi Select Pin num. >>>>
4 = Switch Off PSU. >>>>
5 = Switch On PSU >>>>
6 = Enable BlueTooth AT command mode. >>>>
7 = Enable BlueTooth wireless command mode.. >>>>
8 = Enable Spi Select Pin. >>>>
9 = Disable Spi Select Pin. >>>>
a = Test all Psu, Btm, and Spi Slave Select pins. >>>>
m = Reserved. >>>>
h = Help. >>>>
x = Exit. >>>>

DigitalControl Test Select = ?


// *** FongDigiControl03.h ***

// ********************************************************************
// FongDigiControl03 tlfong01.com 2015feb21hkt1728
// ********************************************************************

#ifndef FongDigiControl03_h
#define FongDigiControl03_h

#include “Arduino.h”
#include <FongDigiOut03.h>

class FongDigiControl03 : public FongDigiOut03

{
public:

// *** Constructor ********************************************************

FongDigiControl03(int8_t initNum, int8_t testNum);

int8_t _initNum;
int8_t _testNum;

enum InitNum {InitNum0 = 0, InitNum1 = 1, InitNum2 = 2, InitNum3 = 3};
enum TestNum {TestNum0 = 0, TestNum1 = 1, TestNum2 = 2, TestNum3 = 3};

// *** Config enum ********************************************************

enum PsuDigiOutPinNum {DigiOutPinPsu0 = DigiOutPinNum0, DigiOutPinPsu1 = DigiOutPinNum1, \
DigiOutPinPsu2 = DigiOutPinNum2};

enum BtmDigiOutPinNum {DigiOutPinBtm0 = DigiOutPinNum3, DigiOutPinBtm1 = DigiOutPinNum4, \
DigiOutPinBtm2 = DigiOutPinNum5};

// *** DigitOutPinNum6, 7 reserved ***

enum SpiDigiOutPinNum {
DigiOutPinSpiSs0 = DigiOutPinNum8, DigiOutPinSpiSs1 = DigiOutPinNum9, \
DigiOutPinSpiSs2 = DigiOutPinNum10, DigiOutPinSpiSs3 = DigiOutPinNum11, \
DigiOutPinSpiSs4 = DigiOutPinNum12, DigiOutPinSpiSs5 = DigiOutPinNum13, \
DigiOutPinSpiSs6 = DigiOutPinNum14, DigiOutPinSpiSs7 = DigiOutPinNum15, \
DigiOutPinSpiSs8 = DigiOutPinNum16, DigiOutPinSpiSs9 = DigiOutPinNum17, \
DigiOutPinSpiSs10 = DigiOutPinNum18, DigiOutPinSpiSs11 = DigiOutPinNum19, \
DigiOutPinSpiSs12 = DigiOutPinNum20, DigiOutPinSpiSs13 = DigiOutPinNum21, \
DigiOutPinSpiSs14 = DigiOutPinNum22, DigiOutPinSpiSs15 = DigiOutPinNum23, \
DigiOutPinSpiSs16 = DigiOutPinNum24, DigiOutPinSpiSs17 = DigiOutPinNum25, \
DigiOutPinSpiSs18 = DigiOutPinNum26, DigiOutPinSpiSs19 = DigiOutPinNum27, \
DigiOutPinSpiSs20 = DigiOutPinNum28};

enum PsuNum {PsuNum0 = 0, PsuNum1 = 1, PsuNum2 = 2,
FirstPsuNum = 0, LastPsuNum = 2, TotalPsuNum = 3};

enum BtmNum {BtmNum0 = 0, BtmNum1 = 1, BtmNum2 = 2, \
FirstBtmNum = 0, LastBtmNum = 2, TotalBtmNum = 3};

enum SpiSsNum {
SpiSsPinNum0 = 0, SpiSsPinNum1 = 1, SpiSsPinNum2 = 2, SpiSsPinNum3 = 3, \
SpiSsPinNum4 = 4, SpiSsPinNum5 = 5, SpiSsPinNum6 = 6, SpiSsPinNum7 = 7, \
SpiSsPinNum8 = 8, SpiSsPinNum9 = 9, SpiSsPinNum10 = 10, SpiSsPinNum11, \
SpiSsPinNum12 = 12, SpiSsPinNum13 = 13, SpiSsPinNum14 = 14, SpiSsPinNum15 = 15, \
SpiSsPinNum16 = 16, SpiSsPinNum17 = 17, SpiSsPinNum18 = 18, SpiSsPinNum19 = 19,
SpiSsPinNum20 = 20, \
FirstSpiSsPinNum = 0, LastSpiSsPinNum = 20, TotalSpiSsPinNum = 21};

// *** Univerasl enum *****************************************************

enum PauseTime {MilliSec10 = 10, MilliSec100 = 100, MilliSec500 = 500, MilliSec1000 = 1000, \
MilliSec2000 = 2000, MilliSec4000 = 4000};

// *** Init and Test functions *****************************************************

void initDigiControl();
void testDigiControl();

// *** Menu functions *****************************************************

enum MenuNum {FirstSelectNum = 0, LastSelectNum = 13, TotalSelectNum = 14};
void printDigiControlSelectMenu(int8_t firstSelectNum, int8_t lastSelectNum);
void printDigiControlSelectMenu();

char selectChar;
char askDigiControlSelectChar(String askString);

void exeDigiControlSelectFunction();

// *** Blink LED and buzzer functions *************************************

void blinkLed(unsigned long highTime, unsigned long lowTime, unsigned long repeatCount);
void blinkLed();
void beep();

// *** PSU (Power Supply Unit) functions **********************************

int8_t psuNum;
int8_t askPsuNum();
int8_t psuNumToDigiOutPinNumArray[TotalPsuNum];

void switchOnPsu(int8_t psuNum);
void switchOffPsu(int8_t psuNum);
void resetPsu(int8_t psuNum);
void testPsu(int8_t psuNum);

// *** BTM (BlueTooth Module) functions **********************************

int8_t btmNum;
int8_t askBtmNum();
int8_t btmNumToDigiOutPinNumArray[TotalPsuNum];
void enableBlueToothDeviceAtCommandMode(int8_t btmNum);
void enableBlueToothDeviceWirelessCommunicationMode(int8_t btmNum);

// *** SPI ***

int8_t spiSsPinNum;
int8_t askSpiSsPinNum();
int8_t spiSsPinNumToDigiOutPinNumArray[TotalSpiSsPinNum];
void enableSpiSlaveSelectPin(int8_t spiSsPinNum);
void disableSpiSlaveSelectPin(int8_t spiSsPinNum);

// *** Test functions ***
void testAllPsuPins();
void testAllBtmPins();
void testAllSpiSlaveSelectPins();

private:
};

#endif

// *** End ***


// *** FongDigiControl03.cpp ***

// ********************************************************************
// FongDigiControl03 tlfong01.com 2015mar29hkt1359
// ********************************************************************

#include “Arduino.h”
#include <FongDigiControl03.h>

// *** Constructor ***

FongDigiControl03::FongDigiControl03(int8_t initNum, int8_t testNum) : FongDigiOut03(initNum, testNum)

{
_initNum = initNum;
_testNum = testNum;

// Serial.println(F(“Begin FongDigiControl03::FongDigiControl03(), … >>>>>>>>>”));

if (initNum <= 0)
initDigiControl();

if (testNum <= TestNum1)
{
blinkLed();
testDigiControl();
}

// Serial.println(F(“End FongDigiControl03::FongDigiControl03(), … >>>>>>>>>”));
}

// *** Menu and Select test functions *****************************************

// *** Init and Test function ***

void FongDigiControl03::initDigiControl()
{
psuNum = 0;
btmNum = 0;
spiSsPinNum = 0;

psuNumToDigiOutPinNumArray[PsuNum0] = DigiOutPinPsu0;
psuNumToDigiOutPinNumArray[PsuNum1] = DigiOutPinPsu1;
psuNumToDigiOutPinNumArray[PsuNum2] = DigiOutPinPsu2;

btmNumToDigiOutPinNumArray[BtmNum0] = DigiOutPinBtm0;
btmNumToDigiOutPinNumArray[BtmNum1] = DigiOutPinBtm1;
btmNumToDigiOutPinNumArray[BtmNum2] = DigiOutPinBtm2;

spiSsPinNumToDigiOutPinNumArray[SpiSsPinNum0] = DigiOutPinSpiSs0;
spiSsPinNumToDigiOutPinNumArray[SpiSsPinNum1] = DigiOutPinSpiSs1;
spiSsPinNumToDigiOutPinNumArray[SpiSsPinNum2] = DigiOutPinSpiSs2;
spiSsPinNumToDigiOutPinNumArray[SpiSsPinNum3] = DigiOutPinSpiSs3;
spiSsPinNumToDigiOutPinNumArray[SpiSsPinNum4] = DigiOutPinSpiSs4;
spiSsPinNumToDigiOutPinNumArray[SpiSsPinNum5] = DigiOutPinSpiSs5;
spiSsPinNumToDigiOutPinNumArray[SpiSsPinNum6] = DigiOutPinSpiSs6;
spiSsPinNumToDigiOutPinNumArray[SpiSsPinNum7] = DigiOutPinSpiSs7;
spiSsPinNumToDigiOutPinNumArray[SpiSsPinNum8] = DigiOutPinSpiSs8;
spiSsPinNumToDigiOutPinNumArray[SpiSsPinNum9] = DigiOutPinSpiSs9;
spiSsPinNumToDigiOutPinNumArray[SpiSsPinNum10] = DigiOutPinSpiSs10;
spiSsPinNumToDigiOutPinNumArray[SpiSsPinNum11] = DigiOutPinSpiSs11;
spiSsPinNumToDigiOutPinNumArray[SpiSsPinNum12] = DigiOutPinSpiSs12;
spiSsPinNumToDigiOutPinNumArray[SpiSsPinNum13] = DigiOutPinSpiSs13;
spiSsPinNumToDigiOutPinNumArray[SpiSsPinNum14] = DigiOutPinSpiSs14;
spiSsPinNumToDigiOutPinNumArray[SpiSsPinNum15] = DigiOutPinSpiSs15;
spiSsPinNumToDigiOutPinNumArray[SpiSsPinNum16] = DigiOutPinSpiSs16;
spiSsPinNumToDigiOutPinNumArray[SpiSsPinNum17] = DigiOutPinSpiSs17;
spiSsPinNumToDigiOutPinNumArray[SpiSsPinNum18] = DigiOutPinSpiSs18;
spiSsPinNumToDigiOutPinNumArray[SpiSsPinNum19] = DigiOutPinSpiSs19;
spiSsPinNumToDigiOutPinNumArray[SpiSsPinNum20] = DigiOutPinSpiSs20;

// testAllPsuPins();
// testAllBtmPins();
// testAllSpiSlaveSelectPins();
}

void FongDigiControl03::testDigiControl()
{
Serial.println(F(“\nBegin FongDigiControl03::testDigiControl(), … >>>>”));

Serial.print(F(“+++ Current Psu Num = “));
Serial.print(psuNum);
Serial.println(F(” +++”));

Serial.print(F(“+++ Current Btm Num = “));
Serial.print(btmNum);
Serial.println(F(” +++”));

Serial.print(F(“+++ Current Spi Select Pin Num = “));
Serial.print(spiSsPinNum);
Serial.println(F(” +++”));;

printDigiControlSelectMenu();

selectChar = askDigiControlSelectChar(“DigitalControl Test Select”);

while (selectChar != ‘x’)
{
exeDigiControlSelectFunction();

Serial.print(F(“+++ Current Psu Num = “));
Serial.print(psuNum);
Serial.println(F(” +++”));

Serial.print(F(“+++ Current Btm Num = “));
Serial.print(btmNum);
Serial.println(F(” +++”));

Serial.print(F(“+++ Current Spi Select Pin Num = “));
Serial.print(spiSsPinNum);
Serial.println(F(” +++”));;

printDigiControlSelectMenu();

selectChar = askDigiControlSelectChar(“DigitalControl Test Select”);
}

Serial.println(F(“\nEnd FongDigiControl03::testDigiControl(), … >>>>”));
}

// *** print select menu, execute selection ***

void FongDigiControl03::printDigiControlSelectMenu()
{
printDigiControlSelectMenu(FirstSelectNum, LastSelectNum);
}

char FongDigiControl03::askDigiControlSelectChar(String askString)
{
char selectChar;
char dummyChar;

// *** flush read buffer ***
while (Serial.available() > 0) {dummyChar = Serial.read();} // flush

// *** get user selection ***
Serial.print(F(“\n### “));
Serial.print(askString);
Serial.println(F(” = ? ### “));

while (Serial.available() == false) {} // wait for char
selectChar = Serial.read();
Serial.print(F(“### “));
Serial.print(askString);
Serial.print(F(” = “));
Serial.print(selectChar);
Serial.println(F(” ###\n”));
return selectChar;
}

int8_t FongDigiControl03::askPsuNum()
{
char dummyReadChar;
char psuNumChar;
int psuNum;

Serial.print(F(“\n*** Select PSU num, …”));
Serial.print(F(“\n 0 = PSU 0″));
Serial.print(F(“\n 1 = PSU 1″));
Serial.print(F(“\n 2 = PSU 2″));

// *** flush read buffer ***
while (Serial.available() > 0) {dummyReadChar = Serial.read();} // flush
Serial.print(F(“\nEnter PSU Num, … \n”));
while (Serial.available() == false) { };
psuNumChar = Serial.read();
psuNum = psuNumChar – ‘0’;
return psuNum;
}

int8_t FongDigiControl03::askBtmNum()
{
char dummyReadChar;
char btmNumChar;
int btmNum;

Serial.print(F(“\n*** Select BlueTooth Device num, …”));
Serial.print(F(“\n 0 = Btm 0″));
Serial.print(F(“\n 1 = Btm 1″));
Serial.print(F(“\n 2 = Btm 2″));

// *** flush read buffer ***
while (Serial.available() > 0) {dummyReadChar = Serial.read();} // flush
Serial.print(F(“\nEnter BlueTooth Device Num, … \n”));
while (Serial.available() == false) { };
btmNumChar = Serial.read();
btmNum = btmNumChar – ‘0’;
return btmNum;
}

int8_t FongDigiControl03::askSpiSsPinNum()
{
char dummyReadChar;
char spiSsPinNumChar;
int spiSelectPinNum;

Serial.print(F(“\n*** Select SPI Select pin num, …”));
Serial.print(F(“\n 0 = SpiSsPin 0″));
Serial.print(F(“\n 1 = SpiSsPin 1″));
Serial.print(F(“\n 2 = SpiSsPin 2″));
Serial.print(F(“\n 3 = SpiSsPin 3″));
Serial.print(F(“\n 4 = SpiSsPin 4″));
Serial.print(F(“\n 5 = SpiSsPin 5″));
Serial.print(F(“\n 6 = SpiSsPin 6″));
Serial.print(F(“\n 7 = SpiSsPin 7″));
Serial.print(F(“\n 8 = SpiSsPin 8″));
Serial.print(F(“\n 9 = SpiSsPin 9″));
Serial.print(F(“\n a = SpiSsPin 10″));
Serial.print(F(“\n b = SpiSsPin 11″));
Serial.print(F(“\n c = SpiSsPin 12″));
Serial.print(F(“\n d = SpiSsPin 13″));
Serial.print(F(“\n e = SpiSsPin 14″));
Serial.print(F(“\n f = SpiSsPin 15″));
Serial.print(F(“\n g = SpiSsPin 16″));
Serial.print(F(“\n h = SpiSsPin 17″));
Serial.print(F(“\n i = SpiSsPin 18″));
Serial.print(F(“\n j = SpiSsPin 19″));
Serial.print(F(“\n k = SpiSsPin 20″));

// *** flush read buffer ***
while (Serial.available() > 0) {dummyReadChar = Serial.read();} // flush
Serial.print(F(“\nEnter SPI Select pin num, … \n”));
while (Serial.available() == false) { };

spiSsPinNumChar = Serial.read();

if ((spiSsPinNumChar == ‘0’) || (spiSsPinNumChar <= ‘9’))
spiSelectPinNum = spiSsPinNumChar – ‘0’;
else if ((spiSsPinNumChar == ‘a’) || (spiSsPinNumChar <= ‘z’))
spiSelectPinNum = (spiSsPinNumChar – ‘a’) + 10;
else
spiSelectPinNum = 0;
return spiSelectPinNum;
}

// *** Psu functions ********************************************************

void FongDigiControl03::switchOnPsu(int8_t psuNum)
{
int8_t digiOutPinNum = psuNumToDigiOutPinNumArray[psuNum];
// Serial.print(F(“digiOutPinNum = “));
// Serial.print(digiOutPinNum);
setDigiOutPinLow(digiOutPinNum);
delay(MilliSec100);
}

void FongDigiControl03::switchOffPsu(int8_t psuNum)
{
int8_t digiOutPinNum = psuNumToDigiOutPinNumArray[psuNum];
// Serial.print(F(“digiOutPinNum = “));
// Serial.print(digiOutPinNum);
setDigiOutPinHigh(digiOutPinNum);
delay(MilliSec100);
}

void FongDigiControl03::resetPsu(int8_t psuNum)
{
switchOffPsu(psuNum);
delay(MilliSec500);
switchOnPsu(psuNum);
delay(MilliSec500);

switchOffPsu(psuNum);
delay(MilliSec500);
switchOnPsu(psuNum);
delay(MilliSec500);
}

void FongDigiControl03::testPsu(int8_t psuNum)
{
//Serial.print(F(“Power off, … “));
switchOffPsu(psuNum);
delay(MilliSec200);
//Serial.print(F(“Power on, … “));
switchOnPsu(psuNum);
delay(MilliSec200);
// Serial.print(F(“Power off, … “));
switchOffPsu(psuNum);
delay(MilliSec200);
}

// *** BlueTooth Functions ****************************************************

void FongDigiControl03::enableBlueToothDeviceAtCommandMode(int8_t btmNum)
{
int8_t digiOutPinNum = btmNumToDigiOutPinNumArray[btmNum];
setDigiOutPinHigh(digiOutPinNum);
delay(MilliSec100);
}

void FongDigiControl03::enableBlueToothDeviceWirelessCommunicationMode(int8_t btmNum)
{
int8_t digiOutPinNum = btmNumToDigiOutPinNumArray[btmNum];
setDigiOutPinLow(digiOutPinNum);
delay(MilliSec100);
}

// *** SPI Select Pin Functions ****************************************************

void FongDigiControl03::enableSpiSlaveSelectPin(int8_t spiSsPinNum)
{
int8_t digiOutPinNum = spiSsPinNumToDigiOutPinNumArray[spiSsPinNum];
setDigiOutPinLow(digiOutPinNum);
// delay(MilliSec100);
}

void FongDigiControl03::disableSpiSlaveSelectPin(int8_t spiSsPinNum)
{
int8_t digiOutPinNum = spiSsPinNumToDigiOutPinNumArray[spiSsPinNum];
setDigiOutPinHigh(digiOutPinNum);
// delay(MilliSec100);
}

// *** Blink LED **************************************************************

void FongDigiControl03::blinkLed(unsigned long highTime, unsigned long lowTime, unsigned long repeatCount)
{
repeatPulseDigiOutPinSingle(DigiOutPinNumLed, highTime, lowTime, repeatCount);
}

void FongDigiControl03::blinkLed()
{
repeatPulseDigiOutPinSingle(DigiOutPinNumLed, MilliSec125, MilliSec250, Twice);
}

void FongDigiControl03::beep()
{
blinkLed();
}

// *** Print select menu ******************************************************
void FongDigiControl03::printDigiControlSelectMenu(int8_t firstSelectNum, int8_t lastSelectNum)
{
String selectMenuTitle = “DigiControl Test Select Menu”;

const char menu0[] PROGMEM = “0 = FongDigiOut03::testDigiOut(). >>>>”;
const char menu1[] PROGMEM = “1 = Change Psu num. >>>>”;
const char menu2[] PROGMEM = “2 = Change Btm num. >>>>”;
const char menu3[] PROGMEM = “3 = Change Spi Select Pin num. >>>>”;
const char menu4[] PROGMEM = “4 = Switch Off PSU. >>>>”;
const char menu5[] PROGMEM = “5 = Switch On PSU >>>>”;
const char menu6[] PROGMEM = “6 = Enable BlueTooth AT command mode. >>>>”;
const char menu7[] PROGMEM = “7 = Enable BlueTooth wireless command mode.. >>>>”;
const char menu8[] PROGMEM = “8 = Enable Spi Select Pin. >>>>”;
const char menu9[] PROGMEM = “9 = Disable Spi Select Pin. >>>>”;
const char menu10[] PROGMEM = “a = Test all Psu, Btm, and Spi Slave Select pins. >>>>”;
const char menu11[] PROGMEM = “m = Reserved. >>>>”;
const char menu12[] PROGMEM = “h = Help. >>>>”;
const char menu13[] PROGMEM = “x = Exit. >>>>”;

const char * const selectMenu[] PROGMEM = {
menu0, menu1, menu2, menu3, menu4, \
menu5, menu6, menu7, menu8, menu9, \
menu10, menu11, menu12, menu13};

Serial.print(F(“\n### “));
Serial.print(selectMenuTitle);
Serial.println(F(” ###\n”));

for (int8_t i = firstSelectNum; i <= lastSelectNum; i++)
{
Serial.println(selectMenu[i]);
}
}

// *** Execute selection function *********************************************
void FongDigiControl03::exeDigiControlSelectFunction()
{
switch (selectChar)
{
case ‘0’:
testDigiOut();
break;
case ‘1’:
psuNum = askPsuNum();
Serial.print(F(“PSU number = “));
Serial.println(psuNum);
break;
case ‘2’:
btmNum = askBtmNum();
Serial.print(F(“Btm number = “));
Serial.println(btmNum);
break;
case ‘3’:
spiSsPinNum = askSpiSsPinNum();
Serial.print(F(“Spi number = “));
Serial.println(spiSsPinNum);
break;
case ‘4’:
switchOffPsu(psuNum);
break;
case ‘5’:
switchOnPsu(psuNum);
break;
case ‘6’:
enableBlueToothDeviceAtCommandMode(btmNum);
break;
case ‘7’:
enableBlueToothDeviceWirelessCommunicationMode(btmNum);
break;
case ‘8’:
enableSpiSlaveSelectPin(spiSsPinNum);
break;
case ‘9’:
disableSpiSlaveSelectPin(spiSsPinNum);
break;
case ‘a':
testAllPsuPins();
testAllBtmPins();
testAllSpiSlaveSelectPins();
// case ‘m':
// printDigiControlSelectMenu();
// break;
case ‘h':
Serial.println(“Sorry, no help available, …\n”);
break;
default:
Serial.print(“\n+++ Sorry, no such option … “);
Serial.println(F(” +++\n”));

break;
}
}

void FongDigiControl03::testAllPsuPins()
{
for (int8_t i = FirstPsuNum; i <= LastPsuNum; i++)
{
switchOffPsu(i);
// delay(100);
switchOnPsu(i);
// delay(100);
switchOffPsu(i);
// delay(100);
switchOnPsu(i);
// delay(100);
switchOffPsu(i);
}
}

void FongDigiControl03::testAllBtmPins()
{
for (int8_t i = FirstBtmNum; i <= LastBtmNum; i++)
{
enableBlueToothDeviceAtCommandMode(i);
// delay(100);
enableBlueToothDeviceWirelessCommunicationMode(i);
// delay(100);
enableBlueToothDeviceAtCommandMode(i);
// delay(100);
enableBlueToothDeviceWirelessCommunicationMode(i);
// delay(100);
enableBlueToothDeviceAtCommandMode(i);
}
}

void FongDigiControl03::testAllSpiSlaveSelectPins()
{
for (int8_t i = FirstSpiSsPinNum; i <= LastSpiSsPinNum; i++)
{
enableSpiSlaveSelectPin(i);
delay(100);
disableSpiSlaveSelectPin(i);
delay(100);
enableSpiSlaveSelectPin(i);
delay(100);
disableSpiSlaveSelectPin(i);
delay(100);
enableSpiSlaveSelectPin(i);
}
}

// *** End ***

.END

Leave a comment

Filed under Electronics DIY Project

FongDigiOut03 refactoring notes

+++ Current DigiOut pin num = 0
+++ Current arduino pin num = 22
+++ DigiOut Test Selection Menu
0 = Select digiOutPin.
1 = Blink system LED (DigiOutPin29 = Arduino Mega Pin13).
2 = Blink digitOutpin.
3 = Blink DigiOut pin 0~7 (Arduino Pin22~29, PSU0~2, BTM0~2, NCx2.
4 = Blink DigiOut pin 8~12 (Arduino Pin53, 46~49, SPI SS 0~5).
5 = Blink DigiOut pin 13~18 (Arduino Pin40~45, SPI SS 6~10).
6 = Blink DigiOut pin 19~28 (Arduino Pin30~39, SPI SS 12~19).
7 = Set digiOutPin High.
8 = Set digiOutPin Low.
9 = Reserved.
a = Reserved.
m = Menu.
h = Help.
x = Exit.
+++ Test Selection Number = ? (‘m’ for menu)
+++ Test Selection Number = 1

+++ Current DigiOut pin num = 0
+++ Current Arduino pin num = 22
+++ Test Selection Number = ? (‘m’ for menu)
+++ Test Selection Number = 3

+++ Current DigiOut pin num = 0
+++ Current Arduino pin num = 22
+++ Test Selection Number = ? (‘m’ for menu)
+++ Test Selection Number = 4

+++ Current DigiOut pin num = 0
+++ Current Arduino pin num = 22
+++ Test Selection Number = ? (‘m’ for menu)
+++ Test Selection Number = 5

+++ Current DigiOut pin num = 0
+++ Current Arduino pin num = 22
+++ Test Selection Number = ? (‘m’ for menu)
+++ Test Selection Number = 6

+++ Current DigiOut pin num = 0
+++ Current Arduino pin num = 22
+++ Test Selection Number = ? (‘m’ for menu)


// *** testFongDuino03v2015mar27hkt1032.ino ****
// ********************************************************************
// FongDuino03 tlfong01.com 201mar27
// ********************************************************************
#include “Arduino.h”
#include “HardwareSerial.h”
#include <SPI.h>
#include <FongDigiOut03.h>
#include <FongDigiControl03.h>
#include <FongHardSerial03.h>
#include <FongBlueToothBase03.h>
#include <FongSpi03.h>8
#include <FongAdc03.h>
#include <FongIox03.h>
#include <FongKeyPad03.h>
#include <FongSegmentLed03.h>

/*
#include <Wire.h>
#include <FongAnaIn02.h>
#include <FongEeprom02.h>
#include <FongI2c02.h>
#include <FongBlueToothConnect02.h>
#include <FongTest02.h>
*/

enum InitNum {InitNum0 = 0, InitNum1 = 1, InitNum2 = 2, InitNum3 = 3};
enum TestNum {TestNum0 = 0, TestNum1 = 1, TestNum2 = 2, TestNum3 = 3, \
TestNum4 = 4, TestNum5 = 5, TestNum6 = 6, TestNum7 = 7, \
TestNum8 = 8};

void setup()
{
Serial.begin(9600);
}

void loop()
{

FongDigiOut03 fdo1(InitNum0, TestNum0); // 2015mar27 testing

// FongDigiControl03 fdc1(InitNum0, TestNum1); // 2015mar06 OK
// FongHardSerial03 fhs1(InitNum0, TestNum3); // 2015mar16 OK
// FongBlueToothBase03 fbtb1(InitNum0, TestNum4); // 2015mar16 OK

// FongSpi03 fspi1(InitNum0, TestNum4); // 2015mar26 testing

// FongAdc03 fadc1(InitNum0, TestNum5); // 2015mar16 OK
// FongIox03 fiox1(InitNum0, TestNum6); // 2015mar16 OK
// FongKeyPad03 fkp1(InitNum0, TestNum7); // 2015mar16 OK

FongSegmentLed03 fsl1(InitNum0, TestNum8); // 2015mar19 testing

// FongAnaIn02 fai1(InitNum0, TestNum0); // OK 2015jan22
// FongI2c02 fi2c1(InitNum0, TestNum7); // testing
// FongEeprom02 feep1(InitNum0, TestNum5); //To test later
// FongBlueToothConnect02 fbtc1(InitNum0, TestNum2); // To test later
// FongTest02 ft1(Init0, Test0); // To test later

while (true) { };
}

// *** End ***

// *** FongDigiOut03.h ***

// ********************************************************************
// FongDigiOut03 tlfong01.com 2015mar27hkt1005
// ********************************************************************

#ifndef FongDigiOut03_h
#define FongDigiOut03_h

#include “Arduino.h”

class FongDigiOut03
{
public:

// *** Constructor ********************************************************

FongDigiOut03(int8_t initNum, int8_t testNum);

int8_t _initNum;
int8_t _testNum;

// *** Configuration constants and data structure**************************

// *** DigiOut configuration ***

// DigiOut pin 0~7 ( 8 pins) = Arduino pin 22~29 (PSU x 3, BTM x 3, NC x2)
// DigiOut pin 8~12 ( 5 pins) = Arduino pin 53, 46~49 (SPI SS 0 ~ 4)
// DigiOut pin 13~18 ( 6 pins) = Arduino pin 40~45 (SPI SS 5 ~ 10)
// DigiOut pin 19~28 (10 pins) = Arduino pin 30~39 (SPI SS 11 ~ 20) !!! pin 23, 24 defective!!!
// DigiOut pin 29 = Arduino pin 13 (System Led)
// Total = 8 + 5 + 6 + 10 + 1 = 30 pins

enum ArduinoPinNum { \
ArduinoDigiOutPinNum0 = 22, \
ArduinoDigiOutPinNum1 = 23, \
ArduinoDigiOutPinNum2 = 24, \
ArduinoDigiOutPinNum3 = 25, \
ArduinoDigiOutPinNum4 = 26, \
ArduinoDigiOutPinNum5 = 27, \
ArduinoDigiOutPinNum6 = 28, \
ArduinoDigiOutPinNum7 = 29, \

ArduinoDigiOutPinNum8 = 53, \
ArduinoDigiOutPinNum9 = 46, \
ArduinoDigiOutPinNum10 = 47, \
ArduinoDigiOutPinNum11 = 48, \
ArduinoDigiOutPinNum12 = 49, \

ArduinoDigiOutPinNum13 = 40, \
ArduinoDigiOutPinNum14 = 41, \
ArduinoDigiOutPinNum15 = 42, \
ArduinoDigiOutPinNum16 = 43, \
ArduinoDigiOutPinNum17 = 44, \
ArduinoDigiOutPinNum18 = 45, \

ArduinoDigiOutPinNum19 = 30, \
ArduinoDigiOutPinNum20 = 31, \
ArduinoDigiOutPinNum21 = 32, \
ArduinoDigiOutPinNum22 = 33, \
ArduinoDigiOutPinNum23 = 34, \
ArduinoDigiOutPinNum24 = 35, \
ArduinoDigiOutPinNum25 = 36, \
ArduinoDigiOutPinNum26 = 37, \
ArduinoDigiOutPinNum27 = 38, \
ArduinoDigiOutPinNum28 = 39, \

ArduinoDigiOutPinNum29 = 13}; // <<< This last pin is system LED pin!!!

// *** digiOutPinNum and digiOutPinNumArray constants ***

enum ArrayDigiOutPinNum {FirstDigiOutPinNum = 0, LastDigiOutPinNum = 29, TotalDigiOutPinNum = 30};

enum GeneralDigiOutPinNum { \
DigiOutPinNum0 = 0, DigiOutPinNum1 = 1, DigiOutPinNum2 = 2, DigiOutPinNum3 = 3, \
DigiOutPinNum4 = 4, DigiOutPinNum5 = 5, DigiOutPinNum6 = 6, DigiOutPinNum7 = 7, \
DigiOutPinNum8 = 8, DigiOutPinNum9 = 9, DigiOutPinNum10 = 10, DigiOutPinNum11 = 11, \
DigiOutPinNum12 = 12, DigiOutPinNum13 = 13, DigiOutPinNum14 = 14, DigiOutPinNum15 = 15, \
DigiOutPinNum16 = 16, DigiOutPinNum17 = 17, DigiOutPinNum18 = 18, DigiOutPinNum19 = 19, \
DigiOutPinNum20 = 20, DigiOutPinNum21 = 21, DigiOutPinNum22 = 22, DigiOutPinNum23 = 23, \
DigiOutPinNum24 = 24, DigiOutPinNum25 = 25, DigiOutPinNum26 = 26, DigiOutPinNum27 = 27, \
DigiOutPinNum28 = 28, DigiOutPinNum29 = 29};

enum DefaultDigiOutPinNum {DefaultDigiOutPinNum = 0};

enum SystemLedPin {DigiOutPinNumLed = DigiOutPinNum29};

// *** digiOutPinNum to map to ArduinoPinNum ***

int8_t _digiOutPinNum;
int8_t _arduinoDigiOutPinNum;

// *** digitOutPinNumArray maps digitOutPinNum to ArduinoPinNum ***

int _digiOutPinNumArray[TotalDigiOutPinNum];

// *** Test constants ***

enum InitTestNum {InitNum0 = 0, InitNum1 = 1, TestNum0 = 0, TestNum1 = 1, TestNum2 = 2};

// *** General constants ***

enum MilliSec {MilliSec20 = 20, MilliSec50 = 50, MilliSec100 = 100, MilliSec125 = 125, MilliSec200 = 200, \
MilliSec250 = 250, MilliSec400 = 400, MilliSec500 = 500, MilliSec600 = 600, \
MilliSec1000 = 1000, MilliSec2000 = 2000, MilliSec4000 = 4000};

enum RepeatCount {Once = 1, Twice = 2, FourTimes = 4, TenTimes = 10, \
OneHundredTimes = 100, OneThousandTimes = 1000};

// *** Functions **********************************************************

// *** Init functions ***

void initDigiOut();

// *** Setup DigiOutPin ***

void setupArduinoDigiOutPinSingle(int8_t arduinoDigiOutPinNum);
void setupDigiOutPinSingle(int8_t DigiOutPinNum);
void setupDigiOutPinRange(int8_t firstDigiOutPinNum, int8_t lastDigiOutPinNum);
void setupDigiOutPinAll();

// *** Set DigiOutPin high or low ***

void setDigiOutPinHigh(int8_t digiOutPinNum);
void setDigiOutPinLow(int8_t digiOutPinNum);

// *** Pulse DigiOutPin ***

void pulseDigiOutPinSingle(int8_t digiOutPinNum, int highTime, int lowTime);

void repeatPulseDigiOutPinSingle(int8_t digiOutPinNum, int highTime, int lowTime, \
unsigned long count);

void repeatPulseDigiOutPinRange(int8_t firstDigiOutPinNum, \
int8_t lastDigiOutPinNum, \
int highTime, int lowTime, unsigned long count);

void repeatPulseDigiOutPinAll(int highTime, int lowTime, unsigned long count);

// *** Test functions *****************************************************

void testDigiOut();

// *** Menu functions *****************************************************

enum MenuNum {FirstSelectNum = 0, LastSelectNum = 13, TotalSelectNum = 14};

void printDigiOutSelectMenu(String menuTitle, int8_t firstSelectNum, int8_t lastSelectNum);

char askMenuSelectChar(String askString);
int askDigiOutPinNum();

// *** Execute test functions ***

void exeDigiOutSelectFunction(char selectChar);

// *** Private ***

private:
};

#endif

// *** End ***


// *** FongDigiOut03.cpp ***

// ********************************************************************
// FongDigiOut03 tlfong01.com 2014mar29hkt1248
// ********************************************************************

#include “Arduino.h”
#include “FongDigiOut03.h”

// *** Constructor ************************************************************

FongDigiOut03::FongDigiOut03(int8_t initNum, int8_t testNum)
{
// Serial.println(F(“\nBegin FongDigiOut03::FongDigiOut03(), … >>>>>>>>>”));

if (initNum <= 0)
initDigiOut();

if (testNum <= 0)
{
repeatPulseDigiOutPinSingle(DigiOutPinNumLed, MilliSec50, MilliSec200, FourTimes); // blink LED
testDigiOut();
}

// Serial.println(F(“End FongDigiOut03::FongDigiOut03(), … >>>>>>>>>”));
}

// *** Functions **************************************************************

// *** Init and setup functions ***********************************************

void FongDigiOut03::initDigiOut()
{
// Serial.println(F(“\nBegin FongDigiOut03::initDigiOut(), … >>>>>>>>>”));

_digiOutPinNumArray[0] = ArduinoDigiOutPinNum0;
_digiOutPinNumArray[1] = ArduinoDigiOutPinNum1;
_digiOutPinNumArray[2] = ArduinoDigiOutPinNum2;
_digiOutPinNumArray[3] = ArduinoDigiOutPinNum3;
_digiOutPinNumArray[4] = ArduinoDigiOutPinNum4;
_digiOutPinNumArray[5] = ArduinoDigiOutPinNum5;
_digiOutPinNumArray[6] = ArduinoDigiOutPinNum6;
_digiOutPinNumArray[7] = ArduinoDigiOutPinNum7;
_digiOutPinNumArray[8] = ArduinoDigiOutPinNum8;
_digiOutPinNumArray[9] = ArduinoDigiOutPinNum9;
_digiOutPinNumArray[10] = ArduinoDigiOutPinNum10;
_digiOutPinNumArray[11] = ArduinoDigiOutPinNum11;
_digiOutPinNumArray[12] = ArduinoDigiOutPinNum12;
_digiOutPinNumArray[13] = ArduinoDigiOutPinNum13;
_digiOutPinNumArray[14] = ArduinoDigiOutPinNum14;
_digiOutPinNumArray[15] = ArduinoDigiOutPinNum15;
_digiOutPinNumArray[16] = ArduinoDigiOutPinNum16;
_digiOutPinNumArray[17] = ArduinoDigiOutPinNum17;
_digiOutPinNumArray[18] = ArduinoDigiOutPinNum18;
_digiOutPinNumArray[19] = ArduinoDigiOutPinNum19;
_digiOutPinNumArray[20] = ArduinoDigiOutPinNum20;
_digiOutPinNumArray[21] = ArduinoDigiOutPinNum21;
_digiOutPinNumArray[22] = ArduinoDigiOutPinNum22;
_digiOutPinNumArray[23] = ArduinoDigiOutPinNum23;
_digiOutPinNumArray[24] = ArduinoDigiOutPinNum24;
_digiOutPinNumArray[25] = ArduinoDigiOutPinNum25;
_digiOutPinNumArray[26] = ArduinoDigiOutPinNum26;
_digiOutPinNumArray[27] = ArduinoDigiOutPinNum27;
_digiOutPinNumArray[28] = ArduinoDigiOutPinNum28;
_digiOutPinNumArray[29] = ArduinoDigiOutPinNum29;

setupDigiOutPinAll();
_digiOutPinNum = DefaultDigiOutPinNum;

// Serial.println(F(“\nEnd FongDigiOut03::initDigiOut(), … >>>>>>>>>”));
}

void FongDigiOut03::setupArduinoDigiOutPinSingle(int8_t arduinoDigiOutPinNum)
{
pinMode(arduinoDigiOutPinNum, OUTPUT);
digitalWrite(arduinoDigiOutPinNum, LOW);
}

void FongDigiOut03::setupDigiOutPinSingle(int8_t digiOutPinNum)
{
int8_t arduinoDigiOutPinNum = _digiOutPinNumArray[digiOutPinNum];
setupArduinoDigiOutPinSingle(arduinoDigiOutPinNum);
}

void FongDigiOut03::setupDigiOutPinRange(int8_t firstDigiOutPinNum, int8_t lastDigiOutPinNum)
{
int8_t arduinoDigiOutPinNum;
for (int8_t i = firstDigiOutPinNum; i <= lastDigiOutPinNum; i++)
{
arduinoDigiOutPinNum = _digiOutPinNumArray[i];
setupArduinoDigiOutPinSingle(arduinoDigiOutPinNum);
}
}

void FongDigiOut03::setupDigiOutPinAll()
{
setupDigiOutPinRange(FirstDigiOutPinNum, LastDigiOutPinNum);
}

// *** Set digiOutPin High/Low ************************************************

void FongDigiOut03::setDigiOutPinHigh(int8_t digiOutPinNum)
{
int8_t arduinoDigiOutPinNum = _digiOutPinNumArray[digiOutPinNum];
digitalWrite(arduinoDigiOutPinNum, HIGH);
}

void FongDigiOut03::setDigiOutPinLow(int8_t digiOutPinNum)
{
int8_t arduinoDigiOutPinNum = _digiOutPinNumArray[digiOutPinNum];
digitalWrite(arduinoDigiOutPinNum, LOW);
}

// *** Pulse digiOutPin ***

void FongDigiOut03::pulseDigiOutPinSingle(int8_t digiOutPinNum, int highTime, int lowTime)
{
setDigiOutPinHigh(digiOutPinNum);
delay(highTime);
setDigiOutPinLow(digiOutPinNum);
delay(lowTime);
}

void FongDigiOut03::repeatPulseDigiOutPinSingle(int8_t digiOutPinNum, int highTime, int lowTime, \
unsigned long count)
{
for (int8_t i = 0; i < count; i++)
{
pulseDigiOutPinSingle(digiOutPinNum, highTime, lowTime);
}
}

void FongDigiOut03::repeatPulseDigiOutPinRange(int8_t firstDigiOutPinNum, \
int8_t lastDigiOutPinNum, \
int highTime, int lowTime, unsigned long count)
{
for (int8_t i = firstDigiOutPinNum; i <= lastDigiOutPinNum; i++)
{
repeatPulseDigiOutPinSingle(i, highTime, lowTime, count);
}
}

void FongDigiOut03::repeatPulseDigiOutPinAll(int highTime, int lowTime, unsigned long count)
{
repeatPulseDigiOutPinRange(FirstDigiOutPinNum, LastDigiOutPinNum, \
highTime, lowTime, count);
}

// *** Test functions *********************************************************

void FongDigiOut03::testDigiOut()
{
char selectChar;
char functionChar;
char portChar;
char repeatChar;

Serial.print(F(“\n+++ Current DigiOut pin num = “));
Serial.println(_digiOutPinNum);

_arduinoDigiOutPinNum = _digiOutPinNumArray[_digiOutPinNum];
Serial.print(F(“+++ Current arduino pin num = “));
Serial.println(_arduinoDigiOutPinNum);

printDigiOutSelectMenu(“+++ DigiOut Test Selection Menu”, FirstSelectNum, LastSelectNum);

selectChar = askMenuSelectChar(“+++ Test Selection Number”);

while (selectChar != ‘x’)
{
exeDigiOutSelectFunction(selectChar);

Serial.print(F(“\n+++ Current DigiOut pin num = “));
Serial.println(_digiOutPinNum);

_arduinoDigiOutPinNum = _digiOutPinNumArray[_digiOutPinNum];
Serial.print(F(“+++ Current Arduino pin num = “));
Serial.println(_arduinoDigiOutPinNum);

selectChar = askMenuSelectChar(“+++ Test Selection Number”);
}

Serial.println(F(“End Test DigiOut. >>>>”));
}

// *** Menu functions *********************************************************

char FongDigiOut03::askMenuSelectChar(String askString)
{
char selectChar;
char dummyChar;

// *** flush read buffer ***
while (Serial.available() > 0) {dummyChar = Serial.read();} // flush

// *** get user selection ***
// Serial.print(F(“\n”));
Serial.print(askString);
Serial.println(F(” = ? (‘m’ for menu)”));

while (Serial.available() == false) {} // wait for char
selectChar = Serial.read();
Serial.print(F(“”));
Serial.print(askString);
Serial.print(F(” = “));
Serial.println(selectChar);
return selectChar;
}

int FongDigiOut03::askDigiOutPinNum()
{
char dummyReadChar;
char digiOutPinChar;
int digiOutPinNum;

Serial.print(F(“\n*** Select DigiOutPinNum, …”));
Serial.print(F(“\n 0 = DigiOutPin 0″));
Serial.print(F(“\n 1 = DigiOutPin 1″));
Serial.print(F(“\n 2 = DigiOutPin 2″));
Serial.print(F(“\n 3 = DigiOutPin 3″));
Serial.print(F(“\n 4 = DigiOutPin 4″));
Serial.print(F(“\n 5 = DigiOutPin 5″));
Serial.print(F(“\n 6 = DigiOutPin 6″));
Serial.print(F(“\n 7 = DigiOutPin 7″));
Serial.print(F(“\n 8 = DigiOutPin 8″));
Serial.print(F(“\n 9 = DigiOutPin 9″));
Serial.print(F(“\n a = DigiOutPin 10″));
Serial.print(F(“\n b = DigiOutPin 11″));
Serial.print(F(“\n c = DigiOutPin 12″));
Serial.print(F(“\n d = DigiOutPin 13″));
Serial.print(F(“\n e = DigiOutPin 14″));
Serial.print(F(“\n f = DigiOutPin 15″));
Serial.print(F(“\n g = DigiOutPin 16″));
Serial.print(F(“\n h = DigiOutPin 17″));
Serial.print(F(“\n i = DigiOutPin 18″));
Serial.print(F(“\n j = DigiOutPin 19″));
Serial.print(F(“\n k = DigiOutPin 20″));
Serial.print(F(“\n l = DigiOutPin 21″));
Serial.print(F(“\n m = DigiOutPin 22″));
Serial.print(F(“\n n = DigiOutPin 23″));
Serial.print(F(“\n o = DigiOutPin 24″));
Serial.print(F(“\n p = DigiOutPin 25″));
Serial.print(F(“\n q = DigiOutPin 26″));
Serial.print(F(“\n r = DigiOutPin 27″));
Serial.print(F(“\n s = DigiOutPin 28″));
Serial.print(F(“\n t = DigiOutPin 29″));

// *** flush read buffer ***
while (Serial.available() > 0) {dummyReadChar = Serial.read();} // flush

Serial.print(F(“\nEnter DigiOutPinNum, … \n”));

while (Serial.available() == false)
{
}

digiOutPinChar = Serial.read();

if ((digiOutPinChar == ‘0’) || (digiOutPinChar <= ‘9’))
digiOutPinNum = digiOutPinChar – ‘0’;
else if ((digiOutPinChar == ‘a’) || (digiOutPinChar <= ‘z’))
digiOutPinNum = (digiOutPinChar – ‘a’) + 10;
else
digiOutPinNum = 0;
return digiOutPinNum;
}

// *** Print select menu ******************************************************
void FongDigiOut03::printDigiOutSelectMenu(String menuTitle, int8_t firstSelectNum, int8_t lastSelectNum)
{
const char menu0[] PROGMEM = “0 = Select digiOutPin.”;
const char menu1[] PROGMEM = “1 = Blink system LED (DigiOutPin29 = Arduino Mega Pin13).”;
const char menu2[] PROGMEM = “2 = Blink digitOutpin.”;
const char menu3[] PROGMEM = “3 = Blink DigiOut pin 0~7 (Arduino Pin22~29, PSU0~2, BTM0~2, NCx2.”;
const char menu4[] PROGMEM = “4 = Blink DigiOut pin 8~12 (Arduino Pin53, 46~49, SPI SS 0~5).”;
const char menu5[] PROGMEM = “5 = Blink DigiOut pin 13~18 (Arduino Pin40~45, SPI SS 6~10).”;
const char menu6[] PROGMEM = “6 = Blink DigiOut pin 19~28 (Arduino Pin30~39, SPI SS 12~19).”;
const char menu7[] PROGMEM = “7 = Set digiOutPin High.”;
const char menu8[] PROGMEM = “8 = Set digiOutPin Low.”;
const char menu9[] PROGMEM = “9 = Reserved.”;
const char menu10[] PROGMEM = “a = Reserved.”;
const char menu11[] PROGMEM = “m = Menu.”;
const char menu12[] PROGMEM = “h = Help.”;
const char menu13[] PROGMEM = “x = Exit.”;

const char * const selectMenu[] PROGMEM = {menu0, menu1, menu2, menu3, \
menu4, menu5, menu6, menu7, \
menu8, menu9, menu10, menu11, \
menu12, menu13};
Serial.println(menuTitle);

for (int8_t i = firstSelectNum; i <= lastSelectNum; i++)
{
Serial.println(selectMenu[i]);
}
}

// *** Execute selection function *********************************************

void FongDigiOut03::exeDigiOutSelectFunction(char selectChar)
{
switch (selectChar)
{
case ‘0’: // Slect DigiOut pin
_digiOutPinNum = askDigiOutPinNum();
break;
case ‘1’: // Blink System LED
repeatPulseDigiOutPinSingle(DigiOutPinNumLed, MilliSec50, MilliSec200, FourTimes);
break;
case ‘2’: // Blink DigiOut pin
repeatPulseDigiOutPinSingle(_digiOutPinNum, MilliSec50, MilliSec200, FourTimes);
break;
case ‘3’: // Blink DigiOut 0~7
repeatPulseDigiOutPinRange(DigiOutPinNum0, DigiOutPinNum7, \
MilliSec200, MilliSec200, Twice);
break;
case ‘4’: // Blink DigiOut 8~12
repeatPulseDigiOutPinRange(DigiOutPinNum8, DigiOutPinNum12, \
MilliSec200, MilliSec200, Twice);
break;
case ‘5’: // Blink DigiOut 13~17
repeatPulseDigiOutPinRange(DigiOutPinNum13, DigiOutPinNum18, \
MilliSec200, MilliSec200, Twice);
break;
case ‘6’: // Blink DigiOut 19~28
repeatPulseDigiOutPinRange(DigiOutPinNum19, DigiOutPinNum28, \
MilliSec200, MilliSec200, Twice);
break;
case ‘7’: // Set digiOutpPin High
setDigiOutPinHigh(_digiOutPinNum);
break;
case ‘8’: // Set digiOutpPin Low
setDigiOutPinLow(_digiOutPinNum);
break;
case ‘m': // print menu
printDigiOutSelectMenu(“DigiOut Test Selection”, FirstSelectNum, LastSelectNum);
break;
case ‘h': // print help
Serial.print(F(“Sorry, no help available, …”));
break;
default: // default selction
Serial.print(F(“Sorry, no such option, …”));
break;
}

/*
else if (selectChar == ‘2’)
{
// *** Repeat pulse DigiOutPin Single ***
repeatPulseDigiOutPinSingle(DigiOutPinNum0, MilliSec200, MilliSec200, FourTimes);
}
else if (selectChar == ‘3’)
{
// *** Repeat pulse DigiOutPin 0 ~ 4 ***
repeatPulseDigiOutPinRange(DigiOutPinNum0, DigiOutPinNum7, \
MilliSec200, MilliSec200, Twice);
}
else if (selectChar == ‘4’)
{
// *** Repeat pulse DigiOutPin ***
repeatPulseDigiOutPinRange(DigiOutPinNum13, DigiOutPinNum29, \
MilliSec1000, MilliSec1000, Twice);
}
else if (selectChar == ‘5’)
{
setDigiOutPinHigh(digiOutPinNum);
}
else if (selectChar == ‘6’)
{
setDigiOutPinLow(digiOutPinNum);
}
else if (selectChar == ‘7’)
{
repeatPulseDigiOutPinSingle(digiOutPinNum, MilliSec100, MilliSec100, \
FourTimes);
}
else if (selectChar == ‘8’)
{
int8_t i;

for (i = 0; i <= 7; i++)
{
setDigiOutPinHigh(i);
}

for (i = 8; i <= 18; i++)
{
setDigiOutPinLow(i);
}

delay(6000);

for (i = 0; i <= 7; i++)
{
setDigiOutPinLow(i);
}
for (i = 8; i <= 18; i++)
{
setDigiOutPinHigh(i);
}
}
else if (selectChar == ‘h’)
{
Serial.print(F(“Sorry, no help available, …”));
}
else if (selectChar == ‘m’)
{
printDigiOutSelectMenu(“DigiOut Test Selection”, FirstSelectNum, LastSelectNum);
}
else
{
Serial.print(F(“Sorry, no such option, …”));
}
*/
}

// *** End ***

.END

Leave a comment

Filed under Electronics DIY Project

每張 真普選 選票都印有特定編號 – 新加坡人民行動黨政府

未審判囚 異見者:為掌權賣友求榮 – 蘋果日報 2015年03月29日

莊明湖批評李光耀為了掌權「賣友求榮」。羅君豪攝

上世紀五十年代,李光耀發動殘酷政治鬥爭掌握政權。

成王敗寇,他上場後繼續鐵腕鎮壓異己,

78歲的莊明湖未經審訊就被囚十年

曾在獄中絕食84天抗議。蓋棺定論,他批評

李光耀為了掌權「賣友求榮」,

雖為新加坡帶來經濟成就,卻犧牲了人民的自由,「他有盡努力,但並不是偉人」。

評價李光耀,莊明湖要從五十年代、新加坡建國前說起。那年代民族主義興起,反殖思潮激盪,李光耀看準形勢,與華文教育者成立人民行動黨,爭取新加坡獨立。

1959年人民行動黨在選舉大勝,李光耀掌權後,卻放棄「初衷」,在1961年表態支持加入馬來西亞聯邦,放棄新加坡內部完全自治的訴求。莊明湖說:「我認為,這是賣友求榮!

李光耀的轉軚,令人民行動黨分裂,1963年的大選,他形勢不妙,選舉前夕先發制人,以「清共」為由,展開「冷藏行動」(operation cold store),引用內部安全法,拘捕逾115名反對派骨幹,

謝太寶、林福壽等多個政治領袖,

未經審訊被判囚19至32年不等

「功過比較 五十對五十」

李光耀掌權後,鎮壓並未停止。莊明湖當年是油漆工人,擔任工會領袖,六十年代領導工人參與反對政府欲關閉南洋大學、消滅華文教育的抗爭。1970年,他終被清算,因公開反對打壓工會的法例等理由被捕。當時他兩個女兒才4、5歲,太太身體虛弱,沒能力做工。

在囚歲月,他每年會被帶到「政治站」獨立囚禁數天,逼他就範簽懺過書,但他拒絕屈服。

被關的第八個年頭,他絕食反抗,「我拒絕單獨囚禁,要求能閱讀書報」

遭獄卒痛毆,被淋尿壺穢物,一周後,他被帶進監獄的醫院,繼續絕食,被獄卒強灌牛奶。他堅持了84天,當局把他帶回「大倉」,他才結束絕食,至1983年獲釋。

莊明湖認為,在經濟發展方面,

李光耀有功,但代價包括付出了人民的自由,破壞了民主精神

「功過比較,最多還是五十對五十」。

記者 雷子樂


軟性獨裁操控國民 培養自我審查 – 蘋果日報 2015年03月29日

區偉鵬認為李光耀是一個控制狂,設計出「軟性獨裁」的制度。羅君豪攝

人人說李光耀創造新加坡奇蹟,「光譜行動」另一名被捕人士區偉鵬卻認為,

李光耀是一個控制狂,精心設計出可掌控國民住屋、升學、就業的操控制度,令國民活在白色恐怖而不自覺。

這種「軟性獨裁」,孕育出新加坡人思想、行為皆自我審查的國民特質。

新加坡政府予人效率高、問責性強、具透明度的印象。區偉鵬說這都是美麗的誤會,

「他只對有錢人有效率,你看看他怎對待外勞?」

正在一個志願團體為外勞爭取權益的他續稱,

「你不會知道,每一個社區,其實有多少罪案;你不會知道,有多少涉及外勞欠薪、被剝削的投訴,當你為外勞申冤,他們並不受理」。

掌控組屋大學 佈「中產陷阱」

區偉鵬指,除了內安法、誹謗罪,李光耀還透過控制組屋、中央公積金、大學、經濟等手段,精心設計出一套「軟性獨裁」制度,令新加坡人怕因提出反對聲音而被捕、失業、影響孩子升學,「墮進了中產陷阱!」白色恐怖的例子,

還有新加坡的選票是寄到國民府上,每張選票都印有特定編號,令人擔心投票取向會被追蹤。

至於移民,永久居民每數年要續證一次,為免影響居留權,他們都傾向噤聲。

軟性獨裁,令新加坡人變得貼貼服服,他舉例指,2011年的大選,反對黨找了一位會計師監票,對方本已答應,但兩小時後卻來電表示,妻子剛告訴他,兒子正報讀大學,怕會影響孩子的前途,所以未能協助。

區認為,李光耀在位時間過長,各種操控機制已運作成熟,更大的遺禍,是這套軟性獨裁制度,向北京政府作了一個邪惡的示範。他寄語港人,要時刻警覺,一旦發現當權者對自由進犯,就要馬上制止。

記者雷子樂


少年拍粗口片罵極權 – 蘋果日報 2015年03月29日

越來越多新加坡年輕人透過網絡抨擊政府。17歲藝人余澎杉(Amos Yee圖)日前上載自拍短片,題為「Lee Kuan Yew Is Finally Dead!」以夾雜粗口英語狠批李光耀是獨裁者、極權者,更指

李就像耶穌般「權力慾強而惡毒,卻想人以為他充滿慈愛」

他自稱無懼惹上麻煩,指新加坡人工時長、貧窮人口比率高,冠絕全球已發展國家,政府在醫療及社會保障的支出卻很少,批評李光耀「強調物質主義,卻犧牲了我們的快樂」。

短片上載一天已有逾27萬次點擊,惹來大批網民留言反擊,更有人報警,指余的言論侮辱李光耀、基督教及基督徒,或觸犯刑事條例。

余曾參演新加坡電影《孩子不壞》,14歲時憑自製短片獲最佳短片及演員獎,曾因發表批評農曆新年短片受關注。

記者朱雋穎

.END

Leave a comment

Filed under Electronics DIY Project

80%的机器人是进口的 – 早报

“中国制造2025”提五大工程 – 早报 王道军 陶宁宁 2015-03-28

工信部副部长苏波3月27日表示,工信部将会同有关部门,推动制造业强国的建设,这里面包括成立国家制造强国建设领导小组,制定“1+X”的实施方案和规划体系。

工信部敲定三个十年“三步走”战略,将设国家制造强国建设领导小组

工信部副部长苏波3月27日表示,工信部将会同有关部门,推动制造业强国的建设,这里面包括成立国家制造强国建设领导小组,制定“1+X”的实施方案和规划体系。

中国制造2025》规划提出制造强国建设三个十年“三步走”的战略,最终在建国一百周年的时候,要实现中国成为制造强国的梦想。

国务院新闻办公室3月27日举行国务院政策例行吹风会,发展改革委副主任林念修、工业和信息化部副部长苏波介绍《中共中央国务院关于深化体制机制改革加快实施创新驱动发展战略的若干意见》、《中国制造2025》有关情况,并答记者问。

苏波透露,3月25日上午,国务院常务会议审议通过了《中国制造2025》战略规划,近期将正式印发。这一规划不能按一个常规性的行业规划,比如说“十三五”、“十四五”这样一个规划来看待,而是起了《中国制造2025》,类似于《德国工业4.0》这样技术性的名称。

工信部介绍,《中国制造2025》提出了9大任务、10大重点领域和5项重大工程。其中,

9大任务包括提高

国家制造业创新能力、推进

信息化与工业化深度融合

强化工业基础能力、

加强质量品牌建设、

全面推行绿色制造、

大力推动重点领域突破发展、

深入推进制造业结构调整、

积极发展服务型制造和生产性服务业、

提高制造业国际化发展水平。

10大重点领域则为

新一代信息通信技术产业、

高档数控机床和机器人

航空航天装备、

海洋工程装备及高技术船舶、

轨道交通装备、

节能与新能源汽车、

电力装备、新材料、生物医药及高性能医疗器械、农业机械装备。

5项重点工程包括

国家制造业创新中心建设、

智能制造

工业强基、

绿色制造、

高端装备创新,

解决长期制约重点领域发展的关键共性技术,

突破一批标志性产品和技术,提升中国制造业的整体竞争力。

智能制造业权威人士告诉早报记者,两化融合是“中国制造2025”的核心。

未来的产品将智能化,信息技术的应用会使机械产品向数字转变。

生产制造将更多依赖于计算机,企业的生产更加自动化、柔性化、智能化。

而在制造模式方面也会有变化,会有许多新的工业化理念,比如协同生产、大规模客户定制等。

今年全国两会期间,工信部首任部长、全国政协财经委员会副主任李毅中透露,到2020年,中国要基本实现工业化,这是第一个百年目标,到2050年实现第二个百年目标,迈入世界工业强国之列。

全程参与规划起草的中国工程院院长周济此前曾表示,“我国制造业强国进程可分为三个阶段:2025年中国制造业可进入世界第二方阵,迈入制造强国行列;2035年中国制造业将位居第二方阵前列,成为名副其实的制造强国;2045年中国制造业可望进入第一方阵,成为具有全球引领影响力的制造强国。”

苏波27日表示,出台这一战略规划,出于几方面考虑:

一是应对全球新一轮科技革命和产业变革所需。最近这几年,对新一轮产业革命议论很多,各国相继采取了很多措施来推进。中国政府在推进制造业的发展方面,也需要一个应对的蓝图。

二是金融危机后各国对制造业的发展都出现了一些新的动向。比如说,发达国家的再工业化取得实质性进展,新兴发展国家的产业调整步伐也在加快,中国作为第一制造大国,也需要有应对的措施,来提升自身产业的竞争力。

三是经过六十多年的快速发展,尤其是改革开放三十多年的发展,中国的制造业在许多非常重要的领域已经具有了全球的竞争力。

苏波称,《中国制造2025》重点对第一个十年的目标、任务进行了具体的部署,是中国实施制造强国战略第一个十年的行动纲领。

传统上,中国喜欢以五年为期编制规划,最有名的当属“十二五”规划。外界认为,拉长规划时间,可提升顶层设计的效力,保证政策的连续性。

中国工程院院士、清华大学教授柳百成参与了“中国制造2025”战略的制定和相关研究,他近期对外表示,目前中国制造业核心技术薄弱,共性技术缺位。“

我国自行研制的大型客机C919的全部发动机均靠进口

正在研制的重型燃气轮机的关键材料和关键零部件,如高温合金定向及单晶工作叶片仍依赖进口。近年来,我国在加大对数控机床研发的投入,但是

80%的高端数控机床至今仍依赖进口

2013年,我国已是机器人消费大国,位居世界第一位,但

80%的机器人进口的。”

复旦大学企业研究所所长张晖明表示,在国家层面提出战略规划很有必要,但必须注意的是,在规划制定后的执行、评估与考核也要及时跟上,如此才能避免规划仅仅停留在“口号”层面,成为“走过场”。

张晖明认为,当前,中国部分产业已经在全球有了一定竞争力,而制造业也面临着升级转型的需求,在此前提下,制造业方面引领性规划的制定是有必要的,也是政府管理水平提升的表现。

但他同时强调,除了纲领性的指导意见之外,如何在体制机制上改革,在绩效考核、评估上跟进,这些同样重要。“如果不能在具体执行上落到实处,没有有效的评估、考核机制,那么规划和目标可能仅仅只是口号。” 张晖明表示。

录入编辑:王卉

.END

Leave a comment

Filed under Electronics DIY Project

Arduino Mega System C assembly notes

arduino_mega_signal_routing_2015mar2801 arduino_mega2560r3_system_c_2015mar2801 - 複製

Arduino Mega System C assembly notes

.END

Leave a comment

Filed under Electronics DIY Project