Exemple #1
0
 def __init__(self):
     for code in self.OUTPUT_PINS:
         pin = Pin(code, code in self.STARTING_HIGH, self, True)
         setattr(self, 'pin_{}'.format(pin.code), pin)
     for code in self.INPUT_PINS:
         pin = Pin(code, code in self.STARTING_HIGH, self)
         setattr(self, 'pin_{}'.format(pin.code), pin)
     self.vcc = Pin('VCC', True, self)
     self.update()
Exemple #2
0
 def __init__(self):
     self.board = "na-satbus-3c0-gcc"
     self.arch = "ARM"
     self.cpu = "stm32f405"
     self.binfiletype = "ELF"
     self.pins = {
         'rst': Pin(name='rst', number=17),
         'pwr': Pin(name='pwr', number=27)
     }
Exemple #3
0
 def __init__(self):
     self.board = "msp430f5529-gcc"
     self.arch = "MSP430"
     self.cpu = "msp430f5529"
     self.binfiletype = "ELF"
     self.pins = {
         'rst' : Pin(name = 'rst', number = 17),
         'pwr' : Pin(name = 'pwr', number = 27),
         'opt' : Pin(name = 'opt', number = 22)  # optional
     }
Exemple #4
0
 def __init__(self):
     self.board = "stm32f407-disco-gcc"
     self.arch = "ARM"
     self.cpu = "stm32f407"
     self.binfiletype = "ELF"
     self.pins = {
         'rst' : Pin(name = 'rst', number = 17),
         'pwr' : Pin(name = 'pwr', number = 27),
         'opt' : Pin(name = 'opt', number = 22)  # optional
     }
Exemple #5
0
 def __init__(self, *args, **kwargs):
     for code in self.OUTPUT_PINS:
         pin = Pin(code, code in self.STARTING_HIGH, self, True)
         setattr(self, 'pin_{}'.format(pin.code), pin)
     for code in self.INPUT_PINS:
         pin = Pin(code, code in self.STARTING_HIGH, self)
         setattr(self, 'pin_{}'.format(pin.code), pin)
     self.vcc = Pin('VCC', True, self)
     self.update()
     self.leds = {pin.code: LED(self.vcc, pin) for pin in self.getpins(self.INPUT_PINS)}
Exemple #6
0
    def __init__(self, directionIO, stepIO):
        self.directionIO = Pin(directionIO, 'OUT')

        self.stepIO = Pin(stepIO, 'OUT')

        self.direction = False
        self.velocity = DEFAULT_VELOCITY
        self.default_wait = DEFAULT_WAIT

        self.position = 0
        self.turn = DEFAULT_POSITION_STEP
Exemple #7
0
 def __init__(self):
     self.board = "pyboard-gcc"
     self.arch = "ARM"
     self.cpu = "stm32f405"
     self.binfiletype = "BIN"
     self.pins = {
         'rst' : Pin(name = 'rst', number = 17),
         'pwr' : Pin(name = 'pwr', number = 27),
         'prg' : Pin(name = 'prg', number = 18),
         'opt' : Pin(name = 'opt', number = 22)
     } 
Exemple #8
0
 def __init__(self, *args, **kwargs):
     self.value = 0
     self.prev_clock_high = False
     for code in self.OUTPUT_PINS:
         pin = Pin(code, code in self.STARTING_HIGH, self, True)
         setattr(self, 'pin_{}'.format(pin.code), pin)
     for code in self.INPUT_PINS:
         pin = Pin(code, code in self.STARTING_HIGH, self)
         setattr(self, 'pin_{}'.format(pin.code), pin)
     self.vcc = Pin('VCC', True, self)
     self.update()
Exemple #9
0
    def __init__(self):
        # input/output pins:
        self.__a = Pin()
        self.__x = Pin()

        # components
        self.__nand1 = Nand()

        # connections:
        self.__connection1 = Connection(
            [self.__a, self.__nand1.b, self.__nand1.a])
        self.__connection2 = Connection([self.__x, self.__nand1.x])
Exemple #10
0
    def __init__(self, IN1, IN2, IN3, IN4, timeout):
        self.P1 = Pin(IN1, Pin.OUT)
        self.P2 = Pin(IN2, Pin.OUT)
        self.P3 = Pin(IN3, Pin.OUT)
        self.P4 = Pin(IN4, Pin.OUT)
        self.P1.value(0)
        self.P2.value(0)
        self.P3.value(0)
        self.P4.value(0)
        self.timeout = timeout

        self.stop = False
        self.turning = False
        self.command = None
        self.loop_running = False
