/*------------------------------------------------------------------------------
 * keypad thread - this function continiously outputs to LEDs and reads buttons
 *------------------------------------------------------------------------------
 */
void * keypad(){
  int col;
  int timeout = DELAY;
  char str[6];
  
  while(alive){
    if(display_flag == CHANGED){
      timeout = 1; //Trigger an update
    }
    if(--timeout == 0){
      update_display();
      timeout = DELAY;
    }
    for(col=0;col<COLSX;col++){
      write_to_port(C, 0);        // LEDS off
      write_to_port(A, (BYTE) (01 << col));     // select column
      write_to_port(C, digits[col]);  // next LED pattern  

      write(fd_RS232,"@00P1?\r",7);             // Read the column
      usleep(SLEEP);
      read(fd_RS232,str,6);
      
      read_button(col,str[4]);
    }
  }
  return 0;
}
Exemple #2
0
/**
 *  @brief Keypad thread.
 *
 *    Continuously outputs to the 7-Segment displays
 *    and reads buttons from the keypad.
 *
 *    Because of the way the 7-Segment HW are wired to the keypad,
 *    each column scan is used to update the LEDs for one 7-Segment at a time.
 *    The only LEDs that are lit at any one time is the one selected by port A.
 *
 *    If the current LEDs are turned off, refreshed with a new value,
 *    and then the next column is selected, there's a ghosting effect.
 *    To resolve this, the command to turn off the LED is given
 *    BEFORE the column is changed.
 *
 *  @param Void.
 *  @return Void.
 */
void * keypad(void){
  int col;
  int timeout = scroll_delay;
  char str[6];
  
  while(alive){
    pthread_mutex_lock(&display_Mutex);
    if(display_flag == CHANGED){
      timeout = 1; //Trigger an update
    }

    if(--timeout == 0){
      update_display(); ///< display.c
      timeout = scroll_delay;
    }
    pthread_mutex_unlock(&display_Mutex);

    for(col=0;col<COLS;col++){
      write_to_port(C, 0);                  // LEDS off
      write_to_port(A, (BYTE) (01 << col)); // select column
      write_to_port(C, digits[col]);        // next LED pattern

      write(fd_RS232,"@00P1?\r",7);         // Read the column
      usleep(SLEEP);
      read(fd_RS232,str,6);
      
      pthread_mutex_lock(&button_Mutex);
      read_button(col,str[4]);
      pthread_mutex_unlock(&button_Mutex);
    }
  }
    pthread_exit(0);
}
Exemple #3
0
void irq_handler(registers_t regs) {
	if (regs.int_no >= 40) {
		write_to_port(0xA0, 0x20);
	}
	write_to_port(0x20, 0x20);

	if (interrupt_handlers[regs.int_no] != 0 &&
		interrupt_handlers[regs.int_no] != NULL) {
		interrupt_handlers[regs.int_no](regs);
	} else {
		print_interrupt_name(regs.int_no);
	}
}
/*------------------------------------------------------------------------------
 * keypad thread - this function continiously outputs to LEDs and reads buttons
 *------------------------------------------------------------------------------
 */
void * keypad(){
  int i;
  int col;
  int out;
  char temp;
  char str[6];
  BYTE keypresses = 0;


  while(alive){
    for (col=0;col<COLSX;col++){
      write_to_port(C, 0);        // LEDS off
      write_to_port(A, (BYTE) (01 << col));     // select column
      write_to_port(C, digits[col]);  // next LED pattern  

      write(fd_RS232,"@00P1?\r",7);             // Read the column
      usleep(SLEEP);
      read(fd_RS232,str,6);

      out = 0;
      if(str[4] > 0x40) {   // Convert output from ASCII to binary
        out |= (0x0F & (str[4]-0x07)); // A-F
      }
      else{
        out |= (0x0F & (str[4]));      // 0-9
      }

      for(i=0; i<ROWSX; i++){     // Scan the rows for key presses
        if((out >> i) & 0x01){
          keypresses++;
          temp = uitab[((col+1)+(i*4))];// Set the detected button
        }
      }

      if(col == COLSX-1){       // After reading all the columns
        switch(keypresses){
          case 0:
            button=FALSE; // No key press detected
            break;
          case 1:
            button=temp; // Write ASCII value from uitab
            break;
          default:
            button=ERROR;       // Multiple keys pressed
            break;
        }
        keypresses = 0;
      }
    }
  }
}
/**
 *  @brief Exit Subroutine.
 *
 *    This function is called when the program is signalled to close.
 *    It performs tidy-up operations, such as killing threads and
 *    clearing the last value on the 7 Segment display.
 *
 *  @param Void.
 *  @return Void.
 */
