Facebook hackcontest, 3d printer, classgen and iPhone Thermostat

Written by Walter Schreppers

< >

Anyway need to post some stuff here, it's been a while.

An iPhone thermostat hack. Basically we have an arduino hooked up to a lm35 temperature sensor and relay. Through the ftdi chip it has a serial connection to a SheevaPlug Plug computer. On this arm based plugpc runs a little perl script that does the serial talk to the arduino to set/get the temperature. The arduino just switches on/off a relay which controls the central heating. There are 2 buttons to inc/dec the wanted temperature. Or it can be set with the web interface.

First up after a hardware hack weekend with friends we build this 3d printer prototype but we haven't found the time to finish it yet. Anyway we ripped some old printers and cdroms apart and drove the stepper motors using attiny2313 and some darlington arrays:

Anyway once it is all finished we will post some more pictures (we started a new version out of wood and much larger steppers nema17's which have 1.3kg of torque). Post will follow next time we finish up the prototype and hopefully this one is strong enough to carry our dremel and we can do some pcb printing ;).

Next up is a nice little tool I've used for years, never posted it cause it was implemented on a few hours and I needed to clean up the code. Still it is so useful (and never got the time to clean up the code). I'm posting it as is. Basically it is a generator that helps you pump out classes quickly command line. This thing is already 5 years old but nowadays it looks a lot like rails generators. So I just had to post it ;).

Anyway here's me c++ scaffolding some classes Car, Mercedes, Audi etc:

classgen Carwschrep@sitonrails:~/cpp-work/testgen$ classgen -help
Usage: classgen [options] 

  -ops      add assign and relational operator
  -stl      adds typical stl includes and sets stl namespace
  -verbose  show output files
  -help     show this usage 

classgen -ops -stl Mercedes
classgen -ops -stl Audi
classgen -ops -stl Opel

This generates some classes (.h and .cpp header and implementation) with nice indentation, comments and empty implementation files. The tool needs to be extended to add arbitrary members and private locals after which it acts much like a rails scaffold. We could even include some ORM library so that it auto generates coupling of the local variables to sql columns.

wschrep@sitonrails:~/cpp-work/testgen$ g++ -c *.cpp
cat car.h
wschrep@sitonrails:~/cpp-work/testgen$ cat car.h
author        : Walter Schreppers
filename      : car.h
created       : 31/3/2011 at 14:49:41
modified      : 
version       : 
copyright     : Walter Schreppers

#ifndef CAR_H
#define CAR_H


using namespace std;

class Car {

    //constructor & destructor

    //public members

    Car& operator=( const Car& );
    friend ostream& operator<<( ostream&, const Car& );
    friend istream& operator>>( istream&, Car& );

    //private members:
    void init();

    //private locals:

}; //end of class Car


Here are the classgen sources (not so pretty but hey it's handy ;): classgen.tar.gz Just tar -xzvf classgen.tar.gz then cd and make it.

Just did this in 5 min's before sleep some time ago to get my mind of a bad day ...

Walter-Schrepperss-MacBook-Pro:wschrep$ cat HoppityHop.cpp
// HIHI Writing the Hoppity Hop! hack in 5 min's c++ on christmas eve ;)

using namespace std;

int main(int argc, char** argv ){
  if( argc != 2 ){
    cerr << "USAGE: "<" <> number;
  for( int count = 1; count <= number; count++ ){
    if( ((count%3)==0) && ((count%5)==0) ){
      cout << "Hop" << endl;
    else if( count%3 == 0 ){ //divisible by 3
      cout << "Hoppity" << endl;
    else if( count%5 == 0 ){ //divisible by 5
      cout << "Hophop" << endl;
  return 0;

Walter-Schrepperss-MacBook-Pro:wschrep$ g++ HoppityHop.cpp -o HoppityHop
Walter-Schrepperss-MacBook-Pro:wschrep$ cat HoppityHop.test 
Walter-Schrepperss-MacBook-Pro:wschrep$ ./HoppityHop HoppityHop.test 
Walter-Schrepperss-MacBook-Pro:wschrep$ ./HoppityHop 
USAGE: ./HoppityHop 
Yep too easy ;)

Back to archive