Exemple #11
0
 def generate_pins(self):
     self.fetch_pin_constants()
     for pin_name in self.pin_data:
         pin_number = self.pin_data[pin_name]["number"]
         pin_node = self.pin_data[pin_name]["node"]
         pin_is_input = self.pin_data[pin_name]["is_input"]
         pin = Pin(pin_node, self, pin_is_input, pin_name, pin_name)
         self.pins[pin_name] = pin
Exemple #12
0
def profile(user):
    dbgp(user)
    profile_img = user.profile_image_url
    profile_bg_img = user.profile_banner_url
    profile_bio = default_str_new_line(user.description)
    profile_location = default_str_new_line(user.location)
    profile_stats = [user.statuses_count, user.friends_count, user.followers_count]
    profile_mapping = ["Tweets", "Following", "Followers"]
    profile_stats_text = ""
    for (i, stat) in enumerate(profile_stats):
        profile_stats_text += "{} {},".format(stat, profile_mapping[i])
    if profile_stats_text:
        profile_stats_text = profile_stats_text[:-1] + "\n"
    profile_elem = (profile_img, profile_bg_img, profile_stats, profile_bio, profile_location)
    content = profile_bio + profile_location + profile_stats_text
    return profile_elem, Pin(profile_url = profile_img, content = content)
Exemple #13
0
def insert_all_pins_or_boards(all_data, class_name):
    counter = 0
    for index, item in enumerate(all_data):
        counter += 1
        data = json.loads(item)

        if class_name == "pin":
            if store.get(Pin, data['id']) is None:
                store.add(Pin(data))
        elif class_name == "board":
            if store.get(Board, data['id']) is None:
                store.add(Board(data))

        if counter == MAX_INMEMORY:
            store_to_db()
            counter = 0
    store_to_db()
Exemple #14
0
def get_pins(pi_id):
    """Returns the pins associated with each RPi. Update this when new RPis/pins are added."""
    i2c = busio.I2C(board.SCL, board.SDA)
    ads1 = ADS.ADS1115(i2c, address=0x48)
    ads2 = ADS.ADS1115(i2c, address=0x49)
    ads3 = ADS.ADS1115(i2c, address=0x4a)

    if pi_id == 1:
        return [
            Pin(1, ads1, ADS.P0, record_values=True),
            Pin(2, ads1, ADS.P1, record_values=True),
            Pin(3, ads1, ADS.P2, record_values=True),
            Pin(4, ads1, ADS.P3, record_values=True),
            Pin(5, ads2, ADS.P0, record_values=True, threshold=20000),
            Pin(6, ads2, ADS.P1, record_values=True),
            Pin(7, ads2, ADS.P2, record_values=True),
            Pin(8, ads2, ADS.P3, record_values=True),
            Pin(9, ads3, ADS.P0, record_values=True, threshold=25000)
        ]

    elif pi_id == 2:
        return [
            Pin(10, ads1, ADS.P0, record_values=True, threshold=15000),
            Pin(11, ads1, ADS.P1, record_values=True),
            Pin(12, ads1, ADS.P2, record_values=True),
            Pin(13, ads1, ADS.P3, record_values=True, threshold=21000),
            Pin(14, ads2, ADS.P0, record_values=True),
            Pin(15, ads2, ADS.P1, record_values=True),
            Pin(16, ads2, ADS.P2, record_values=True),
            Pin(17, ads2, ADS.P3, record_values=True),
            Pin(18, ads3, ADS.P0, record_values=True),
        ]

    raise ValueError('invalid rapsberry pi id : ' + str(pi_id))
Exemple #15
0
g_server = None
stream_enabled = True
webserver_restart = True

# Stepper
pin_IN1 = 15
pin_IN2 = 18
pin_IN3 = 4
pin_IN4 = 17
pulse_timeout = 0.001 # time to wait before sending another pulse to the stepper motor (smaller = faster but less strong and less precise)
stepper = Stepper(pin_IN1, pin_IN2, pin_IN3, pin_IN4, pulse_timeout)