void closing_time(void){
  alive = FALSE;
  extern int sockfd; //close the recv functions file descriptor

  pthread_mutex_lock(&state_Mutex);
  button_thread_state = STATE_KILL;
  pthread_cond_broadcast(&state_Signal);
  pthread_mutex_unlock(&state_Mutex);

  pthread_mutex_lock(&button_Mutex);
  pthread_cond_broadcast(&button_Signal);
  pthread_mutex_unlock(&button_Mutex);
  
  close(sockfd);
  pthread_mutex_lock(&network_Mutex);
  pthread_cond_broadcast(&network_Signal);
  pthread_mutex_unlock(&network_Mutex);

  pthread_join(keypad_thread, NULL);
  pthread_join(state_machine_thread, NULL);
  printf("Signalled threads to close\n");

  //pthread_join(network_thread, NULL);
  //pthread_join(receive_thread, NULL);
  

  write_to_port(C, 0);      /* Last LED off */
  close_term();


  pthread_mutex_destroy(&button_Mutex);
  pthread_mutex_destroy(&state_Mutex);
  pthread_mutex_destroy(&display_Mutex);

  pthread_mutex_destroy(&network_Mutex);
  pthread_mutex_destroy(&request_Mutex);
  
  pthread_cond_destroy(&button_Signal);
  pthread_cond_destroy(&state_Signal);
  pthread_cond_destroy(&display_Signal);

  pthread_cond_destroy(&network_Signal);
  pthread_cond_destroy(&request_Signal);
  printf("Closing\n");
  exit(0);
}
/*------------------------------------------------------------------------------
 * exit subroutine
 *------------------------------------------------------------------------------
 */
void closing_time() {
  alive = FALSE;
  pthread_join(keypad_thread, NULL);
  write_to_port(C, 0);      // Last LED off
}
Exemple #7
0
bool write_message(int fd, const char* data) {
    
    return write_to_port(fd, data);
}
Exemple #8
0
bool write_to_port(int fd, const char* data) {
    return write_to_port(fd, data, int(strlen(data)));
}
Exemple #9
0
bool close_message(int fd) {
    return write_to_port(fd, code_EOT);
    
}
Exemple #10
0
bool buildNhlHeader(int fd, const char* file, const char* mode, const char* color, const char* font)
{
    bool status = true;
    status = status && write_to_port(fd, code_NUL, 1);
    status = status && write_to_port(fd, code_NUL, 1);
    status = status && write_to_port(fd, code_NUL, 1);
    status = status && write_to_port(fd, code_NUL, 1);
    status = status && write_to_port(fd, code_NUL, 1);
    status = status && write_to_port(fd, code_SOH);
    
    status = status && write_to_port(fd, ALL_SIGNS_TYPE);
    status = status && write_to_port(fd, "00");
    status = status && write_to_port(fd, code_STX);
    status = status && write_to_port(fd, WRITE_TXT_FILE);
    status = status && write_to_port(fd, file);
    
    status = status && write_to_port(fd, code_ESC);
    status = status && write_to_port(fd, " ");
    status = status && write_to_port(fd, mode);  
    
    set_color(fd, color);
    set_font(fd, font);

    return status;
}