Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Things-completed-today-meter
const int voltPin = 4;
const int maxVoltAdjust = 230; // analog out is max 255, but for my voltmeter 230 == 100%
void setup() {
pinMode(voltPin, OUTPUT);
Serial.begin(19200);
}
String inData;
void loop() {
while (Serial.available() > 0)
{
char recieved = Serial.read();
inData += recieved;
// Process message when new line character is recieved
if (recieved == '\n') {
Serial.print("Received: ");
Serial.print(inData);
char char_string[inData.length()+1];
inData.toCharArray(char_string, inData.length()+1);
int num = atoi(char_string);
analogWrite(voltPin, (float) num / 100 * maxVoltAdjust);
delay(200);
inData = ""; // Clear recieved buffer
}
}
}
#!/usr/bin/ruby
require 'filewatcher'
require 'sqlite3'
require 'rubygems'
require 'serialport'
port_str = "/dev/tty.usbmodem1801"
baud_rate = 19200
data_bits = 8
stop_bits = 1
parity = SerialPort::NONE
sp = SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity)
sp.sync = true
FileWatcher.new(["ThingsLibrary.db"]).watch do
# ~/Library/Containers/com.culturedcode.things/Data/Library/Application\ Support/Cultured\ Code/Things/ThingsLibrary.db
# cough cough cough
`cp ThingsLibrary.db ThingsLibrary_cache.db`
db = SQLite3::Database.new("ThingsLibrary_cache.db")
db.results_as_hash = true
row = db.get_first_row( "SELECT count(ZTHING.Z_PK) as today FROM ZTHING LEFT OUTER JOIN ZTHING PROJECT on ZTHING.ZPROJECT = PROJECT.Z_PK LEFT OUTER JOIN ZTHING AREA on ZTHING.ZAREA = AREA.Z_PK WHERE ZTHING.ZSTARTDATE != '' and ZTHING.ZSTATUS != 3 and ZTHING.ZSTATUS != 2 and ZTHING.ZTRASHED = 0 and ZTHING.ZSTART = 1 ORDER BY ZTHING.ZTODAYINDEX;" )
today = row['today']
puts "(today #{today})"
row = db.get_first_row( "SELECT date(ZSTOPPEDDATE, 'unixepoch', '+31 years', 'localtime') as date, count(Z_PK) as completed from ZTHING WHERE ZSTATUS = 3 and date = (SELECT date('now')); " )
completed = row['completed']
puts "(completed #{completed})"
total = completed + today
puts "(total #{total})"
percent = completed.to_f / total * 100
puts percent.round
sp.puts percent.round
db.close
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.