# PIR sensors
IR_PIN = 23
IR2_PIN = 27
IR_front = Pin(IR_PIN, Pin.IN)
IR_back = Pin(IR2_PIN, Pin.IN)
IR_timestamp = monotonic()
IR_time_threshold = 15 # seconds before subsequent IR input is recognized again
IR_loop_running = False

# Processes object detection results and calculates if the device should adjust its rotation or not
def process_coords(data):
    im_width = stream_resolution[0]
    prioritized_target = None
    targets = data["tar"]
    for target in targets:
        if not prioritized_target:
            prioritized_target = target
        else:
            if object_detection_targets.index(target["n"]) < object_detection_targets.index(prioritized_target["n"]):
Exemple #16
0
 def set_pins(self):
     pinOne = Pin()
     pinTwo = Pin()
     pinThree = Pin()
     self.pins = [pinOne, pinTwo, pinThree]
 def __init__(self):
     self.pin = Pin(Board.BUZZ_PIN)
Exemple #18
0
 def __init__(self):
     # input pins
     self.a = Pin()
     self.b = Pin()
     # output pins
     self.x = Pin()
Exemple #19
0
 def test_output(self):
     p24 = Pin(24)
     p24.output(.5)
     self.assertEqual(p24.value, 0.5)
Exemple #20
0
def get_tweets_api(twitter_id, dtos, api):
    dbgpi("Getting tweets for {}".format(twitter_id))
    # get profile contents
    profile_elem = None
    user = api.GetUser(screen_name=twitter_id)
    profile_elem, profile_pin = profile(user)
    profile_img, profile_bg_img, profile_stats, profile_bio, profile_location = profile_elem
    # activities
    # TODO: indicates profile in activities
    # Or always has profile at 0th index
    # and other activities for e.g next page
    # starting at 1th index
    acts = [profile_pin]
    # TODO : Get all tweets for days
    timeline = api.GetUserTimeline(screen_name=twitter_id, count=number_of_tweets)
    tweets = []
    for tweet in timeline:
        tweets.append(str(tweet))
        dbgp(tweet)
        replies = ()
        author = () # (screen_name, profile_image_url)
        # favor whatever url it has
        urls = None
        medias = None
        profile_name = ""
        profile_url = ""
        created_at = tweet.created_at
        relations = []
        if tweet.retweeted_status: # retweet has to pull different stuff
            dbgp("Retweeting")
            rt = tweet.retweeted_status
            profile_name = tweet.user.screen_name
            profile_url = rt.user.profile_image_url
            medias = rt.media
            # TODO: medias on all these
        elif tweet.quoted_status:
            dbgp("Quote status")
            qt = tweet.quoted_status
            profile_name = tweet.user.screen_name
            profile_url = qt.user.profile_image_url
            medias = qt.media
        else:
            dbgp("Not Retweeting")
            profile_name = tweet.user.screen_name
            profile_url = tweet.user.profile_image_url
            medias = tweet.media

        urls = [status_link.format(profile_name, tweet.id)]
        media_urls = []
        if medias:
            for media in medias:
                media_url = [media.type, media.media_url]
                media_url.append(media.media_url)
                # TODO: Confirm gif saved as mp4 ?
                if media.type == "video" or media.type == "animated_gif":
                    video_url = media.video_info["variants"][-1]["url"]
                    dbgp("video {}".format(video_url))
                    media_url = ["video", media.media_url, video_url]
                media_urls.append(media_url)
        content = "@" + profile_name
        if tweet.in_reply_to_screen_name: # not replying to self
            dbgp("Replying to {}".format(tweet.in_reply_to_screen_name))
            content += " replies to @" + tweet.in_reply_to_screen_name
            if not urls:
                dbgp("Reconstructing urls:")
                urls = [status_link.format(tweet.in_reply_to_screen_name, tweet.in_reply_to_status_id)]
        elif tweet.quoted_status: # TODO: Refactor these
            content += " (quoted @" + tweet.quoted_status.user.screen_name + ": \"" + tweet.quoted_status.text + "\")"
        content += " : " + tweet.text
        dbgp(("final_urls:", urls))
        # TODO: relation
        acts.append(Pin(profile_name, profile_url, created_at, content, urls, media_urls))
    if debug:
        with open(twitter_id + ".json", "w") as json_file:
            json_dict = {}
            json_dict["profile_img"] = profile_img
            json_dict["profile_bg_img"] = profile_bg_img
            json_dict["profile_stats"] = profile_stats
            json_dict["profile_bio"] = profile_bio
            json_dict["profile_location"] = profile_location
            json_dict["acts"] = [json.dumps(dataclasses.asdict(act)) for act in acts]
            json_dict["tweets"] = tweets
            json.dump(json_dict, json_file, indent=4)
    dtos[twitter_id] = (profile_elem, acts)
    dbgpi("Finished getting tweets for {}".format(twitter_id))
    return dtos
Exemple #21
0
                dbgp("{} does not exist!!!".format(twitter_id_json))
            else:
                with open(twitter_id_json, "r") as json_file:
                    json_dict = json.load(json_file)
                    # TODO: idiomatic way of deserialize json
                    # TODO : better way to write out debugs
                    acts = []
                    for act_str in json_dict["acts"]:
                        act = json.loads(act_str)
                        profile_name = act["profile_name"]
                        profile_url = act["profile_url"]
                        created_at = act["created_at"]
                        content = act["content"]
                        urls = act["urls"]
                        media_urls = act["media_urls"]
                        acts.append(Pin(profile_name, profile_url, created_at, content, urls, media_urls))
                    profile_elem = (json_dict["profile_img"], json_dict["profile_bg_img"], json_dict["profile_stats"], json_dict["profile_bio"], json_dict["profile_location"])
                    dtos[twitter_id] = (profile_elem, acts)
            continue

        if not use_api:
            dbgp("not user api")
            dtos = get_tweets(twitter_id, dtos)
        else:
            dbgp("use api")
            dtos = get_tweets_api(twitter_id, dtos, api)
        dbgp(dtos[twitter_id])


    if ui:
        app = QApplication([])
Exemple #22
0
# Fonts
small_font = pygame.font.SysFont("quicksand", 20)
large_font = pygame.font.SysFont("quicksand", 64)

# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)

### RPi.GPIO ###
# Define board layout
gpio.setmode(gpio.BCM)

# Define pins
# Pin(number, name, pullup/down)
pins = [Pin(1, "Grip", False), Pin(2, "Pull", False), Pin(4, "Flip", True)]


# Write data to specified file
def write_to_file(data):
    with open("/home/pi/Child_Strength/data.txt", "a") as f:
        f.write(data)


# Control loop
flip = False
while running:

    ### Logic ###
    # Default values
    active_sensor = ""
Exemple #23
0
 def test_thread_running(self):
     p24 = Pin(24)
     p24.output(.5)
     self.assertTrue(p24._thread.is_alive())
Exemple #24
0
 def test_output_zero(self):
     p24 = Pin(24)
     p24.output(0)
     self.assertEqual(p24.value, 0.0)
     self.assertTrue(p24._stopped)
Exemple #25
0
 def test_intitialization(self):
     p24 = Pin(24)
     self.assertEqual(p24.pin_number, 24)
     self.assertEqual(p24.period, 10e-3)
     self.assertEqual(p24.value, 0.0)
     self.assertTrue(p24._stopped)
Exemple #26
0
 def test_output_one(self):
     p24 = Pin(24)
     p24.output(1)
     self.assertEqual(p24.value, 1.0)
     self.assertTrue(p24._stopped)
Exemple #27
0
        if left > 580:
            left = 300
            top += 60


#----------------------------------------------------------------------------# Main

initialise_gpio()
initialise_window()

screen = pygame.display.set_mode(window_size)
button_font = pygame.font.Font(None, 36)

pins7 = [
    Pin(a_pin_num, False, True),
    Pin(b_pin_num, False, True),
    Pin(c_pin_num, False, True),
    Pin(d_pin_num, False, True),
    Pin(e_pin_num, False, True),
    Pin(f_pin_num, False, True),
    Pin(g_pin_num, False, True)
]

buttons = [
    PinButton(20, 20, 'Red', button_font, red, off, 120, 75, 31, 22,
              Pin(red_pin)),
    PinButton(160, 20, 'Amber', button_font, amber, off, 120, 75, 22, 22,
              Pin(amber_pin)),
    PinButton(300, 20, 'Green', button_font, green, off, 120, 75, 22, 22,
              Pin(green_pin)),
Exemple #28
0
 def __init__(self, enable, pin1, pin2):
     self._enable = Pin(enable, GPIO.OUT)
     self._pin1 = Pin(pin1, GPIO.OUT)
     self._pin2 = Pin(pin2, GPIO.OUT)