Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gwens committed Nov 24, 2016
0 parents commit 22aea6f
Show file tree
Hide file tree
Showing 106 changed files with 4,482 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
@@ -0,0 +1,2 @@
*.ext3 filter=lfs diff=lfs merge=lfs -text
*.sh filter=lfs diff=lfs merge=lfs -text
Binary file added 9781430268390.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions LICENSE.txt
@@ -0,0 +1,27 @@
Freeware License, some rights reserved

Copyright (c) 2014 Manoel Ramon

Permission is hereby granted, free of charge, to anyone obtaining a copy
of this software and associated documentation files (the "Software"),
to work with the Software within the limits of freeware distribution and fair use.
This includes the rights to use, copy, and modify the Software for personal use.
Users are also allowed and encouraged to submit corrections and modifications
to the Software for the benefit of other users.

It is not allowed to reuse, modify, or redistribute the Software for
commercial use in any way, or for a user�s educational materials such as books
or blog articles without prior permission from the copyright holder.

The above copyright notice and this permission notice need to be included
in all copies or substantial portions of the software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS OR APRESS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


15 changes: 15 additions & 0 deletions README.md
@@ -0,0 +1,15 @@
#Apress Source Code

This repository accompanies [*Intel Galileo and Intel Galileo Gen 2*](http://www.apress.com/9781430268390) by Manoel Ramon (Apress, 2014).

![Cover image](9781430268390.jpg)

Download the files as a zip using the green button, or clone the repository to your machine using Git.

##Releases

Release v1.0 corresponds to the code in the published book, without corrections or updates.

##Contributions

See the file Contributing.md for more information on how you can contribute to this repository.
Binary file added Source code/9781430268390_Ch13.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
6 changes: 6 additions & 0 deletions Source code/Chapter_02/code/HelloWorld.c
@@ -0,0 +1,6 @@
#include <stdio.h>
int main(int argc, char const* argv[])
{
printf("Hello, World! This is Intel Galileo!\n");
return 0;
}
14 changes: 14 additions & 0 deletions Source code/Chapter_02/code/Makefile.txt
@@ -0,0 +1,14 @@
SHELL = /bin/bash
TARGET_NAME = i586-poky-linux-uclibc
DIST = clanton-tiny
CC = $(TARGET_NAME)-gcc -m32 -march=i586 --sysroot=/opt/$(DIST)/1.4.2/sysroots/$(TARGET_NAME)
CFLAGS = -O2 -pipe -g -feliminate-unused-debug-types
OUTPUT_FILE = HelloWorld

all: target

target: $(patsubst %.c,%.o,$(wildcard *.c))
$(CC) $(CFLAGS) $^ -o $(OUTPUT_FILE)

clean:
rm -f $(TARGET_BIN) *.o $(OUTPUT_FILE)
Binary file added Source code/Chapter_02/code/cool_binary.bin
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions Source code/Chapter_02/code/patch.sh
Git LFS file not shown
Binary file not shown.
12 changes: 12 additions & 0 deletions Source code/Chapter_03/emailCounter.py
@@ -0,0 +1,12 @@
# based in the discussion in:
# http://stackoverflow.com/questions/953561/check-unread-count-of-gmail-messages-with-python
# by manoel.c.ramon@intel.com

import imaplib
import sys

obj = imaplib.IMAP4_SSL('imap.gmail.com','993')
obj.login(sys.argv[1],sys.argv[2])
obj.select()
obj.search(None,'UnSeen')
print len(obj.search(None,'UnSeen')[1][0].split())
12 changes: 12 additions & 0 deletions Source code/Chapter_03/gmailAlarm/gmail.py
@@ -0,0 +1,12 @@
# based in the discussion in:
# http://stackoverflow.com/questions/953561/check-unread-count-of-gmail-messages-with-python
# by manoel.c.ramon@intel.com

import imaplib
import sys

obj = imaplib.IMAP4_SSL('imap.gmail.com','993')
obj.login(sys.argv[1],sys.argv[2])
obj.select()
obj.search(None,'UnSeen')
print len(obj.search(None,'UnSeen')[1][0].split())
121 changes: 121 additions & 0 deletions Source code/Chapter_03/gmailAlarm/gmailAlarm.ino
@@ -0,0 +1,121 @@
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>

// the led
int led = 2; // the built-in LED

// emails counters
int current_emails_counter = -1;
int last_emails_counter = -1;


// add here your credentials
String gmailUserName=""; // email or password
String gmailPassword=""; // your password

String script_name = "python /home/root/emailCounter.py ";

// this function calls a python script to read the number of emails not read
int processEmailCounter()
{

char cmd_rsp[8]; // This buffer will containg the script response

FILE *fpipe;


String command = script_name;

command += gmailUserName;
command += " ";

command += gmailPassword;

// buffer to be used with popen
char cmd_char[300];

// clear message buffer
memset((void *)cmd_char, sizeof(cmd_char), 0);

// convert the message to char array
command.toCharArray(cmd_char, sizeof(cmd_char), 0);

if ( !(fpipe = (FILE*)popen((char *)cmd_char,"r")) )
{ // If fpipe is NULL
Serial.println("Problems with pipe");
}
else
{

while ( fgets( cmd_rsp, sizeof(cmd_rsp), fpipe)) {}

pclose(fpipe);

// let's print the serial result
Serial.println(cmd_rsp);

return atoi(cmd_rsp);
}

return -1;
}


// this is my time handler...
void timerHandler (int signum)
{
current_emails_counter = processEmailCounter();
if (last_emails_counter == -1)
{
last_emails_counter = current_emails_counter;
Serial.println("I am ready to check now... ");
}

if (current_emails_counter != last_emails_counter)
{
// turn on the LED
digitalWrite(led, HIGH);
}
}

int setAlarm ()
{
struct sigaction sa;
struct itimerval timer;

/* Install timer_handler as the signal handler for SIGVTALRM. */
memset (&sa, 0, sizeof (sa));
sa.sa_handler = &timerHandler;
sigaction (SIGVTALRM, &sa, NULL);

// Configure the timer to expire after 1 seconds
timer.it_value.tv_sec = 1;
timer.it_value.tv_usec = 0;
// ... and every 10 seconds after that
timer.it_interval.tv_sec = 10;
timer.it_interval.tv_usec = 0;

// Start a virtual timer. Counter while sketch runs
setitimer (ITIMER_VIRTUAL, &timer, NULL);

}


void setup() {
// only a small delay to allow you press CTRL+SHIT+M
// and see the Serial Monitor
delay(3000);

// set the alarm
setAlarm();
pinMode(led, OUTPUT);
digitalWrite(led, LOW);
}

void loop() {
// put your main code here, to run repeatedly:


}
39 changes: 39 additions & 0 deletions Source code/Chapter_03/serialtest/serialtest.ino
@@ -0,0 +1,39 @@

String inputString = ""; // a string to hold incoming data
boolean stringComplete = false; // whether the string is complete

void setup() {
// put your setup code here, to run once:
Serial.begin(9600); // does not matter for this object
delay(3000);
}

void loop() {
// transmitting something from Galileo to IDE
Serial.println("Hi there!! type something and press SEND button!!! ");
delay(1000);

// if the developer sent something from IDE to Galileo
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();

// add it to the inputString:
inputString += inChar;

if (inChar == '\n') {
stringComplete = true;

}
}

if (stringComplete == true) {

Serial.print("\nCOOL!! RECEIVED YOUR MESSAGE: ");
Serial.println(inputString);
inputString = "";
stringComplete=false;

}

}

0 comments on commit 22aea6f

Please sign in to comment.