Commit 1c39996d authored by Daniel STAN's avatar Daniel STAN

lotus: improvements

parent 4de3f6b6
/* Arduino directement connecté à kugel, pour communiquer
avec programme python coté port série*/
// Pin du moteur
#define RF_M_CONT 12 //EN 3,4, ex 10
#define RF_M_CONT 12 //EN 3,4
#define RF_M_DRV1 11 //3A
#define RF_M_DRV2 10 //4A, ex 12
#define RF_M_DRV2 10 //4A
// Pin relai ampoule
#define PIN_BULB 9
......@@ -12,92 +10,114 @@ avec programme python coté port série*/
// Pin pour mesurer la position
#define PIN_POS A0
// Position hautes et basses
#define POS_HIGH 280
#define POS_LOW 107
#define BOUNCE 3
void setup()
{
Serial.begin(9600);
delay(2000);
while(!Serial);//delay for Leonardo
pinMode(RF_M_CONT, OUTPUT);
pinMode(RF_M_DRV1, OUTPUT);
pinMode(RF_M_DRV2, OUTPUT);
pinMode(PIN_BULB, OUTPUT);
digitalWrite(PIN_BULB, HIGH);
digitalWrite(RF_M_CONT, LOW);
digitalWrite(RF_M_DRV1, LOW);
digitalWrite(RF_M_DRV2, LOW);
// Default light
pinMode(PIN_BULB, OUTPUT);
digitalWrite(PIN_BULB, LOW);
// Serial !
Serial.begin(9600);
// And the motor
pinMode(RF_M_CONT, OUTPUT);
pinMode(RF_M_DRV1, OUTPUT);
pinMode(RF_M_DRV2, OUTPUT);
digitalWrite(RF_M_CONT, LOW);
digitalWrite(RF_M_DRV1, LOW);
digitalWrite(RF_M_DRV2, LOW);
}
void move(bool going_up) {
int target;
int comp;
int val;
if(going_up) {
comp=1;
target = POS_HIGH;
Serial.println("Going up");
digitalWrite(RF_M_DRV1, HIGH);
digitalWrite(RF_M_DRV2, LOW);
} else {
comp=-1;
target = POS_LOW;
Serial.println("Going down");
digitalWrite(RF_M_DRV1, LOW);
digitalWrite(RF_M_DRV2, HIGH);
}
digitalWrite(RF_M_CONT, HIGH);
if(false) {
delay(1);
while((val = analogRead(PIN_POS)*comp) < target*comp) {
//if(My_Receiver.GetResults(&My_Decoder)) {
// My_Receiver.resume();
//if( My_Decoder.decode() == BTN_STOP ) {
// Serial.println("Manual stop");
// break;
//}
//}
delay(1);
}
Serial.print("Stopping because");
Serial.println(val);
report_pos();
}
else {
delay(300);
if(going_up)
delay(200);
}
digitalWrite(RF_M_CONT, LOW);
void move(bool going_up, int target=0, int timeout=0) {
int comp;
int val;
if(target) {
target = min(max(target, POS_LOW), POS_HIGH);
going_up = target < get_position();
}
Serial.print("Move:");
Serial.print(going_up?"Up":"Down");
Serial.print(",Target:");
Serial.print(target);
Serial.print(",Timeout:");
Serial.println(timeout);
if(going_up) {
comp=1;
target = POS_HIGH;
digitalWrite(RF_M_DRV1, HIGH);
digitalWrite(RF_M_DRV2, LOW);
} else {
comp=-1;
target = POS_LOW;
digitalWrite(RF_M_DRV1, LOW);
digitalWrite(RF_M_DRV2, LOW);
digitalWrite(RF_M_DRV2, HIGH);
}
digitalWrite(RF_M_CONT, HIGH);
if(target) {
do {
delay(1);
val = get_position();
}
while(val *comp < target*comp);
report_pos();
}
if(timeout)
delay(timeout);
digitalWrite(RF_M_CONT, LOW);
digitalWrite(RF_M_DRV1, LOW);
digitalWrite(RF_M_DRV2, LOW);
}
void report_pos() {
Serial.println("Report");
Serial.println(analogRead(PIN_POS));
int get_position() {
int value = 0;
const int count = 10;
for(int i=0; i < count; i++)
value += analogRead(PIN_POS);
return value/count;
}
void report_pos() {
Serial.print("Report:"); Serial.println(get_position());
}
void loop() {
int incomingByte = 0;
if(Serial.available()) {
incomingByte = Serial.read();
Serial.print("Read");
Serial.println(incomingByte);
if(incomingByte == '0')
move(false);
else if(incomingByte == '1')
move(true);
else if(incomingByte == 'r')
report_pos();
else if(incomingByte == 'o')
digitalWrite(PIN_BULB, LOW);
else if(incomingByte == 'f')
digitalWrite(PIN_BULB, HIGH);
// Debug:
Serial.print("Input:"); Serial.println(incomingByte);
switch(incomingByte) {
case 'd':
move(false, 0, 300);
break;
case 'u':
move(true, 0, 500);
break;
case 'U':
move(false, 1024);
break;
case 'D':
move(true, 0);
break;
case 'm':
move(false, Serial.parseInt());
case 'r':
report_pos();
break;
case 'o':
digitalWrite(PIN_BULB, LOW);
break;
case 'f':
digitalWrite(PIN_BULB, HIGH);
break;
default:
Serial.println("Ignored");
}
}
}
......
#!/bin/env python3
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import bs4
import decimal
def parse_decimal(txt):
"""Parse un décimal vu comme un montant en €"""
"""Parse a decimal seen as an amount in €"""
txt = txt.replace(' ','').replace(',', '.').replace('€', '')
return decimal.Decimal(txt)
value = parse_decimal(dep.findAll(attrs={'class':'col-xs-3'})[0].text)
doc = bs4.BeautifulSoup(open('1.example', 'r').read())
......@@ -18,9 +17,21 @@ r = doc.find(attrs={'id': 'expenses_accordion'})
depenses = r.findAll(attrs={'class': 'panel panel-default'})
# On va parser une dépense donnée
dep = depenses[0]
def parse_depense(dep):
return {
'title': dep.find(attrs={'class': 'col-xs-6'}).text,
'value': parse_decimal(dep.findAll(attrs={'class':'col-xs-3'})[0].text),
'id': int(dep.findAll('a')[-1].attrs['href'].split('=')[-1]),
'participants': dep.find(attrs={'class': 'panel-body'}).text.split('\n')[1],
}
def parse_participants(txt):
"""Take a participant list, and returns a dictionnary whose keys are
participants names and values are the integral number of shares they
take in the bill"""
raise NotImplementedError
#print(parse_depense(depenses[0]))
print(parse_participants('Payé par PEB ; participants : 20-100, b2moo (2 parts), Chopopope (2 parts), PEB.'))
title = dep.find(attrs={'class': 'col-xs-6'}).text
value = parse_decimal(dep.findAll(attrs={'class':'col-xs-3'})[0].text)
unique_id = int(dep.findAll('a')[-1].attrs['href'].split('=')[-1])
participants = dep.find(attrs={'class': 'panel-body'}).text.split('\n')[1]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment